"use strict"; var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property"); var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise")); var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of")); var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator")); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator")); var _EventEmitter = _interopRequireDefault(require("./EventEmitter")); var _LiveQueryClient = _interopRequireDefault(require("./LiveQueryClient")); var _CoreManager = _interopRequireDefault(require("./CoreManager")); /** * @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
*/
var LiveQuery = new _EventEmitter.default();
/**
* After open is called, the LiveQuery will try to send a connect request
* to the LiveQuery server.
*/
LiveQuery.open = /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
var liveQueryClient;
return _regenerator.default.wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return getLiveQueryClient();
case 2:
liveQueryClient = _context.sent;
liveQueryClient.open();
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
/**
* 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 = /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
var liveQueryClient;
return _regenerator.default.wrap(function (_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return getLiveQueryClient();
case 2:
liveQueryClient = _context2.sent;
liveQueryClient.close();
case 4:
case "end":
return _context2.stop();
}
}, _callee2);
}));
// Register a default onError callback to make sure we do not crash on error
LiveQuery.on('error', function () {});
var _default = LiveQuery;
exports.default = _default;
var defaultLiveQueryClient;
var DefaultLiveQueryController = {
setDefaultLiveQueryClient: function (liveQueryClient /*: LiveQueryClient*/) {
defaultLiveQueryClient = liveQueryClient;
},
getDefaultLiveQueryClient: function () /*: Promise