SkylinkEvents

SkylinkEvents

Events triggered by SkylinkJS. Event constants referenced here - SkylinkConstants.EVENTS

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

candidateGenerationState

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 SkylinkRoom

The current room

peerId String

The peer's id

state SkylinkConstants.CANDIDATE_GENERATION_STATE

The current Peer connection ICE gathering state.

Source:

candidateProcessingState

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 SkylinkRoom

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:

candidatesGathered

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 SkylinkRoom

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:

channelClose

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:

channelError

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:

channelMessage

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:

channelOpen

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:

channelReopen

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(el, stream);
  })
});

channelRetry

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:

encryptSecretsUpdated

Event triggered when encrypt secret data is updated.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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 peerJoinedEvent.

Source:

getConnectionStatusStateChange

Event triggered when PeerConnection.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 getConnectionStatus() retrieval state.

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:

getPeersStateChange

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:

handshakeProgress

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 SkylinkRoom

The room.

error Error | String <optional>

The error object. Defined only when state is ERROR.

Source:

localMediaMuted

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:

loggedOnConsole

Event triggered when Skylink logs to browser's console.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
level JSON

The log level.

message String

The log message.

debugObject JSON

A JavaScript object to be logged to help with analysis.

Source:

mediaAccessError

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:

mediaAccessFallback

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 had failed to retrieve both audio and video tracks.

streamId String

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

Source:

mediaAccessRequired

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

Parameters:
Name Type Description
detail Object

Event's payload.

Source:

mediaAccessStopped

Event triggered when Stream has stopped streaming.

Parameters:
Name Type Description
detail.isScreensharing Object

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

detail.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.

detail.streamId String

The Stream ID.

Source:

mediaAccessSuccess

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.

Source:

onDataChannelStateChanged

Event triggered when a Datachannel connection state has changed.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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:

onIncomingMessage

Event triggered when receiving message from Peer.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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 Skylink#sendMessage. Defined as User's Peer ID when isSelf payload value is false. Defined as null when provided targetPeerId in Skylink#sendP2PMessage or Skylink#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 Skylink#sendP2PMessage or Skylink#sendMessage.

isDataChannel boolean

The flag if message is sent from Skylink#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 peerJoinedEvent.

isSelf boolean

The flag if Peer is User.

Source:

onIncomingScreenStream

Event triggered when receving Peer Screenshare Stream.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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.

isReplace Boolean

The flag if the incoming screenshare stream results from shareScreen() called with replaceUserMediaStream = true.

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:

onIncomingStream

Event triggered when receiving Peer Stream.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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.

isReplace String

The The flag if the incoming stream has replaced an existing stream.

replacedStreamId String

The streamId of the replaced stream.

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:

peerConnectionState

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:

peerJoined

Event triggered when a Peer joins the room.

Parameters:
Name Type Description
detail Object

Event's payload

Properties
Name Type Description
room SkylinkRoom

The current room.

peerId String

The Peer ID.

peerInfo peerInfo

The Peer session information.

isSelf boolean

The flag if Peer is User.

Source:

peerLeft

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:

peerUpdated

Event triggered when a Peer session information has been updated.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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 peerJoined event.

Source:

persistentMessageState

Event triggered when persistent message state changes.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

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 peerJoinedEvent.

Source:

readyStateChange

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 init() ready state.

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:

recordingState

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:

roomLock

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 peerJoined event.

isSelf Boolean

The flag if User changed the Room locked status.

Source:

rtmpState

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:

serverPeerJoined

Event triggered when a server Peer joins the room.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

The current room

peerId String

The peer's id

serverPeerType SkylinkConstants.SERVER_PEER_TYPE

The server Peer type

Source:

serverPeerLeft

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 SkylinkRoom

The room.

serverPeerType SkylinkConstants.SERVER_PEER_TYPE

The server Peer type

Source:

sessionDisconnect

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 thepeerJoined event.

Source:

socketError

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:

storedMessages

Event triggered when receiving stored messages from the Signaling Server.

Parameters:
Name Type Description
detail Object

Event's payload.

Properties
Name Type Description
room SkylinkRoom

The current room

storedMessages Array

The stored messages result.

Properties
Name Type Description
targetPeerId String

The value of the targetPeerId defined in Skylink#sendP2PMessage or Skylink#sendMessage. Defined as User's Peer ID when isSelf payload value is false. Defined as null when provided targetPeerId in Skylink#sendP2PMessage or Skylink#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 Skylink#sendP2PMessage or Skylink#sendMessage. Value will always be false for stored messages.

isDataChannel boolean

The flag if message is sent from Skylink#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 peerJoinedEvent.

isSelf boolean

The flag if Peer is User.

Source:

streamEnded

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 SkylinkRoom

The room.

peerInfo peerInfo

The Peer session information. Object signature matches the peerInfo parameter payload received in the peerJoined 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:

streamMuted

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 peerJoined event.

isSelf Boolean

The flag if Peer is User.

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:

systemAction

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. [Rel: Skylink.SYSTEM_ACTION]

message String

The message.

reason SkylinkConstants.SYSTEM_ACTION_REASON

The Signaling server reaction state reason of action code.

Source: