-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow consumer to pass the call without hanging up (#827)
* Allow consumer to pass the call without hanging up * e2e test case for call pass * include changeset
- Loading branch information
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@signalwire/realtime-api': minor | ||
'@signalwire/core': minor | ||
--- | ||
|
||
Introduce call.pass function to pass the call to another consumer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import tap from 'tap' | ||
import { Voice } from '@signalwire/realtime-api' | ||
import { createTestRunner } from './utils' | ||
|
||
const handler = () => { | ||
return new Promise<number>(async (resolve, reject) => { | ||
const options = { | ||
host: process.env.RELAY_HOST || 'relay.swire.io', | ||
project: process.env.RELAY_PROJECT as string, | ||
token: process.env.RELAY_TOKEN as string, | ||
contexts: [process.env.VOICE_CONTEXT as string], | ||
// logLevel: "trace", | ||
debug: { | ||
// logWsTraffic: true, | ||
}, | ||
} | ||
|
||
const [client1, client2, client3] = [ | ||
new Voice.Client(options), | ||
new Voice.Client(options), | ||
new Voice.Client(options), | ||
] | ||
|
||
let callPassed = false | ||
|
||
client2.on('call.received', async (call) => { | ||
console.log( | ||
'Got call on client 2', | ||
call.id, | ||
call.from, | ||
call.to, | ||
call.direction | ||
) | ||
|
||
if (callPassed) return | ||
|
||
try { | ||
const passed = await call.pass() | ||
tap.equal(passed, undefined, 'Call passed!') | ||
callPassed = true | ||
} catch (error) { | ||
console.error('Inbound - voicePass client 2 error', error) | ||
reject(4) | ||
} | ||
}) | ||
|
||
client3.on('call.received', async (call) => { | ||
console.log( | ||
'Got call on client 3', | ||
call.id, | ||
call.from, | ||
call.to, | ||
call.direction | ||
) | ||
|
||
if (!callPassed) return | ||
|
||
try { | ||
const resultAnswer = await call.answer() | ||
tap.ok(resultAnswer.id, 'Inbound - Call answered') | ||
|
||
await call.hangup() | ||
} catch (error) { | ||
console.error('error', error) | ||
reject(4) | ||
} | ||
}) | ||
|
||
try { | ||
const call = await client1.dialPhone({ | ||
// make an outbound call to an `office` context to trigger the `call.received` event above | ||
to: process.env.VOICE_DIAL_TO_NUMBER as string, | ||
from: process.env.VOICE_DIAL_FROM_NUMBER as string, | ||
timeout: 30, | ||
}) | ||
tap.ok(call.id, 'Call resolved') | ||
|
||
const waitForParams = ['ended', 'ending', ['ending', 'ended']] as const | ||
const results = await Promise.all( | ||
waitForParams.map((params) => call.waitFor(params as any)) | ||
) | ||
waitForParams.forEach((value, i) => { | ||
if (typeof value === 'string') { | ||
tap.ok(results[i], `"${value}": completed successfully.`) | ||
} else { | ||
tap.ok( | ||
results[i], | ||
`${JSON.stringify(value)}: completed successfully.` | ||
) | ||
} | ||
}) | ||
|
||
resolve(0) | ||
} catch (error) { | ||
console.error('Outbound - voicePass error', error) | ||
reject(4) | ||
} | ||
}) | ||
} | ||
|
||
async function main() { | ||
const runner = createTestRunner({ | ||
name: 'Voice Pass E2E', | ||
testHandler: handler, | ||
executionTime: 60_000, | ||
}) | ||
|
||
await runner.run() | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters