Add screenshare support (#138)
This commit is contained in:
parent
238857f368
commit
c05ea63dae
@ -6,29 +6,30 @@ import { Track } from "livekit-client";
|
|||||||
type ConfigurationPanelItemProps = {
|
type ConfigurationPanelItemProps = {
|
||||||
title: string;
|
title: string;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
deviceSelectorKind?: MediaDeviceKind;
|
source?: Track.Source;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ConfigurationPanelItem: React.FC<ConfigurationPanelItemProps> = ({
|
export const ConfigurationPanelItem: React.FC<ConfigurationPanelItemProps> = ({
|
||||||
children,
|
children,
|
||||||
title,
|
title,
|
||||||
deviceSelectorKind,
|
source,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div className="w-full text-gray-300 py-4 border-b border-b-gray-800 relative">
|
<div className="w-full text-gray-300 py-4 border-b border-b-gray-800 relative">
|
||||||
<div className="flex flex-row justify-between items-center px-4 text-xs uppercase tracking-wider">
|
<div className="flex flex-row justify-between items-center px-4 text-xs uppercase tracking-wider">
|
||||||
<h3>{title}</h3>
|
<h3>{title}</h3>
|
||||||
{deviceSelectorKind && (
|
{source && (
|
||||||
<span className="flex flex-row gap-2">
|
<span className="flex flex-row gap-2">
|
||||||
<TrackToggle
|
<TrackToggle
|
||||||
className="px-2 py-1 bg-gray-900 text-gray-300 border border-gray-800 rounded-sm hover:bg-gray-800"
|
className="px-2 py-1 bg-gray-900 text-gray-300 border border-gray-800 rounded-sm hover:bg-gray-800"
|
||||||
source={
|
source={source}
|
||||||
deviceSelectorKind === "audioinput"
|
|
||||||
? Track.Source.Microphone
|
|
||||||
: Track.Source.Camera
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<PlaygroundDeviceSelector kind={deviceSelectorKind} />
|
{source === Track.Source.Camera && (
|
||||||
|
<PlaygroundDeviceSelector kind="videoinput" />
|
||||||
|
)}
|
||||||
|
{source === Track.Source.Microphone && (
|
||||||
|
<PlaygroundDeviceSelector kind="audioinput" />
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -79,9 +79,12 @@ export default function Playground({
|
|||||||
const localTracks = tracks.filter(
|
const localTracks = tracks.filter(
|
||||||
({ participant }) => participant instanceof LocalParticipant
|
({ participant }) => participant instanceof LocalParticipant
|
||||||
);
|
);
|
||||||
const localVideoTrack = localTracks.find(
|
const localCameraTrack = localTracks.find(
|
||||||
({ source }) => source === Track.Source.Camera
|
({ source }) => source === Track.Source.Camera
|
||||||
);
|
);
|
||||||
|
const localScreenTrack = localTracks.find(
|
||||||
|
({ source }) => source === Track.Source.ScreenShare
|
||||||
|
);
|
||||||
const localMicTrack = localTracks.find(
|
const localMicTrack = localTracks.find(
|
||||||
({ source }) => source === Track.Source.Microphone
|
({ source }) => source === Track.Source.Microphone
|
||||||
);
|
);
|
||||||
@ -339,15 +342,34 @@ export default function Playground({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
{localVideoTrack && (
|
{roomState === ConnectionState.Connected && config.settings.inputs.screen && (
|
||||||
|
<ConfigurationPanelItem
|
||||||
|
title="Screen"
|
||||||
|
source={Track.Source.ScreenShare}
|
||||||
|
>
|
||||||
|
{localScreenTrack ? (
|
||||||
|
<div className="relative">
|
||||||
|
<VideoTrack
|
||||||
|
className="rounded-sm border border-gray-800 opacity-70 w-full"
|
||||||
|
trackRef={localScreenTrack}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center justify-center text-gray-700 text-center w-full h-full">
|
||||||
|
Press the button above to share your screen.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</ConfigurationPanelItem>
|
||||||
|
)}
|
||||||
|
{localCameraTrack && (
|
||||||
<ConfigurationPanelItem
|
<ConfigurationPanelItem
|
||||||
title="Camera"
|
title="Camera"
|
||||||
deviceSelectorKind="videoinput"
|
source={Track.Source.Camera}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<VideoTrack
|
<VideoTrack
|
||||||
className="rounded-sm border border-gray-800 opacity-70 w-full"
|
className="rounded-sm border border-gray-800 opacity-70 w-full"
|
||||||
trackRef={localVideoTrack}
|
trackRef={localCameraTrack}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
@ -355,7 +377,7 @@ export default function Playground({
|
|||||||
{localMicTrack && (
|
{localMicTrack && (
|
||||||
<ConfigurationPanelItem
|
<ConfigurationPanelItem
|
||||||
title="Microphone"
|
title="Microphone"
|
||||||
deviceSelectorKind="audioinput"
|
source={Track.Source.Microphone}
|
||||||
>
|
>
|
||||||
<AudioInputTile trackRef={localMicTrack} />
|
<AudioInputTile trackRef={localMicTrack} />
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
@ -389,7 +411,8 @@ export default function Playground({
|
|||||||
localParticipant,
|
localParticipant,
|
||||||
name,
|
name,
|
||||||
roomState,
|
roomState,
|
||||||
localVideoTrack,
|
localCameraTrack,
|
||||||
|
localScreenTrack,
|
||||||
localMicTrack,
|
localMicTrack,
|
||||||
themeColors,
|
themeColors,
|
||||||
setUserSettings,
|
setUserSettings,
|
||||||
|
|||||||
@ -47,6 +47,11 @@ const settingsDropdown: SettingValue[] = [
|
|||||||
type: "inputs",
|
type: "inputs",
|
||||||
key: "mic",
|
key: "mic",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Allow screenshare",
|
||||||
|
type: "inputs",
|
||||||
|
key: "screen",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const SettingsDropdown = () => {
|
export const SettingsDropdown = () => {
|
||||||
@ -59,7 +64,7 @@ export const SettingsDropdown = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(setting.type === "inputs") {
|
if(setting.type === "inputs") {
|
||||||
const key = setting.key as "camera" | "mic";
|
const key = setting.key as "camera" | "mic" | "screen";
|
||||||
return config.settings.inputs[key];
|
return config.settings.inputs[key];
|
||||||
} else if(setting.type === "outputs") {
|
} else if(setting.type === "outputs") {
|
||||||
const key = setting.key as "video" | "audio";
|
const key = setting.key as "video" | "audio";
|
||||||
@ -77,7 +82,7 @@ export const SettingsDropdown = () => {
|
|||||||
if(setting.type === "chat") {
|
if(setting.type === "chat") {
|
||||||
newSettings.chat = newValue;
|
newSettings.chat = newValue;
|
||||||
} else if(setting.type === "inputs") {
|
} else if(setting.type === "inputs") {
|
||||||
newSettings.inputs[setting.key as "camera" | "mic"] = newValue;
|
newSettings.inputs[setting.key as "camera" | "mic" | "screen"] = newValue;
|
||||||
} else if(setting.type === "outputs") {
|
} else if(setting.type === "outputs") {
|
||||||
newSettings.outputs[setting.key as "video" | "audio"] = newValue;
|
newSettings.outputs[setting.key as "video" | "audio"] = newValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ export type UserSettings = {
|
|||||||
chat: boolean;
|
chat: boolean;
|
||||||
inputs: {
|
inputs: {
|
||||||
camera: boolean;
|
camera: boolean;
|
||||||
|
screen: boolean;
|
||||||
mic: boolean;
|
mic: boolean;
|
||||||
};
|
};
|
||||||
outputs: {
|
outputs: {
|
||||||
@ -49,6 +50,7 @@ const defaultConfig: AppConfig = {
|
|||||||
chat: true,
|
chat: true,
|
||||||
inputs: {
|
inputs: {
|
||||||
camera: true,
|
camera: true,
|
||||||
|
screen: true,
|
||||||
mic: true,
|
mic: true,
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
@ -117,6 +119,7 @@ export const ConfigProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
theme_color: params.get("theme_color"),
|
theme_color: params.get("theme_color"),
|
||||||
inputs: {
|
inputs: {
|
||||||
camera: params.get("cam") === "1",
|
camera: params.get("cam") === "1",
|
||||||
|
screen: params.get("screen") === "1",
|
||||||
mic: params.get("mic") === "1",
|
mic: params.get("mic") === "1",
|
||||||
},
|
},
|
||||||
outputs: {
|
outputs: {
|
||||||
@ -148,6 +151,7 @@ export const ConfigProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
const obj = new URLSearchParams({
|
const obj = new URLSearchParams({
|
||||||
cam: boolToString(us.inputs.camera),
|
cam: boolToString(us.inputs.camera),
|
||||||
mic: boolToString(us.inputs.mic),
|
mic: boolToString(us.inputs.mic),
|
||||||
|
screen: boolToString(us.inputs.screen),
|
||||||
video: boolToString(us.outputs.video),
|
video: boolToString(us.outputs.video),
|
||||||
audio: boolToString(us.outputs.audio),
|
audio: boolToString(us.outputs.audio),
|
||||||
chat: boolToString(us.chat),
|
chat: boolToString(us.chat),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user