@@ -37,6 +37,8 @@ class WebRTCApp {
37
37
private selfViewVideo ! : HTMLVideoElement ;
38
38
private videoContainer ! : HTMLElement ;
39
39
private botName ! : HTMLElement ;
40
+ private sendBtn ! : HTMLElement ;
41
+ private msgInput ! : HTMLInputElement ;
40
42
41
43
// State
42
44
private connected : boolean = false ;
@@ -228,6 +230,10 @@ class WebRTCApp {
228
230
"bot-video-container"
229
231
) as HTMLElement ;
230
232
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 ;
231
237
}
232
238
233
239
private setupDOMEventListeners ( ) : void {
@@ -306,8 +312,50 @@ class WebRTCApp {
306
312
this . cameraChevronBtn . classList . remove ( "active" ) ;
307
313
}
308
314
} ) ;
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
+
309
328
}
310
329
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
+
311
359
private togglePopover ( popover : HTMLElement , chevronBtn : HTMLElement ) : void {
312
360
popover . classList . toggle ( "show" ) ;
313
361
chevronBtn . classList . toggle ( "active" ) ;
0 commit comments