diff --git a/src/livekit/options.ts b/src/livekit/options.ts new file mode 100644 index 0000000..8bd4789 --- /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 90f9eba..4bd68a6 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.