SkylinkEvents

SkylinkEvents

Since:
  • 2.0
Source:

Example

Import SkylinkEventManager and SkylinkConstants from 'skylinkjs'

Example 1: Adding a listener
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.ON_INCOMING_STREAM, evt => {
  const { detail } = evt;
  // do something
});

Example 2: Removing a listener
SkylinkEventManager.removeEventListener(SkylinkConstants.EVENTS.ON_INCOMING_STREAM, evt => {
  const { detail } = evt;
  // do something
});

Events

CANDIDATE_GENERATION_STATE

Event triggered when a Peer connection ICE gathering state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

state SkylinkConstants.CANDIDATE_GENERATION_STATE

The current Peer connection ICE gathering state.

Source:

CANDIDATE_PROCESSING_STATE

Event triggered when remote ICE candidate processing state has changed when Peer is using trickle ICE.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

state SkylinkConstants.CANDIDATE_PROCESSING_STATE

The ICE candidate processing state.

candidateId String

The remote ICE candidate session ID.

candidateType String

The remote ICE candidate type.

candidate Object

The remote ICE candidate.

Properties
Name Type Description
candidate String

The remote ICE candidate connection description.

sdpMid- String

The remote ICE candidate identifier based on the remote session description.

sdpMLineIndex number

The remote ICE candidate media description index (starting from 0) based on the remote session description.

error Error

The error object.

Source:

CANDIDATES_GATHERED

Event triggered when all remote ICE candidates gathering has completed and been processed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

candidatesLength Object

The remote ICE candidates length.

Properties
Name Type Description
expected number

The expected total number of remote ICE candidates to be received.

received number

The actual total number of remote ICE candidates received.

processed number

The total number of remote ICE candidates processed.

Source:

CHANNEL_CLOSE

Event triggered when socket connection to Signaling server has closed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
session socketSession

The socket connection session information.

Source:

CHANNEL_ERROR

This may be caused by Javascript errors in the event listener when subscribing to events.
It may be resolved by checking for code errors in your Web App in the event subscribing listener.
Event triggered when socket connection encountered exception.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
error Error | String

The error object.

session socketSession

The socket connection session information.

Source:

CHANNEL_MESSAGE

Note that this is used only for SDK developer purposes. Event triggered when receiving socket message from the Signaling server.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
message Object

The socket message object.

session socketSession

The socket connection session information.

Source:

CHANNEL_OPEN

Event triggered when socket connection to Signaling server has opened.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
session socketSession

The socket connection session information.

Source:

CHANNEL_REOPEN

Event triggered when socket connection to Signaling server has re-opened.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
session socketSession

The socket connection session information.

Source:
Example
Example 1: Listen on channelReopen to handle successful socket reconnection if socket was disconnected
(channelClose event emitted).
SkylinkEventManager.addEventListener(SkylinkConstants.EVENTS.CHANNEL_REOPEN, evt => {
  const { detail } = evt;
  skylink.leaveRoom() // call leaveRoom to ensure that previous peer information will be removed
  .then(() => skylink.joinRoom(joinRoomOptions))
  .then((streams) => {
    window.attachMediaStream(audioEl, streams[0]);
    window.attachMediaStream(videoEl, streams[1]);
  })
});

CHANNEL_RETRY

Event triggered when attempting to establish socket connection to Signaling server when failed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
fallbackType SkylinkConstants.SOCKET_FALLBACK

The current fallback state.

currentAttempt Number

The current socket reconnection attempt.

session socketSession

The socket connection session information.

Source:

DATA_CHANNEL_STATE

Event triggered when a Datachannel connection state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

state SkylinkConstants.DATA_CHANNEL_STATE

The current Datachannel connection state.

error Error

The error object. Defined only when state payload is ERROR or SEND_MESSAGE_ERROR.

channelName String

The Datachannel ID.

channelType SkylinkConstants.DATA_CHANNEL_TYPE

The Datachannel type.

messageType SkylinkConstants.DATA_CHANNEL_MESSAGE_ERROR

The Datachannel sending Datachannel message error type. Defined only when state payload is SEND_MESSAGE_ERROR.

bufferAmount Object

The Datachannel - buffered amount information.

Properties
Name Type Description
bufferedAmount number

The size of currently queued data to send on the Datachannel connection.

bufferedAmountLowThreshold number

Threshold The current buffered amount low threshold configured.

