Implement WebSocketServer Adapter (#5866)

* Implement WebSocketServerAdapter

* lint

* clean up
This commit is contained in:
Diamond Lewis
2019-07-30 09:05:41 -05:00
committed by GitHub
parent 7c8e940f53
commit 218c3499f9
10 changed files with 571 additions and 522 deletions

View File

@@ -0,0 +1,22 @@
/*eslint no-unused-vars: "off"*/
import { WSSAdapter } from './WSSAdapter';
const WebSocketServer = require('ws').Server;
/**
* Wrapper for ws node module
*/
export class WSAdapter extends WSSAdapter {
constructor(options: any) {
super(options);
const wss = new WebSocketServer({ server: options.server });
wss.on('listening', this.onListen);
wss.on('connection', this.onConnection);
}
onListen() {}
onConnection(ws) {}
start() {}
close() {}
}
export default WSAdapter;

View File

@@ -0,0 +1,52 @@
/*eslint no-unused-vars: "off"*/
// WebSocketServer Adapter
//
// Adapter classes must implement the following functions:
// * onListen()
// * onConnection(ws)
// * start()
// * close()
//
// Default is WSAdapter. The above functions will be binded.
/**
* @module Adapters
*/
/**
* @interface WSSAdapter
*/
export class WSSAdapter {
/**
* @param {Object} options - {http.Server|https.Server} server
*/
constructor(options) {
this.onListen = () => {}
this.onConnection = () => {}
}
// /**
// * Emitted when the underlying server has been bound.
// */
// onListen() {}
// /**
// * Emitted when the handshake is complete.
// *
// * @param {WebSocket} ws - RFC 6455 WebSocket.
// */
// onConnection(ws) {}
/**
* Initialize Connection.
*
* @param {Object} options
*/
start(options) {}
/**
* Closes server.
*/
close() {}
}
export default WSSAdapter;