@@ -4,21 +4,25 @@ const typeMap = new Map([['disconnect', 'close']]);
|
||||
const getWS = function() {
|
||||
try {
|
||||
return require('uws');
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return require('ws');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export class ParseWebSocketServer {
|
||||
server: Object;
|
||||
|
||||
constructor(server: any, onConnect: Function, websocketTimeout: number = 10 * 1000) {
|
||||
constructor(
|
||||
server: any,
|
||||
onConnect: Function,
|
||||
websocketTimeout: number = 10 * 1000
|
||||
) {
|
||||
const WebSocketServer = getWS().Server;
|
||||
const wss = new WebSocketServer({ server: server });
|
||||
wss.on('listening', () => {
|
||||
logger.info('Parse LiveQuery Server starts running');
|
||||
});
|
||||
wss.on('connection', (ws) => {
|
||||
wss.on('connection', ws => {
|
||||
onConnect(new ParseWebSocket(ws));
|
||||
// Send ping to client periodically
|
||||
const pingIntervalId = setInterval(() => {
|
||||
|
||||
Reference in New Issue
Block a user