Skylink

Skylink

Class representing a SkylinkJS instance.

Constructor

Parameters:
Name Type Description
options initOptions

Skylink authentication and initialisation configuration options.

Source:
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);

Methods

cancelBlobTransfer(roomName, peerId, transferId) → {Promise.<({peerId, transferId}|Error)>}

Method that cancels a data transfer

Parameters:
Name Type Description
roomName String

The room name.

peerId String

The Peer Id.

transferId String

The Transfer Id to cancel.

Since:
  • 2.0.0
Source:
Fires:

deleteEncryptSecrets(roomName, secretIdopt)

Method that deletes an encrypt secret.

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.

Since:
  • 2.0.0
Source:

generateUUID() → {String}

Method that generates an UUID (Unique ID).

Since:
  • 0.5.9
Source:

getConnectionStatus(roomName, peerIdopt) → {Promise.<Array.<object.<(String|statistics)>>>}

Method that retrieves peer connection bandwidth stats and ICE connection status.

Parameters:
Name Type Attributes Description
roomName String

The room name.

peerId String | Array <optional>

The target peer id to retrieve connection stats from.

  • When provided as an Array, it will retrieve all connection stats from all the peer ids provided.
  • When not provided, it will retrieve all connection stats from the currently connected peers in the room.
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
 }

getEncryptSecrets(roomName) → {Object|Object}

Method that returns all the secret and secret id pairs.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 2.0.0
Source:

getMessagePersistence(roomName) → {Boolean}

Method that retrieves the persistent message feature configured.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 2.0.0
Source:

getPeerInfo(roomName, peerIdopt) → {peerInfo|null}

Method that returns the user / peer current session information.

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.

  • When not provided or that the peer id is does not exists, it will return the user 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();

getPeers(roomName, showAllopt) → {Promise.<Object.<String, Array.<String>>>}

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 the initOptions, 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?
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.

Since:
  • 0.6.1
Source:
Fires:
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
 })

getPeersCustomSettings(roomName) → {Object.<String, customSettings>|null}

Method that gets the list of current custom peer settings sent and set.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.18
Source:
Example
Example 1: Get the list of current peer custom settings from peers in a room.

const currentPeerSettings = skylink.getPeersCustomSettings("Room_1");

getPeersDataChannels(roomName) → {Object.<string, Object.<String, dataChannelInfo>>}

Method that gets the current list of connected peers data channel connections in the room.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.18
Source:
Example
Example 1: Get the list of current peers data channels in the same room

const channels = skylink.getPeersDataChannels("Room_1");

getPeersInRoom(roomName) → {JSON.<String, peerInfo>|null}

Method that gets the list of connected peers in the room.

Parameters:
Name Type Description
roomName String

The name of the room.

Source:
Example
Example 1: Get the list of currently connected peers in the same room

const peers = skylink.getPeersInRoom(roomName);

getRecordings(roomName) → {recordingSessions|Object}

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 the Temasys Developer Console, please contact us on our support portal here.
Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.16
Source:
Example
Example 1: Get recording sessions

skylink.getRecordings(roomName);

getSdkVersion()

Method that retrieves the sdk version.

Since:
  • 2.1.6
Source:

getSelectedSecret(roomName, secretId) → {String}

Method that returns the secret used in encrypting and decrypting messages.

Parameters:
Name Type Description
roomName String

The room name.

secretId String

The id of the secret.

Since:
  • 2.0.0
Source:

getStoredMessages(roomName, roomSessionIdopt)

Method that retrieves the message history from server if Persistent Message feature is enabled for the key.

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 peerInfo object in most event payloads, e.g. PEER_JOINED.

  • A room session starts when the first peer joins a room. A room session ends when the last peer leaves the room.
  • Subsequent peers that join the same room, i.e. the same room name, starts a new room session.
Since:
  • 2.1
Source:
Fires:
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);
}

getStreams(roomName, includeSelfopt) → {JSON.<String, streamsList>}

Method that returns the list of connected peers streams in the room both user media streams and screen share streams.

Parameters:
Name Type Attributes Default Description
roomName String

The room name.

includeSelf Boolean <optional>
true

The flag if self streams are included.

Since:
  • 0.6.16
