Skip to content

Commit

Permalink
properly expose the header to the web component
Browse files Browse the repository at this point in the history
this way the logging stuff can happen in the example only as it should be.
  • Loading branch information
pschichtel committed Jun 21, 2024
1 parent 765f679 commit 90d6a7f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,6 @@ export function triggerControls(environment: string, resellerToken: string, dest
}
return telephony.createCall(destination, createCallOptions)
.then(call => {
console.log("Headers received from accept:", call.acceptHeaders)
const dialogIds = call.acceptHeaders
.filter(([name,]) => name.toLowerCase() == "x-cvg-dialogid")
.map(([, value]) => value)
if (dialogIds.length > 0) {
console.log(`DialogId: ${dialogIds[0]}`)
}

const [, controlsCleanup] = generateCallControls(call, options)
call.callCompletion.then(() => {
controlsCleanup()
Expand Down
11 changes: 11 additions & 0 deletions src/custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const TRIGGER_BUTTON_DISABLED_PART = `${TRIGGER_BUTTON_PART}-disabled`

export interface CvgWebRtcButtonEventMap extends HTMLElementEventMap {
new_call: NewCallEvent
call_accepted: CallAcceptedEvent
call_ended: CallEndedEvent
attribute_validation_failed: AttributeValidationFailedEvent
}
Expand Down Expand Up @@ -245,6 +246,16 @@ export class NewCallEvent extends CallEvent<void> {
}
}

export interface CallAcceptedDetails {
headers: HeaderList,
}

export class CallAcceptedEvent extends CallEvent<CallAcceptedDetails> {
constructor(headers: HeaderList) {
super('call_accepted', { headers })
}
}

export class CallEndedEvent extends CallEvent<any | null> {
constructor(error: any | null) {
if (error === undefined) {
Expand Down
11 changes: 11 additions & 0 deletions src/web-call-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ window.addEventListener('DOMContentLoaded', () => {
connectButton.innerHTML = images.endCall
})

connectButton.addEventListener('call_accepted', (e) => {
const headers = e.detail.headers
console.log("Headers received from accept:", headers)
const dialogIds = headers
.filter(([name,]) => name.toLowerCase() == "x-cvg-dialogid")
.map(([, value]) => value)
if (dialogIds.length > 0) {
console.log(`DialogId: ${dialogIds[0]}`)
}
})

connectButton.addEventListener('call_ended', (e: CallEndedEvent) => {
connectButton.innerHTML = images.newCall
if (e.detail !== null) {
Expand Down

0 comments on commit 90d6a7f

Please sign in to comment.