Source:

ENCRYPT_SECRETS_UPDATED

Event triggered when encrypt secret data is updated.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

encryptSecrets Object

The secretId and secret pair.

selectedSecretId String

The id of the secret that is used for encryption and decryption of messages. If value is an empty string, message will not be encrypted.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

Source:

GET_CONNECTION_STATUS_STATE_CHANGE

Event triggered when getConnectionStatus method retrieval state changes.

Parameters:
Name Type Description
detail Object

Event's payload/

Properties
Name Type Attributes Description
state SkylinkConstants.GET_CONNECTION_STATUS_STATE

The current retrieval state from getConnectionStatus method.

peerId String

The Peer ID.

stats statistics <optional>

The Peer connection current stats.

error Error

The error object. Defined only when state payload is RETRIEVE_ERROR.

Source:

GET_PEERS_STATE_CHANGE

Event triggered when getPeers method retrieval state changes.

Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
state SkylinkConstants.GET_PEERS_STATE

The current getPeers retrieval state.

privilegePeerId SkylinkUser.sid

The Users privileged Peer Id.

peerList Object

The list of Peer IDs Rooms within the same App space.

Properties
Name Type Description
#room Array

The list of Peer IDs associated with the Room defined in #room property.

Source:

HANDSHAKE_PROGRESS

Event triggered when a Peer connection establishment state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Attributes Description
state SkylinkConstants.HANDSHAKE_PROGRESS

The current Peer connection establishment state.

peerId String

The Peer ID.

room roomInfo

The room.

error Error | String <optional>

The error object. Defined only when state is ERROR.

Source:

ICE_CONNECTION_STATE

Learn more about how ICE works in this article here. Event triggered when a Peer connection ICE connection state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
state SkylinkConstants.ICE_CONNECTION_STATE

The current Peer connection ICE connection state.

state String

The Peer ID.

Source:

LOCAL_MEDIA_MUTED

Event triggered when muteStreams method changes User Streams audio and video tracks muted status.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
streamId String

The muted Stream Id.

isScreensharing Boolean

The flag if the media muted was screensharing.

mediaStatus JSON

The Peer streaming media status. This indicates the media status for both getUserMedia Stream and shareScreen Stream.

Properties
Name Type Description
audioMuted Boolean

The value of the audio status. If Peer mediaStatus is -1, audio is not present in the stream. If Peer mediaStatus is 1, audio is present in the stream and active (not muted). If Peer mediaStatus is 0, audio is present in the stream and muted.

videoMuted Boolean

The value of the video status. If Peer mediaStatus is -1, video is not present in the stream. If Peer mediaStatus is 1, video is present in the stream and active (not muted). If Peer mediaStatus is 0, video is present in the stream and muted.

Source:

MEDIA_ACCESS_ERROR

Event triggered when retrieval of Stream failed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
error Error | String

The error object.

isScreensharing Boolean

The flag if event occurred during shareScreen method and not getUserMedia method.

isAudioFallbackError Boolean

The flag if event occurred during retrieval of audio tracks only when getUserMedia method had failed to retrieve both audio and video tracks.

Source:

MEDIA_ACCESS_FALLBACK

Event triggered when Stream retrieval fallback state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
error JSON

The error result.

Properties
Name Type Description
error String

The error object.

diff JSON

The list of excepted but received audio and video tracks in Stream. Defined only when state payload is FALLBACKED.

video JSON

The expected and received video tracks.

Properties
Name Type Description
expected Number

The expected video tracks.

received Number

The received video tracks.

audio JSON

The expected and received audio tracks.

Properties
Name Type Description
expected Number

The expected audio tracks.

received Number

The received audio tracks.

state SkylinkConstants.MEDIA_ACCESS_FALLBACK_STATE

The fallback state.

isScreensharing boolean

The flag if event occurred during shareScreen method and not getUserMedia method.

isAudioFallback boolean

The flag if event occurred during retrieval of audio tracks only when getUserMedia method failed to retrieve both audio and video tracks.

streamId String

The Stream ID. Defined only when state payload is FALLBACKED.

Source:

MEDIA_ACCESS_REQUIRED

Event triggered when retrieval of Stream is required to complete joinRoom method request.

Parameters:
Name Type Description
detail Object

Event's payload.

Source:

MEDIA_ACCESS_STOPPED

Event triggered when Stream has stopped streaming.

