"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _EventEmitter = _interopRequireDefault(require("./EventEmitter")); var _LiveQueryClient = _interopRequireDefault(require("./LiveQueryClient")); var _CoreManager = _interopRequireDefault(require("./CoreManager")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @flow */ function getLiveQueryClient() /*: LiveQueryClient*/{ return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient(); } /** * We expose three events to help you monitor the status of the WebSocket connection: * *
Open - When we establish the WebSocket connection to the LiveQuery server, you'll get this event. * *
* Parse.LiveQuery.on('open', () => { * * });* *
Close - When we lose the WebSocket connection to the LiveQuery server, you'll get this event. * *
* Parse.LiveQuery.on('close', () => { * * });* *
Error - When some network error or LiveQuery server error happens, you'll get this event. * *
* Parse.LiveQuery.on('error', (error) => { * * });* * @class Parse.LiveQuery * @static */ const LiveQuery = new _EventEmitter.default(); /** * After open is called, the LiveQuery will try to send a connect request * to the LiveQuery server. */ LiveQuery.open = async () => { const liveQueryClient = await getLiveQueryClient(); liveQueryClient.open(); }; /** * When you're done using LiveQuery, you can call Parse.LiveQuery.close(). * This function will close the WebSocket connection to the LiveQuery server, * cancel the auto reconnect, and unsubscribe all subscriptions based on it. * If you call query.subscribe() after this, we'll create a new WebSocket * connection to the LiveQuery server. */ LiveQuery.close = async () => { const liveQueryClient = await getLiveQueryClient(); liveQueryClient.close(); }; // Register a default onError callback to make sure we do not crash on error LiveQuery.on('error', () => {}); var _default = LiveQuery; exports.default = _default; let defaultLiveQueryClient; const DefaultLiveQueryController = { setDefaultLiveQueryClient(liveQueryClient /*: LiveQueryClient*/) { defaultLiveQueryClient = liveQueryClient; }, async getDefaultLiveQueryClient() /*: Promise