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.

SKWPeerCredential::ttl
NSUInteger ttl
Time to live; The credential expires at timestamp + ttl.
Definition: SKWPeerCredential.h:24
-[SKWPeer callWithId:stream:options:]
SKWMediaConnection *__nullable callWithId:stream:options:(NSString *__nonnull peerId,[stream] SKWMediaStream *__nullable stream,[options] SKWCallOption *__nullable options)
Calls the remote peer specified by id and returns a media connection.
SKWDataConnection
Alternative class as DataConnection.
Definition: SKWDataConnection.h:41
-[SKWPeer destroy]
BOOL destroy()
Close the connection to the server and terminate all existing connections.
-[SKWPeer on:callback:]
void on:callback:(SKWPeerEventEnum event,[callback] SKWPeerEventCallback __nullable callback)
Set blocks for peer events.
SKWPeerError
Error information class.
Definition: SKWPeerError.h:55
SKWPeerOption::key
NSString *__nullable key
API key for the cloud PeerServer.
Definition: SKWPeerOption.h:63
SKWPeer
A peer class.
Definition: SKWPeer.h:98
SKWMediaStream
Media stream.
Definition: SKWMediaStream.h:18
-[SKWPeer reconnect]
void reconnect()
Attempt to reconnect to the server with the peer's old ID.
SKWPeerCredential
The credential used to authenticate peer.
Definition: SKWPeerCredential.h:14
-[SKWPeer connectWithId:]
SKWDataConnection *__nullable connectWithId:(NSString *__nonnull peerId)
Connects to the remote peer specified by id and returns a data connection.
SKWMediaConnection
Alternative class as MediaConnection.
Definition: SKWMediaConnection.h:52
SKWPeerOption::domain
NSString *__nullable domain
Domain related to the SkyWay API Key.
Definition: SKWPeerOption.h:98
SKWPeerCredential::timestamp
NSUInteger timestamp
Current UNIX timestamp.
Definition: SKWPeerCredential.h:19
SKW_ROOM_MODE_MESH
@ SKW_ROOM_MODE_MESH
Fullmesh type room.
Definition: SKWRoomOption.h:21
SKWCallOption::metadata
NSString *__nullable metadata
Any type of metadata associated with the connection, passed in by whoever initiated the connection.
Definition: SKWCallOption.h:23
SKWPeerOption::debug
SKWDebugLevelEnum debug
Prints log messages depending on the debug level passed in.
Definition: SKWPeerOption.h:93
SKWConnectOption::label
NSString *__nullable label
Label to easily identify the connection on either peer.
Definition: SKWConnectOption.h:19
SKWPeerOption::turn
BOOL turn
Using SkyWay TURN server.
Definition: SKWPeerOption.h:103
-[SKWPeer disconnect]
BOOL disconnect()
Close the connection to the server, leaving all existing data and media connections intact.
-[SKWPeer connectWithId:options:]
SKWDataConnection *__nullable connectWithId:options:(NSString *__nonnull peerId,[options] SKWConnectOption *__nullable options)
Connects to the remote peer specified by id and returns a data connection.
SKWConnectOption
SKWPeer connect options.
Definition: SKWConnectOption.h:14
SKWPeerCredential::authToken
NSString * authToken
Credential token calculated with HMAC.
Definition: SKWPeerCredential.h:29
SKW_ROOM_MODE_SFU
@ SKW_ROOM_MODE_SFU
SFU type room.
Definition: SKWRoomOption.h:25
-[SKWPeer callWithId:stream:]
SKWMediaConnection *__nullable callWithId:stream:(NSString *__nonnull peerId,[stream] SKWMediaStream *__nullable stream)
Calls the remote peer specified by id and returns a media connection.
SKWConnectOption::metadata
NSString *__nullable metadata
Any type of metadata associated with the connection, passed in by whoever initiated the connection.
Definition: SKWConnectOption.h:27
SKWSFURoom
SFU room class.
Definition: SKWSFURoom.h:24
SKWCallOption
SKWPeer call options.
Definition: SKWCallOption.h:14
SKWPeerOption
SKWPeer initialize option class.
Definition: SKWPeerOption.h:53
-[SKWPeer listAllPeers:]
void listAllPeers:(void(^ __nullable callback)(NSArray *__nullable))
Listing peer ID.
SKWRoomOption::mode
SKWRoomModeEnum mode
Room Mode.
Definition: SKWRoomOption.h:36
-[SKWPeer updateCredential:]
void updateCredential:(SKWPeerCredential *__nonnull newCredential)
SKWMeshRoom
Mesh room class.
Definition: SKWMeshRoom.h:22
SKWRoomOption
Room Options.
Definition: SKWRoomOption.h:31
SKWConnectOption::serialization
SKWSerializationEnum serialization
The serialization format of the data sent over the connection.
Definition: SKWConnectOption.h:32
SKW_SERIALIZATION_NONE
@ SKW_SERIALIZATION_NONE
NONE.
Definition: SKWConnection.h:26