Skip to content

Commit d3aed43

Browse files
committed
Add text chat UI
1 parent cd9e136 commit d3aed43

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

client/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
</div>
8383
</div>
8484

85+
<!-- TODO: add logic in app.ts for whether or not to display this -->
86+
<!-- <div class="main-content" style="display: none;"> -->
87+
<div class="main-content">
88+
<div id="input-area">
89+
<input type="text" id="message-input" placeholder="Type your message to the bot here...">
90+
<button id="send-btn">Send</button>
91+
</div>
92+
</div>
93+
8594
<!-- Hidden elements for compatibility -->
8695
<div style="display: none;">
8796
<button id="disconnect-btn">Disconnect</button>

client/src/app.ts

+48
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class WebRTCApp {
3737
private selfViewVideo!: HTMLVideoElement;
3838
private videoContainer!: HTMLElement;
3939
private botName!: HTMLElement;
40+
private sendBtn!: HTMLElement;
41+
private msgInput!: HTMLInputElement;
4042

4143
// State
4244
private connected: boolean = false;
@@ -228,6 +230,10 @@ class WebRTCApp {
228230
"bot-video-container"
229231
) as HTMLElement;
230232
this.botName = document.getElementById("bot-name") as HTMLElement;
233+
this.sendBtn = document.getElementById("send-btn") as HTMLElement;
234+
this.msgInput = document.getElementById(
235+
"message-input"
236+
) as HTMLInputElement;
231237
}
232238

233239
private setupDOMEventListeners(): void {
@@ -306,8 +312,50 @@ class WebRTCApp {
306312
this.cameraChevronBtn.classList.remove("active");
307313
}
308314
});
315+
316+
// Text chat handlers
317+
this.sendBtn.addEventListener('click', () => this.handleTextSubmit());
318+
const _this = this;
319+
this.msgInput.addEventListener(
320+
'keydown',
321+
function (event: KeyboardEvent<HTMLTextAreaElement>) {
322+
if (event.key === 'Enter') {
323+
_this.handleTextSubmit();
324+
}
325+
}
326+
);
327+
309328
}
310329

330+
async handleTextSubmit() {
331+
const text = this.msgInput.value;
332+
const message = text.trim();
333+
334+
try {
335+
await this.rtviClient?.action({
336+
service: "llm",
337+
action: "append_to_messages",
338+
arguments: [
339+
{
340+
name: "messages",
341+
value: [
342+
{
343+
role: "user",
344+
content: message,
345+
},
346+
],
347+
},
348+
],
349+
});
350+
this.log(`User: ${message}`);
351+
} catch (e) {
352+
console.error(e);
353+
} finally {
354+
this.msgInput.value = ""
355+
}
356+
};
357+
358+
311359
private togglePopover(popover: HTMLElement, chevronBtn: HTMLElement): void {
312360
popover.classList.toggle("show");
313361
chevronBtn.classList.toggle("active");

client/src/style.css

+14
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,20 @@ audio {
381381
display: none; /* Hide audio but keep it functional */
382382
}
383383

384+
#input-area {
385+
display: flex;
386+
width: 100%;
387+
}
388+
389+
#message-input {
390+
flex-grow: 1;
391+
padding: 10px;
392+
border: 1px solid #ccc;
393+
border-radius: 4px;
394+
margin-right: 10px;
395+
width: 100%;
396+
}
397+
384398
/* Media queries */
385399
@media (max-width: 768px) {
386400
.container {

0 commit comments

Comments
 (0)