123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.ParseWebSocketServer = exports.ParseWebSocket = void 0;
- var _AdapterLoader = require("../Adapters/AdapterLoader");
- var _WSAdapter = require("../Adapters/WebSocketServer/WSAdapter");
- var _logger = _interopRequireDefault(require("../logger"));
- var _events = _interopRequireDefault(require("events"));
- var _util = require("util");
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- class ParseWebSocketServer {
- constructor(server, onConnect, config) {
- config.server = server;
- const wss = (0, _AdapterLoader.loadAdapter)(config.wssAdapter, _WSAdapter.WSAdapter, config);
- wss.onListen = () => {
- _logger.default.info('Parse LiveQuery Server started running');
- };
- wss.onConnection = ws => {
- ws.waitingForPong = false;
- ws.on('pong', () => {
- ws.waitingForPong = false;
- });
- ws.on('error', error => {
- _logger.default.error(error.message);
- _logger.default.error((0, _util.inspect)(ws, false));
- });
- onConnect(new ParseWebSocket(ws));
- // Send ping to client periodically
- const pingIntervalId = setInterval(() => {
- if (!ws.waitingForPong) {
- ws.ping();
- ws.waitingForPong = true;
- } else {
- clearInterval(pingIntervalId);
- ws.terminate();
- }
- }, config.websocketTimeout || 10 * 1000);
- };
- wss.onError = error => {
- _logger.default.error(error);
- };
- wss.start();
- this.server = wss;
- }
- close() {
- if (this.server && this.server.close) {
- this.server.close();
- }
- }
- }
- exports.ParseWebSocketServer = ParseWebSocketServer;
- class ParseWebSocket extends _events.default.EventEmitter {
- constructor(ws) {
- super();
- ws.onmessage = request => this.emit('message', request && request.data ? request.data : request);
- ws.onclose = () => this.emit('disconnect');
- this.ws = ws;
- }
- send(message) {
- this.ws.send(message);
- }
- }
- exports.ParseWebSocket = ParseWebSocket;
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfQWRhcHRlckxvYWRlciIsInJlcXVpcmUiLCJfV1NBZGFwdGVyIiw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