Skylink

Skylink

Class representing a SkylinkJS instance.

Constructor

Creates a SkylinkJS instance.

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

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:

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

Method that retrieves peer connection bandwidth and ICE connection stats.

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:

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

getPeersScreenshare(roomName) → {Object.<String, MediaStream>|null}

Method that returns the screenshare stream id of peers.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 2.0.0
Source:

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

getScreenSources() → {Promise.<screenSources>}

Method that returns the screensharing sources.

Since:
  • 2.0.0
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)

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

Parameters:
Name Type Description
roomName String

The name of the room.

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) → {streamList|null}

Method that returns all active user streams including screenshare stream if present.

Parameters:
Name Type Description
roomName String

The room name.

Since:
  • 2.0.0
Source:

getStreamSources() → {Promise.<streamSources>}

Method that returns the camera and microphone sources.

Source:

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 JSON <optional>

The camera stream configuration options.

  • When not provided, the value is set to { audio: true, video: true }. To fallback to retrieve audio track only when retrieving of audio and video tracks failed, enable the audioFallback flag in the initOptions.
Properties
Name Type Attributes Default Description
useExactConstraints Boolean <optional>
false

Note that by enabling this flag, exact values will be requested when retrieving camera stream, but it does not prevent constraints related errors. By default when not enabled, expected mandatory maximum values (or optional values for source id) will requested to prevent constraints related errors, with an exception for options.video.frameRate option in Safari and IE (any plugin-enabled) browsers, where the expected maximum value will not be requested due to the lack of support.
The flag if getUserMedia() should request for camera stream to match exact requested values of options.audio.deviceId and options.video.deviceId, options.video.resolution and options.video.frameRate when provided.

audio Boolean | JSON <optional>
false

Note that the current Edge browser implementation does not support the options.audio.optional, options.audio.deviceId, options.audio.echoCancellation.
The audio configuration options.

Properties
Name Type Attributes Default Description
stereo Boolean <optional>
false

Deprecation Warning! This property has been deprecated. Configure this with the options.codecParams.audio.opus.stereo and the options.codecParams.audio.opus["sprop-stereo"] parameter in the initOptions instead. If the options.codecParams.audio.opus.stereo or options.codecParams.audio.opus["sprop-stereo"] is configured, this overrides the options.audio.stereo setting.
The flag if OPUS audio codec stereo band should be configured for sending encoded audio data. When not provided, the default browser configuration is used.

usedtx Boolean <optional>

Deprecation Warning! This property has been deprecated. Configure this with the options.codecParams.audio.opus.stereo parameter in the initOptions instead. If the options.codecParams.audio.opus.stereo is configured, this overrides the options.audio.stereo setting. Note that this feature might not work depending on the browser support and implementation.
The flag if OPUS audio codec should enable DTX (Discontinuous Transmission) for sending encoded audio data. This might help to reduce bandwidth as it reduces the bitrate during silence or background noise, and goes hand-in-hand with the options.voiceActivityDetection flag in joinRoom() method. When not provided, the default browser configuration is used.

useinbandfec Boolean <optional>

Deprecation Warning! This property has been deprecated. Configure this with the options.codecParams.audio.opus.useinbandfec parameter in the initOptions instead. If the options.codecParams.audio.opus.useinbandfec is configured, this overrides the options.audio.useinbandfec setting. Note that this parameter should only be used for debugging purposes only.
The flag if OPUS audio codec has the capability to take advantage of the in-band FEC (Forward Error Correction) when sending encoded audio data. This helps to reduce the harm of packet loss by encoding information about the previous packet loss. When not provided, the default browser configuration is used.

maxplaybackrate Number <optional>

Deprecation Warning! This property has been deprecated. Configure this with the options.codecParams.audio.opus.maxplaybackrate parameter in the initOptions instead. If the options.codecParams.audio.opus.maxplaybackrate is configured, this overrides the options.audio.maxplaybackrate setting. Note that this feature might not work depending on the browser support and implementation. Note that this parameter should only be used for debugging purposes only.
The OPUS audio codec maximum output sampling rate in Hz (hertz) that is is capable of receiving decoded audio data, to adjust to the hardware limitations and ensure that any sending audio data would not encode at a higher sampling rate specified by this. This value must be between 8000 to 48000. When not provided, the default browser configuration is used.

mute Boolean <optional>
false

The flag if audio tracks should be muted upon receiving them. Providing the value as false sets peerInfo.mediaStatus.audioMuted to 1, but when provided as true, this sets the peerInfo.mediaStatus.audioMuted value to 0 and mutes any existing shareScreen() stream audio tracks as well.

