一旦发出“call”,我就会使用下面的代码创建本地视频流。我的iPhone 6的本地媒体流未生成,但远程媒体流在我的手机上运行正常。有谁知道为什么我无法获得iPhone的本地媒体流?
我正在使用带有node.js的Kurento Media Server。
- (RTCMediaStream *)createLocalMediaStream {
RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
self.peerConnection = [self.peerConnectionFactory peerConnectionWithICEServers:server
constraints:constraints
delegate:self];
RTCMediaStream *localStream = [self createLocalMediaStream];
[self.peerConnection addStream:localStream];
[_peerConnection createOfferWithDelegate:self constraints:[self defaultOfferConstraints]];
RTCMediaStream* localStream = [self.peerConnectionFactory mediaStreamWithLabel:@"ARDAMS"];
RTCVideoTrack* localVideoTrack = nil;
#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE
NSString *cameraID = nil;
for (AVCaptureDevice *captureDevice in
[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if (captureDevice.position == AVCaptureDevicePositionFront) {
cameraID = [captureDevice localizedName];
break;
}
}
NSAssert(cameraID, @"Unable to get the front camera id");
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
RTCMediaConstraints* constraints = [self defaultMediaStreamConstraints];
RTCVideoSource *videoSource = [self.peerConnectionFactory videoSourceWithCapturer:capturer constraints:constraints];
localVideoTrack =
[self.peerConnectionFactory videoTrackWithID:@"ARDAMSv0" source:videoSource];
if (localVideoTrack) {
[localStream addVideoTrack:localVideoTrack];
}
[self.delegate connectionManager:self didReceiveLocalVideoTrack:localVideoTrack];
#endif
[localStream addAudioTrack:[self.peerConnectionFactory audioTrackWithID:@"ARDAMSa0"]];
return localStream;
}
- (RTCMediaConstraints *)defaultPeerConnectionConstraints {
NSArray *optionalConstraints = @[
[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]
];
RTCMediaConstraints* constraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:optionalConstraints];
return constraints;
}
- (RTCMediaConstraints *)defaultOfferConstraints {
NSArray *mandatoryConstraints = @[
[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"],
[[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]
];
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
return constraints;
}
- (RTCMediaConstraints *)defaultMediaStreamConstraints {
NSArray *mandatoryConstraints = @[
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"minWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"maxFrameRate" value:@"30"],
[[RTCPair alloc] initWithKey:@"minFrameRate" value:@"5"],
[[RTCPair alloc] initWithKey:@"googLeakyBucket" value:@"true"]
];
RTCMediaConstraints *constrains = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
return constrains;
}