mediasoup-ios-client
为构建基于 mediasoup 的 iOS 应用程序而提供的 libmediasoupclient 的 Objective-C 封装库。
此项目支持 64 位 iOS 设备和 64 位 iOS 模拟器
网站和文档
支持论坛
开始使用
Cocoapods
将以下内容添加到您的 Podfile 中
use_frameworks!
target "target" do
pod "mediasoup_ios_client"
end
您需要设置 enable bitcode 为 false
由于带有位码的WebRTC.framework的大小,它不能上传到GitHub。
Swift用户需要实现Objective-C桥接头
桥接头示例
文档
API
https://github.com/ethand91/mediasoup-ios-client/blob/master/documentation/Api.md
安装(只适用于开发,如果你只想使用项目则不需要)
https://github.com/ethand91/mediasoup-ios-client/blob/master/documentation/Installation.md
使用示例
#import "mediasoup_client_ios/Mediasoupclient.h
// Initialize the underlaying libmediasoupclient
[Mediasoupclient initializePC];
// Create a Device
MediasoupDevice *device = [[MediasoupDevice alloc] init];
// Communicate with our server app to retrieve router RTP capabilities
NSString *routerRtpCapabilities = [mySignalling request:@"getRouterRtpCapabilities"];
// Load the device with the routerRtpCapabilities
[device load:routerRtpCapabilities];
// Check whether we can produce video to the router
if ![device canProduce:@"video"] {
NSLog(@"cannot produce video");
// Abort next steps
}
// Create a transport in the server for sending our media through it
NSDictionary *transportData = [mySignalling request:@"createTransport"];
// Object to handle SendTransportListener events
@interface SendTransportHandler: NSObject<SendTransportListener>
@property (nonatomic) id delegate;
@end
@implementation SendTransportHandler
-(void)onConnect:(Transport *)transport dtlsParameters:(NSString *)dtlsParameters {
// Here we communicate out local parameters to our remote transport
[mySignalling request:@"transport-connect" transportId:[transport getId] dtlsParameters:dtlsParameters];
}
-(void)onConnectionStateChange:(Transport *)transport connectionState:(NSString *)connectionState {
NSLog(@"sendTransport::onConnectionStateChange newState = %@", connectionState);
}
-(NSString *)onProduce:(Transport *)transport kind:(NSString *)kind rtpParameters:(NSString *)rtpParameters appData:(NSString *)appData callback:(void(^)(NSString *))callback {
// Here we must communicate our local parameters to our remote transport
NSString *id = [mySignalling request:@"produce" transportId:[transport getId] kind:kind rtpParameters:rtpParameters appData:appData];
callback(id);
}
@end
SendTransport *sendTransport = [device createSendTransport:sendTransportHandler.delegate id:transportData["id"] iceParameters:transportData["iceParameters"] iceCandidates:transportData["iceCandidates"] dtlsParameters:transportData["dtlsParameters"]];
// Get the device camera
NSArray *devices = [AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo];
// Start capturing it
RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init];
RTCCameraVideoCapturer *videoCapturer = [[RTCCameraVideoCapturer alloc] init];
[videoCapturer startCaptureWithDevice:devices[0] format:[devices[0] activeFormat] fps:30];
RTCVideoSource *videoSource = [factory videoSource];
[videoSource adaptOutputFormatToWidth:640 height:480 fps:30];
RTCVideoTrack *videoTrack = [factory videoTrackWithSource:videoSource trackId:@"trackId"];
// Handler to handle producer events
@interface ProducerHandler : NSObject<ProducerListener>
@property (nonatomic) id delegate;
@end
@implementation ProducerHandler
-(void)onTransportClose:(Producer *)producer {
NSLog(@"Producer::onTransportClose");
}
@end
// Produce out camera video
Producer *videoProducer = [sendTransport produce:producerHandler.delegate track:videoTrack encodings:nil codecOptions:nil];
贡献
克隆仓库并安装子模块
由于WebRTC静态库的大小,它不能上传到GitHub,因此您需要按照构建文件夹中的说明自行构建。(此步骤仅适用于开发,不适用于库使用)
git clone https://github.com/ethand91/mediasoup-ios-client.git
git submodule init
git submodule update