optional Array <optional>

This property has been deprecated. "optional" constraints has been moved from specs.
Note that this may result in constraints related error when options.useExactConstraints value is true. If you are looking to set the requested source id of the audio track, use options.audio.deviceId instead.
The navigator.getUserMedia() API audio: { optional [..] } property.

deviceId String <optional>

Note this is currently not supported in Firefox browsers.
The audio track source id of the device to use. The list of available audio source id can be retrieved by the mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices.

echoCancellation Boolean <optional>
true

For Chrome/Opera/IE/Safari/Bowser, the echo cancellation @description Methodality may not work and may produce a terrible feedback. It is recommended to use headphones or other microphone devices rather than the device in-built microphones.
The flag to enable echo cancellation for audio track.

video Boolean | JSON <optional>
false

Note that the current Edge browser implementation does not support the options.video.optional, options.video.deviceId, options.video.resolution and options.video.frameRate, options.video.facingMode.
The video configuration options.

Properties
Name Type Attributes Default Description
mute Boolean <optional>
false

The flag if video tracks should be muted upon receiving them. Providing the value as false sets the peerInfo.mediaStatus.videoMuted value to 1, but when provided as true, this sets the peerInfo.mediaStatus.videoMuted value to 0 and mutes any existing shareScreen() stream video tracks as well.

resolution JSON <optional>

The video resolution. By default, VGA resolution option is selected when not provided. [Rel: VIDEO_RESOLUTION]

Properties
Name Type Attributes Description
width Number | JSON <optional>

The video resolution width.

  • When provided as a number, it is the video resolution width.
  • When provided as a JSON, it is the navigator.mediaDevices.getUserMedia() .width settings. Parameters are "ideal" for ideal resolution width, "exact" for exact video resolution width, "min" for min video resolution width and "max" for max video resolution width. Note that this may result in constraints related errors depending on the browser/hardware supports.
height Number | JSON <optional>

The video resolution height.

  • When provided as a number, it is the video resolution height.
  • When provided as a JSON, it is the navigator.mediaDevices.getUserMedia() .height settings. Parameters are "ideal" for ideal video resolution height, "exact" for exact video resolution height, "min" for min video resolution height and "max" for max video resolution height. Note that this may result in constraints related errors depending on the browser/hardware supports.
frameRate Number | JSON <optional>

The video https://en.wikipedia.org/wiki/Frame_rate per second (fps).

  • When provided as a number, it is the video framerate.
  • When provided as a JSON, it is the navigator.mediaDevices.getUserMedia() .frameRate settings. Parameters are "ideal" for ideal video framerate, "exact" for exact video framerate, "min" for min video framerate and "max" for max video framerate. Note that this may result in constraints related errors depending on the browser/hardware supports.
optional Array <optional>

This property has been deprecated. "optional" constraints has been moved from specs.
Note that this may result in constraints related error when options.useExactConstraints value is true. If you are looking to set the requested source id of the video track, use options.video.deviceId instead.
The navigator.getUserMedia() API video: { optional [..] } property.

deviceId String <optional>

Note this is currently not supported in Firefox browsers.
The video track source id of the device to use. The list of available video source id can be retrieved by the mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices.

facingMode String | JSON <optional>

The video camera facing mode. The list of available video source id can be retrieved by the /en-US/docs/Web/API/MediaTrackConstraints/facingMode.

Since:
  • 0.5.6
Source:
Fires:
  • If retrieval of fallback audio stream is successful:
    - mediaAccessSuccessEvent 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)
      - mediaAccessFallbackEvent 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
    - mediaAccessErrorEvent with parameter payload isScreensharing=false and isAudioFallbackError=false.
  • If retrieval of fallback audio stream is successful:
    - mediaAccessSuccessEvent with parameter payload isScreensharing=false and isAudioFallback=true.
  • If retrieval of fallback audio stream is unsuccessful:
    - mediaAccessFallbackEvent with parameter payload state=ERROR, isScreensharing=false and isAudioFallback=true.
    - mediaAccessErrorEvent 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);
Example 6: Get media sources before joinRoom - only available on Chrome browsers

const audioInputDevices = [];
const videoInputDevices = [];

navigator.mediaDevices.enumerateDevices().then((devices) => {
  devices.forEach((device) => {
    if (device.kind === "audioinput") {
      audioInputDevices.push(device);
    }

    if (device.kind === "videoinput") {
      videoInputDevices.push(device);
    }
  })
}).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);