Source:
Example
Example 1: Get the list of current peers streams in the same room

const streams = skylink.getStreams("Room_1");

getStreamSources() → {Promise.<streamSources>}

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);

getUserData(roomName, peerIdopt) → {Object|null}

Method that returns the user / peer current custom data.

Parameters:
Name Type Attributes Description
roomName String

The room name.

peerId String <optional>

The peer id to return the current custom data from.

  • When not provided or that the peer id is does not exists, it will return the user 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();

getUserMedia(roomName, optionsopt) → {Promise.<MediaStreams>}

Method that retrieves camera stream.

Resolves with an array of MediaStreams. First item in array is MediaStream of kind audio and second item is MediaStream of kind video.

Parameters:
Name Type Attributes Default Description
roomName String | null null

The room name.

  • If no roomName is passed or getUserMedia() is called before joinRoom, the returned stream will not be associated with a room. The stream must be maintained independently. To stop the stream, call stopPrefetchedStream method.
options getUserMediaOptions <optional>

The camera stream configuration options.

  • When not provided, the value is set to { audio: true, video: true }.
Since:
  • 0.5.6
Source:
Fires:
  • If retrieval of fallback audio stream is successful:
    - MEDIA ACCESS SUCCESS event with parameter payload isScreensharing=false and isAudioFallback=false if initial retrieval is successful.
  • If initial retrieval is unsuccessful:
    Fallback to retrieve audio only stream is triggered (configured in initOptions audioFallback)
      - MEDIA ACCESS SUCCESS eventMEDIA ACCESS FALLBACK event with parameter payload state=FALLBACKING, isScreensharing=false and isAudioFallback=true and options.video=true and options.audio=true.
    No fallback to retrieve audio only stream
    - MEDIA ACCESS ERROR event with parameter payload isScreensharing=false and isAudioFallbackError=false.
  • If retrieval of fallback audio stream is successful:
    - MEDIA ACCESS SUCCESS event with parameter payload isScreensharing=false and isAudioFallback=true.
  • If retrieval of fallback audio stream is unsuccessful:
    - MEDIA ACCESS SUCCESS eventMEDIA ACCESS FALLBACK event with parameter payload state=ERROR, isScreensharing=false and isAudioFallback=true.
    - MEDIA ACCESS ERROR event with parameter payload isScreensharing=false and isAudioFallbackError=true.
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);

(async) joinRoom(optionsopt, prefetchedStreamopt) → {Promise.<MediaStreams>}

Method that starts a room session.

Resolves with an array of MediaStreams or null if pre-fetched stream was passed into joinRoom method. First item in array is MediaStream of kind audio and second item is MediaStream of kind video.

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 getUserMedia method before joinRoom method.

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
   });

leaveAllRooms(stopStreams) → {Promise.<Array.<String>>}

Method that stops all room sessions.

Parameters:
Name Type Default Description
stopStreams Boolean true

The flag if streams should be stopped. Defaults to true.

Since:
  • 2.0.0
Source:

leaveRoom(roomName, stopStreamsopt) → {Promise.<String>}

Method that stops the room session.

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.

Since:
  • 0.5.5
Source:
Fires:
  • PEER LEFT event on the remote end of the connection.
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);

lockRoom(roomName) → {Boolean}

Method that locks a room.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.5.0
Source:
Fires:
  • ROOM LOCK event with payload parameters isLocked=true when the room is successfully locked.
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);

muteStreams(roomName, options, streamIdopt) → {null}

Method that mutes both userMedia [getUserMedia] stream and screen [shareScreen] stream.

Parameters:
Name Type Attributes Description
roomName String

The room name.

options JSON

The streams muting options.

Properties
Name Type Attributes Default Description
audioMuted Boolean <optional>
true

The flag if all streams audio tracks should be muted or not.

videoMuted Boolean <optional>
true

The flag if all streams video tracks should be muted or not.

streamId String <optional>

The id of the stream to mute.

Since:
  • 0.5.7
Source:
Fires:
  • On local peer: LOCAL MEDIA MUTED event, STREAM MUTED event, PEER UPDATED event with payload parameters isSelf=true and isAudio=true if a local audio stream is muted or isVideo if local video stream is muted.
  • On remote peer: STREAM MUTED event, PEER UPDATED event with with parameter payload isSelf=false and isAudio=true if a remote audio stream is muted or isVideo if remote video stream is muted.
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
});

