Created
December 19, 2021 22:18
-
-
Save woodja/264ff6b9762f811404281c969df9552c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async sipDialout( | |
sessionId: string, | |
pin: string, | |
sipUri: string | |
): Promise<OpenTokSipReponse> { | |
this.logger.verbose( | |
`Sip dialout [Session: ${sessionId}] [Pin: ${pin}] [Uri: ${sipUri}]` | |
); | |
return new Promise((resolve, reject) => { | |
const token: string = this.OT.generateToken(sessionId, { | |
data: JSON.stringify({ | |
bridge: true, | |
pin: pin | |
}) | |
}); | |
const sipDomain: string = configService.getSipDomain(); | |
this.OT.dial( | |
sessionId, | |
token, | |
sipUri, | |
{ | |
from: `Webcast * Audio <${pin}@${sipDomain}>`, | |
secure: false | |
}, | |
(error, interconnect) => { | |
if (error) { | |
this.logger.error(error); | |
reject(error); | |
} else { | |
if (interconnect.id) { | |
this.logger.verbose( | |
`Sip dialout successful. [SIP: ${interconnect.id}] [Stream: ${interconnect.streamId}] [Connection: ${interconnect.connectionId}] [Uri: ${sipUri}] [Pin: ${pin}] [Token: ${token}]` | |
); | |
resolve({ | |
success: true, | |
id: interconnect.id, | |
streamId: interconnect.streamId, | |
connectionId: interconnect.connectionId, | |
token: token | |
}); | |
} else { | |
this.logger.warn( | |
`Sip dialout failed. [Session: ${sessionId}] [Uri: ${sipUri}]` | |
); | |
resolve({ | |
success: false, | |
id: null, | |
streamId: null, | |
connectionId: null, | |
token: null | |
}); | |
} | |
} | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment