PeerObjC is PeerJS port to iOS. It allows you to setup your client easily and communicate to peerjs-server.
This library inspires from AppRTCDemo (that Google has been published) for peerjs-server signaling process and PeerJS and PeerObjectiveC.
-
Install via cocoapods
$ pod 'PeerObjC'
-
Get PeerJS API Key or setup your own server Go to PeerJS Server and create an API key.
-
Initialize
OGPeerOptions
and set server details as needed:Custom server
OGPeerOptions * options = [[OGPeerOptions alloc] init]; options.key = @"peerjs"; options.host = @"192.198.0.3"; options.port = @(9000); options.path = @""; options.secure = NO; options.config = [OGPeerConfig defaultConfig]; options.debugLevel = DDLogLevelDebug;
PeerJS Cloud
OGPeerOptions * options = [[OGPeerOptions alloc] init]; options.key = @"<your api key>"; options.config = [OGPeerConfig defaultConfig]; options.debugLevel = DDLogLevelDebug;
-
Initialize
OGPeer
with options to create connectionOGPeer * peer = [[OGPeer alloc] initWithId:@"<your peer id>" options:options]; [peer addDelegate:self]; //Important for receiving updates from peer
-
Connect to a peer for data/messages exchange
OGDataConnectionOptions * options = [[OGDataConnectionOptions alloc] init]; options.label = @"MyLabel"; options.serialization = OGSerializationBinary; OGDataConnection * conn = [_peer connect:@"<other peer id>" options:options];
-
Call a peer with Audio/Video call
OGMediaConnectionOptions* moptions = [[OGMediaConnectionOptions alloc] init]; moptions.type = OGStreamTypeBoth; moptions.direction = AVCaptureDevicePositionFront; OGMediaConnection * mconnection = [_peer call:@"<other peer id>" options:moptions];
-
To receive data and media connections. Implement
OGMediaConnectionDelegate
andOGDataConnectionDelegate
and remember to add the delegate class viaaddDelegate:
method
MIT