Methods and Events
Events

Events

List of all the methods and events available in the Samvyo SDK Instance, along with explanations and code examples for implementation.

micStart

Emitted when a new audio channel is created, indicating that a remote peer has started sending audio.

Parameters:

  • peerId: The ID of the peer sending audio.
  • micTrack: The audio track being sent.
  • type: Indicates whether the audio is from a local or remote source.

Example:

samvyoInstance.on("micStart", (data) => {
  console.log(`Audio started from peer: ${data.peerId}`);
  // Handle the incoming audio track
});

micEnd

Emitted when a remote audio channel is closed, indicating that the audio stream has ended.

Parameters:

  • peerId: The ID of the peer whose audio has ended.
  • micTrack: The audio traack that has ended.

Example:

samvyoInstance.on("micEnd", (data) => {
  console.log(`Audio ended from peer: ${data.peerId}`);
  // Update UI or internal state
});

videoStart

Emitted when a new video channel is created, indicating that a remote peer has started sending video.

Parameters:

  • peerId: The ID of the peer sending video.
  • videoTrack: The video track being sent.
  • type: Indicates the source of the video.

Example:

samvyoInstance.on("videoStart", (data) => {
  console.log(`Video started from peer: ${data.peerId}`);
  // Display the incoming video track
});

videoEnd

Emitted when a remote video channel is closed, indicating that the video stream has ended.

Parameters:

  • peerId: The ID of the peer whose video has ended.
  • videoTrack: The video track that has ended.

Example:

samvyoInstance.on("videoEnd", (data) => {
  console.log(`Video ended from peer: ${data.peerId}`);
  // Update UI or internal state
});

newPeer

Emitted when a new peer joins the room, providing details about the peer.

Parameters:

  • peerId: The ID of the new peer.
  • peerName: The name of the new peer.
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("newPeer", (data) => {
  console.log(`New peer joined: ${data.peerId}`);
  // Update UI to reflect new peer
});

peerLeft

Emitted when a peer leaves the room, allowing the application to handle peer disconnections.

Parameters:

  • peerId: The ID of the new peer.

Example:

samvyoInstance.on("peerLeft", (data) => {
  console.log(`Peer left: ${data.peerId}`);
  // Update UI to remove the peer
});

activeSpeaker

Emitted when a peer is detected as the active speaker, which can be used for UI updates.

Parameters:

  • peerId: The ID of the active speaker
  • volume: Volume of the current active speaker

Variables

  • These values are also available in the currentlyActiveSpeaker variable. It the peerId and the volume of currently active speaker. The value changes whenever the currently active speaker changes.
const currentlyActiveSpeaker = samvyoInstance.currentlyActiveSpeaker;

Example:

samvyoInstance.on("activeSpeaker", (data) => {
  console.log(`Active Speaker: ${data.peerId}`);
  // Update UI to highlight speaker
});

peerMuted / peerUnmuted

Emitted when a peer mutes or unmutes their audio, allowing for updates to the UI or internal state. Parameters:

  • peerId: The ID of the peer who muted/unmuted.
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("peerMuted", (data) => {
  console.log(`Peer muted: ${data.peerId}`);
  // Update UI to reflect muted state
});
samvyoInstance.on("peerUnMuted", (data) => {
  console.log(`Peer unmuted: ${data.peerId}`);
  // Update UI to reflect unmuted state
});

deviceListUpdated

Emitted when a new audioInput or videoInput device is detected. deviceList variable will be updated with all the avaliable devices

Example:

samvyoInstance.on("deviceListUpdated", () => {
  console.log(`New device detected`);
  // Update UI to let user know that a new device is detected
  const updatedDeviceList = samvyoInstance.deviceList;
});

updatedDeviceList will look similar to this

{ videoInputs:[{deviceId:"1234556assafdfrgregsrdfsfa", label:"logitech c320"},{deviceId:"1234556assafdfrbhbhgtdrtdghffsfa", label:"dell super hd a100"}],
	audioInputs:[{deviceId:"12qwertyueafdfrgregsrdfsfa", label:"logitech c320 mic"},{deviceId:"12345kjbdjsgygtusdbhbhgtdrtdghffsfa", label:"dell super hd a100 mic"}]}

ssVideoStart

Emitted when a screenshare is started by a peer.

Parameters:

  • peerId: The ID of the peer who started screen share.
  • videoTrack: Screen share video track
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("ssVideoStart", (data) => {
  console.log(`Screen share started by peer: ${data.peerId}`);
  // Update UI to display the screen to other users using videoTrack
});

ssVideoStop

Emitted when a screenshare is stoped by a peer.

Parameters:

  • peerId: The ID of the peer who stoped the screen share.
  • videoTrack: null
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("ssVideoStop", (data) => {
  console.log(`Screen share stoped by peer: ${data.peerId}`);
  // Update UI accordingly
});

