Skip to content

Commit 362f939

Browse files
committed
revert changes
1 parent ffc4e68 commit 362f939

File tree

1 file changed

+3
-138
lines changed

1 file changed

+3
-138
lines changed

internal/e2e-client/utils.ts

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type {
44
SignalWire,
55
SignalWireClient,
66
SignalWireContract,
7-
CallSessionEvents,
8-
CallSessionEventParams,
97
} from '@signalwire/client'
108
import type { MediaEventNames } from '@signalwire/webrtc'
119
import { createServer } from 'vite'
@@ -18,16 +16,13 @@ import express, { Express, Request, Response } from 'express'
1816
import { Server } from 'http'
1917
import { spawn, ChildProcessWithoutNullStreams } from 'child_process'
2018
import { EventEmitter } from 'events'
21-
import { CallStateManager } from './CallStateManage'
22-
2319
declare global {
2420
interface Window {
2521
_SWJS: {
2622
SignalWire: typeof SignalWire
2723
}
2824
_client?: SignalWireClient
2925
_callObj?: CallSession
30-
_callState?: CallStateManager
3126
}
3227
}
3328

@@ -449,7 +444,6 @@ const createCFClientWithToken = async (
449444
const client: SignalWireContract = await SignalWire({
450445
host: options.RELAY_HOST,
451446
token: options.API_TOKEN,
452-
logLevel: 'info',
453447
debug: { logWsTraffic: true },
454448
...(options.attachSagaMonitor && { sagaMonitor }),
455449
})
@@ -466,59 +460,13 @@ const createCFClientWithToken = async (
466460
return swClient
467461
}
468462

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-
514463
interface DialAddressParams {
515464
address: string
516465
dialOptions?: Partial<DialParams>
517466
reattach?: boolean
518467
shouldWaitForJoin?: boolean
519468
shouldStartCall?: boolean
520469
shouldPassRootElement?: boolean
521-
shouldListenToEvent?: boolean
522470
timeoutMs?: number
523471
}
524472

@@ -531,7 +479,6 @@ export const dialAddress = <TReturn = any>(
531479
shouldPassRootElement: true,
532480
shouldStartCall: true,
533481
shouldWaitForJoin: true,
534-
shouldListenToEvent: false,
535482
timeoutMs: 15000,
536483
}
537484
) => {
@@ -570,113 +517,31 @@ export const dialAddress = <TReturn = any>(
570517
shouldPassRootElement,
571518
shouldStartCall,
572519
shouldWaitForJoin,
573-
shouldListenToEvent,
574520
}) => {
575521
return new Promise<any>(async (resolve, _reject) => {
576522
if (!window._client) {
577523
throw new Error('Client is not defined')
578524
}
579525
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-
}
659526

660527
const dialer = reattach ? client.reattach : client.dial
661528

662-
const call = await dialer({
529+
const call = dialer({
663530
to: address,
664531
...(shouldPassRootElement && {
665532
rootElement: document.getElementById('rootElement')!,
666533
}),
667534
...JSON.parse(dialOptions),
668-
listen: listenHandlers,
669535
})
670536

671-
// Store call object and resolvers in window for test access
672-
window._callObj = call
673-
674537
if (shouldWaitForJoin) {
675538
call.on('room.joined', (params) => {
676539
resolve(params)
677540
})
678541
}
679542

543+
window._callObj = call
544+
680545
if (shouldStartCall) {
681546
await call.start()
682547
}

0 commit comments

Comments
 (0)