Parameters:
Name Type Description
detail.isScreensharing Object

The flag if event occurred during shareScreen method and not jgetUserMedia method.

detail.isAudioFallback boolean

The flag if event occurred during retrieval of audio tracks only when jgetUserMedia method had failed to retrieve both audio and video tracks.

detail.streamId String

The Stream ID.

Source:

MEDIA_ACCESS_SUCCESS

Event triggered when retrieval of Stream is successful.

Parameters:
Name Type Description
detail Object
Properties
Name Type Description
stream MediaStream

The Stream object. To attach it to an element: attachMediaStream(videoElement, stream);.

isScreensharing Boolean

The flag if event occurred during shareScreen method and not getUserMedia method.

isAudioFallback Boolean

The flag if event occurred during retrieval of audio tracks only when getUserMedia method had failed to retrieve both audio and video tracks.

streamId String

The Stream ID.

isVideo boolean

The flag if the incoming stream has a video track.

isAudio boolean

The flag if the incoming stream has an audio track.

Source:

ON_INCOMING_MESSAGE

Event triggered when receiving message from Peer.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

message JSON

The message result.

Properties
Name Type Attributes Description
content JSON | string

The message.

senderPeerId String

The sender Peer ID.

targetPeerId String | Array <optional>

The value of the targetPeerId defined in Skylink#sendP2PMessage or sendMessage. Defined as User's Peer ID when isSelf payload value is false. Defined as null when provided targetPeerId in sendP2PMessage or sendMessage is not defined.

listOfPeers Array <optional>

The list of Peers that the message has been sent to. Defined only when isSelf payload value is true.

isPrivate boolean

The flag if message is targeted or not, basing off the targetPeerId parameter being defined in sendP2PMessage or sendMessage.

isDataChannel boolean

The flag if message is sent from sendP2PMessage.

timeStamp String

The time stamp when the message was sent.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

isSelf boolean

The flag if Peer is User.

Source:

ON_INCOMING_SCREEN_STREAM

Event triggered when receiving Peer Screenshare Stream.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room.

peerId String

The peer's id.

stream MediaStream

The Stream object.

streamId String

The Stream id.

isSelf Boolean

The flag if Peer is User.

peerInfo peerInfo

The Peer session information.

isVideo boolean

The flag if the incoming screen stream has a video track.

isAudio boolean

The flag if the incoming screen stream has an audio track.

Source:

ON_INCOMING_STREAM

Event triggered when receiving Peer Stream.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

stream MediaStream

The Stream object. To attach it to an element: attachMediaStream(videoElement, stream);.

streamId String

The stream id.

isSelf boolean

The flag if Peer is User.

peerInfo peerInfo

The Peer session information.

isVideo boolean

The flag if the incoming stream has a video track.

isAudio boolean

The flag if the incoming stream has an audio track.

Source:

PEER_CONNECTION_STATE

Event triggered when a Peer connection session description exchanging state has changed.

Learn more about how ICE works in this article here.
Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
state SkylinkConstants.PEER_CONNECTION_STATE

The current Peer connection session description exchanging states.

peerId String

The Peer ID

Source:

PEER_JOINED

Event triggered when a Peer joins the room.

PEER_JOINED event with isSelf=true indicates that the local peer has successfully joined the room. All call actions should be done after the PEER_JOINED event is registered. If MCU feature is enabled on the appKey, SERVER PEER JOINED is the corresponding event.
Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
room roomInfo

The current room.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information.

isSelf boolean

The flag if Peer is User.

Source:

PEER_LEFT

Event triggered when a Peer leaves the room.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in thepeerJoined event.

isSelf boolean

The flag if Peer is User.

Source:

PEER_UPDATED

Event triggered when a Peer session information has been updated.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

isSelf boolean

The flag if Peer is User.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

Source:

PERSISTENT_MESSAGE_STATE

Event triggered when persistent message state changes.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

isPersistent Object

The flag if messages should be persistent.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

Source:

READY_STATE_CHANGE

Event triggered when init() method ready state changes.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
readyState SkylinkConstants.READY_STATE_CHANGE

The current ready state when instantiating new Skylink().

error JSON

The error result. Defined only when state is ERROR.

Properties
Name Type Description
status Number

The HTTP status code when failed.

errorCode SkylinkConstants.READY_STATE_CHANGE_ERROR

The ready state change failure code.

content Error

