VideoSDK Class Methods - Javascript
config()
- Before initializing the meeting, you will first need to provide
token
. By usingconfig()
method, you can set the token property of VideoSDK class. - Please refer this documentation to generate a token.
Returns
void
getDevices()
-
The
getDevices()
method returns a list of the currently available media input and output devices, such as microphones, cameras, headsets, and so forth. The returnedPromise
is resolved with an array ofDeviceInfo
objects describing the devices. -
DeviceInfo
class has four properties :-
DeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
DeviceInfo.groupId
- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
-
DeviceInfo.kind
- Returns an enumerated value that is either
videoinput
,audioinput
oraudiooutput
.
- Returns an enumerated value that is either
-
DeviceInfo.label
- Returns a string describing this device (for example "External USB Webcam").
-
Returns
Promise<Array<DeviceInfo>>
getCameras()
-
The
getCameras()
method returns a list of currently available video input devices. The returnedPromise
is resolved with an array ofCameraDeviceInfo
objects describing the video input devices. -
CameraDeviceInfo
class has four properties :-
CameraDeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
CameraDeviceInfo.groupId
- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
-
CameraDeviceInfo.kind
- Returns an enumerated value that is
videoinput
.
- Returns an enumerated value that is
-
CameraDeviceInfo.label
- Returns a string describing this device (for example "External USB Webcam").
-
Returns
Promise<Array<CameraDeviceInfo>>
getMicrophones()
-
The
getMicrophones()
method returns a list of currently available audio input devices. The returnedPromise
is resolved with an array ofMicrophoneDeviceInfo
objects describing the audio input devices. -
MicrophoneDeviceInfo
class has four properties :-
MicrophoneDeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
MicrophoneDeviceInfo.groupId
- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
-
MicrophoneDeviceInfo.kind
- Returns an enumerated value that is
audioinput
.
- Returns an enumerated value that is
-
MicrophoneDeviceInfo.label
- Returns a string describing this device (for example "External Microphone").
-
Returns
Promise<Array<MicrophoneDeviceInfo>>
getPlaybackDevices()
-
The
getPlaybackDevices()
method returns a list of currently available playback devices. The returnedPromise
is resolved with an array ofPlaybackDeviceInfo
objects describing the playback devices. -
PlaybackDeviceInfo
class has four properties :-
PlaybackDeviceInfo.deviceId
- Returns a string that is an identifier for the represented device, persisted across sessions.
-
PlaybackDeviceInfo.groupId
- Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
-
PlaybackDeviceInfo.kind
- Returns an enumerated value that is
audiooutput
.
- Returns an enumerated value that is
-
PlaybackDeviceInfo.label
- Returns a string describing this device (for example "External HeadPhones").
-
Returns
Promise<Array<PlaybackDeviceInfo>>
getNetworkStats()
- The
getNetworkStats()
method will return aPromise
that resolves with an object, containing network speed statistics or rejects with an error message, if the operation fails or exceeds the specified timeout. - The result object will include the
downloadSpeed
anduploadSpeed
, expressed in megabytes per second (MB/s).
Parameters
timeoutDuration
- It helps prevent the method from getting stuck indefinitely when fetching network statistics. It lets you set a maximum time for the operation, and if it takes longer than that, the method stops gracefully.
- You can specify
timeoutDuration
in milliseconds. If it is not provided or is not an integer, the default timeout is set to60,000
milliseconds (1 minute). Optional
Returns
Promise<{downloadSpeed: number,uploadSpeed: number}>
Example
try {
const options = { timeoutDuration: 45000 }; // Set a custom timeout of 45 seconds
const networkStats = await VideoSDK.getNetworkStats(options);
console.log("Download Speed: ", networkStats["downloadSpeed"]); // will return value in Mb/s
console.log("Upload Speed: ", networkStats["uploadSpeed"]); // will return value in Mb/s
} catch(ex)
{
console.log("Error in networkStats: ", ex);
}
requestPermission()
- The
requestPermission()
method prompts the user for permission to use a media input. It returns aPromise
that resolves to aMap<string, boolean>
object.
Parameters
Permission
- A
string
specifying the specific kinds of media, that you want to request. Optional
- Allow Values :
audio
,video
,audio_video
- Default :
audio_video
- A
Returns
Promise<Map<string, boolean>>
Example
try {
const requestPermission = await VideoSDK.requestPermission(
VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
console.log(
"request Audio and Video Permissions",
requestPermission.get(VideoSDK.Constants.permission.AUDIO),
requestPermission.get(VideoSDK.Constants.permission.VIDEO)
);
} catch(ex)
{
console.log("Error in requestPermission ", ex);
}
requestPermission()
will throw an error when matching media is not available.
checkPermissions()
- The
checkPermissions()
method checks for permission to use a media input. It returns aPromise
that resolves to aMap<string, boolean>
object.
Parameters
Permission
- A
string
specifying the types of media to check. Optional
- Allow Values :
audio
,video
,audio_video
- Default :
audio_video
- A
Returns
Promise<Map<string, boolean>>
Example
try {
const checkAudioVideoPermission = await VideoSDK.checkPermissions(
VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
console.log(
"check Audio and Video Permissions",
checkAudioVideoPermission.get(VideoSDK.Constants.permission.AUDIO),
checkAudioVideoPermission.get(VideoSDK.Constants.permission.VIDEO)
);
} catch(ex)
{
console.log("Error in checkPermissions ", ex);
}
checkPermissions()
will throw an error when the browser doesn't support permission check functionality.
on()
Parameters
- eventType :
event of VideoSDK class
- listener :
function
Returns
void
Example
//for device-changed-event
VideoSDK.on("device-changed", deviceChangeEventListener);
off()
Parameters
- eventType :
event of VideoSDK class
- listener :
function
Returns
void
Example
//for device-changed-event
VideoSDK.off("device-changed", deviceChangeEventListener);
Got a Question? Ask us on discord