(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 prefetchedStream = skylink.getUserMedia();

skylink.joinRoom(prefetchedStream)
   .catch((error) => {
   // handle error
   });

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

Method that stops all room sessions.

Since:
  • 2.0.0
Source:

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

Method that stops the room session.

Parameters:
Name Type Description
roomName String

The room name to leave.

Since:
  • 0.5.5
Source:
Fires:
  • peerLeft 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:
  • roomLockEvent 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: localMediaMutedEvent, streamMuted, peerUpdatedEvent 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: streamMuted, peerUpdatedEvent 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.

Note that Edge browser does not support renegotiation. For MCU enabled peer connections with options.mcuUseRenegoRestart set to false in the initOptions, the restart method may differ, you may learn more about how to workaround it in this article here. For restarts with peers connecting from Android, iOS or C++ SDKs, restarts might not work as written in this article here. Note that this functionality should be used when peer connection stream freezes during a connection. For a better user experience for only MCU enabled peer connections, the method is throttled when invoked many times in less than the milliseconds interval configured in initOptions.
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 Skylink#joinRoomagain, 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 state can be retrieved with the iceConnectionStateEvent

options JSON <optional>

Note that for MCU connections, the bandwidth or googleXBandwidth 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 Skylink#joinRoom options.bandwidth settings.

googleXBandwidth JSON <optional>

The configuration to set the experimental google video streaming bandwidth sent to peers. Object signature follows Skylink#joinRoom options.googleXBandwidth 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");

sendMessage(roomName, message, targetPeerIdopt)

Function that sends a message to peers via the Signaling socket connection.

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.
Since:
  • 0.4.0
Source:
Fires:
Examples
Example 1: Broadcasting to all peers

let sendMessage = (roomName) => {
   const message = "Hi!";
   const selectedPeers = this.state[location]['selectedPeers'];
   this.skylink.sendMessage(roomName, message, selectedPeers);
}
Example 2: Broadcasting to selected peers

let sendMessage = (roomName) => {
   const message = "Hi all!";
   const selectedPeers = ["PeerID_1", "PeerID_2"];
   this.skylink.sendMessage(roomName, message, selectedPeers);
}

sendP2PMessage(roomNameopt, message, targetPeerIdopt)

Method that sends a message to peers via the data channel connection. Consider using sendURLData if you are sending large strings to peers.

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(message, null, roomName);
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(message, targetPeerId, roomName);
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(message, selectedPeers, roomName);
// 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.

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 Description
roomName String

The room name.

options JSON | MediaStream

The getUserMedia options parameter settings. The MediaStream to send to the remote peer.

  • 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.
Since:
  • 0.5.6
Source:
Fires:
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:

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, replaceUserMediaStream, streamIdopt) → {MediaStream|null}

Method that returns starts screenshare and returns the stream.

Parameters:
Name Type Attributes Description
roomName String

The room name.

replaceUserMediaStream Boolean

The flag if screenshare replaces the userMedia stream.

streamId String <optional>

The stream id of the userMedia stream to replace. streamId must be provided if there is more than one userMedia stream on the peer connection and replaceUserMediaStream is true.

Since:
  • 2.0.0
Source:
Example
Example 1: Replace selected stream with screen share stream

let shareScreenReplace = () => {
   // Retrieve all userMedia streams
   const streamList = skylink.getStreams(roomName);
   skylink.shareScreen(roomName, true, Object.keys(streamList.userMedia)[0]).then((screenStream) => {
     window.attachMediaStream(localVideoElement, screenStream);
   });
}

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:
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:
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:
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:
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:
  • mediaAccessStoppedEvent with parameter payload isScreensharing value as true and isAudioFallback value as false if there is a screen stream
  • streamEndedEvent with parameter payload isSelf value as true and isScreensharing value as true if user is in the room
  • peerUpdatedEvent with parameter payload isSelf value as true
  • onIncomingStreamEvent 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 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:
  • mediaAccessStoppedEvent with parameter payload isSelf=true and isScreensharing=false if there is a getUserMedia stream.
  • streamEndedEvent with parameter payload isSelf=true and isScreensharing=false if there is a getUserMedia stream and user is in a room.
  • peerUpdatedEvent with parameter payload isSelf=true.
Example
skylink.stopStreams(roomName)
.then(() => // do some thing);

unlockRoom(roomName) → {Boolean}

Method that unlocks a room.

Parameters:
Name Type Description
roomName String

The room name.

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