From a5daa4f0464a600586a18bafc98ee41350d4d16f Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Mon, 20 May 2019 13:53:24 +0300 Subject: [PATCH 1/2] WebAdapter: add getConnection method --- packages/botbuilder-adapter-web/src/web_adapter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/botbuilder-adapter-web/src/web_adapter.ts b/packages/botbuilder-adapter-web/src/web_adapter.ts index f62c21d0f..ebab6e3c2 100644 --- a/packages/botbuilder-adapter-web/src/web_adapter.ts +++ b/packages/botbuilder-adapter-web/src/web_adapter.ts @@ -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. * @@ -316,4 +316,15 @@ export class WebAdapter extends BotAdapter { public isConnected(user: string): boolean { return typeof clients[user] !== 'undefined'; } + + /** + * Returns websocket connection of given user + * @param user + */ + public getConnection(user: string): WebSocket { + if (!this.isConnected(user)) { + throw new Error('User ' + user + ' is not connected'); + } + return clients[user]; + } } From 2415fb5960ec8f0d3bbc86c4c5f3cece56ee2c4a Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Mon, 20 May 2019 18:06:04 +0300 Subject: [PATCH 2/2] docs: Add example --- packages/botbuilder-adapter-web/src/web_adapter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/botbuilder-adapter-web/src/web_adapter.ts b/packages/botbuilder-adapter-web/src/web_adapter.ts index ebab6e3c2..8e377bdd5 100644 --- a/packages/botbuilder-adapter-web/src/web_adapter.ts +++ b/packages/botbuilder-adapter-web/src/web_adapter.ts @@ -319,6 +319,7 @@ export class WebAdapter extends BotAdapter { /** * Returns websocket connection of given user + * Example: `if (message.action === 'disconnect') bot.controller.adapter.getConnection(message.user).terminate()` * @param user */ public getConnection(user: string): WebSocket {