LocalMediaClient
const localMedia = client.getLocalMedia();
LocalMediaClient manages the local audio/video streams and state of a client. It exposes state subscriptions and provides actions to manage media and devices. If you want the client to join the session with media, you should start local media before joining the room. Local media is retrieved from the WherebyClient.
Utilities
destroy
void
Destroy the LocalMediaClient instance.
State Subscriptions
All subscribe methods follow this format:
Call signature:
subscribeX(callback: (payload: T) => void: () => void
Contract: Invokes a callback on initial subscription and whenever the state changes.
Returns: an unsubscribe function
Methods
subscribeCameraDeviceError
error: unknown | null
Emits local camera device error if detected
subscribeIsSettingCameraDevice
isSetting: boolean
Emits true or false when the local camera device is being set
subscribeIsSettingMicrophoneDevice
isSetting: boolean
Emits true or false when the local microphone device is being set
subscribeMicrophoneDeviceError
error: unknown | null
Emits local microphone device error if detected
subscribeCurrentCamera
cameraId?: string
Emits the cameraId of the currently selected camera device
subscribeCurrentMicrophone
microphoneId?: string
Emits the cameraId of the currently selected microphone device
subscribeCurrentSpeaker
speakerId?: string
Emits the cameraId of the currently selected speaker device
subscribeLocalMediaStarting
starting: boolean
Emits true or false whether the localMedia is starting
subscribeLocalMediaStartError
error: unknown | null
Emits any local media starting errors
Actions
startMedia
options:
LocalMediaOptions
| MediaStream
(default { audio: true, video: true })
Promise<void>
Initializes local media (mic/camera). Pass constraints or an existing MediaStream
.
toggleMicrophone
(enabled?: boolean)
void
Enables / disables microphone
toggleLowDataMode
(enabled?: boolean)
void
Enables / disables low data mode
setCameraDevice
(deviceId: string)
void
Set the camera device to the specified deviceId
setMicrophoneDevice
(deviceId: string)
void
Set the microphone device to the specified deviceId
setSpeakerDevice
(deviceId: string)
void
Set the speaker device to the specified deviceId
stopMedia
void
Stops local media
Events
LocalMediaClient
extends EventEmitter
. You can listen to lifecycle and state change events directly:
import { LOCAL_STREAM_CHANGED } from "@whereby.com/core";
const localMedia = client.getLocalMedia();
function localMediaChanged(stream: MediaStream) {
console.log("Local media has changed", stream);
}
localMedia.on(LOCAL_STREAM_CHANGED, localMediaChanged);
LocalMediaEvents
CAMERA_DEVICE_ERROR_CHANGED
local-media:camera-device-error-changed
error: unknown | null
A camera error occurs
CAMERA_DEVICES_CHANGED
ocal-media:camera-devices-changed
cameraDevices:
MediaDeviceInfo
There's a change to camera devices
IS_SETTING_CAMERA_DEVICE
local-media:is-setting-camera-device
isSetting: boolean
Camera device is being set
IS_SETTING_MICROPHONE_DEVICE
local-media:is-setting-microphone-device
isSetting: boolean
Microphone device is being set
MICROPHONE_DEVICE_ERROR_CHANGED
ocal-media:microphone-device-error-changed
error: unknown | null
A microphone error occurs
MICROPHONE_DEVICES_CHANGED
ocal-media:microphone-devices-changed
microphoneDevices:
MediaDeviceInfo
There is a change to microphone devices
SPEAKER_DEVICES_CHANGED
local-media:speaker-devices-changed
speakerDevices:
MediaDeviceInfo
When there is a change to speaker devices
CURRENT_CAMERA_CHANGED
ocal-media:current-camera-changed
cameraId?: string
When selected camera is changed
CURRENT_MICROPHONE_CHANGED
local-media:current-microphone-changed
microphoneId?: string
When selected microphone is changed
CURRENT_SPEAKER_CHANGED
local-media:current-speaker-changed
speakerId?: string
When selected speaker is changed
LOCAL_MEDIA_STARTING
local-media:starting
starting: boolean
When local media is starting
LOCAL_STREAM_CHANGED
local-media:local-stream-changed
stream?: MediaStream
When media stream is changed
LOCAL_MEDIA_START_ERROR_CHANGED
ocal-media:start-error-changed
error: unknown | null
An error occus when starting local media
Last updated
Was this helpful?