File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,16 @@ const WebSocketServer = require('ws').Server;
88export class WSAdapter extends WSSAdapter {
99 constructor ( options : any ) {
1010 super ( options ) ;
11- const wss = new WebSocketServer ( { server : options . server } ) ;
12- wss . on ( 'listening' , this . onListen ) ;
13- wss . on ( 'connection' , this . onConnection ) ;
11+ this . options = options ;
1412 }
1513
1614 onListen ( ) { }
1715 onConnection ( ws ) { }
18- start ( ) { }
16+ start ( ) {
17+ const wss = new WebSocketServer ( { server : this . options . server } ) ;
18+ wss . on ( 'listening' , this . onListen ) ;
19+ wss . on ( 'connection' , this . onConnection ) ;
20+ }
1921 close ( ) { }
2022}
2123
Original file line number Diff line number Diff line change @@ -6,21 +6,13 @@ import events from 'events';
66export class ParseWebSocketServer {
77 server : Object ;
88
9- constructor (
10- server : any ,
11- onConnect : Function ,
12- config
13- ) {
9+ constructor ( server : any , onConnect : Function , config ) {
1410 config . server = server ;
15- const wss = loadAdapter (
16- config . wssAdapter ,
17- WSAdapter ,
18- config ,
19- ) ;
11+ const wss = loadAdapter ( config . wssAdapter , WSAdapter , config ) ;
2012 wss . onListen = ( ) => {
2113 logger . info ( 'Parse LiveQuery Server starts running' ) ;
2214 } ;
23- wss . onConnection = ( ws ) => {
15+ wss . onConnection = ws => {
2416 onConnect ( new ParseWebSocket ( ws ) ) ;
2517 // Send ping to client periodically
2618 const pingIntervalId = setInterval ( ( ) => {
@@ -47,7 +39,8 @@ export class ParseWebSocket extends events.EventEmitter {
4739
4840 constructor ( ws : any ) {
4941 super ( ) ;
50- ws . onmessage = ( request ) => this . emit ( 'message' , request ) ;
42+ ws . onmessage = request =>
43+ this . emit ( 'message' , request && request . data ? request . data : request ) ;
5144 ws . onclose = ( ) => this . emit ( 'disconnect' ) ;
5245 this . ws = ws ;
5346 }
You can’t perform that action at this time.
0 commit comments