refreshConnection(roomName, targetPeerIdopt, iceRestartopt, optionsopt) → {Promise.<refreshConnectionResolve>}

Method that refreshes peer connections to update with the current streaming.

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 initOptions. refreshConnection() will "refresh" all peer connections.
- 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 where options.mcuUseRenegoRestart flag is set to false as it is not necessary since for MCU "restart" case is to invoke joinRoom again, or that it is not supported by the MCU.
The 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 bandwidth settings will override for all peers or the current room connection session settings.
The custom peer configuration settings.
Properties
Name Type Attributes Description
bandwidth JSON <optional>

The configuration to set the maximum streaming bandwidth to send to peers. Object signature follows joinRoom options.bandwidth settings.

Since:
  • 0.5.5
Source:
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
  });
});

refreshDatachannel(roomName, peerId) → {null}

Method that refreshes the main messaging data channel.

Parameters:
Name Type Description
roomName String

The room name.

peerId String

The target peer id of the peer data channel to refresh.

Since:
  • 0.6.30
Source:
Example
Example 1: Initiate refresh data channel

skylink.refreshDatachannel("Room_1", "peerID_1");

respondBlobRequest(roomName, peerId, transferId, accept) → {Promise.<dataTransferResult>}

Method that responds to a sendBlobData request.

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.

Since:
  • 2.0.0
Source:
Fires:
  • DATA TRANSFER STATE event with state value as DOWNLOAD_STARTED when user accepts the data transfer request.
  • DATA TRANSFER STATE event with state value as USER_REJECTED when user rejects the data transfer request.
  • DATA TRANSFER STATE event with state value as DOWNLOADING when data is in the process of being transferred.
  • DATA TRANSFER STATE event with state value as DOWNLOAD_COMPLETED when data transfer has completed.
  • DATA TRANSFER STATE event with state value as ERROR when data transfer timeout limit is reached.

sendBlobData(roomName, data, peerIdopt, timeoutopt) → {Promise.<dataTransferResult>}

Method that sends a Blob to all connected peers in the room.

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

Since:
  • 2.0.0
Source:
Fires:
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);
}

sendMessage(roomName, message, targetPeerIdopt, peerSessionIdopt)

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.

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.

  • 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 in the room.
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.

Since:
  • 0.4.0
Source:
Fires:
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 });
     }
   });

sendP2PMessage(roomNameopt, message, targetPeerIdopt)

Method that sends a message to peers via the data channel connection.

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.

Source:
Fires:
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
  }
}

sendStream(roomName, options) → {Promise.<MediaStreams>}

Method that sends a new userMedia stream to all connected peers in a room.

Parameters:
Name Type Description
roomName String

The room name.

options JSON | MediaStream | Array.<MediaStream>

The getUserMedia options parameter settings. The MediaStream to send to the remote peer or array of MediaStreams.

  • When provided as a MediaStream object, this configures the options.audio and options.video based on the tracks available in the MediaStream object. Object signature matches the options parameter in the getUserMedia method.
Note that the MediaStream object should be obtained by using the getUserMedia method and NOT navigator.mediaDevices.getUserMedia. Using the latter may result in unintended side effects such as the ON INCOMING STREAM event not triggering as expected.
- 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.
Since:
  • 0.5.6
Source:
Fires:
  • MEDIA ACCESS SUCCESS event with parameter payload isScreensharing=false and isAudioFallback=false if userMedia options is passed into sendStream method.event:
  • ON INCOMING STREAM event with parameter payload isSelf=true and stream as userMedia stream.event:
  • PEER UPDATED event with parameter payload isSelf=true.
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) });
}

setEncryptSecret(roomName, secret, secretId)

Method that stores a secret and secret id pair used for encrypting and decrypting messages.

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.

Since:
  • 2.0.0
Source:

setMessagePersistence(roomName, isPersistent)

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.
Parameters:
Name Type Description
roomName String

The room name.

isPersistent Boolean

The flag if messages should be persisted.

Since:
  • 2.0.0
Source:

setSelectedSecret(roomName, secretId)

