client.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  14. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  15. return new (P || (P = Promise))(function (resolve, reject) {
  16. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  17. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  18. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  19. step((generator = generator.apply(thisArg, _arguments || [])).next());
  20. });
  21. };
  22. var __generator = (this && this.__generator) || function (thisArg, body) {
  23. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  24. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  25. function verb(n) { return function (v) { return step([n, v]); }; }
  26. function step(op) {
  27. if (f) throw new TypeError("Generator is already executing.");
  28. while (_) try {
  29. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  30. if (y = 0, t) op = [op[0] & 2, t.value];
  31. switch (op[0]) {
  32. case 0: case 1: t = op; break;
  33. case 4: _.label++; return { value: op[1], done: false };
  34. case 5: _.label++; y = op[1]; op = [0]; continue;
  35. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  36. default:
  37. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  38. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  39. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  40. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  41. if (t[2]) _.ops.pop();
  42. _.trys.pop(); continue;
  43. }
  44. op = body.call(thisArg, _);
  45. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  46. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  47. }
  48. };
  49. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  50. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  51. if (ar || !(i in from)) {
  52. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  53. ar[i] = from[i];
  54. }
  55. }
  56. return to.concat(ar || Array.prototype.slice.call(from));
  57. };
  58. Object.defineProperty(exports, "__esModule", { value: true });
  59. exports.SubscriptionClient = void 0;
  60. var _global = typeof global !== 'undefined' ? global : (typeof window !== 'undefined' ? window : {});
  61. var NativeWebSocket = _global.WebSocket || _global.MozWebSocket;
  62. var Backoff = require("backo2");
  63. var eventemitter3_1 = require("eventemitter3");
  64. var is_string_1 = require("./utils/is-string");
  65. var is_object_1 = require("./utils/is-object");
  66. var printer_1 = require("graphql/language/printer");
  67. var getOperationAST_1 = require("graphql/utilities/getOperationAST");
  68. var symbol_observable_1 = require("symbol-observable");
  69. var protocol_1 = require("./protocol");
  70. var defaults_1 = require("./defaults");
  71. var message_types_1 = require("./message-types");
  72. var SubscriptionClient = (function () {
  73. function SubscriptionClient(url, options, webSocketImpl, webSocketProtocols) {
  74. var _a = (options || {}), _b = _a.connectionCallback, connectionCallback = _b === void 0 ? undefined : _b, _c = _a.connectionParams, connectionParams = _c === void 0 ? {} : _c, _d = _a.minTimeout, minTimeout = _d === void 0 ? defaults_1.MIN_WS_TIMEOUT : _d, _e = _a.timeout, timeout = _e === void 0 ? defaults_1.WS_TIMEOUT : _e, _f = _a.reconnect, reconnect = _f === void 0 ? false : _f, _g = _a.reconnectionAttempts, reconnectionAttempts = _g === void 0 ? Infinity : _g, _h = _a.lazy, lazy = _h === void 0 ? false : _h, _j = _a.inactivityTimeout, inactivityTimeout = _j === void 0 ? 0 : _j, _k = _a.wsOptionArguments, wsOptionArguments = _k === void 0 ? [] : _k;
  75. this.wsImpl = webSocketImpl || NativeWebSocket;
  76. if (!this.wsImpl) {
  77. throw new Error('Unable to find native implementation, or alternative implementation for WebSocket!');
  78. }
  79. this.wsProtocols = webSocketProtocols || protocol_1.GRAPHQL_WS;
  80. this.connectionCallback = connectionCallback;
  81. this.url = url;
  82. this.operations = {};
  83. this.nextOperationId = 0;
  84. this.minWsTimeout = minTimeout;
  85. this.wsTimeout = timeout;
  86. this.unsentMessagesQueue = [];
  87. this.reconnect = reconnect;
  88. this.reconnecting = false;
  89. this.reconnectionAttempts = reconnectionAttempts;
  90. this.lazy = !!lazy;
  91. this.inactivityTimeout = inactivityTimeout;
  92. this.closedByUser = false;
  93. this.backoff = new Backoff({ jitter: 0.5 });
  94. this.eventEmitter = new eventemitter3_1.EventEmitter();
  95. this.middlewares = [];
  96. this.client = null;
  97. this.maxConnectTimeGenerator = this.createMaxConnectTimeGenerator();
  98. this.connectionParams = this.getConnectionParams(connectionParams);
  99. this.wsOptionArguments = wsOptionArguments;
  100. if (!this.lazy) {
  101. this.connect();
  102. }
  103. }
  104. Object.defineProperty(SubscriptionClient.prototype, "status", {
  105. get: function () {
  106. if (this.client === null) {
  107. return this.wsImpl.CLOSED;
  108. }
  109. return this.client.readyState;
  110. },
  111. enumerable: false,
  112. configurable: true
  113. });
  114. SubscriptionClient.prototype.close = function (isForced, closedByUser) {
  115. if (isForced === void 0) { isForced = true; }
  116. if (closedByUser === void 0) { closedByUser = true; }
  117. this.clearInactivityTimeout();
  118. if (this.client !== null) {
  119. this.closedByUser = closedByUser;
  120. if (isForced) {
  121. this.clearCheckConnectionInterval();
  122. this.clearMaxConnectTimeout();
  123. this.clearTryReconnectTimeout();
  124. this.unsubscribeAll();
  125. this.sendMessage(undefined, message_types_1.default.GQL_CONNECTION_TERMINATE, null);
  126. }
  127. this.client.close();
  128. this.client.onopen = null;
  129. this.client.onclose = null;
  130. this.client.onerror = null;
  131. this.client.onmessage = null;
  132. this.client = null;
  133. this.eventEmitter.emit('disconnected');
  134. if (!isForced) {
  135. this.tryReconnect();
  136. }
  137. }
  138. };
  139. SubscriptionClient.prototype.request = function (request) {
  140. var _a;
  141. var getObserver = this.getObserver.bind(this);
  142. var executeOperation = this.executeOperation.bind(this);
  143. var unsubscribe = this.unsubscribe.bind(this);
  144. var opId;
  145. this.clearInactivityTimeout();
  146. return _a = {},
  147. _a[symbol_observable_1.default] = function () {
  148. return this;
  149. },
  150. _a.subscribe = function (observerOrNext, onError, onComplete) {
  151. var observer = getObserver(observerOrNext, onError, onComplete);
  152. opId = executeOperation(request, function (error, result) {
  153. if (error === null && result === null) {
  154. if (observer.complete) {
  155. observer.complete();
  156. }
  157. }
  158. else if (error) {
  159. if (observer.error) {
  160. observer.error(error[0]);
  161. }
  162. }
  163. else {
  164. if (observer.next) {
  165. observer.next(result);
  166. }
  167. }
  168. });
  169. return {
  170. unsubscribe: function () {
  171. if (opId) {
  172. unsubscribe(opId);
  173. opId = null;
  174. }
  175. },
  176. };
  177. },
  178. _a;
  179. };
  180. SubscriptionClient.prototype.on = function (eventName, callback, context) {
  181. var handler = this.eventEmitter.on(eventName, callback, context);
  182. return function () {
  183. handler.off(eventName, callback, context);
  184. };
  185. };
  186. SubscriptionClient.prototype.onConnected = function (callback, context) {
  187. return this.on('connected', callback, context);
  188. };
  189. SubscriptionClient.prototype.onConnecting = function (callback, context) {
  190. return this.on('connecting', callback, context);
  191. };
  192. SubscriptionClient.prototype.onDisconnected = function (callback, context) {
  193. return this.on('disconnected', callback, context);
  194. };
  195. SubscriptionClient.prototype.onReconnected = function (callback, context) {
  196. return this.on('reconnected', callback, context);
  197. };
  198. SubscriptionClient.prototype.onReconnecting = function (callback, context) {
  199. return this.on('reconnecting', callback, context);
  200. };
  201. SubscriptionClient.prototype.onError = function (callback, context) {
  202. return this.on('error', callback, context);
  203. };
  204. SubscriptionClient.prototype.unsubscribeAll = function () {
  205. var _this = this;
  206. Object.keys(this.operations).forEach(function (subId) {
  207. _this.unsubscribe(subId);
  208. });
  209. };
  210. SubscriptionClient.prototype.applyMiddlewares = function (options) {
  211. var _this = this;
  212. return new Promise(function (resolve, reject) {
  213. var queue = function (funcs, scope) {
  214. var next = function (error) {
  215. if (error) {
  216. reject(error);
  217. }
  218. else {
  219. if (funcs.length > 0) {
  220. var f = funcs.shift();
  221. if (f) {
  222. f.applyMiddleware.apply(scope, [options, next]);
  223. }
  224. }
  225. else {
  226. resolve(options);
  227. }
  228. }
  229. };
  230. next();
  231. };
  232. queue(__spreadArray([], _this.middlewares, true), _this);
  233. });
  234. };
  235. SubscriptionClient.prototype.use = function (middlewares) {
  236. var _this = this;
  237. middlewares.map(function (middleware) {
  238. if (typeof middleware.applyMiddleware === 'function') {
  239. _this.middlewares.push(middleware);
  240. }
  241. else {
  242. throw new Error('Middleware must implement the applyMiddleware function.');
  243. }
  244. });
  245. return this;
  246. };
  247. SubscriptionClient.prototype.getConnectionParams = function (connectionParams) {
  248. return function () { return new Promise(function (resolve, reject) {
  249. if (typeof connectionParams === 'function') {
  250. try {
  251. return resolve(connectionParams.call(null));
  252. }
  253. catch (error) {
  254. return reject(error);
  255. }
  256. }
  257. resolve(connectionParams);
  258. }); };
  259. };
  260. SubscriptionClient.prototype.executeOperation = function (options, handler) {
  261. var _this = this;
  262. if (this.client === null) {
  263. this.connect();
  264. }
  265. var opId = this.generateOperationId();
  266. this.operations[opId] = { options: options, handler: handler };
  267. this.applyMiddlewares(options)
  268. .then(function (processedOptions) {
  269. _this.checkOperationOptions(processedOptions, handler);
  270. if (_this.operations[opId]) {
  271. _this.operations[opId] = { options: processedOptions, handler: handler };
  272. _this.sendMessage(opId, message_types_1.default.GQL_START, processedOptions);
  273. }
  274. })
  275. .catch(function (error) {
  276. _this.unsubscribe(opId);
  277. handler(_this.formatErrors(error));
  278. });
  279. return opId;
  280. };
  281. SubscriptionClient.prototype.getObserver = function (observerOrNext, error, complete) {
  282. if (typeof observerOrNext === 'function') {
  283. return {
  284. next: function (v) { return observerOrNext(v); },
  285. error: function (e) { return error && error(e); },
  286. complete: function () { return complete && complete(); },
  287. };
  288. }
  289. return observerOrNext;
  290. };
  291. SubscriptionClient.prototype.createMaxConnectTimeGenerator = function () {
  292. var minValue = this.minWsTimeout;
  293. var maxValue = this.wsTimeout;
  294. return new Backoff({
  295. min: minValue,
  296. max: maxValue,
  297. factor: 1.2,
  298. });
  299. };
  300. SubscriptionClient.prototype.clearCheckConnectionInterval = function () {
  301. if (this.checkConnectionIntervalId) {
  302. clearInterval(this.checkConnectionIntervalId);
  303. this.checkConnectionIntervalId = null;
  304. }
  305. };
  306. SubscriptionClient.prototype.clearMaxConnectTimeout = function () {
  307. if (this.maxConnectTimeoutId) {
  308. clearTimeout(this.maxConnectTimeoutId);
  309. this.maxConnectTimeoutId = null;
  310. }
  311. };
  312. SubscriptionClient.prototype.clearTryReconnectTimeout = function () {
  313. if (this.tryReconnectTimeoutId) {
  314. clearTimeout(this.tryReconnectTimeoutId);
  315. this.tryReconnectTimeoutId = null;
  316. }
  317. };
  318. SubscriptionClient.prototype.clearInactivityTimeout = function () {
  319. if (this.inactivityTimeoutId) {
  320. clearTimeout(this.inactivityTimeoutId);
  321. this.inactivityTimeoutId = null;
  322. }
  323. };
  324. SubscriptionClient.prototype.setInactivityTimeout = function () {
  325. var _this = this;
  326. if (this.inactivityTimeout > 0 && Object.keys(this.operations).length === 0) {
  327. this.inactivityTimeoutId = setTimeout(function () {
  328. if (Object.keys(_this.operations).length === 0) {
  329. _this.close();
  330. }
  331. }, this.inactivityTimeout);
  332. }
  333. };
  334. SubscriptionClient.prototype.checkOperationOptions = function (options, handler) {
  335. var query = options.query, variables = options.variables, operationName = options.operationName;
  336. if (!query) {
  337. throw new Error('Must provide a query.');
  338. }
  339. if (!handler) {
  340. throw new Error('Must provide an handler.');
  341. }
  342. if ((!(0, is_string_1.default)(query) && !(0, getOperationAST_1.getOperationAST)(query, operationName)) ||
  343. (operationName && !(0, is_string_1.default)(operationName)) ||
  344. (variables && !(0, is_object_1.default)(variables))) {
  345. throw new Error('Incorrect option types. query must be a string or a document,' +
  346. '`operationName` must be a string, and `variables` must be an object.');
  347. }
  348. };
  349. SubscriptionClient.prototype.buildMessage = function (id, type, payload) {
  350. var payloadToReturn = payload && payload.query ? __assign(__assign({}, payload), { query: typeof payload.query === 'string' ? payload.query : (0, printer_1.print)(payload.query) }) :
  351. payload;
  352. return {
  353. id: id,
  354. type: type,
  355. payload: payloadToReturn,
  356. };
  357. };
  358. SubscriptionClient.prototype.formatErrors = function (errors) {
  359. if (Array.isArray(errors)) {
  360. return errors;
  361. }
  362. if (errors && errors.errors) {
  363. return this.formatErrors(errors.errors);
  364. }
  365. if (errors && errors.message) {
  366. return [errors];
  367. }
  368. return [{
  369. name: 'FormatedError',
  370. message: 'Unknown error',
  371. originalError: errors,
  372. }];
  373. };
  374. SubscriptionClient.prototype.sendMessage = function (id, type, payload) {
  375. this.sendMessageRaw(this.buildMessage(id, type, payload));
  376. };
  377. SubscriptionClient.prototype.sendMessageRaw = function (message) {
  378. switch (this.status) {
  379. case this.wsImpl.OPEN:
  380. var serializedMessage = JSON.stringify(message);
  381. try {
  382. JSON.parse(serializedMessage);
  383. }
  384. catch (e) {
  385. this.eventEmitter.emit('error', new Error("Message must be JSON-serializable. Got: " + message));
  386. }
  387. this.client.send(serializedMessage);
  388. break;
  389. case this.wsImpl.CONNECTING:
  390. this.unsentMessagesQueue.push(message);
  391. break;
  392. default:
  393. if (!this.reconnecting) {
  394. this.eventEmitter.emit('error', new Error('A message was not sent because socket is not connected, is closing or ' +
  395. 'is already closed. Message was: ' + JSON.stringify(message)));
  396. }
  397. }
  398. };
  399. SubscriptionClient.prototype.generateOperationId = function () {
  400. return String(++this.nextOperationId);
  401. };
  402. SubscriptionClient.prototype.tryReconnect = function () {
  403. var _this = this;
  404. if (!this.reconnect || this.backoff.attempts >= this.reconnectionAttempts) {
  405. return;
  406. }
  407. if (!this.reconnecting) {
  408. Object.keys(this.operations).forEach(function (key) {
  409. _this.unsentMessagesQueue.push(_this.buildMessage(key, message_types_1.default.GQL_START, _this.operations[key].options));
  410. });
  411. this.reconnecting = true;
  412. }
  413. this.clearTryReconnectTimeout();
  414. var delay = this.backoff.duration();
  415. this.tryReconnectTimeoutId = setTimeout(function () {
  416. _this.connect();
  417. }, delay);
  418. };
  419. SubscriptionClient.prototype.flushUnsentMessagesQueue = function () {
  420. var _this = this;
  421. this.unsentMessagesQueue.forEach(function (message) {
  422. _this.sendMessageRaw(message);
  423. });
  424. this.unsentMessagesQueue = [];
  425. };
  426. SubscriptionClient.prototype.checkConnection = function () {
  427. if (this.wasKeepAliveReceived) {
  428. this.wasKeepAliveReceived = false;
  429. return;
  430. }
  431. if (!this.reconnecting) {
  432. this.close(false, true);
  433. }
  434. };
  435. SubscriptionClient.prototype.checkMaxConnectTimeout = function () {
  436. var _this = this;
  437. this.clearMaxConnectTimeout();
  438. this.maxConnectTimeoutId = setTimeout(function () {
  439. if (_this.status !== _this.wsImpl.OPEN) {
  440. _this.reconnecting = true;
  441. _this.close(false, true);
  442. }
  443. }, this.maxConnectTimeGenerator.duration());
  444. };
  445. SubscriptionClient.prototype.connect = function () {
  446. var _a;
  447. var _this = this;
  448. this.client = new ((_a = this.wsImpl).bind.apply(_a, __spreadArray([void 0, this.url, this.wsProtocols], this.wsOptionArguments, false)))();
  449. this.checkMaxConnectTimeout();
  450. this.client.onopen = function () { return __awaiter(_this, void 0, void 0, function () {
  451. var connectionParams, error_1;
  452. return __generator(this, function (_a) {
  453. switch (_a.label) {
  454. case 0:
  455. if (!(this.status === this.wsImpl.OPEN)) return [3, 4];
  456. this.clearMaxConnectTimeout();
  457. this.closedByUser = false;
  458. this.eventEmitter.emit(this.reconnecting ? 'reconnecting' : 'connecting');
  459. _a.label = 1;
  460. case 1:
  461. _a.trys.push([1, 3, , 4]);
  462. return [4, this.connectionParams()];
  463. case 2:
  464. connectionParams = _a.sent();
  465. this.sendMessage(undefined, message_types_1.default.GQL_CONNECTION_INIT, connectionParams);
  466. this.flushUnsentMessagesQueue();
  467. return [3, 4];
  468. case 3:
  469. error_1 = _a.sent();
  470. this.sendMessage(undefined, message_types_1.default.GQL_CONNECTION_ERROR, error_1);
  471. this.flushUnsentMessagesQueue();
  472. return [3, 4];
  473. case 4: return [2];
  474. }
  475. });
  476. }); };
  477. this.client.onclose = function () {
  478. if (!_this.closedByUser) {
  479. _this.close(false, false);
  480. }
  481. };
  482. this.client.onerror = function (err) {
  483. _this.eventEmitter.emit('error', err);
  484. };
  485. this.client.onmessage = function (_a) {
  486. var data = _a.data;
  487. _this.processReceivedData(data);
  488. };
  489. };
  490. SubscriptionClient.prototype.processReceivedData = function (receivedData) {
  491. var parsedMessage;
  492. var opId;
  493. try {
  494. parsedMessage = JSON.parse(receivedData);
  495. opId = parsedMessage.id;
  496. }
  497. catch (e) {
  498. throw new Error("Message must be JSON-parseable. Got: " + receivedData);
  499. }
  500. if ([message_types_1.default.GQL_DATA,
  501. message_types_1.default.GQL_COMPLETE,
  502. message_types_1.default.GQL_ERROR,
  503. ].indexOf(parsedMessage.type) !== -1 && !this.operations[opId]) {
  504. this.unsubscribe(opId);
  505. return;
  506. }
  507. switch (parsedMessage.type) {
  508. case message_types_1.default.GQL_CONNECTION_ERROR:
  509. if (this.connectionCallback) {
  510. this.connectionCallback(parsedMessage.payload);
  511. }
  512. break;
  513. case message_types_1.default.GQL_CONNECTION_ACK:
  514. this.eventEmitter.emit(this.reconnecting ? 'reconnected' : 'connected', parsedMessage.payload);
  515. this.reconnecting = false;
  516. this.backoff.reset();
  517. this.maxConnectTimeGenerator.reset();
  518. if (this.connectionCallback) {
  519. this.connectionCallback();
  520. }
  521. break;
  522. case message_types_1.default.GQL_COMPLETE:
  523. var handler = this.operations[opId].handler;
  524. delete this.operations[opId];
  525. handler.call(this, null, null);
  526. break;
  527. case message_types_1.default.GQL_ERROR:
  528. this.operations[opId].handler(this.formatErrors(parsedMessage.payload), null);
  529. delete this.operations[opId];
  530. break;
  531. case message_types_1.default.GQL_DATA:
  532. var parsedPayload = !parsedMessage.payload.errors ?
  533. parsedMessage.payload : __assign(__assign({}, parsedMessage.payload), { errors: this.formatErrors(parsedMessage.payload.errors) });
  534. this.operations[opId].handler(null, parsedPayload);
  535. break;
  536. case message_types_1.default.GQL_CONNECTION_KEEP_ALIVE:
  537. var firstKA = typeof this.wasKeepAliveReceived === 'undefined';
  538. this.wasKeepAliveReceived = true;
  539. if (firstKA) {
  540. this.checkConnection();
  541. }
  542. if (this.checkConnectionIntervalId) {
  543. clearInterval(this.checkConnectionIntervalId);
  544. this.checkConnection();
  545. }
  546. this.checkConnectionIntervalId = setInterval(this.checkConnection.bind(this), this.wsTimeout);
  547. break;
  548. default:
  549. throw new Error('Invalid message type!');
  550. }
  551. };
  552. SubscriptionClient.prototype.unsubscribe = function (opId) {
  553. if (this.operations[opId]) {
  554. delete this.operations[opId];
  555. this.setInactivityTimeout();
  556. this.sendMessage(opId, message_types_1.default.GQL_STOP, undefined);
  557. }
  558. };
  559. return SubscriptionClient;
  560. }());
  561. exports.SubscriptionClient = SubscriptionClient;
  562. //# sourceMappingURL=client.js.map