-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.js
233 lines (223 loc) · 6.4 KB
/
App.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import DailyIframe from "@daily-co/daily-js";
import { DailyProvider } from "@daily-co/daily-react";
import { useCallback, useEffect, useRef, useState } from "react";
import { ClosedCaptions, disableCCId } from "./ClosedCaptions";
import {
CustomButtonEffects,
assistantId,
transcriptId,
} from "./CustomButtonEffects";
import {
getDisableCCButton,
getOpenRobotButton,
getOpenTranscriptButton,
} from "../utils/custom-buttons";
import { GlobalStyles } from "./GlobalStyles";
import { CopyRoomURLButton } from "./CopyRoomURLButton";
import { useRouter } from "next/router";
import { AIAssistant } from "./AIAssistant";
import { Transcript } from "./Transcript";
export default function App() {
const { query } = useRouter();
const [url, setUrl] = useState("");
const [daily, setDaily] = useState(null);
const [isJoining, setIsJoining] = useState(false);
const [aiView, setAiView] = useState(null);
const wrapperRef = useRef(null);
const joinRoom = useCallback(async (url) => {
setIsJoining(true);
const response = await fetch("/api/create-session", {
method: "POST",
body: JSON.stringify({
room_url: url,
}),
});
const body = await response.json();
if (body.url) {
setUrl(body.url);
}
setIsJoining(false);
}, []);
useEffect(() => {
if (query.url && typeof query.url === "string") {
joinRoom(query.url);
}
}, [query]);
const handleSubmit = async (ev) => {
ev.preventDefault();
const roomUrl = ev.target.elements?.url?.value;
joinRoom(roomUrl);
};
useEffect(
function initAppEffect() {
if (!url) return;
const handleCustomButtonClick = (ev) => {
switch (ev.button_id) {
case assistantId:
setAiView((v) => (v === assistantId ? null : assistantId));
break;
case transcriptId:
setAiView((v) => (v === transcriptId ? null : transcriptId));
break;
}
};
const initFrame = async () => {
if (DailyIframe.getCallInstance()) {
await DailyIframe.getCallInstance().destroy();
}
const frame = DailyIframe.createFrame(wrapperRef.current, {
showLeaveButton: true,
showUserNameChangeUI: true,
url,
customTrayButtons: {
[assistantId]: getOpenRobotButton(),
[transcriptId]: getOpenTranscriptButton(),
[disableCCId]: getDisableCCButton(),
},
});
setDaily(frame);
await frame.join();
frame.on("custom-button-click", handleCustomButtonClick);
frame.once("left-meeting", () => {
frame.off("custom-button-click", handleCustomButtonClick);
frame.destroy();
setDaily(null);
setUrl("");
setAiView(null);
});
};
initFrame();
},
[url],
);
return (
<DailyProvider callObject={daily}>
<div className="App">
<h1>Daily AI Meeting Assistant Demo</h1>
{url ? (
<>
<div className="actions">
<CopyRoomURLButton url={url} />
</div>
<div className="container">
<div className="call">
<div
className="ai-view"
style={{ display: aiView ? "" : "none" }}
>
<div
style={{
display: aiView === assistantId ? "" : "none",
height: "100%",
}}
>
<AIAssistant roomUrl={url} />
</div>
<div
style={{
display: aiView === transcriptId ? "" : "none",
height: "100%",
}}
>
<Transcript roomUrl={url} />
</div>
</div>
<div id="frame" ref={wrapperRef} />
<ClosedCaptions
style={{
left: aiView ? `calc(50% + 150px)` : "50%",
maxWidth: aiView ? `calc(100% - 300px)` : "100%",
}}
/>
<CustomButtonEffects />
</div>
</div>
</>
) : (
<>
<p>
Join the call and the AI Assistant bot joins and starts
transcription automatically.
</p>
<p>
Once there's enough context, you can ask the AI for a summary or
other information, based on the spoken words.
</p>
<div>
<form onSubmit={handleSubmit}>
<input
readOnly={isJoining}
type="url"
name="url"
placeholder="Room URL (optional)"
/>
<button disabled={isJoining} type="submit">
Join
</button>
</form>
</div>
</>
)}
</div>
<GlobalStyles />
<style jsx>{`
.App {
align-items: center;
display: flex;
flex-direction: column;
font-family: sans-serif;
gap: 8px;
height: 100%;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
form {
display: flex;
gap: 8px;
justify-content: center;
}
.actions {
display: flex;
gap: 4px;
justify-content: center;
}
.container {
align-items: center;
display: flex;
flex-grow: 1;
gap: 8px;
justify-content: center;
min-height: 0;
position: relative;
width: 100%;
}
.call {
align-items: center;
border: 1px solid var(--border);
display: flex;
flex-direction: row;
flex: 1 1 auto;
height: 100%;
justify-content: center;
position: relative;
width: 100%;
}
.ai-view {
border-right: 1px solid var(--border);
height: 100%;
text-align: initial;
width: 320px;
}
#frame {
align-self: stretch;
flex-grow: 2;
}
#frame iframe {
display: block;
}
`}</style>
</DailyProvider>
);
}