This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeviceControls.tsx
86 lines (84 loc) · 2.04 KB
/
DeviceControls.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
PeerStatus,
UseMicrophoneResult,
UseCameraResult,
UseScreenShareResult,
} from "@jellyfish-dev/react-client-sdk";
import { TrackMetadata } from "./jellyfishSetup";
type DeviceControlsProps = {
status: PeerStatus;
metadata: TrackMetadata;
} & (
| {
device: UseMicrophoneResult<TrackMetadata>;
type: "audio";
}
| {
device: UseCameraResult<TrackMetadata>;
type: "video";
}
| {
device: UseScreenShareResult<TrackMetadata>;
type: "screenshare";
}
);
export const DeviceControls = ({ device, type, status, metadata }: DeviceControlsProps) => {
return (
<div className="flex flex-col gap-2">
<button
className="btn btn-success btn-sm"
disabled={!!device?.stream}
onClick={() => {
device?.start();
}}
>
Start {type} device
</button>
<button
className="btn btn-error btn-sm"
disabled={!device?.stream}
onClick={() => {
device?.stop();
}}
>
Stop {type} device
</button>
<button
className="btn btn-success btn-sm"
disabled={!device?.stream || device?.enabled}
onClick={() => {
device?.setEnable(true);
}}
>
Enable {type} track
</button>
<button
className="btn btn-error btn-sm"
disabled={!device?.enabled}
onClick={() => {
device?.setEnable(false);
}}
>
Disable {type} track
</button>
<button
className="btn btn-success btn-sm"
disabled={status !== "joined" || !device?.stream || !!device?.broadcast?.trackId}
onClick={() => {
device?.addTrack(metadata);
}}
>
Stream {type} track
</button>
<button
className="btn btn-error btn-sm"
disabled={status !== "joined" || !device?.stream || !device?.broadcast?.trackId}
onClick={() => {
device?.removeTrack();
}}
>
Stop {type} track stream
</button>
</div>
);
};