Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async useWebSocket(req: WebRequest, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise): Promise {
// Use the provided NodeWebSocketFactoryBase on BotFrameworkAdapter construction,
// otherwise create a new NodeWebSocketFactory.
const webSocketFactory = this.webSocketFactory || new NodeWebSocketFactory();
if (!logic) {
throw new Error('Streaming logic needs to be provided to `useWebSocket`');
}
this.logic = logic;
try {
await this.authenticateConnection(req, this.settings.channelService);
} catch (err) {
// If the authenticateConnection call fails, send back the correct error code and close
// the connection.
if (typeof(err.message) === 'string' && err.message.toLowerCase().startsWith('unauthorized')) {
abortWebSocketUpgrade(socket, 401);
} else if (typeof(err.message) === 'string' && err.message.toLowerCase().startsWith(`'authheader'`)) {
abortWebSocketUpgrade(socket, 400);