Skip to content

Fix live query #5871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Adapters/WebSocketServer/WSAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}

Expand Down
17 changes: 5 additions & 12 deletions src/LiveQuery/ParseWebSocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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;
}
Expand Down