iOS SDK API Reference

Instance Methods | Class Methods | Properties | List of all members
SKWPeer Class Reference

A peer class. More...

#import <SKWPeer.h>

Inheritance diagram for SKWPeer:

Instance Methods

(instancetype __nullable) - initWithOptions:
 A peer can connect to other peers and listen for connections. More...
 
(instancetype __nullable) - initWithId:options:
 A peer can connect to other peers and listen for connections. More...
 
(SKWDataConnection *__nullable) - connectWithId:
 Connects to the remote peer specified by id and returns a data connection. More...
 
(SKWDataConnection *__nullable) - connectWithId:options:
 Connects to the remote peer specified by id and returns a data connection. More...
 
(SKWMediaConnection *__nullable) - callWithId:stream:
 Calls the remote peer specified by id and returns a media connection. More...
 
(SKWMediaConnection *__nullable) - callWithId:stream:options:
 Calls the remote peer specified by id and returns a media connection. More...
 
(void) - on:callback:
 Set blocks for peer events. More...
 
(BOOL) - disconnect
 Close the connection to the server, leaving all existing data and media connections intact. More...
 
(void) - reconnect
 Attempt to reconnect to the server with the peer's old ID. More...
 
(BOOL) - destroy
 Close the connection to the server and terminate all existing connections. More...
 
(void) - listAllPeers:
 Listing peer ID. More...
 
(SKWRoom *__nullable) - joinRoomWithName:options:
 Full mesh room example: More...
 
(void) - updateCredential:
 

Class Methods

(nonnull NSString *) + sdkVersion
 Getting current SDK version.
 

Properties

NSString *__nullable identity
 The brokering ID of this peer. More...
 
NSDictionary *__nullable connections
 A object array of all connections this peer, keyed by the remote peer's ID.
 
BOOL isDisconnected
 false if there is an active connection to the PeerServer.
 
BOOL isDestroyed
 true if this peer and all of its connections can no longer be used.
 

Detailed Description

A peer class.

Method Documentation

◆ callWithId:stream:()

- (SKWMediaConnection* __nullable) callWithId: (NSString *__nonnull)  peerId
stream: (SKWMediaStream *__nullable)  stream 

Calls the remote peer specified by id and returns a media connection.

Be sure to listen on the error event in case the connection fails.

SKWPeer* peer;
NSString* destId;
SKWMediaConnection* media = [peer callWithId:destId stream:stream];
Parameters
peerIdRemote peer ID
streamVideo stream
Returns
Media connection object

◆ callWithId:stream:options:()

- (SKWMediaConnection* __nullable) callWithId: (NSString *__nonnull)  peerId
stream: (SKWMediaStream *__nullable)  stream
options: (SKWCallOption *__nullable)  options 

Calls the remote peer specified by id and returns a media connection.

Be sure to listen on the error event in case the connection fails.

SKWPeer* peer;
NSString* destId;
SKWCallOption* options = [[SKWCallOption alloc] init];
options.metadata = @"yourMetadata";
SKWMediaConnection* media = [peer callWithId:destId stream:stream options:options];
Parameters
peerIdRemote peer ID
streamVideo stream
optionsOption seeting dictionary
Returns
Media connection object

◆ connectWithId:()

- (SKWDataConnection* __nullable) connectWithId: (NSString *__nonnull)  peerId

Connects to the remote peer specified by id and returns a data connection.

Be sure to listen on the error event in case the connection fails.

SKWPeer* peer;
SKWDataConnection* data = [peer connectWithId:destId];
Parameters
peerIdThe brokering ID of the remote peer (their peer.id).
Returns

Data connection object

◆ connectWithId:options:()

- (SKWDataConnection* __nullable) connectWithId: (NSString *__nonnull)  peerId
options: (SKWConnectOption *__nullable)  options 

Connects to the remote peer specified by id and returns a data connection.

Be sure to listen on the error event in case the connection fails.

SKWPeer* peer;
SKWConnectOption* options = [[SKWConnectOption alloc] init];
options.label = @"chat";
options.metadata = @"hi !!!";
SKWDataConnection* data = [peer connectWithId:destId options:options];
Parameters
peerIdThe brokering ID of the remote peer (their peer.id).
optionsOption setting dictionary
Returns

Data connection object

◆ destroy()

- (BOOL) destroy

Close the connection to the server and terminate all existing connections.

peer.destroyed will be set to true.

SKWPeer* peer;
[peer destroy];
Returns
Processing result

◆ disconnect()

- (BOOL) disconnect

Close the connection to the server, leaving all existing data and media connections intact.

peer.disconnected will be set to true and the disconnected event will fire.

SKWPeer* peer;
[peer disconnect];
Returns
Processing result

◆ initWithId:options:()

