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
  • recordingType: Type of recording (e.g., "a" for audio-only, "av" for audio/video)

Example:

samvyoInstance.on("recordingStarted", ({peerId, startTime, recordingType}) => {
  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
});

liveStreamingStarted

Emitted when a live stream to an external RTMP endpoint has started.

Parameters:

  • startTime: The timestamp when streaming started.

Example:

samvyoInstance.on("liveStreamingStarted", ({ startTime }) => {
  console.log(`Live streaming started at ${startTime}`);
});

liveStreamingEnded

Emitted when the live stream is stopped.

Parameters:

  • peerId: The ID of the peer who stopped the stream (usually the moderator).

Example:

samvyoInstance.on("liveStreamingEnded", ({ peerId }) => {
  console.log("Live streaming ended by peer:", peerId);
});

transcriptionStarted

Emitted when the transcription service has successfully started.

Example:

samvyoInstance.on("transcriptionStarted", () => {
  console.log("Transcription service started");
});

transcriptionStopped

Emitted when the transcription service has stopped.

Example:

samvyoInstance.on("transcriptionStopped", () => {
  console.log("Transcription service stopped");
});

transcription

Emitted when a transcription result is received (e.g., from Deepgram).

Parameters:

  • transcript: The transcribed text.
  • isFinal: Boolean indicating if the result is final or interim.
  • peerId: The ID of the speaker.

Example:

samvyoInstance.on("transcription", (data) => {
  console.log(`Transcription [${data.isFinal ? 'Final' : 'Interim'}]: ${data.transcript}`);
});

transcriptionError

Emitted when an error occurs with the transcription service.

Parameters:

  • error: The error message string.

Example:

samvyoInstance.on("transcriptionError", ({ error }) => {
  console.error("Transcription error:", error);
});

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

customMessage

Emitted when a custom message is received from another peer.

Parameters:

  • data: The custom message payload.
  • type: The type of the message.
  • peerId: The ID of the sender.
  • senderType: The type of the sender (e.g., "participant").
  • messageType: The subtype of the message.
  • customData: Additional metadata.

Example:

samvyoInstance.on("customMessage", (message) => {
  console.log(`Received custom message from ${message.peerId}:`, message.data);
});

participantUpgraded

Emitted when a participant is upgraded to a presenter.

Parameters:

  • peerId: The ID of the upgraded peer.
  • audioStatus: Boolean, if audio is enabled.
  • videoStatus: Boolean, if video is enabled.
  • participantType: "presenter".

Example:

samvyoInstance.on("participantUpgraded", (data) => {
  console.log(`Peer ${data.peerId} upgraded to presenter.`);
});

participantDowngraded

Emitted when a participant is downgraded to a viewer.

Parameters:

  • peerId: The ID of the downgraded peer.
  • participantType: "viewer".

Example:

samvyoInstance.on("participantDowngraded", (data) => {
  console.log(`Peer ${data.peerId} downgraded to viewer.`);
});

upgraded

Emitted to the local user when they are upgraded to a presenter.

Parameters:

  • audioStatus: Boolean, if audio is enabled.
  • videoStatus: Boolean, if video is enabled.
  • participantType: "presenter".

Example:

samvyoInstance.on("upgraded", (data) => {
  console.log("I have been upgraded to presenter!", data);
});

upgradeRequestSent

Emitted when an upgrade request is successfully sent.

Parameters:

  • peerId: The ID of the target peer.
  • status: The status of the request.

Example:

samvyoInstance.on("upgradeRequestSent", (data) => {
  console.log(`Upgrade request sent to ${data.peerId}`);
});

upgradeRequestRejected

Emitted when a moderator rejects an upgrade request.

Parameters:

  • moderatorPeerId: The ID of the moderator who rejected the request.

Example:

samvyoInstance.on("upgradeRequestRejected", (data) => {
  console.log(`Upgrade request rejected by ${data.moderatorPeerId}`);
});

handRaised

Emitted when a peer raises their hand.

Parameters:

  • peerId: The ID of the peer who raised their hand.

Example:

samvyoInstance.on("handRaised", ({ peerId }) => {
  console.log(`Peer ${peerId} raised their hand.`);
});

handDropped

Emitted when a peer's hand is lowered.

Parameters:

  • peerId: The ID of the peer whose hand was lowered.
  • moderator: Boolean, true if lowered by a moderator.

Example:

samvyoInstance.on("handDropped", ({ peerId, moderator }) => {
  console.log(`Peer ${peerId} hand lowered. Moderator action: ${moderator}`);
});

peersWaiting

Emitted when there are peers waiting in the lobby (for locked rooms or approval).

Parameters:

  • peersWaiting: Array of waiting peer objects.
  • count: Number of waiting peers.

Example:

samvyoInstance.on("peersWaiting", ({ peersWaiting, count }) => {
  console.log(`${count} peers are waiting to join.`);
});

roomClosed

Emitted when the room is closed by a moderator or the system.

Parameters:

  • roomId: The ID of the closed room.
  • reason: Reason for closure (e.g., "removed_by_moderator").

Example:

samvyoInstance.on("roomClosed", (data) => {
  console.log("Room closed:", data.reason);
});

roomLockStatusChanged

Emitted when the room is locked or unlocked by a moderator.

Parameters:

  • locked: Boolean, true if the room is locked.
  • message: Status message string.

Example:

samvyoInstance.on("roomLockStatusChanged", ({ locked, message }) => {
  console.log(`Room is now ${locked ? 'locked' : 'unlocked'}: ${message}`);
});

upgradeLimitReached

Emitted when a participant cannot be upgraded because the maximum number of presenters has been reached.

Parameters:

  • limit: The maximum number of presenters allowed.
  • message: Error message string.

Example:

samvyoInstance.on("upgradeLimitReached", ({ limit, message }) => {
  console.warn(`Cannot upgrade: ${message}. Limit is ${limit}.`);
});

screenShareLimitReached

Emitted when a user tries to share their screen but the room's limit for simultaneous screen shares has been reached.

Parameters:

  • limit: The maximum number of screen shares allowed.
  • message: Error message string.

Example:

samvyoInstance.on("screenShareLimitReached", ({ limit, message }) => {
  console.warn(`Cannot share screen: ${message}. Limit is ${limit}.`);
});

micForcedOff

Emitted when the moderator forcefully mutes the local user's microphone.

Parameters:

  • message: Notification message string.

Example:

samvyoInstance.on("micForcedOff", ({ message }) => {
  console.log("Microphone was muted by moderator:", message);
});