Reputation: 497
I am trying to implement WebRTC in an iOS application using GoogleWebRTC pod. i can place a video call between iOS app and a web client, in which case the audio/video works just fine. however when i place a video call between two iOS devices there is no video(audio works). i've checked if there is remote stream and there is.
let localStream = connectionFactory?.mediaStream(withStreamId: "StreamID")
let audioTrack = connectionFactory?.audioTrack(withTrackId: "AudioTrackID")
let videoSource = connectionFactory?.avFoundationVideoSource(with: mediaConstraint)
let videoTrack = connectionFactory?.videoTrack(with: videoSource!, trackId: "VideoTrackID")
localStream?.addAudioTrack(audioTrack!)
localStream?.addVideoTrack(videoTrack!)
peerConnection?.add(localStream!)
Upvotes: 5
Views: 5511
Reputation: 257
As my understanding, you can add a remote video track when first create your local video track, then video track will auto produce frames when it is receiving from peer connection, an example code from WebRTC iOS client:
- (void)createMediaSenders {
RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints];
RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints];
if (_isAudioEnabled) {
RTCAudioTrack *track = [_factory audioTrackWithSource:source trackId:kDSAudioTrackId];
[_peerConnection addTrack:track streamIds:@[ kDSMediaStreamId ]];
}
if (_isVideoEnabled) {
_localVideoTrack = [self createLocalVideoTrack];
if (_localVideoTrack) {
[_peerConnection addTrack:_localVideoTrack streamIds:@[ kDSMediaStreamId ]];
// Create remote video track
RTCVideoTrack *track = (RTCVideoTrack *)([self videoTransceiver].receiver.track);
[_delegate appRTC:self didReceiveRemoteVideoTrack:track];
}
}
}
Upvotes: 1
Reputation: 324
in func rtcClient(client : RTCClient, didReceiveRemoteVideoTrack remoteVideoTrack: RTCVideoTrack) perform a selector that will call after 2 sec then in that selector add track to remoteview
Upvotes: 0
Reputation: 497
Found the problem. I was giving a hard coded string as id when creating stream and video track. which when a connection is established becomes the same for both local and remote streams. providing unique strings as ids solves the problem.
Upvotes: 0