Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

WebAdapter: add getConnection method #1666

Merged
merged 2 commits into from
May 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/botbuilder-adapter-web/src/web_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class WebAdapter extends BotAdapter {
}

/**
* Is given user currently connected? Use this to test the websocket connection
* Is given user currently connected? Use this to test the websocket connection
* between the bot and a given user before sending messages,
* particularly in cases where a long period of time may have passed.
*
Expand All @@ -316,4 +316,16 @@ export class WebAdapter extends BotAdapter {
public isConnected(user: string): boolean {
return typeof clients[user] !== 'undefined';
}

/**
* Returns websocket connection of given user
* Example: `if (message.action === 'disconnect') bot.controller.adapter.getConnection(message.user).terminate()`
* @param user
*/
Naktibalda marked this conversation as resolved.
Show resolved Hide resolved
public getConnection(user: string): WebSocket {
if (!this.isConnected(user)) {
throw new Error('User ' + user + ' is not connected');
}
return clients[user];
}
}