Skip to content

Commit

Permalink
remove unnecessary enableWebSockets flag, cleanup useWebSocket()
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengum committed Nov 23, 2019
1 parent 06cc3e4 commit b08c9fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
29 changes: 10 additions & 19 deletions libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ export interface BotFrameworkAdapterSettings {
channelService?: string;

/**
* Optional. The option to determine if this adapter accepts WebSocket connections
*/
enableWebSockets?: boolean;

/**
* Optional. Used to pass in a NodeWebSocketFactoryBase instance. Allows bot to accept WebSocket connections.
* Optional. Used to pass in a NodeWebSocketFactoryBase instance.
*/
webSocketFactory?: NodeWebSocketFactoryBase;
}
Expand Down Expand Up @@ -269,12 +264,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide
this.credentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope;
}

// If the developer wants to use WebSockets, but didn't provide a WebSocketFactory,
// create a NodeWebSocketFactory.
if (this.settings.enableWebSockets && !this.settings.webSocketFactory) {
this.webSocketFactory = new NodeWebSocketFactory();
}

// If a NodeWebSocketFactoryBase was passed in, set it on the BotFrameworkAdapter.
if (this.settings.webSocketFactory) {
this.webSocketFactory = this.settings.webSocketFactory;
}
Expand Down Expand Up @@ -1146,13 +1136,14 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide
/**
* Process the initial request to establish a long lived connection via a streaming server.
* @param req The connection request.
* @param res The response sent on error or connection termination.
* @param logic The logic that will handle incoming requests.
* @param socket The raw socket connection between the bot (server) and channel/caller (client).
* @param head The first packet of the upgraded stream.
* @param logic The logic that handles incoming streaming requests for the lifetime of the WebSocket connection.
*/
public async useWebSocket(req: IncomingMessage, socket: Socket, head: Buffer, logic: (context: TurnContext) => Promise<any>): Promise<void> {
if (!this.webSocketFactory || !this.webSocketFactory.createWebSocket) {
throw new Error('BotFrameworkAdapter must have a WebSocketFactory in order to support streaming.');
}
public async useWebSocket(req: IncomingMessage, socket: Socket, head: Buffer, logic: (context: TurnContext) => Promise<any>): Promise<void> {
// 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`');
Expand All @@ -1177,7 +1168,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide
throw err;
}

const nodeWebSocket = await this.webSocketFactory.createWebSocket(req, socket, head);
const nodeWebSocket = await webSocketFactory.createWebSocket(req, socket, head);

await this.startWebSocket(nodeWebSocket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const createNetSocket = (readable = true, writable = true) => {
};

class TestAdapterSettings {
constructor(appId = undefined, appPassword = undefined, channelAuthTenant, oAuthEndpoint, openIdMetadata, channelServce) {
constructor(appId, appPassword) {
this.appId = appId;
this.appPassword = appPassword;
this.enableWebSockets = true;
}
}

Expand Down

0 comments on commit b08c9fa

Please sign in to comment.