Skip to content

Commit 6ab5cde

Browse files
davimacedodplewis
authored andcommitted
Fix live query (parse-community#5871)
* Fix live query * fix test
1 parent 02fa574 commit 6ab5cde

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/Adapters/WebSocketServer/WSAdapter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const WebSocketServer = require('ws').Server;
88
export 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

src/LiveQuery/ParseWebSocketServer.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@ import events from 'events';
66
export 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
}

0 commit comments

Comments
 (0)