Constructor
new Skylink(options)
Example
import Skylink from 'skylinkjs';
const initOptions = {
// Obtain your app key from https://console.temasys.io
appKey: 'temasys-appKey-XXXXX-XXXXXX',
defaultRoom: "Default_Room",
};
const skylink = new Skylink(initOptions);
Parameters:
Name | Type | Description |
---|---|---|
options |
initOptions | Skylink authentication and initialisation configuration options. |
Methods
cancelBlobTransfer(roomName, peerId, transferId) → {Promise.<({peerId, transferId}|Error)>}
- Description:
Method that cancels a data transfer
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
peerId |
String | The Peer Id. |
transferId |
String | The Transfer Id to cancel. |
Fires:
DATA TRANSFER STATE
event withstate
value asCANCEL
.
Returns:
- Type
- Promise.<({peerId, transferId}|Error)>
deleteEncryptSecrets(roomName, secretIdopt)
- Description:
Method that deletes an encrypt secret.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String | The room name. |
|
secretId |
String |
<optional> |
The id of the secret to be deleted. If no secret id is provided, all secrets will be deleted. |
generateUUID() → {String}
- Description:
Method that generates an UUID (Unique ID).
- Source:
- Since:
- 0.5.9
Returns:
Returns a generated UUID (Unique ID).
- Type
- String
getConnectionStatus(roomName, peerIdopt) → {Promise.<Array.<object.<(String|statistics)>>>}
- Description:
Method that retrieves peer connection bandwidth stats and ICE connection status.
- Source:
Examples
Example 1: Retrieving connection statistics from all peers in a room
skylink.getConnectionStatus("Room_1")
.then((statistics) => {
// handle statistics
}
.catch((error) => {
// handle error
}
Example 2: Retrieving connection statistics from selected peers
const selectedPeers = ["peerId_1", "peerId_2"];
skylink.getConnectionStatus("Room_1", selectedPeers)
.then((statistics) => {
// handle statistics
}
.catch((error) => {
// handle error
}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String | The room name. |
|
peerId |
String | Array |
<optional> |
The target peer id to retrieve connection stats from.
|
Returns:
- Type
- Promise.<Array.<object.<(String|statistics)>>>
getEncryptSecrets(roomName) → {Object|Object}
- Description:
Method that returns all the secret and secret id pairs.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Returns:
- Type
- Object | Object
getMessagePersistence(roomName) → {Boolean}
- Description:
Method that retrieves the persistent message feature configured.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Returns:
isPersistent
- Type
- Boolean
getPeerInfo(roomName, peerIdopt) → {peerInfo|null}
- Description:
Method that returns the user / peer current session information.
- Source:
Examples
Example 1: Get peer current session information
const peerPeerInfo = skylink.getPeerInfo(peerId);
Example 2: Get user current session information
const userPeerInfo = skylink.getPeerInfo();
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | The name of the room. |
||
peerId |
String | null |
<optional> |
null
|
The peer id to return the current session information from.
|
Returns:
The user / peer current session information.
- Type
- peerInfo | null
getPeers(roomName, showAllopt) → {Promise.<Object.<String, Array.<String>>>}
- Description:
Method that retrieves the list of peer ids from rooms within the same App space.
Note that this feature requires
"isPrivileged"
flag to be enabled for the App Key provided in theinitOptions
, as only Users connecting using the App Key with this flag enabled (which we call privileged Users / peers) can retrieve the list of peer ids from rooms within the same App space.What is a privileged key?
- Source:
- Since:
- 0.6.1
Example
Example 1: Retrieve un-privileged peers
skylink.getPeers(location)
.then((result) => {
// do something
})
.catch((error) => {
// handle error
})
Example 2: Retrieve all (privileged and un-privileged) peers
skylink.getPeers(location, true)
.then((result) => {
// do something
})
.catch((error) => {
// handle error
})
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | The room name |
||
showAll |
Boolean |
<optional> |
false
|
The flag if Signaling server should also return the list of privileged peer ids. By default, the Signaling server does not include the list of privileged peer ids in the return result. |
Fires:
GET PEERS STATE CHANGE
event with parameter payloadstate=ENQUIRED
upon callinggetPeers
method.GET PEERS STATE CHANGE
event with parameter payloadstate=RECEIVED
when peer list is received from Signaling server.
Returns:
peerList - Array of peer ids, keyed by room name.
- Type
- Promise.<Object.<String, Array.<String>>>
getPeersCustomSettings(roomName) → {Object.<String, customSettings>|null}
- Description:
Method that gets the list of current custom peer settings sent and set.
- Source:
- Since:
- 0.6.18
Example
Example 1: Get the list of current peer custom settings from peers in a room.
const currentPeerSettings = skylink.getPeersCustomSettings("Room_1");
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Returns:
- The peer custom settings keyed by peer id.
- Type
- Object.<String, customSettings> | null
getPeersDataChannels(roomName) → {Object.<string, Object.<String, dataChannelInfo>>}
- Description:
Method that gets the current list of connected peers data channel connections in the room.
- Source:
- Since:
- 0.6.18
Example
Example 1: Get the list of current peers data channels in the same room
const channels = skylink.getPeersDataChannels("Room_1");
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Returns:
- The list of peer data channels keyed by peer id, keyed by data channel id.
- Type
- Object.<string, Object.<String, dataChannelInfo>>
getPeersInRoom(roomName) → {JSON.<String, peerInfo>|null}
- Description:
Method that gets the list of connected peers in the room.
- Source:
Example
Example 1: Get the list of currently connected peers in the same room
const peers = skylink.getPeersInRoom(roomName);
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The name of the room. |
Returns:
peerInfo
keyed by peer id. Additional isSelf
flag to determine if peer is user or not. Null is returned if room has not been created.
- Type
- JSON.<String, peerInfo> | null
getRecordings(roomName) → {recordingSessions|Object}
- Description:
Method that retrieves the list of recording sessions.
Note that this feature requires MCU and recording to be enabled for the App Key provided in
initOptions
. If recording feature is not available to be enabled in theTemasys Developer Console
, please contact us on our support portalhere
.
- Source:
- Since:
- 0.6.16
Example
Example 1: Get recording sessions
skylink.getRecordings(roomName);
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Returns:
The list of recording sessions.
- Type
- recordingSessions | Object
getSdkVersion()
- Description:
Method that retrieves the sdk version.
- Source:
- Since:
- 2.1.6
getSelectedSecret(roomName, secretId) → {String}
- Description:
Method that returns the secret used in encrypting and decrypting messages.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
secretId |
String | The id of the secret. |
Returns:
secret - The secret used for encrypting and decrypting messages.
- Type
- String
getStoredMessages(roomName, roomSessionIdopt)
- Description:
Method that retrieves the message history from server if Persistent Message feature is enabled for the key.
- Source:
- Since:
- 2.1
Example
Example 1: Retrieving stored messages
// add event listener to catch storedMessages event
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.STORED_MESSAGES, (evt) => {
const { storedMessages } = evt.detail;
storedMessages.content.forEach((message) => {
// do something
})
});
let getStoredMessages = (roomName) => {
this.skylink.getStoredMessages(roomName);
}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String | The name of the room. |
|
roomSessionId |
String |
<optional> |
The room session id to retrieve the messages from. The room session id is found in the
|
Fires:
STORED_MESSAGES
event
getStreamSources() → {Promise.<streamSources>}
- Description:
Method that returns the camera and microphone sources.
- Source:
Example
Example 1: Get media sources before joinRoom - only available on Chrome browsers
const audioInputDevices = [];
const videoInputDevices = [];
skylink.getStreamSources.then((sources) => {
audioInputDevices = sources.audio.input;
videoInputDevices = sources.video.input;
}).catch((error) => // handle error);
skylink.getUserMedia(roomName, {
audio: {
deviceId: audioInputDevices[0].deviceId,
},
video: {
deviceId: videoInputDevices[0].deviceId,
}
}).then((streams) => // do something)
.catch((error) => // handle error);
Returns:
outputSources
- Type
- Promise.<streamSources>
getStreams(roomName, includeSelfopt) → {JSON.<String, streamsList>}
- Description:
Method that returns the list of connected peers streams in the room both user media streams and screen share streams.
- Source:
- Since:
- 0.6.16
Example
Example 1: Get the list of current peers streams in the same room
const streams = skylink.getStreams("Room_1");
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | The room name. |
||
includeSelf |
Boolean |
<optional> |
true
|
The flag if self streams are included. |
Returns:
- The list of peer stream objects keyed by peer id.
- Type
- JSON.<String, streamsList>
getUserData(roomName, peerIdopt) → {Object|null}
- Description:
Method that returns the user / peer current custom data.
- Source:
Examples
Example 1: Get peer current custom data
const peerUserData = skylink.getUserData(peerId);
Example 2: Get user current custom data
const userUserData = skylink.getUserData();
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String | The room name. |
|
peerId |
String |
<optional> |
The peer id to return the current custom data from.
|
Returns:
The user / peer current custom data.
- Type
- Object | null
getUserMedia(roomName, optionsopt) → {Promise.<MediaStreams>}
- Description:
Method that retrieves camera stream.
Resolves with an array of
MediaStreams
. First item in array isMediaStream
of kind audio and second item isMediaStream
of kind video.
- Source:
- Since:
- 0.5.6
Examples
Example 1: Get both audio and video after joinRoom
skylink.getUserMedia(roomName, {
audio: true,
video: true,
}).then((streams) => // do something)
.catch((error) => // handle error);
Example 2: Get only audio
skylink.getUserMedia(roomName, {
audio: true,
video: false,
}).then((streams) => // do something)
.catch((error) => // handle error);
Example 3: Configure resolution for video
skylink.getUserMedia(roomName, {
audio: true,
video: { resolution: skylinkConstants.VIDEO_RESOLUTION.HD },
}).then((streams) => // do something)
.catch((error) => // handle error);
Example 4: Configure stereo flag for OPUS codec audio (OPUS is always used by default)
this.skylink.getUserMedia(roomName, {
audio: {
stereo: true,
},
video: true,
}).then((streams) => // do something)
.catch((error) => // handle error);
Example 5: Get both audio and video before joinRoom
// Note: the prefetched stream must be maintained independently
skylink.getUserMedia({
audio: true,
video: true,
}).then((streams) => // do something)
.catch((error) => // handle error);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | null |
null
|
The room name.
|
|
options |
getUserMediaOptions |
<optional> |
The camera stream configuration options.
|
Fires:
- If retrieval of fallback audio stream is successful:
-MEDIA ACCESS SUCCESS
event with parameter payloadisScreensharing=false
andisAudioFallback=false
if initial retrieval is successful. - If initial retrieval is unsuccessful:
Fallback to retrieve audio only stream is triggered (configured ininitOptions
audioFallback
)
-MEDIA ACCESS SUCCESS
eventMEDIA ACCESS FALLBACK
event with parameter payloadstate=FALLBACKING
,isScreensharing=false
andisAudioFallback=true
andoptions.video=true
andoptions.audio=true
.
No fallback to retrieve audio only stream
-MEDIA ACCESS ERROR
event with parameter payloadisScreensharing=false
andisAudioFallbackError=false
. - If retrieval of fallback audio stream is successful:
-MEDIA ACCESS SUCCESS
event with parameter payloadisScreensharing=false
andisAudioFallback=true
. - If retrieval of fallback audio stream is unsuccessful:
-MEDIA ACCESS SUCCESS
eventMEDIA ACCESS FALLBACK
event with parameter payloadstate=ERROR
,isScreensharing=false
andisAudioFallback=true
.
-MEDIA ACCESS ERROR
event with parameter payloadisScreensharing=false
andisAudioFallbackError=true
.
Returns:
- Type
- Promise.<MediaStreams>
(async) joinRoom(optionsopt, prefetchedStreamopt) → {Promise.<MediaStreams>}
- Description:
Method that starts a room session.
Resolves with an array of
MediaStreams
or null if pre-fetched stream was passed intojoinRoom
method. First item in array isMediaStream
of kind audio and second item isMediaStream
of kind video.
- Source:
Examples
Example 1: Calling joinRoom with options
const joinRoomOptions = {
audio: true,
video: true,
roomName: "Room_1",
userData: {
username: "GuestUser_1"
},
};
skylink.joinRoom(joinRoomOptions)
.then((streams) => {
if (streams[0]) {
window.attachMediaStream(audioEl, streams[0]); // first item in array is an audio stream
}
if (streams[1]) {
window.attachMediaStream(videoEl, streams[1]); // second item in array is a video stream
}
})
.catch((error) => {
// handle error
});
Example 2: Retrieving a pre-fetched stream before calling joinRoom
// REF: getUserMedia
const prefetchedStreams = skylink.getUserMedia();
const joinRoomOptions = {
roomName: "Room_1",
userData: {
username: "GuestUser_1"
},
};
skylink.joinRoom(joinRoomOptions, prefetchedStreams)
.catch((error) => {
// handle error
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
joinRoomOptions |
<optional> |
The options available to join the room and configure the session. |
prefetchedStream |
MediaStream |
<optional> |
The pre-fetched media stream object obtained when the user calls |
Returns:
- Type
- Promise.<MediaStreams>
leaveAllRooms(stopStreams) → {Promise.<Array.<String>>}
- Description:
Method that stops all room sessions.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Default | Description |
---|---|---|---|
stopStreams |
Boolean |
true
|
The flag if streams should be stopped. Defaults to true. |
Returns:
- Type
- Promise.<Array.<String>>
leaveRoom(roomName, stopStreamsopt) → {Promise.<String>}
- Description:
Method that stops the room session.
- Source:
- Since:
- 0.5.5
Example
Example 1:
// add event listener to catch peerLeft events when remote peer leaves room
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.PEER_LEFT, (evt) => {
const { detail } = evt;
// handle remote peer left
});
skylink.leaveRoom(roomName)
.then((roomName) => {
// handle local peer left
})
.catch((error) => // handle error);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | The room name to leave. |
||
stopStreams |
Boolean |
<optional> |
true
|
The flag if streams should be stopped. Defaults to true. |
Fires:
PEER LEFT
event on the remote end of the connection.
Returns:
- Type
- Promise.<String>
lockRoom(roomName) → {Boolean}
- Description:
Method that locks a room.
- Source:
- Since:
- 0.5.0
Example
// add event listener to listen for room locked state when peer tries to join a locked room
skylinkEventManager.addEventListener(SkylinkEvents.SYSTEM_ACTION, (evt) => {
const { detail } = evt;
if (detail.reason === SkylinkConstants.SYSTEM_ACTION.LOCKED') {
// handle event
}
}
// add event listener to listen for room locked/unlocked event after calling lockRoom method
skylinkEventManager.addEventListener(SkylinkEvents.ROOM_LOCK, (evt) => {
const { detail } = evt;
if (detail.isLocked) {
// handle room lock event
} else {
// handle room unlock event
}
}
skylink.lockRoom(roomName);
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Fires:
ROOM LOCK
event with payload parametersisLocked=true
when the room is successfully locked.
Returns:
- Type
- Boolean
muteStreams(roomName, options, streamIdopt) → {null}
- Description:
Method that mutes both
userMedia
[getUserMedia
] stream andscreen
[shareScreen
] stream.
- Source:
- Since:
- 0.5.7
Examples
Example 1: Mute both audio and video tracks in all streams
skylink.muteStreams(roomName, {
audioMuted: true,
videoMuted: true
});
Example 2: Mute only audio tracks in all streams
skylink.muteStreams(roomName, {
audioMuted: true,
videoMuted: false
});
Example 3: Mute only video tracks in all streams
skylink.muteStreams(roomName, {
audioMuted: false,
videoMuted: true
});
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
roomName |
String | The room name. |
||||||||||||||||
options |
JSON | The streams muting options. Properties
|
||||||||||||||||
streamId |
String |
<optional> |
The id of the stream to mute. |
Fires:
- On local peer:
LOCAL MEDIA MUTED
event,STREAM MUTED
event,PEER UPDATED
event with payload parametersisSelf=true
andisAudio=true
if a local audio stream is muted orisVideo
if local video stream is muted. - On remote peer:
STREAM MUTED
event,PEER UPDATED
event with with parameter payloadisSelf=false
andisAudio=true
if a remote audio stream is muted orisVideo
if remote video stream is muted.
Returns:
- Type
- null
refreshConnection(roomName, targetPeerIdopt, iceRestartopt, optionsopt) → {Promise.<refreshConnectionResolve>}
- Description:
Method that refreshes peer connections to update with the current streaming.
- Source:
- Since:
- 0.5.5
Examples
Example 1: Refreshing a peer connection
skylink.refreshConnection(roomName, peerId)
.then((result) => {
const failedRefreshIds = Object.keys(result.refreshErrors);
failedRefreshIds.forEach((peerId) => {
// handle error
});
});
Example 2: Refreshing a list of peer connections
let selectedPeers = ["peerID_1", "peerID_2"];
skylink.refreshConnection(roomName, selectedPeers)
.then((result) => {
const failedRefreshIds = Object.keys(result.refreshErrors);
failedRefreshIds.forEach((peerId) => {
// handle error
});
});
Example 3: Refreshing all peer connections
skylink.refreshConnection(roomName)
.then((result) => {
const failedRefreshIds = Object.keys(result.refreshErrors);
failedRefreshIds.forEach((peerId) => {
// handle error
});
});
Parameters:
Name | Type | Attributes | Default | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
roomName |
String | The name of the room. |
||||||||||
targetPeerId |
String | Array |
<optional> |
Note that this is ignored if MCU is enabled for the App Key provided in- The target peer id to refresh connection with. - When provided as an Array, it will refresh all connections with all the peer ids provided. - When not provided, it will refresh all the currently connected peers in the room. |
|||||||||
iceRestart |
Boolean |
<optional> |
false
|
Note that this flag will not be honoured for MCU enabled peer connections whereThe flag if ICE connections should restart when refreshing peer connections. This is used when ICE connection state is FAILED or DISCONNECTED , which
can be retrieved with the ICE CONNECTION STATE event. |
||||||||
options |
JSON |
<optional> |
Note that for MCU connections, the
The custom peer configuration settings.
Properties
|
Returns:
- The Promise will always resolve.
- Type
- Promise.<refreshConnectionResolve>
refreshDatachannel(roomName, peerId) → {null}
- Description:
Method that refreshes the main messaging data channel.
- Source:
- Since:
- 0.6.30
Example
Example 1: Initiate refresh data channel
skylink.refreshDatachannel("Room_1", "peerID_1");
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
peerId |
String | The target peer id of the peer data channel to refresh. |
Returns:
- Type
- null
respondBlobRequest(roomName, peerId, transferId, accept) → {Promise.<dataTransferResult>}
- Description:
Method that responds to a
sendBlobData
request.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
peerId |
String | The Peer Id. |
transferId |
String | The transfer Id. |
accept |
Boolean | The flag if the data transfer is accepted by the user. |
Fires:
DATA TRANSFER STATE
event withstate
value asDOWNLOAD_STARTED
when user accepts the data transfer request.DATA TRANSFER STATE
event withstate
value asUSER_REJECTED
when user rejects the data transfer request.DATA TRANSFER STATE
event withstate
value asDOWNLOADING
when data is in the process of being transferred.DATA TRANSFER STATE
event withstate
value asDOWNLOAD_COMPLETED
when data transfer has completed.DATA TRANSFER STATE
event withstate
value asERROR
when data transfer timeout limit is reached.
Returns:
- Always resolves with success or error object.
- Type
- Promise.<dataTransferResult>
sendBlobData(roomName, data, peerIdopt, timeoutopt) → {Promise.<dataTransferResult>}
- Description:
Method that sends a Blob to all connected peers in the room.
- Source:
- Since:
- 2.0.0
Example
Example 1: Send a file
// Add listener to incomingStream event
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.DATA_TRANSFER_STATE, (evt) => {
const { state } = evt.detail;
switch (state) {
case SkylinkConstants.DATA_TRANSFER_STATE.UPLOAD_REQUEST:
// Alert peer that a file transfer is requested
// Record user response and call <code>respondBlobRequest</code>
skylink.respondBlobRequest(config.defaultRoom, peerId, transferId, result)
.then((result) => // handle success or error)
.catch((err) => // handle error)
break;
case SkylinkConstants.DATA_TRANSFER_STATE.DOWNLOAD_COMPLETED:
// Surface download link to user
break;
}
})
skylink.sendBlobData(roomName, data)
.then((result) => {
// always resolves with success or error object
})
.catch((error) => // handle error);
}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
roomName |
String | The room name |
||
data |
Blob | The Blob object |
||
peerId |
String | Array |
<optional> |
The peer ID or array of peer IDs. When not provided, it will start uploading data transfers with all peers in the room |
|
timeout |
Number |
<optional> |
60
|
The duration for which to wait for a response from the remote peer before terminating the transfer |
Fires:
DATA TRANSFER STATE
event withstate
value asUSER_UPLOAD_REQUEST
on the local peer.DATA TRANSFER STATE
event withstate
value asUPLOAD_REQUEST
on the remote peer.DATA TRANSFER STATE
event withstate
value asUPLOAD_STARTED
when remote peer accepts data transfer.DATA TRANSFER STATE
event withstate
value asREJECTED
when remote peer rejects data transfer.DATA TRANSFER STATE
event withstate
value asUPLOADING
when data is in the process of being transferred.DATA TRANSFER STATE
event withstate
value asUPLOAD_COMPLETED
when data transfer has completed.DATA TRANSFER STATE
event withstate
value asERROR
when data transfer timeout limit is reached.
Returns:
- Always resolves with success or error object.
- Type
- Promise.<dataTransferResult>
sendMessage(roomName, message, targetPeerIdopt, peerSessionIdopt)
- Description:
Function that sends a message to peers via the Signaling socket connection.
sendMessage
can also be used to trigger call actions on the remote. Refer to Example 3 for muting the remote peer.
- Source:
- Since:
- 0.4.0
Examples
Example 1: Broadcasting to all peers in a room
let sendMessage = (roomName) => {
const message = "Hi!";
skylink.sendMessage(roomName, message);
}
Example 2: Broadcasting to selected peers
let sendMessage = (roomName) => {
const message = "Hi all!";
const selectedPeers = ["PeerID_1", "PeerID_2"];
skylink.sendMessage(roomName, message, selectedPeers);
}
Example 3: Muting the remote peer
// The local peer - send custom message object
const msgObject = JSON.stringify({ data: "data-content", type: "muteStreams", audio: true, video: false });
this.skylink.sendP2PMessage(roomName, msgObject);
// The remote peer - add an event listener for ON_INCOMING_MESSAGE and check for the custom message object
SkylinkEventManager.addEventListener(skylinkConstants.EVENTS.ON_INCOMING_MESSAGE, (evt) => {
const {message, peerId, isSelf, room} = evt.detail;
const msg = JSON.parse(message.content);
if (msg.type === "muteStreams") {
skylink.muteStreams(roomName, { audioMuted: msg.audio, videoMuted: msg.video });
}
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String | room name to send the message. |
|
message |
String | JSON | The message. |
|
targetPeerId |
String | Array |
<optional> |
The target peer id to send message to.
|
peerSessionId |
String |
<optional> |
The peer session id can be used to attribute the message to a client across sessions. It will replace the peerId. The peer session id is returned in the peerInfo object. This is an advanced feature. |
Fires:
ON_INCOMING_MESSAGE
event
sendP2PMessage(roomNameopt, message, targetPeerIdopt)
- Description:
Method that sends a message to peers via the data channel connection.
- Source:
Examples
Example 1: Broadcasting to all peers in all rooms
const message = "Hello everyone!";
skylink.sendP2PMessage(message);
Example 2: Broadcasting to all peers in a room
const message = "Hello everyone!";
const roomName = "Room_1";
skylink.sendP2PMessage(roomName, message);
Example 3: Sending message to a peer in all rooms
const message = "Hello!";
const targetPeerId = "peerId";
skylink.sendP2PMessage(message, targetPeerId);
Example 4: Sending message to a peer in a room
const message = "Hello!";
const targetPeerId = "peerId";
const roomName = "Room_1";
skylink.sendP2PMessage(roomName, message, targetPeerId);
Example 5: Sending message to selected Peers in a room
const message = "Hello!";
const selectedPeers = ["peerId_1", "peerId_2"];
const roomName = "Room_1";
skylink.sendP2PMessage(roomName, message, selectedPeers);
// Listen for onIncomingMessage event
skylink.addEventListener(SkylinkEvents.ON_INCOMING_MESSAGE, (evt) => {
const detail = evt.detail;
if (detail.isSelf) {
// handle message from self
} else {
// handle message from remote peer
}
}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
roomName |
String |
<optional> |
The name of the room the message is intended for. When not provided, the message will be broadcast to all rooms where targetPeerId(s) are found (if provided). Note when roomName is provided, targetPeerId should be provided as null. |
message |
String | JSON | The message. |
|
targetPeerId |
String | Array |
<optional> |
The target peer id to send message to. When provided as an Array, it will send the message to only peers which ids are in the list. When not provided, it will broadcast the message to all connected peers with data channel connection in a room. |
Fires:
ON_INCOMING_MESSAGE
event
sendStream(roomName, options) → {Promise.<MediaStreams>}
- Description:
Method that sends a new
userMedia
stream to all connected peers in a room.
- Source:
- Since:
- 0.5.6
Example
Example 1: Send new MediaStream with audio and video
let sendStream = (roomName) => {
const options = { audio: true, video: true };
// Add listener to incomingStream event
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.ON_INCOMING_STREAM, (evt) => {
const { detail } = evt;
window.attachMediaStream(localVideoEl, detail.stream);
})
skylink.sendStream(roomName, options)
// streams can also be obtained from resolved promise
.then((streams) => {
if (streams[0]) {
window.attachMediaStream(audioEl, streams[0]); // first item in array is an audio stream
}
if (streams[1]) {
window.attachMediaStream(videoEl, streams[1]); // second item in array is a video stream
}
})
.catch((error) => { console.error(error) });
}
Example 2: Use pre-fetched media streams
const prefetchedStreams = null;
skylink.getUserMedia(null, {
audio: { stereo: true },
video: true,
})
.then((streams) => {
prefetchedStream = streams
});
skylink.sendStream(roomName, prefetchedStreams)
.catch((error) => { console.error(error) });
}
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
options |
JSON | MediaStream | Array.<MediaStream> | The
Note that the- If options are passed as argument into the method, it resolves with an array of MediaStreams . First item in array is
MediaStream of kind audio and second item is MediaStream of kind video. Otherwise it resolves with the array or
MediaStream . |
Fires:
MEDIA ACCESS SUCCESS
event with parameter payloadisScreensharing=false
andisAudioFallback=false
ifuserMedia
options
is passed intosendStream
method.event:ON INCOMING STREAM
event with parameter payloadisSelf=true
andstream
asuserMedia
stream.event:PEER UPDATED
event with parameter payloadisSelf=true
.
Returns:
- Type
- Promise.<MediaStreams>
setEncryptSecret(roomName, secret, secretId)
- Description:
Method that stores a secret and secret id pair used for encrypting and decrypting messages.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
secret |
String | A secret to use for encrypting and decrypting messages. |
secretId |
String | The id of the secret. |
setMessagePersistence(roomName, isPersistent)
- Description:
Method that overrides the persistent message feature configured at the key level.
Note that to set message persistence at the app level, the persistent message feature MUST be enabled at the key level in the Temasys Developers Console. Messages will also only be persisted if the messages are encrypted, are public messages and, are sent via the signaling server using the
sendMessage
method.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
isPersistent |
Boolean | The flag if messages should be persisted. |
setSelectedSecret(roomName, secretId)
- Description:
Method that sets the secret to be used in encrypting and decrypting messages.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
secretId |
String | The id of the secret to be used for encrypting and decrypting messages. |
setUserData(roomName, userData)
- Description:
Method that overwrites the user current custom data.
- Source:
Example
Example 1: Update user custom data after joinRoom()
// add event listener to catch setUserData changes
SkylinkEventManager.addEventListener(SkylinkConstants.peerUpdated, (evt) => {
const { detail } = evt;
// do something
});
const userData = "afterjoin";
skylink.setUserData(userData);
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
userData |
JSON | String | The updated custom data. |
Fires:
PEER_UPDATED
event if peer is in room withisSelf=true
.
shareScreen(roomName, options) → {MediaStream|null}
- Description:
Method that returns starts screenshare and returns the stream.
- Source:
- Since:
- 2.0.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
options |
getDisplayMediaOptions | Screen share options. |
Returns:
- The screen share stream.
- Type
- MediaStream | null
startRTMPSession(roomName, streamId, endpoint) → {Promise.<String>}
- Description:
Method that starts a RTMP session. [Beta]
Note that this feature requires MCU to be enabled for the App Key provided in the
initOptions
.
- Source:
- Since:
- 0.6.36
Example
Example 1: Start a rtmp session
skylink.startRTMPSession(roomName, streamId, endpoint)
.then(rtmpId => {
// do something
})
.catch(error => {
// handle error
});
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
streamId |
String | The stream id to live stream for the session. |
endpoint |
String | The RTMP endpoint. |
Fires:
RTMP STATE
event with parameter payloadstate=START
.
Returns:
rtmpId - The RTMP session id.
- Type
- Promise.<String>
startRecording(roomName) → {Promise.<String>}
- Description:
Method that starts a recording session.
Note that this feature requires MCU and recording to be enabled for the App Key provided in
initOptions
. If recording feature is not available to be enabled in theTemasys Developer Console
, please contact us on our support portalhere
.
- Source:
- Since:
- 0.6.16
Example
Example 1: Start a recording session
skylink.startRecording(roomName)
.then(recordingId => {
// do something
})
.catch(error => {
// handle error
});
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Fires:
RECORDING STATE
event with payloadstate=START
if recording has started successfully.event:RECORDING STATE
event with payloaderror
if an error occurred during recording.
Returns:
recordingId - The recording session id.
- Type
- Promise.<String>
stopRTMPSession(roomName, rtmpId) → {Promise.<String>}
- Description:
Method that stops a RTMP session. [Beta]
Note that this feature requires MCU to be enabled for the App Key provided in
initOptions
.
- Source:
- Since:
- 0.6.36
Example
Example 1: Stop rtmp session
skylink.stopRTMPSession(roomName, rtmpId)
.then(rtmpId => {
// do something
})
.catch(error => {
// handle error
});
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
rtmpId |
String | The RTMP session id. |
Fires:
RTMP STATE
event with parameter payloadstate=STOP
.
Returns:
- Type
- Promise.<String>
stopRecording(roomName) → {Promise.<String>}
- Description:
Method that stops a recording session.
-
Note that this feature requires MCU and recording to be enabled for the App Key provided in the
initOptions
. If recording feature is not available to be enabled in theTemasys Developer Console
, please contact us on our support portalhere
. -
It is mandatory for the recording session to have elapsed for more than 4 minutes before calling
stopRecording
method.
-
Note that this feature requires MCU and recording to be enabled for the App Key provided in the
- Source:
- Since:
- 0.6.16
Example
Example 1: Stop the recording session
skylink.stopRecording(roomName)
.then(recordingId => {
// do something
})
.catch(error => {
// handle error
});
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Fires:
RECORDING STATE
event with payloadstate=STOP
if recording has stopped successfully.event:RECORDING STATE
event with payloaderror
if an error occurred during recording.
Returns:
recordingId - The recording session id.
- Type
- Promise.<String>
stopScreen(roomName) → {null}
- Description:
Method that stops the screen share stream returned from
shareScreen
method.
- Source:
- Since:
- 0.6.0
Example
Example 1
skylink.stopScreen(roomName);
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Fires:
MEDIA ACCESS STOPPED
event with parameter payloadisScreensharing
value astrue
andisAudioFallback
value asfalse
if there is a screen streamSTREAM ENDED
event with parameter payloadisSelf
value astrue
andisScreensharing
value astrue
if user is in the roomPEER UPDATED
event with parameter payloadisSelf
value astrue
ON INCOMING STREAM
event with parameter payloadisSelf
value astrue
andstream
asSkylink#event:getUserMedia
stream if there is an existinguserMedia
stream
Returns:
- Type
- null
stopStreams(roomName, streamId) → {Promise}
- Description:
Method that stops the
userMedia
stream (also known as a prefetched stream) returned fromgetUserMedia
method.
- Source:
- Since:
- 0.5.6
Example
Example 1: Stopping all the streams in a room
skylink.stopStreams(roomName)
.then(() => // do some thing);
NOTE: If there is a need to call multiple stopStreams, it is recommended to implement it as a promise chain i.e. the previous call should
resolve before the next call is made. This applies also to calling sendStream at the end of the stopStreams chain.
Example 2: Stopping multiple streams with streamId
skylink.stopStreams(roomName, streamID_1)
.then(() => skylink.stopStreams(roomName, streamID_2));
Example 3: Stopping a stream then sending a stream
skylink.stopStreams(roomName, streamID_1)
.then(() => skylink.sendStream(roomName, stream));
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
streamId |
String | The stream id of the stream to stop. If streamId is not set, all |
Fires:
MEDIA ACCESS STOPPED
event with parameter payloadisSelf=true
andisScreensharing=false
if there is agetUserMedia
stream.STREAM ENDED
event with parameter payloadisSelf=true
andisScreensharing=false
if there is agetUserMedia
stream and user is in a room.PEER UPDATED
event with parameter payloadisSelf=true
.
Returns:
- Type
- Promise
unlockRoom(roomName) → {Boolean}
- Description:
Method that unlocks a room.
- Source:
- Since:
- 0.5.0
Parameters:
Name | Type | Description |
---|---|---|
roomName |
String | The room name. |
Fires:
ROOM LOCK
event with payload parametersisLocked=false
when the room is successfully locked.
Returns:
- Type
- Boolean