iOS SDK API Reference

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

Alternative class as DataConnection. More...

#import <SKWDataConnection.h>

Inheritance diagram for SKWDataConnection:
SKWConnection

Instance Methods

(BOOL) - send:
 data is sent to the remote peer. More...
 
(void) - close
 Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections. More...
 
(void) - close:
 Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections with the forceClose option. More...
 
(void) - on:callback:
 Set callbacks for data connection events. More...
 
(void) - getStats:
 Get statistics of the connection. More...
 

Properties

NSString *__nullable connectionId
 Connection ID.
 
NSString *__nullable metadata
 Any type of metadata associated with the connection, passed in by whoever initiated the connection.
 
BOOL isOpen
 This is true if the connection is open and ready for read/write.
 
NSString *__nullable peer
 The ID of the peer on the other end of this connection.
 
NSString *__nullable type
 For type of connection.
 
NSString *__nullable label
 The optional label passed in or assigned by PeerJS when the connection was initiated.
 
BOOL reliable
 Whether the underlying data channels are reliable; defined when the connection was initiated.
 
SKWSerializationEnum serialization
 The serialization format of the data sent over the connection. More...
 
SKWPeer *__nullable provider
 Provider PeerObjC object.
 

Detailed Description

Alternative class as DataConnection.

Method Documentation

◆ close

- (void) close

Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections.

Run the forceClose option as NO. May be changed to YES from a future version.

[data close];
data = nil;

◆ close:

- (void) close: (BOOL)  forceClose

Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections with the forceClose option.

[data close:YES];
data = nil;
Parameters
forceCloseSet to YES and the connection on remote peer will close immediately.

◆ getStats:

- (void) getStats: (SKWConnectionGetStatsCallback __nullable)  callback

Get statistics of the connection.

Parameters
callbackCallback block literal
SKWMediaConnection *connection;
[connection getStats:^(NSArray * _Nullable stats) {
// Do something
}];

◆ on:callback:

- (void) on: (SKWDataConnectionEventEnum event
callback: (__nullable SKWDataConnectionEventCallback callback 

Set callbacks for data connection events.

(Block Literal Syntax)

[data on:SKW_DATACONNECTION_EVENT_OPEN callback:^(NSObject* obj) {
// オープンしたときの処理等を記述
}];
[data on:SKW_DATACONNECTION_EVENT_DATA callback:^(NSObject* obj) {
if ([obj isKindOfClass:[NSData class]]) {
NSData* dat = (NSData *)obj;
} else if ([obj isKindOfClass:[NSDictionary class]]) {
NSDictionary* dic = (NSDictionary *)obj;
}
else if ([obj isKindOfClass:[NSArray class]]) {
NSArray* ary = (NSArray *)obj;
} else if ([obj isKindOfClass:[NSString class]]) {
NSString* string = (NSString *)obj;
}
}];
[data on:SKW_DATACONNECTION_EVENT_CLOSE callback:^(NSObject* obj) {
// コネクションが切断したときの処理を記述
}];
[data on:SKW_DATACONNECTION_EVENT_ERROR callback:^(NSObject* obj) {
SKWPeerError* err = (SKWPeerError *)obj;
NSLog(@"%@", err);
}];
Parameters
eventEvent type
callbackCallback block

◆ send:

- (BOOL) send: (NSObject *__nonnull)  data

data is sent to the remote peer.

NSString* strMsg = @"Send data.";
BOOL bResult = [data send:strMsg];
if (bResult) {
// success
}
else {
// failure
}
Parameters
dataYou can send any type of NSData object.
Returns
method result

Property Documentation

◆ serialization

- (SKWSerializationEnum) serialization
readnonatomicassigninherited

The serialization format of the data sent over the connection.

Can be binary (default), binary-utf8, json, or none.

SKWDataConnection
Alternative class as DataConnection.
Definition: SKWDataConnection.h:41
SKWPeerError
Error information class.
Definition: SKWPeerError.h:76
-[SKWDataConnection close]
void close()
Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections.
-[SKWDataConnection send:]
BOOL send:(NSObject *__nonnull data)
data is sent to the remote peer.
-[SKWDataConnection on:callback:]
void on:callback:(SKWDataConnectionEventEnum event,[callback] __nullable SKWDataConnectionEventCallback callback)
Set callbacks for data connection events.
SKWMediaConnection
Alternative class as MediaConnection.
Definition: SKWMediaConnection.h:52
-[SKWDataConnection close:]
void close:(BOOL forceClose)
Closes the data connection gracefully, cleaning up underlying DataChannels and PeerConnections with t...
-[SKWConnection getStats:]
void getStats:(SKWConnectionGetStatsCallback __nullable callback)
Get statistics of the connection.