gpt4 book ai didi

ios - 'RTCPeerConnection' 没有可见的@interface 声明选择器 'setLocalDescription:'

转载 作者:行者123 更新时间:2023-11-29 00:30:18 26 4
gpt4 key购买 nike

我对需要做什么才能将 webRTC 包含到我的应用程序中感到有点困惑。我跟着这个tutorial首先在 webRTC 网站上将 webRTC 添加到我的 IOS 应用程序中。一切都很顺利,直到最后我遇到了这些错误。不幸的是,我在网上找不到任何有关这些错误或如何在 IOS 上包含 webRTC 的信息。

最终目标是拥有跨平台的视频通话服务。

.h

#import "RTCPeerConnectionDelegate.h"
#import "RTCSessionDescriptionDelegate.h"
...

<RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate>

.m

    #import "RTCICEServer.h"
#import "RTCPeerConnectionFactory.h"
#import "RTCMediaStream.h"
#import "RTCVideoCapturer.h"
#import "RTCPeerConnection.h"
#import "RTCAudioSource.h"
#import "RTCAudioTrack.h"
#import "RTCMediaConstraints.h"
#import "RTCSessionDescription.h"
#import "RTCPair.h"
#import "RTCEAGLVideoView.h"
#import "RTCICECandidate.h"



//The code below is for the webRTC

RTCICEServer *iceServer;
RTCMediaConstraints *constraints;
RTCPeerConnection *peerConnectionRTC;

- (void) setUpVideoCall{
//Set up for my TURN and STUN servers
iceServer = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@""]
username:@""
password:@""];


NSMutableArray *iceServers = [[NSMutableArray alloc] init];
[iceServers addObject: iceServer];



//Creating the RTCPeerConnection
// Enable SSL globally for WebRTC in our app
[RTCPeerConnectionFactory initializeSSL];
RTCPeerConnectionFactory *pcFactory = [[RTCPeerConnectionFactory alloc] init];


// Create the peer connection using the ICE server list and the current class as the delegate
peerConnectionRTC = [pcFactory peerConnectionWithICEServers: iceServers
constraints:nil delegate:self];



//Use this code when the call is ended or the app closes
//[RTCPeerConnectionFactory deinitializeSSL];


RTCMediaStream *localStream = [pcFactory mediaStreamWithLabel:@"uniqueStreamLabel"];
RTCAudioTrack *audioTrack = [pcFactory audioTrackWithID:@"audio0"];
[localStream addAudioTrack:audioTrack];





// Find the device that is the front facing camera
AVCaptureDevice *device;
for (AVCaptureDevice *captureDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] ) {
if (captureDevice.position == AVCaptureDevicePositionFront) {
device = captureDevice;
break;
}
}

// Create a video track and add it to the media stream
if (device) {
RTCVideoSource *videoSource;
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:device.localizedName];
videoSource = [pcFactory videoSourceWithCapturer:capturer constraints:nil];
RTCVideoTrack *videoTrack = [pcFactory videoTrackWithID: @"videoId" source:videoSource];
[localStream addVideoTrack:videoTrack];
}

[peerConnectionRTC addStream:localStream];





constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:
@[
[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"],
[[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]
]
optionalConstraints: nil];

//[peerConnectionRTC createOfferWithConstraints:constraints];






}































//The two delaget methods below are for the RTCSessionDescriptionDelegate
- (void)peerConnection:(RTCPeerConnection *)peerConnection didCreateSessionDescription:(RTCSessionDescription *)sdp error:(NSError *)error;{

[peerConnection setLocalDescription:sdp];

}


- (void)peerConnection:(RTCPeerConnection *)peerConnection
didSetSessionDescriptionWithError:(NSError *)error;{
if (peerConnection.signalingState == RTCSignalingHaveLocalOffer) {
RTCSessionDescription *remoteDesc = [[RTCSessionDescription alloc] initWithType:@"offer" sdp: @"sdp"];
[peerConnection setRemoteDescription:remoteDesc];
}


// If we have a local offer we should signal it
if (peerConnection.signalingState == RTCSignalingHaveLocalOffer) {

RTCSessionDescription *remoteDesc = [[RTCSessionDescription alloc] initWithType:@"answer" sdp:sdp];
[peerConnection setRemoteDescription:remoteDesc];

} else if (peerConnection.signalingState == RTCSignalingHaveRemoteOffer) {
// If we have a remote offer we should add it to the peer connection
[peerConnection createAnswerWithConstraints:constraints];
}


// If we have a local offer OR answer we should signal it
if ((peerConnection.signalingState == RTCSignalingHaveLocalOffer) | RTCSignalingHaveLocalPrAnswer ) {
// Send offer/answer through the signaling channel of our application
} else if (peerConnection.signalingState == RTCSignalingHaveRemoteOffer) {
// If we have a remote offer we should add it to the peer connection
[peerConnection createAnswerWithConstraints:constraints];
}
}



- (void)peerConnection:(RTCPeerConnection *)peerConnection
gotICECandidate:(RTCICECandidate *)candidate
{
RTCICECandidate *candidate = [[RTCICECandidate alloc] initWithMid:SDP_MID
index:SDP_M_LINE_INDEX
sdp:SDP_CANDIDATE];
[self.rtcPeerConnection addICECandidate:candidate];
}



RTCEAGLVideoView *renderView;
- (void)peerConnection:(RTCPeerConnection *)peerConnection addedStream:(RTCMediaStream *)stream
{
// Create a new render view with a size of your choice
renderView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[stream.videoTracks.lastObject addRenderer:self.renderView];

// RTCEAGLVideoView is a subclass of UIView, so renderView
// can be inserted into your view hierarchy where it suits your application.
}







//More RTC delagate methods below that i need

- (void)peerConnection:(RTCPeerConnection *)peerConnection iceConnectionChanged:(RTCICEConnectionState)newState{

}

- (void)peerConnection:(RTCPeerConnection *)peerConnection iceGatheringChanged:(RTCICEGatheringState)newState{

}

- (void)peerConnection:(RTCPeerConnection *)peerConnection removedStream:(RTCMediaStream *)stream{

}

- (void)peerConnection:(RTCPeerConnection *)peerConnection signalingStateChanged:(RTCSignalingState)stateChanged{

}

- (void)peerConnection:(RTCPeerConnection *)peerConnection didOpenDataChannel:(RTCDataChannel *)dataChannel{

}

- (void)peerConnectionOnRenegotiationNeeded:(RTCPeerConnection *)peerConnection{

}

感谢任何帮助,文档或教程等信息非常有帮助!谢谢!

enter image description here

最佳答案

您遇到编译错误是因为最新的 libjingle 版本,对等连接 api 发生了变化。例如设置远程描述更改为以下 api

    [peerconnection setRemoteDescriptionWithDelegate:<#(id<RTCSessionDescriptionDelegate>)#> sessionDescription:<#(RTCSessionDescription *)#>]

你可以查看apprtc demo谷歌提供的应用程序,用于在您的应用程序中集成 webrtc api。

关于ios - 'RTCPeerConnection' 没有可见的@interface 声明选择器 'setLocalDescription:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42048182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com