Skip to content

Commit

Permalink
Expose detect_interruptions and handle beep in the detect events (#…
Browse files Browse the repository at this point in the history
…866)

* Expose  and handle  in the detect events

* include changeset

* Update packages/realtime-api/src/voice/CallDetect.ts

Co-authored-by: Edoardo Gallo <edoardo@signalwire.com>

---------

Co-authored-by: Edoardo Gallo <edoardo@signalwire.com>
  • Loading branch information
iAmmar7 and Edoardo Gallo authored Sep 6, 2023
1 parent ac23f88 commit 1086a1b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/eighty-otters-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/realtime-api': minor
'@signalwire/core': minor
---

Expose `detect_interruptions` params for detect methods and handle `beep` in the detect events
3 changes: 3 additions & 0 deletions packages/core/src/types/voiceCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ export interface VoiceCallDetectMachineParams
type: 'machine'
initialTimeout?: number
endSilenceTimeout?: number
machineReadyTimeout?: number
machineVoiceThreshold?: number
machineWordsThreshold?: number
detectInterruptions?: boolean
}

export interface VoiceCallDetectFaxParams extends VoiceCallDetectBaseParams {
Expand Down Expand Up @@ -1122,6 +1124,7 @@ interface CallingCallDetectFax {
interface CallingCallDetectMachine {
type: 'machine'
params: {
beep: boolean
event:
| 'MACHINE'
| 'HUMAN'
Expand Down
13 changes: 5 additions & 8 deletions packages/realtime-api/src/voice/CallDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ export class CallDetectAPI
{
private _payload: CallingCallDetectEventParams
private _waitForBeep: boolean
private _waitingForReady: boolean
private _result: DetectorResult = 'UNKNOWN'

constructor(options: CallDetectOptions) {
super(options)

this._payload = options.payload
this._waitForBeep = options.payload.waitForBeep
this._waitingForReady = false
}

get id() {
Expand Down Expand Up @@ -78,12 +76,11 @@ export class CallDetectAPI
return this._waitForBeep
}

get waitingForReady() {
return this._waitingForReady
}

set waitingForReady(ready: boolean) {
this._waitingForReady = ready
get beep() {
if (this.detect?.params.event === 'MACHINE') {
return Boolean(this.detect.params.beep)
}
return undefined
}

/** @internal */
Expand Down
11 changes: 3 additions & 8 deletions packages/realtime-api/src/voice/workers/voiceCallDetectWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ export const voiceCallDetectWorker = function* (
const { detect } = payload
if (!detect) return

const {
type,
params: { event },
} = detect
const { type, params } = detect
const { event } = params

switch (event) {
case 'finished':
Expand All @@ -60,16 +58,13 @@ export const voiceCallDetectWorker = function* (

switch (type) {
case 'machine':
if (detectInstance.waitingForReady && event === 'READY') {
if (params.beep && detectInstance.waitForBeep) {
// @ts-expect-error
callInstance.emit('detect.ended', detectInstance)

// To resolve the ended() promise in CallDetect
detectInstance.emit('detect.ended', detectInstance)
}
if (detectInstance.waitForBeep) {
detectInstance.waitingForReady = true
}
break
case 'digit':
case 'fax':
Expand Down

0 comments on commit 1086a1b

Please sign in to comment.