1
- import { Voice } from '@signalwire/realtime-api'
1
+ import { SignalWire , Voice } from '@signalwire/realtime-api'
2
2
import {
3
3
createCFClient ,
4
4
expectPageReceiveAudio ,
@@ -11,30 +11,34 @@ test.describe('CallFabric Relay Application', () => {
11
11
test ( 'should connect to the relay app and expect an audio playback' , async ( {
12
12
createCustomPage,
13
13
} ) => {
14
- const client = new Voice . Client ( {
14
+ const client = await SignalWire ( {
15
15
host : process . env . RELAY_HOST ,
16
16
project : process . env . CF_RELAY_PROJECT as string ,
17
17
token : process . env . CF_RELAY_TOKEN as string ,
18
- topics : [ 'cf-e2e-test-relay' ] ,
19
18
debug : {
20
19
logWsTraffic : true ,
21
20
} ,
22
21
} )
23
22
24
- client . on ( 'call.received' , async ( call ) => {
25
- try {
26
- console . log ( 'Call received' , call . id )
27
-
28
- await call . answer ( )
29
- console . log ( 'Inbound call answered' )
30
-
31
- const playback = await call . playAudio ( {
32
- url : 'https://cdn.signalwire.com/default-music/welcome.mp3' ,
33
- } )
34
- await playback . setVolume ( 10 )
35
- } catch ( error ) {
36
- console . error ( 'Inbound call error' , error )
37
- }
23
+ await client . voice . listen ( {
24
+ topics : [ 'cf-e2e-test-relay' ] ,
25
+ onCallReceived : async ( call ) => {
26
+ try {
27
+ console . log ( 'Call received' , call . id )
28
+
29
+ await call . answer ( )
30
+ console . log ( 'Inbound call answered' )
31
+
32
+ const playback = await call
33
+ . playAudio ( {
34
+ url : 'https://cdn.signalwire.com/default-music/welcome.mp3' ,
35
+ } )
36
+ . onStarted ( )
37
+ await playback . setVolume ( 10 )
38
+ } catch ( error ) {
39
+ console . error ( 'Inbound call error' , error )
40
+ }
41
+ } ,
38
42
} )
39
43
40
44
try {
@@ -84,28 +88,30 @@ test.describe('CallFabric Relay Application', () => {
84
88
test ( 'should connect to the relay app and expect a silence' , async ( {
85
89
createCustomPage,
86
90
} ) => {
87
- const client = new Voice . Client ( {
91
+ const client = await SignalWire ( {
88
92
host : process . env . RELAY_HOST ,
89
93
project : process . env . CF_RELAY_PROJECT as string ,
90
94
token : process . env . CF_RELAY_TOKEN as string ,
91
- topics : [ 'cf-e2e-test-relay' ] ,
92
95
debug : {
93
96
logWsTraffic : true ,
94
97
} ,
95
98
} )
96
99
97
- client . on ( 'call.received' , async ( call ) => {
98
- try {
99
- console . log ( 'Call received' , call . id )
100
+ await client . voice . listen ( {
101
+ topics : [ 'cf-e2e-test-relay' ] ,
102
+ onCallReceived : async ( call ) => {
103
+ try {
104
+ console . log ( 'Call received' , call . id )
100
105
101
- await call . answer ( )
102
- console . log ( 'Inbound call answered' )
106
+ await call . answer ( )
107
+ console . log ( 'Inbound call answered' )
103
108
104
- const playback = await call . playSilence ( { duration : 60 } )
105
- await playback . setVolume ( 10 )
106
- } catch ( error ) {
107
- console . error ( 'Inbound call error' , error )
108
- }
109
+ const playback = await call . playSilence ( { duration : 60 } ) . onStarted ( )
110
+ await playback . setVolume ( 10 )
111
+ } catch ( error ) {
112
+ console . error ( 'Inbound call error' , error )
113
+ }
114
+ } ,
109
115
} )
110
116
111
117
try {
@@ -157,27 +163,29 @@ test.describe('CallFabric Relay Application', () => {
157
163
test ( 'should connect to the relay app and expect a hangup' , async ( {
158
164
createCustomPage,
159
165
} ) => {
160
- const client = new Voice . Client ( {
166
+ const client = await SignalWire ( {
161
167
host : process . env . RELAY_HOST ,
162
168
project : process . env . CF_RELAY_PROJECT as string ,
163
169
token : process . env . CF_RELAY_TOKEN as string ,
164
- topics : [ 'cf-e2e-test-relay' ] ,
165
170
debug : {
166
171
logWsTraffic : true ,
167
172
} ,
168
173
} )
169
174
170
- client . on ( 'call.received' , async ( call ) => {
171
- try {
172
- console . log ( 'Call received' , call . id )
175
+ await client . voice . listen ( {
176
+ topics : [ 'cf-e2e-test-relay' ] ,
177
+ onCallReceived : async ( call ) => {
178
+ try {
179
+ console . log ( 'Call received' , call . id )
173
180
174
- await call . answer ( )
175
- console . log ( 'Inbound call answered' )
181
+ await call . answer ( )
182
+ console . log ( 'Inbound call answered' )
176
183
177
- await call . hangup ( )
178
- } catch ( error ) {
179
- console . error ( 'Inbound call error' , error )
180
- }
184
+ await call . hangup ( )
185
+ } catch ( error ) {
186
+ console . error ( 'Inbound call error' , error )
187
+ }
188
+ } ,
181
189
} )
182
190
183
191
const page = await createCustomPage ( { name : '[page]' } )
0 commit comments