ssAudioStart

Emitted when audio is shared along with screen share.

Parameters:

  • peerId: The ID of the peer who shared the audio along with screen share.
  • audioTrack: Audio track that is played during screen share
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("ssAudioStart", (data) => {
  console.log(`Audio and screen share started by peer: ${data.peerId}`);
  // Add new audio track
});

ssAudioStop

Emitted when audio is stoped during screen share.

Parameters:

  • peerId: The ID of the peer who stoped sharing the audio during screen share.
  • audioTrack: null
  • type: The type of peer(e.g., local or remote).

Example:

samvyoInstance.on("ssAudioStop", (data) => {
  console.log(`Audio stoped during screen share by peer: ${data.peerId}`);
  // Remove audio track that is being played
});

recordingStarted

Emitted when recording is started in a room.

Parameters:

  • peerId: The ID of the peer who started the recording(Only available to the user who started the recording).
  • startTime: The time when the recording is started

Example:

samvyoInstance.on("recordingStarted", ({peerId,startTime}) => {
  console.log(`Recording has been started in this room at ${startTime}`);
  // The start time is provided as a unix timestamp value, please use a library like moment to convert it to a readable format like "HH:MM DD-MM-YYYY"
});

recordingEnded

Emitted when recording is ended.

Parameters:

  • None

Example:

samvyoInstance.on("recordingEnded", ({}) => {
  console.log(`Recording has been ended in this room`);
  // Remove audio track that is being played
});

moderatorAuthentication

Emitted when a moderator authentication request is received.

Parameters:

  • moderatorName: Name of the moderator
  • requesterName: Name of the user requesting authentication
  • requesterPeerId: Peer ID of the user requesting authentication
  • text: Additional text message for the authentication request

Example:

samvyoInstance.on("moderatorAuthentication", (data) => {
  console.log(`Authentication request from ${data.requesterName} to ${data.moderatorName}`);
  // Handle moderator authentication request
});

authenticationRequested

Emitted when an authentication request is made.

Parameters:

  • requesterName: Name of the user requesting authentication
  • requesterId: ID of the user requesting authentication
  • text: Additional text message for the authentication request

Example:

samvyoInstance.on("authenticationRequested", (data) => {
  console.log(`Authentication requested by ${data.requesterName}`);
  // Handle authentication request
});

moderatorAuthStatus

Emitted when a moderator responds to an authentication request.

Parameters:

  • requesterId: ID of the user who requested authentication
  • moderatorActed: Boolean indicating whether the moderator approved or rejected the request

Example:

samvyoInstance.on("moderatorAuthStatus", (data) => {
  console.log(`Moderator ${data.moderatorActed ? 'approved' : 'rejected'} authentication for ${data.requesterId}`);
  // Handle moderator's authentication decision
});

notification

Emitted for various notification events in the system.

Parameters:

  • eventType: Type of the notification event
  • eventText: Text message describing the notification

Example:

samvyoInstance.on("notification", (data) => {
  console.log(`Notification: ${data.eventText}`);
  // Handle notification based on eventType
});

processingStarted

Emitted when file processing begins.

Parameters:

  • processingStartTime: Timestamp when processing started
  • requestId: Unique identifier for the processing request

Example:

samvyoInstance.on("processingStarted", (data) => {
  console.log(`Processing started at ${new Date(data.processingStartTime)}`);
  console.log(`Request ID: ${data.requestId}`);
  // Handle processing start
});

processingCompleted

Emitted when file processing is successfully completed.

Parameters:

  • totalProcessingTime: Total time taken for processing in seconds
  • hlsFileKey: Key of the generated HLS file
  • size: Size of the processed file in MB
  • originalFile: Information about the original input file
  • lastFile: Boolean indicating if this is the last file in the processing array
  • requestId: The request identifier

Example:

samvyoInstance.on("processingCompleted", (data) => {
  console.log(`Processing completed in ${data.totalProcessingTime} seconds`);
  console.log(`HLS file key: ${data.hlsFileKey}`);
  console.log(`File size: ${data.size}MB`);
  console.log(`Is last file: ${data.lastFile}`);
  // Handle processing completion
});

processingError

Emitted when an error occurs during file processing.

Parameters:

  • totalProcessingTime: Time taken before the error occurred
  • hlsFileKey: Key of the HLS file (if any was generated)
  • size: Size of the processed file (if any)
  • originalFile: Information about the original input file
  • lastFile: Boolean indicating if this was the last file in the processing array
  • requestId: The request identifier
  • error: Error details

Example:

samvyoInstance.on("processingError", (data) => {
  console.error(`Processing failed for request ${data.requestId}`);
  console.error(`Error: ${data.error}`);
  console.log(`Processing time before error: ${data.totalProcessingTime} seconds`);
  // Handle processing error
});