File tree 2 files changed +11
-16
lines changed 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;
8
8
export class WSAdapter extends WSSAdapter {
9
9
constructor ( options : any ) {
10
10
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 ;
14
12
}
15
13
16
14
onListen ( ) { }
17
15
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
+ }
19
21
close ( ) { }
20
22
}
21
23
Original file line number Diff line number Diff line change @@ -6,21 +6,13 @@ import events from 'events';
6
6
export class ParseWebSocketServer {
7
7
server : Object ;
8
8
9
- constructor (
10
- server : any ,
11
- onConnect : Function ,
12
- config
13
- ) {
9
+ constructor ( server : any , onConnect : Function , config ) {
14
10
config . server = server ;
15
- const wss = loadAdapter (
16
- config . wssAdapter ,
17
- WSAdapter ,
18
- config ,
19
- ) ;
11
+ const wss = loadAdapter ( config . wssAdapter , WSAdapter , config ) ;
20
12
wss . onListen = ( ) => {
21
13
logger . info ( 'Parse LiveQuery Server starts running' ) ;
22
14
} ;
23
- wss . onConnection = ( ws ) => {
15
+ wss . onConnection = ws => {
24
16
onConnect ( new ParseWebSocket ( ws ) ) ;
25
17
// Send ping to client periodically
26
18
const pingIntervalId = setInterval ( ( ) => {
@@ -47,7 +39,8 @@ export class ParseWebSocket extends events.EventEmitter {
47
39
48
40
constructor ( ws : any ) {
49
41
super ( ) ;
50
- ws . onmessage = ( request ) => this . emit ( 'message' , request ) ;
42
+ ws . onmessage = request =>
43
+ this . emit ( 'message' , request && request . data ? request . data : request ) ;
51
44
ws . onclose = ( ) => this . emit ( 'disconnect' ) ;
52
45
this . ws = ws ;
53
46
}
You can’t perform that action at this time.
0 commit comments