@@ -4,8 +4,6 @@ import type {
4
4
SignalWire ,
5
5
SignalWireClient ,
6
6
SignalWireContract ,
7
- CallSessionEvents ,
8
- CallSessionEventParams ,
9
7
} from '@signalwire/client'
10
8
import type { MediaEventNames } from '@signalwire/webrtc'
11
9
import { createServer } from 'vite'
@@ -18,16 +16,13 @@ import express, { Express, Request, Response } from 'express'
18
16
import { Server } from 'http'
19
17
import { spawn , ChildProcessWithoutNullStreams } from 'child_process'
20
18
import { EventEmitter } from 'events'
21
- import { CallStateManager } from './CallStateManage'
22
-
23
19
declare global {
24
20
interface Window {
25
21
_SWJS : {
26
22
SignalWire : typeof SignalWire
27
23
}
28
24
_client ?: SignalWireClient
29
25
_callObj ?: CallSession
30
- _callState ?: CallStateManager
31
26
}
32
27
}
33
28
@@ -449,7 +444,6 @@ const createCFClientWithToken = async (
449
444
const client : SignalWireContract = await SignalWire ( {
450
445
host : options . RELAY_HOST ,
451
446
token : options . API_TOKEN ,
452
- logLevel : 'info' ,
453
447
debug : { logWsTraffic : true } ,
454
448
...( options . attachSagaMonitor && { sagaMonitor } ) ,
455
449
} )
@@ -466,59 +460,13 @@ const createCFClientWithToken = async (
466
460
return swClient
467
461
}
468
462
469
- export const createCallStateUtility = ( page : Page ) => {
470
- return page . evaluate ( ( ) => {
471
- // Initialize the global _callState with a state utility that keeps the history of the call state
472
- window . _callState = new CallStateManager ( )
473
-
474
- return window . _callState
475
- } )
476
- }
477
-
478
- export const waitSefState = async (
479
- page : Page ,
480
- criteria : any ,
481
- options ?: {
482
- interval ?: number [ ]
483
- timeout ?: number
484
- message ?: string
485
- }
486
- ) => {
487
- try {
488
- return page . waitForFunction (
489
- ( criteria ) => {
490
- if ( ! criteria ) return true
491
-
492
- if ( typeof criteria !== 'object' ) {
493
- const self = window . _callState ?. getSelfState ( )
494
- return Object . keys ( criteria ) . every (
495
- ( key ) => self [ key ] === criteria [ key ]
496
- )
497
- }
498
-
499
- return false
500
- } ,
501
- criteria ,
502
- { timeout : 5_000 , ...options }
503
- )
504
- } catch ( error ) {
505
- page . evaluate ( ( ) => window . _callState ?. logHistory ( ) )
506
- if ( options ?. message ) {
507
- throw new Error ( `waitSefState: ${ options . message } ` )
508
- } else {
509
- throw new Error ( 'waitSefState:' , error )
510
- }
511
- }
512
- }
513
-
514
463
interface DialAddressParams {
515
464
address : string
516
465
dialOptions ?: Partial < DialParams >
517
466
reattach ?: boolean
518
467
shouldWaitForJoin ?: boolean
519
468
shouldStartCall ?: boolean
520
469
shouldPassRootElement ?: boolean
521
- shouldListenToEvent ?: boolean
522
470
timeoutMs ?: number
523
471
}
524
472
@@ -531,7 +479,6 @@ export const dialAddress = <TReturn = any>(
531
479
shouldPassRootElement : true ,
532
480
shouldStartCall : true ,
533
481
shouldWaitForJoin : true ,
534
- shouldListenToEvent : false ,
535
482
timeoutMs : 15000 ,
536
483
}
537
484
) => {
@@ -570,113 +517,31 @@ export const dialAddress = <TReturn = any>(
570
517
shouldPassRootElement,
571
518
shouldStartCall,
572
519
shouldWaitForJoin,
573
- shouldListenToEvent,
574
520
} ) => {
575
521
return new Promise < any > ( async ( resolve , _reject ) => {
576
522
if ( ! window . _client ) {
577
523
throw new Error ( 'Client is not defined' )
578
524
}
579
525
const client : SignalWireContract = window . _client
580
- const listenHandlers : Partial < CallSessionEvents > = { }
581
-
582
- // If shouldListenToEvent is true, add listeners for all events to update window._callState
583
- if ( shouldListenToEvent && window . _callState ) {
584
- console . log ( 'Adding call event listeners...' )
585
- // Define all events to listen to
586
- const eventsToListen : ( keyof CallSessionEvents ) [ ] = [
587
- // Core Call Events
588
- 'call.joined' ,
589
- 'call.updated' ,
590
- 'call.left' ,
591
- 'call.state' ,
592
- 'call.play' ,
593
- 'call.connect' ,
594
- 'call.room' ,
595
- 'room.joined' ,
596
- 'room.subscribed' ,
597
- 'room.updated' ,
598
- 'room.left' ,
599
-
600
- 'member.joined' ,
601
- 'member.updated' ,
602
- 'member.updated.audioMuted' ,
603
- 'member.updated.videoMuted' ,
604
- 'member.updated.deaf' ,
605
- 'member.updated.visible' ,
606
- 'member.updated.onHold' ,
607
- 'member.updated.inputVolume' ,
608
- 'member.updated.outputVolume' ,
609
- 'member.updated.inputSensitivity' ,
610
- 'member.updated.handraised' ,
611
- 'member.updated.echoCancellation' ,
612
- 'member.updated.autoGain' ,
613
- 'member.updated.noiseCancellation' ,
614
- 'member.updated.noiseSuppression' ,
615
- 'member.left' ,
616
- 'member.talking' ,
617
- 'memberList.updated' ,
618
- 'media.connected' ,
619
- 'media.reconnecting' ,
620
- 'media.disconnected' ,
621
- 'connecting' ,
622
- 'connected' ,
623
- 'disconnected' ,
624
- 'disconnecting' ,
625
- 'reconnecting' ,
626
- 'reconnected' ,
627
- 'active' ,
628
- 'answering' ,
629
- 'early' ,
630
- 'hangup' ,
631
- 'held' ,
632
- 'new' ,
633
- 'purge' ,
634
- 'recovering' ,
635
- 'requesting' ,
636
- 'ringing' ,
637
- 'trying' ,
638
- 'layout.changed' ,
639
- 'device.updated' ,
640
- 'device.disconnected' ,
641
- 'track' ,
642
- 'destroy' ,
643
- 'camera.updated' ,
644
- 'camera.disconnected' ,
645
- 'microphone.updated' ,
646
- 'microphone.disconnected' ,
647
- 'speaker.updated' ,
648
- 'speaker.disconnected' ,
649
- ] as ( keyof CallSessionEvents ) [ ]
650
- // Add listeners for each event
651
- eventsToListen . forEach ( ( eventName ) => {
652
- // @ts -expect-error not all event have params
653
- listenHandlers [ eventName ] = ( params : CallSessionEventParams ) => {
654
- console . log ( `Event ${ eventName } received` )
655
- window . _callState ?. update ( eventName , params )
656
- }
657
- } )
658
- }
659
526
660
527
const dialer = reattach ? client . reattach : client . dial
661
528
662
- const call = await dialer ( {
529
+ const call = dialer ( {
663
530
to : address ,
664
531
...( shouldPassRootElement && {
665
532
rootElement : document . getElementById ( 'rootElement' ) ! ,
666
533
} ) ,
667
534
...JSON . parse ( dialOptions ) ,
668
- listen : listenHandlers ,
669
535
} )
670
536
671
- // Store call object and resolvers in window for test access
672
- window . _callObj = call
673
-
674
537
if ( shouldWaitForJoin ) {
675
538
call . on ( 'room.joined' , ( params ) => {
676
539
resolve ( params )
677
540
} )
678
541
}
679
542
543
+ window . _callObj = call
544
+
680
545
if ( shouldStartCall ) {
681
546
await call . start ( )
682
547
}
0 commit comments