Media Devices

Media Devices

Check permission

checkPermission method helps to check whether permission is given or not for given type.

Parameters

NameTypeDescription
mediaDeviceKind'cam' | 'mic' | 'speaker'Type of device whose permission you want to check

Example

const isCamPermission = await huddleClient.localPeer.deviceHandler.checkPermission({
	mediaDeviceKind: 'cam'
});
 
const isMicPermission = await huddleClient.localPeer.deviceHandler.checkPermission({
	mediaDeviceKind: 'mic'
});

getMediaPermission

getMediaPermission method retrieves the media permission for the specified device type.

Parameters

NameTypeDescription
mediaDeviceKind'cam' | 'mic' | 'speaker'Type of device

Example

// Get permission for cam
await huddleClient.localPeer.deviceHandler.getMediaPermission({
	mediaDeviceKind: 'cam'
});
 
// Get permission for mic
await huddleClient.localPeer.deviceHandler.getMediaPermission({
	mediaDeviceKind: 'mic'
});

getMediaDevices

getMediaDevices method returns MediaDeviceInfo[], which contains a list of all the devices available in the system based on the specified deviceKind.

Parameters

NameTypeDescription
filterByDeviceKind'mic' | 'cam' | 'speaker'Type of device

Example

const camDevices = await huddleClient.localPeer.deviceHandler.getMediaDevices({
	filterByDeviceKind: 'cam' 
});
 
const micDevices = await huddleClient.localPeer.deviceHandler.getMediaDevices({
	filterByDeviceKind: 'mic' 
});
 
const speakerDevices = await huddleClient.localPeer.deviceHandler.getMediaDevices({
	filterByDeviceKind: 'speaker' 
});

setPreferredDevice

setPreferredDevice method sets the preferred device for the specified media kind.

Parameters

NameTypeDescription
deviceIdstringdevideId of the device you want to set as preferred
deviceKind'cam' | 'mic' | 'speaker'Type of device

Example

// Set preferred cam device
await huddleClient.localPeer.deviceHandler.setPreferredDevice({
  deviceId: 'YOUR_DEVICE_ID',
  deviceKind: 'cam'
});

fetchStream

fetchStream method retrieves the stream from the device for the specified media kind. If no preferred device is found, it will throw an error.

Parameters

NameTypeDescription
mediaDeviceKind'mic' | 'cam'Type of device

Example

const streamResponse = await huddleClient.localPeer.deviceHandler.fetchStream({mediaDeviceKind: 'cam'});
 
const stream = streamResponse.stream;

stopStream

stopStream method stops the stream from the device for the specified media kind. If no preferred device is found, it will throw an error.

Parameters

NameTypeDescription
mediaDeviceKind'mic' | 'cam'Type of device

Example

await huddleClient.localPeer.deviceHandler.stopStream({mediaDeviceKind: 'cam'});

fetchScreen

fetchScreen method retrieves the screen stream from the device.

Example

const streamResponse = await huddleClient.localPeer.deviceHandler.fetchScreen();
 
const stream = streamResponse.stream;

Events

NameDescriptionReturns
device-changeEmitted when a device is added or removed
permission-grantedEmitted when permission is granted for a device{ deviceKind: 'cam' | 'mic' | 'speaker' }
permission-deniedEmitted when permission is denied for a device{ deviceKind: 'cam' | 'mic' | 'speaker', error: Error }
preferred-device-changedEmitted when preferred device is changed{ deviceKind: 'cam' | 'mic' | 'speaker', deviceId: string | null }

Example

huddleClient.localPeer.deviceHandler.on('device-change', (devices) => {
  console.log('devices', devices);
});
Audio/Video Infrastructure designed for developers to empower them to ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.