LogoLogo
WherebyStatusCommunity
  • 📹Whereby 101
    • Create Your Video Experience
      • Get started in 3 steps
      • Embedding Whereby in a web app
        • Using Whereby's Web Component & Pre-built UI
          • Script Tags
          • With Low Code
            • Embedding in Squarespace or Wordpress
            • No code video conferencing in Bubble
        • Using Whereby's Browser SDK with React Hooks for a fully custom UI
      • Embedding Whereby in a mobile app
        • Embedding Whereby in iOS
          • Using Whereby's Native iOS SDK
        • Embedding Whereby in Android
          • Using Whereby's Native SDK
        • Using Flutter
        • Using React Native
      • Github SDK Examples
      • Meeting scheduling with Cronofy
    • Generating Room URLs
      • Name prefixes
      • Using “Create a room”
      • Using Postman
    • Customize Your Video Experience
      • During room creation
      • Using Attributes/URL Params
      • Global preferences
      • Branding elements
      • Dial-In
      • File sharing
      • Breakout Groups with Embedded
      • Waiting Rooms
    • User roles & Meeting Permissions
    • FAQ
      • Accessibility
      • Whereby Words
      • Firewall & Security
      • HIPAA compliant setup
      • Allowed Domains & Localhost
      • Whereby Embedded Feature Comparison
  • 🔍Meeting Content & Quality
    • Recording
      • Cloud Recording
      • Local Recording
    • Transcribing
      • Session Transcription
      • Recording Transcription
    • Live Captions
    • Session summaries
    • Live streaming RTMP
    • Quality Insights
      • Real-time troubleshooting
      • Using the Insights dashboard
      • Improving call quality
      • Tracking room events with Webhooks
  • 🤷End User
    • End User Support Guides
      • Supported Browsers & Devices
      • Screen Sharing Setup & Usage
      • Using Breakout Groups
      • Troubleshooting & Basics
  • 🚚Developer Guides
    • Quickly deploy Whereby to your domain
    • Tracking Customer Usage
    • Migrating from Twilio
      • Twilio JS SDK Quick Migration
      • Twilio JS SDK Direct Migration
  • 🖥️Reference
    • REST API Reference
      • /meetings
      • /insights
      • /recordings
      • /transcriptions
      • /summaries
      • /rooms
    • Web Component Reference
    • React Hooks Reference
      • Quick Start
        • Getting started with the Browser SDK
      • Guides & Tutorials
        • Migrate from version 2.x to 3
        • Grid logic
        • Custom Video Tiles with React
        • Usage with Next.js
        • How to customize the toolbar
      • API Reference
        • WherebyProvider
        • VideoView
        • VideoGrid
        • useLocalMedia
        • useRoomConnection
      • Types
    • React Native Reference
      • Quick Start
      • WherebyEmbed
    • Webhooks Reference
Powered by GitBook
On this page
  • Parameters
  • Return type
  • state
  • actions
  • Usage

Was this helpful?

Edit on GitHub
  1. Reference
  2. React Hooks Reference
  3. API Reference

useLocalMedia

The useLocalMedia hook enables preview and selection of local devices (camera & microphone) prior to establishing a connection within a Whereby room. Use this hook to build rich pre-call and waiting room experiences, allowing end users to confirm their device selection up-front. This hook works seamlessly with the useRoomConnection hook.

useLocalMedia(mediaStreamConstraints: MediaStreamConstraints): Object | null

Parameters

Parameter
Required
Type
Description

mediaStreamConstraints

Options to use for initializing local media

Return type

The hook returns a LocalMediaReference object with the following properties.

Property
Type
Description

state

Object representing the state of local media

actions

Object representing the available actions on local media

state

The state of local media

Property
Type
Description

currentCameraDeviceId

string | undefined

The Id of the current camera device

currentMicrophoneDeviceId

string | undefined

The id of the current microphone device

cameraDeviceError

unknown

cameraDevices

List of the available camera devices

isSettingCameraDevice

boolean

isSettingMicrophoneDevice

boolean

isStarting

boolean

localStream

The stream of local media (camera & microphone)

lowDataMode

boolean

State of low data mode

microphoneDeviceError

unknown

microphoneDevices

List of the available microphone devices

speakerDevices

List of the available speaker devices

startError

unknown

actions

Name
Parameters
Description

setCameraDevice

(deviceId: string) => void

Change the current camera device

setMicrophoneDevice

(deviceId: string) => void

Change the current microphone device

setSpeakerDevice

(deviceId: string) => void

Change the current speaker device

toggleCameraEnabled

(enabled?: boolean) => void

Change the state of your camera. Omitting the enabled parameter toggles the current value

toggleMicrophoneEnabled

(enabled?: boolean) => void

Change the state of your microphone. Omitting the enabled parameter toggles the current value

toggleLowDataModeEnabled

(enabled?: boolean) => void

Change the state of low data mode. Omitting the enabled parameter toggles the current value

Usage

import { useLocalMedia, VideoView } from "@whereby.com/browser-sdk/react";

function MyPreCallUX() {
    const localMedia = useLocalMedia({ audio: false, video: true });

    const { currentCameraDeviceId, cameraDevices, localStream } = localMedia.state;
    const { setCameraDevice, toggleCameraEnabled } = localMedia.actions;

    return <div className="preCallView">
        { /* Render any UI, making use of state */ }
        { cameraDevices.map((d) => (
            <p
                key={d.deviceId}
                onClick={() => {
                    if (d.deviceId !== currentCameraDeviceId) {
                        setCameraDevice(d.deviceId);
                    }
                }}
            >
                {d.label}
            </p>
        )) }
        <VideoView muted stream={localStream} />
    </div>;
}

Last updated 1 year ago

Was this helpful?

[]

| undefined

[]

[]

The actions property contains a map of functions which can be invoked to perform an action on local media. All these functions are sync and return void, and you should rely on the to render the effect of their invocation.

🖥️
state
✅
LocalMediaState
LocalMediaActions
MediaStreamConstraints
MediaDeviceInfo
MediaStream
MediaDeviceInfo
MediaDeviceInfo