Skip to content

Commit a21e6ba

Browse files
committed
fix call fabric relay application test
1 parent 5f7d69d commit a21e6ba

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

internal/e2e-js/tests/callfabric/relayApp.spec.ts

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Voice } from '@signalwire/realtime-api'
1+
import { SignalWire, Voice } from '@signalwire/realtime-api'
22
import {
33
createCFClient,
44
expectPageReceiveAudio,
@@ -11,30 +11,34 @@ test.describe('CallFabric Relay Application', () => {
1111
test('should connect to the relay app and expect an audio playback', async ({
1212
createCustomPage,
1313
}) => {
14-
const client = new Voice.Client({
14+
const client = await SignalWire({
1515
host: process.env.RELAY_HOST,
1616
project: process.env.CF_RELAY_PROJECT as string,
1717
token: process.env.CF_RELAY_TOKEN as string,
18-
topics: ['cf-e2e-test-relay'],
1918
debug: {
2019
logWsTraffic: true,
2120
},
2221
})
2322

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+
},
3842
})
3943

4044
try {
@@ -84,28 +88,30 @@ test.describe('CallFabric Relay Application', () => {
8488
test('should connect to the relay app and expect a silence', async ({
8589
createCustomPage,
8690
}) => {
87-
const client = new Voice.Client({
91+
const client = await SignalWire({
8892
host: process.env.RELAY_HOST,
8993
project: process.env.CF_RELAY_PROJECT as string,
9094
token: process.env.CF_RELAY_TOKEN as string,
91-
topics: ['cf-e2e-test-relay'],
9295
debug: {
9396
logWsTraffic: true,
9497
},
9598
})
9699

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)
100105

101-
await call.answer()
102-
console.log('Inbound call answered')
106+
await call.answer()
107+
console.log('Inbound call answered')
103108

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+
},
109115
})
110116

111117
try {
@@ -157,27 +163,29 @@ test.describe('CallFabric Relay Application', () => {
157163
test('should connect to the relay app and expect a hangup', async ({
158164
createCustomPage,
159165
}) => {
160-
const client = new Voice.Client({
166+
const client = await SignalWire({
161167
host: process.env.RELAY_HOST,
162168
project: process.env.CF_RELAY_PROJECT as string,
163169
token: process.env.CF_RELAY_TOKEN as string,
164-
topics: ['cf-e2e-test-relay'],
165170
debug: {
166171
logWsTraffic: true,
167172
},
168173
})
169174

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)
173180

174-
await call.answer()
175-
console.log('Inbound call answered')
181+
await call.answer()
182+
console.log('Inbound call answered')
176183

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+
},
181189
})
182190

183191
const page = await createCustomPage({ name: '[page]' })

0 commit comments

Comments
 (0)