From 048dce05c381a307f54bd5e6d3e50ce2fd29e249 Mon Sep 17 00:00:00 2001 From: Daniel Abramov Date: Fri, 9 Jun 2023 19:04:46 +0200 Subject: [PATCH] Explicitly configure options for the LiveKit room --- src/livekit/options.ts | 45 +++++++++++++++++++++++++++++++++++++++ src/livekit/useLiveKit.ts | 3 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/livekit/options.ts diff --git a/src/livekit/options.ts b/src/livekit/options.ts new file mode 100644 index 00000000..8bd47898 --- /dev/null +++ b/src/livekit/options.ts @@ -0,0 +1,45 @@ +import { + AudioPresets, + DefaultReconnectPolicy, + RoomOptions, + ScreenSharePresets, + TrackPublishDefaults, + VideoPreset, + VideoPresets, +} from "livekit-client"; + +const publishOptions: TrackPublishDefaults = { + audioPreset: AudioPresets.music, + dtx: true, + red: true, + forceStereo: false, + simulcast: true, + videoSimulcastLayers: [VideoPresets.h180, VideoPresets.h216] as VideoPreset[], + screenShareEncoding: ScreenSharePresets.h1080fps15.encoding, + stopMicTrackOnMute: false, + videoCodec: "vp8", + videoEncoding: VideoPresets.h360.encoding, + backupCodec: { codec: "vp8", encoding: VideoPresets.h360.encoding }, +} as const; + +export const roomOptions: RoomOptions = { + // automatically manage subscribed video quality + adaptiveStream: true, + + // optimize publishing bandwidth and CPU for published tracks + dynacast: true, + + // capture settings + videoCaptureDefaults: { + resolution: VideoPresets.h360.resolution, + }, + + // publish settings + publishDefaults: publishOptions, + + // default LiveKit options that seem to be sane + stopLocalTrackOnUnpublish: true, + reconnectPolicy: new DefaultReconnectPolicy(), + disconnectOnPageLeave: true, + expWebAudioMix: false, +}; diff --git a/src/livekit/useLiveKit.ts b/src/livekit/useLiveKit.ts index 90f9eba1..4bd68a6b 100644 --- a/src/livekit/useLiveKit.ts +++ b/src/livekit/useLiveKit.ts @@ -7,6 +7,7 @@ import { import { MediaDevicesState, MediaDevices } from "../settings/mediaDevices"; import { LocalMediaInfo, MediaInfo } from "../room/VideoPreview"; +import { roomOptions } from "./options"; type LiveKitState = { // The state of the media devices (changing the devices will also change them in the room). @@ -25,7 +26,7 @@ type LiveKitState = { export function useLiveKit(): LiveKitState | undefined { // TODO: Pass the proper paramters to configure the room (supported codecs, simulcast, adaptive streaming, etc). const [room] = React.useState(() => { - return new Room(); + return new Room(roomOptions); }); // Create a React state to store the available devices and the selected device for each kind.