This repository was archived by the owner on Oct 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathApp.tsx
More file actions
118 lines (103 loc) · 2.84 KB
/
App.tsx
File metadata and controls
118 lines (103 loc) · 2.84 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { useEffect, useReducer } from 'react';
import {
RealtimeKitProvider,
useRealtimeKitClient,
useRealtimeKitMeeting,
useRealtimeKitSelector,
} from '@cloudflare/realtimekit-react';
import {
RtkCameraToggle,
RtkChatToggle,
RtkGrid,
RtkLogo,
RtkMeetingTitle,
RtkMicToggle,
RtkPollsToggle,
RtkScreenShareToggle,
RtkSetupScreen,
RtkSidebar,
RtkSpinner,
defaultConfig,
provideRtkDesignSystem,
} from '@cloudflare/realtimekit-react-ui';
const config = { ...defaultConfig };
if (config.root) {
config.root['dyte-participant-tile'] = (
config.root['dyte-participant-tile'] as any
).children;
}
function Meeting() {
const { meeting } = useRealtimeKitMeeting();
const roomJoined = useRealtimeKitSelector((m) => m.self.roomJoined);
const [states, updateStates] = useReducer(
(state: any, payload: any) => ({
...state,
...payload,
}),
{ meeting: 'joined', activeSidebar: false },
);
if (!meeting) {
return <RtkSpinner />;
}
if (!roomJoined) {
return <RtkSetupScreen meeting={meeting} />;
}
return (
<div
className="flex flex-col w-full h-full"
ref={(el) => {
el?.addEventListener('rtkStateUpdate', (e: any) => {
updateStates(e.detail);
});
}}
>
<header className="flex items-center gap-3 h-12 border-b w-full px-2 text-sm">
<RtkLogo meeting={meeting} />
<RtkMeetingTitle meeting={meeting} />
</header>
<main className="flex flex-1 p-2">
<RtkGrid meeting={meeting} config={config} />
{states.activeSidebar && <RtkSidebar meeting={meeting} states={states} />}
</main>
<footer className="p-2 flex place-items-center justify-center">
<RtkMicToggle meeting={meeting} />
<RtkCameraToggle meeting={meeting} />
<RtkScreenShareToggle meeting={meeting} />
<RtkChatToggle meeting={meeting} />
<RtkPollsToggle meeting={meeting} />
</footer>
</div>
);
}
function App() {
const [meeting, initMeeting] = useRealtimeKitClient();
useEffect(() => {
const searchParams = new URL(window.location.href).searchParams;
const authToken = searchParams.get('authToken');
if (!authToken) {
alert(
"An authToken wasn't passed, please pass an authToken in the URL query to join a meeting.",
);
return;
}
provideRtkDesignSystem(document.body, {
theme: 'light',
});
initMeeting({
authToken,
defaults: {
audio: false,
video: false,
},
}).then((m) => m?.join());
}, []);
// By default this component will cover the entire viewport.
// To avoid that and to make it fill a parent container, pass the prop:
// `mode="fill"` to the component.
return (
<RealtimeKitProvider value={meeting}>
<Meeting />
</RealtimeKitProvider>
);
}
export default App;