The error object.

room String

The Room to The Room to retrieve session token for.

Source:

RECORDING_STATE

Event triggered when recording session state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
state SkylinkConstants.RECORDING_STATE

The current recording session state.

recordingId String

The recording session ID.

error Error | String

The error object. Defined only when state payload is ERROR.

Source:

ROOM_LOCK

Event triggered when Room locked status has changed.

Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
isLocked Boolean

The flag if Room is locked.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

isSelf Boolean

The flag if User changed the Room locked status.

Source:

ROOM_REJOIN

Event triggered when joinRoom can be re-initiated. This event is preceded by leaveRoom initiated by the SDK in response to peer connection changing to FAILED state.

Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
room roomInfo

The previous room

peerId String

The previous peer id

Source:

RTMP_STATE

Event triggered when rtmp session state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
state SkylinkConstants.RTMP_STATE

The current recording session state.

rtmpId String

The rtmp session ID.

error Error | String

The error object. Defined only when state payload is ERROR.

Source:

SERVER_PEER_JOINED

Event triggered when a server Peer joins the room.

  • SERVER_PEER_JOINED event indicates that the MCU has successfully joined the

room. All call actions should be done after the SERVER_PEER_JOINED event is registered. For P2P key, PEER JOINED is the corresponding event.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

peerId String

The peer's id

serverPeerType SkylinkConstants.SERVER_PEER_TYPE

The server Peer type

Source:

SERVER_PEER_LEFT

Event triggered when a server Peer leaves the room.

Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
peerId String

The Peer ID

room roomInfo

The room.

serverPeerType SkylinkConstants.SERVER_PEER_TYPE

The server Peer type

Source:

SESSION_DISCONNECT

Event triggered when Room session has ended abruptly due to network disconnections.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
peerId String

The User's Room session Peer ID

peerInfo peerInfo

The User's Room session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

Source:

SOCKET_ERROR

Event triggered when attempt to establish socket connection to Signaling server has failed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
errorCode SkylinkConstants.SOCKET_ERROR

The socket connection error code.

error Error | String | Number

The error object.

type SkylinkConstants.SOCKET_FALLBACK

The fallback state of the socket connection attempt.

session socketSession

The socket connection session information.

Source:

STORED_MESSAGES

Event triggered when receiving stored messages from the Signaling Server.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room roomInfo

The current room

storedMessages Array

The stored messages result.

Properties
Name Type Description
targetPeerId String

The value of the targetPeerId defined in sendP2PMessage or sendMessage. Defined as User's Peer ID when isSelf payload value is false. Defined as null when provided targetPeerId in sendP2PMessage or sendMessage is not defined.

senderPeerId JSON | String

The sender Peer ID.

content JSON | String

The message.

timeStamp JSON | String

The timestamp when the message was sent, in simplified extended ISO format.

isPrivate boolean

The flag if message is targeted or not, basing off the targetPeerId parameter being defined in sendP2PMessage or sendMessage. Value will always be false for stored messages.

isDataChannel boolean

The flag if message is sent from sendP2PMessage. Value will always be true for stored messages.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

isSelf boolean

The flag if Peer is User.

Source:

STREAM_ENDED

Event triggered when a Peer Stream streaming has stopped. Note that it may not be the currently sent Stream to User, and it also triggers when User leaves the Room for any currently sent Stream to User from Peer.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
peerId String

The Peer ID.

room roomInfo

The room.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

isSelf Boolean

The flag if Peer is User.

isScreensharing Boolean

The flag if Peer Stream is a screensharing Stream.

streamId String

The Stream ID.

isVideo boolean

The flag if the ended stream has a video track.

isAudio boolean

The flag if the ended stream has an audio track.

Source:

STREAM_MUTED

Event triggered when Peer Stream audio or video tracks has been muted / unmuted.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the PEER JOINED event.

isSelf Boolean

The flag if Peer is User.

isVideo boolean

The flag if the muted stream has a video track.

isAudio boolean

The flag if the muted stream has an audio track.

isScreensharing boolean

The flag if the muted stream is a screensharing stream.

Source:

SYSTEM_ACTION

Event triggered when Signaling server reaction state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
action SkylinkConstants.SYSTEM_ACTION

The current Signaling server reaction state.

message String

The message.

reason SkylinkConstants.SYSTEM_ACTION_REASON

The Signaling server reaction state reason of action code.

Source: