Skip to content

Instantly share code, notes, and snippets.

@woodja
Created December 19, 2021 22:18
Show Gist options
  • Save woodja/264ff6b9762f811404281c969df9552c to your computer and use it in GitHub Desktop.
Save woodja/264ff6b9762f811404281c969df9552c to your computer and use it in GitHub Desktop.
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