@lenne.tech/ng-base 0.3.8 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -541,8 +541,11 @@
541
541
  return this._token.value;
542
542
  },
543
543
  set: function (token) {
544
+ var _a, _b;
544
545
  this._token.next(token);
545
546
  this.storageService.save('token', token);
547
+ (_a = this.subscriptionClient) === null || _a === void 0 ? void 0 : _a.close();
548
+ (_b = this.subscriptionClient) === null || _b === void 0 ? void 0 : _b.connect();
546
549
  },
547
550
  enumerable: false,
548
551
  configurable: true
@@ -588,27 +591,17 @@
588
591
  return forward(operation);
589
592
  });
590
593
  if (baseModuleConfig.wsUrl) {
591
- var wsClient = void 0;
592
- if (localStorage) {
593
- var token = authService.token || null;
594
- wsClient = new ws.WebSocketLink({
595
- uri: baseModuleConfig.wsUrl,
596
- options: {
597
- reconnect: true,
598
- connectionParams: {
599
- authToken: token,
600
- },
601
- },
602
- });
603
- }
604
- else {
605
- wsClient = new ws.WebSocketLink({
606
- uri: baseModuleConfig.wsUrl,
607
- options: {
608
- reconnect: true,
609
- },
610
- });
611
- }
594
+ var wsLink = new ws.WebSocketLink({
595
+ uri: baseModuleConfig.wsUrl,
596
+ options: {
597
+ reconnect: true,
598
+ connectionParams: function () { return ({
599
+ Authorization: authService.token ? 'Bearer ' + authService.token : undefined,
600
+ }); },
601
+ },
602
+ });
603
+ // Set client for reconnection on logout/login
604
+ authService.subscriptionClient = wsLink.subscriptionClient;
612
605
  // using the ability to split links, you can send data to each link
613
606
  // depending on what kind of operation is being sent
614
607
  links.push(core.split(
@@ -618,7 +611,7 @@
618
611
  // @ts-ignore
619
612
  var _b = utilities.getMainDefinition(query), kind = _b.kind, operation = _b.operation;
620
613
  return kind === 'OperationDefinition' && operation === 'subscription';
621
- }, wsClient, core.concat(authMiddleware, http)));
614
+ }, wsLink, core.concat(authMiddleware, http)));
622
615
  }
623
616
  else {
624
617
  links.push(http);