client.js 24 KB

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