- (instancetype __nullable) initWithId: (NSString *__nullable)  peerId
options: (SKWPeerOption *__nullable)  options 

A peer can connect to other peers and listen for connections.

NSString* curtomPeerId = @"my-peer-id";
SKWPeerOption* options = [[SKWPeerOption alloc] init];
options.key = @"{your-dev-key}";
options.domain = @”{your-domain}”;
options.debug = SKW_PEER_DEBUG_LEVEL_ALL_LOGS;
options.turn = YES;
SKWPeer* peer = [[SKWPeer alloc] initWithId:curtomPeerId options:options];
Parameters
peerIdOther peers can connect to this peer using the provided ID. If no ID is given, one will be generated by the brokering server.
optionsOption seetings.
Returns
PeerObjC object

◆ initWithOptions:()

- (instancetype __nullable) initWithOptions: (SKWPeerOption *__nullable)  options

A peer can connect to other peers and listen for connections.

ID is retrieve from brokering server.

SKWPeerOption* options = [[SKWPeerOption alloc] init];
options.key = @"{your-dev-key}";
options.domain = @”{your-domain}”;
options.debug = SKW_PEER_DEBUG_LEVEL_ALL_LOGS;
options.turn = YES;
SKWPeer* peer = [[SKWPeer alloc] initWithOptions:options];
Parameters
optionsOption seetings.
Returns
PeerObjC object

◆ joinRoomWithName:options:()

- (SKWRoom* __nullable) joinRoomWithName: (NSString *__nonnull)  roomName
options: (SKWRoomOption *__nonnull)  option 

Full mesh room example:

SKWPeer* peer;
SKWMediaStream* localStream;
NSString* roomName = @"fullmesh_videochat_room";
SKWRoomOption* options = [[SKWRoomOptions alloc] init];
option.mode = SKW_ROOM_MODE_MESH;
option.stream = localStream;
SKWMeshRoom* meshRoom = (SKWMeshRoom*)[peer joinRoomWithName:roomName options:options];

SFU room example:

SKWPeer* peer;
NSString* roomName = @"sfu_textchat_room";
SKWRoomOption* options = [[SKWRoomOptions alloc] init];
SKWSFURoom* sfuRoom = (SKWSFURoom*)[peer joinRoomWithName:roomName options:options];
Parameters
roomNameRoom name
optionRoom option
Returns
Room object

◆ listAllPeers:()

- (void) listAllPeers: (void(^)(NSArray *__nullable))  callback

Listing peer ID.

SKWPeer* peer;
[peer listAllPeers:^(NSArray* aryPeers) {
for (NSString* strPeer in aryPeers) {
// something to do.
}
}];
Parameters
callbackCallback block

◆ on:callback:()

- (void) on: (SKWPeerEventEnum event
callback: (SKWPeerEventCallback __nullable)  callback 

Set blocks for peer events.

(Block Literal Syntax)

SKWPeer* peer;
[peer on:SKW_PEER_EVENT_OPEN callback:^(NSObject* obj) {
if (YES == [obj isKindOfClass:[NSString class]]) {
NSString* ownId = (NSString *)obj;
}
}];
[peer on:SKW_PEER_EVENT_CONNECTION callback:^(NSObject* obj) {
SKWDataConnection* data = (SKWDataConnection *)obj;
}];
[peer on:SKW_PEER_EVENT_CALL callback:^(NSObject* obj) {
SKWMediaConnection* media = (SKWMediaConnection *)obj;
}];
[peer on:SKW_PEER_EVENT_CLOSE callback:^(NSObject* obj) {
// ...
}];
[peer on:SKW_PEER_EVENT_DISCONNECTED callback:^(NSObject* obj) {
// ...
}];
[peer on:SKW_PEER_EVENT_ERROR callback:^(NSObject* obj) {
SKWPeerError* err = (SKWPeerError *)obj;
NSLog(@"%@", err);
}];
Parameters
eventEvent type
callbackCallback block literal

◆ reconnect()

- (void) reconnect

Attempt to reconnect to the server with the peer's old ID.

SKWPeer* peer;
[peer reconnect];

◆ updateCredential:()

- (void) updateCredential: (SKWPeerCredential *__nonnull)  newCredential
SKWPeer* peer;
SKWPeerCredential* credential = [[SKWPeerCredential alloc] init];
credential.timestamp = [[NSDate date] timeIntervalSince1970];
credential.ttl = 86400;
credential.authToken = @"calculated auth token";
[peer updateCredential:credential];
Parameters
newCredentialnew credential

Property Documentation

◆ identity

- (NSString* __nullable) identity
readnonatomicassign

The brokering ID of this peer.

If no ID was specified in the constructor, this will be undefined until the open event is emitted.