Method that sets the secret to be used in encrypting and decrypting messages.

Parameters:
Name Type Description
roomName String

The room name.

secretId String

The id of the secret to be used for encrypting and decrypting messages.

Since:
  • 2.0.0
Source:

setUserData(roomName, userData)

Method that overwrites the user current custom data.

Parameters:
Name Type Description
roomName String

The room name.

userData JSON | String

The updated custom data.

Source:
Fires:
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);

shareScreen(roomName, options) → {MediaStream|null}

Method that returns starts screenshare and returns the stream.

Parameters:
Name Type Description
roomName String

The room name.

options getDisplayMediaOptions

Screen share options.

Since:
  • 2.0.0
Source:

startRecording(roomName) → {Promise.<String>}

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 the Temasys Developer Console, please contact us on our support portal here.
Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.16
Source:
Fires:
  • RECORDING STATE event with payload state=START if recording has started successfully.event:
  • RECORDING STATE event with payload error if an error occurred during recording.
Example
Example 1: Start a recording session

skylink.startRecording(roomName)
.then(recordingId => {
  // do something
})
.catch(error => {
  // handle error
});

startRTMPSession(roomName, streamId, endpoint) → {Promise.<String>}

Method that starts a RTMP session. [Beta]

Note that this feature requires MCU to be enabled for the App Key provided in the initOptions.
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.

Since:
  • 0.6.36
Source:
Fires:
  • RTMP STATE event with parameter payload state=START.
Example
Example 1: Start a rtmp session

skylink.startRTMPSession(roomName, streamId, endpoint)
.then(rtmpId => {
  // do something
})
.catch(error => {
  // handle error
});

stopRecording(roomName) → {Promise.<String>}

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 the Temasys Developer Console, please contact us on our support portal here.
  • It is mandatory for the recording session to have elapsed for more than 4 minutes before calling stopRecording method.
Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.16
Source:
Fires:
  • RECORDING STATE event with payload state=STOP if recording has stopped successfully.event:
  • RECORDING STATE event with payload error if an error occurred during recording.
Example
Example 1: Stop the recording session

skylink.stopRecording(roomName)
.then(recordingId => {
  // do something
})
.catch(error => {
  // handle error
});

stopRTMPSession(roomName, rtmpId) → {Promise.<String>}

Method that stops a RTMP session. [Beta]

Note that this feature requires MCU to be enabled for the App Key provided in initOptions.
Parameters:
Name Type Description
roomName String

The room name.

rtmpId String

The RTMP session id.

Since:
  • 0.6.36
Source:
Fires:
  • RTMP STATE event with parameter payload state=STOP.
Example
Example 1: Stop rtmp session

skylink.stopRTMPSession(roomName, rtmpId)
.then(rtmpId => {
  // do something
})
.catch(error => {
  // handle error
});

stopScreen(roomName) → {null}

Method that stops the screen share stream returned from shareScreen method.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.6.0
Source:
Fires:
  • MEDIA ACCESS STOPPED event with parameter payload isScreensharing value as true and isAudioFallback value as false if there is a screen stream
  • STREAM ENDED event with parameter payload isSelf value as true and isScreensharing value as true if user is in the room
  • PEER UPDATED event with parameter payload isSelf value as true
  • ON INCOMING STREAM event with parameter payload isSelf value as true and stream as Skylink#event:getUserMedia stream if there is an existing userMedia stream
Example
Example 1

skylink.stopScreen(roomName);

stopStreams(roomName, streamId) → {Promise}

Method that stops the userMedia stream (also known as a prefetched stream) returned from getUserMedia method.

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 userMedia streams will be stopped.

Since:
  • 0.5.6
Source:
Fires:
  • MEDIA ACCESS STOPPED event with parameter payload isSelf=true and isScreensharing=false if there is a getUserMedia stream.
  • STREAM ENDED event with parameter payload isSelf=true and isScreensharing=false if there is a getUserMedia stream and user is in a room.
  • PEER UPDATED event with parameter payload isSelf=true.
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));

unlockRoom(roomName) → {Boolean}

Method that unlocks a room.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 0.5.0
Source:
Fires:
  • ROOM LOCK event with payload parameters isLocked=false when the room is successfully locked.