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
 (deprecated) Close the connection to the signaling server. More...
 
(void) - reconnect
 (deprecated) Reconnect to the signaling server. More...
 
(BOOL) - destroy
 Close the connection to the signaling server and the already connected mediaConnection and dataConnection. More...
 
(void) - listAllPeers:
 Listing peer ID. More...
 
(void) - fetchPeerExistsWithPeerId:success:error:
 Fetch whether Peer specified by Peer ID exists from the signaling server. 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 signaling server and the already connected mediaConnection and dataConnection.

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

◆ disconnect

- (BOOL) disconnect

(deprecated) Close the connection to the signaling server.

In addition, the connected mediaConnection and dataConnection are continued.

Deprecated:
This method is now deprecated. Use [SKWPeer -destroy] instead.

◆ fetchPeerExistsWithPeerId:success:error:

- (void) fetchPeerExistsWithPeerId: (NSString *__nonnull)  peerId
success: (void(^)(BOOL))  successCallback
error: (void(^)(NSString *__nonnull))  errorCallback 

Fetch whether Peer specified by Peer ID exists from the signaling server.

SKWPeer* peer;
NSString* peerId;
[peer fetchPeerExistsWithPeerId:peerId success:^(BOOL exists) {
// something to do.
} error:^(NSString* __nonnull message) {
// something to do.
}];
Parameters
peerIdSpecify the Peer ID of the Peer whose existence you want to check.
successSet the callback to be executed when the existence of the Peer is fetched.
errorSet the callback to be executed when an error is occured.

◆ 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;
options.tryReconnectMedia = YES:
options.tryReconnectData = 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;
options.tryReconnectMedia = YES:
options.tryReconnectData = 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

(deprecated) Reconnect to the signaling server.

Use the assigned Peer ID when reconnecting.

Deprecated:
This method is now deprecated. Recreate peer instance instead.

◆ 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 signaling server and the already connected mediaConnection and dataConnec...
-[SKWPeer on:callback:]
void on:callback:(SKWPeerEventEnum event,[callback] SKWPeerEventCallback __nullable callback)
Set blocks for peer events.
SKWPeerOption::tryReconnectData
BOOL tryReconnectData
Set the value to YES to try to reconnect automatically when the data connection is lost.
Definition: SKWPeerOption.h:125
SKWPeerError
Error information class.
Definition: SKWPeerError.h:76
SKWPeerOption::key
NSString *__nullable key
API key for the cloud PeerServer.
Definition: SKWPeerOption.h:63
SKWPeer
A peer class.
Definition: SKWPeer.h:106
SKWMediaStream
Media stream.
Definition: SKWMediaStream.h:18
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
-[SKWPeer fetchPeerExistsWithPeerId:success:error:]
void fetchPeerExistsWithPeerId:success:error:(NSString *__nonnull peerId,[success] void(^ __nonnull successCallback)(BOOL),[error] void(^ __nullable errorCallback)(NSString *__nonnull))
Fetch whether Peer specified by Peer ID exists from the signaling server.
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::tryReconnectMedia
BOOL tryReconnectMedia
Set the value to YES to try to reconnect automatically when the SKWMediaConnection with the other sid...
Definition: SKWPeerOption.h:120
SKWPeerOption::turn
BOOL turn
Using SkyWay TURN server.
Definition: SKWPeerOption.h:103
-[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