Implement WebSocketServer Adapter (#5866)
* Implement WebSocketServerAdapter * lint * clean up
This commit is contained in:
22
src/Adapters/WebSocketServer/WSAdapter.js
Normal file
22
src/Adapters/WebSocketServer/WSAdapter.js
Normal 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;
|
||||
52
src/Adapters/WebSocketServer/WSSAdapter.js
Normal file
52
src/Adapters/WebSocketServer/WSSAdapter.js
Normal 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;
|
||||
Reference in New Issue
Block a user