committed by
Diamond Lewis
parent
d4fa62ae26
commit
bde96a9002
@@ -8,14 +8,16 @@ const WebSocketServer = require('ws').Server;
|
||||
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);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
onListen() {}
|
||||
onConnection(ws) {}
|
||||
start() {}
|
||||
start() {
|
||||
const wss = new WebSocketServer({ server: this.options.server });
|
||||
wss.on('listening', this.onListen);
|
||||
wss.on('connection', this.onConnection);
|
||||
}
|
||||
close() {}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,21 +6,13 @@ import events from 'events';
|
||||
export class ParseWebSocketServer {
|
||||
server: Object;
|
||||
|
||||
constructor(
|
||||
server: any,
|
||||
onConnect: Function,
|
||||
config
|
||||
) {
|
||||
constructor(server: any, onConnect: Function, config) {
|
||||
config.server = server;
|
||||
const wss = loadAdapter(
|
||||
config.wssAdapter,
|
||||
WSAdapter,
|
||||
config,
|
||||
);
|
||||
const wss = loadAdapter(config.wssAdapter, WSAdapter, config);
|
||||
wss.onListen = () => {
|
||||
logger.info('Parse LiveQuery Server starts running');
|
||||
};
|
||||
wss.onConnection = (ws) => {
|
||||
wss.onConnection = ws => {
|
||||
onConnect(new ParseWebSocket(ws));
|
||||
// Send ping to client periodically
|
||||
const pingIntervalId = setInterval(() => {
|
||||
@@ -47,7 +39,8 @@ export class ParseWebSocket extends events.EventEmitter {
|
||||
|
||||
constructor(ws: any) {
|
||||
super();
|
||||
ws.onmessage = (request) => this.emit('message', request);
|
||||
ws.onmessage = request =>
|
||||
this.emit('message', request && request.data ? request.data : request);
|
||||
ws.onclose = () => this.emit('disconnect');
|
||||
this.ws = ws;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user