@socket-mesh/client 18.1.5 → 18.1.6

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.
@@ -1,22 +1,22 @@
1
- import { SignedAuthToken } from "@socket-mesh/auth";
1
+ import { SignedAuthToken } from '@socket-mesh/auth';
2
2
  export interface ClientAuthEngine {
3
+ loadToken(): Promise<null | SignedAuthToken>;
4
+ removeToken(): Promise<null | SignedAuthToken>;
3
5
  saveToken(token: SignedAuthToken, options?: {
4
6
  [key: string]: any;
5
7
  }): Promise<SignedAuthToken>;
6
- removeToken(): Promise<SignedAuthToken>;
7
- loadToken(): Promise<SignedAuthToken | null>;
8
8
  }
9
- export declare function isAuthEngine(auth: ClientAuthEngine | LocalStorageAuthEngineOptions): auth is ClientAuthEngine;
10
9
  export interface LocalStorageAuthEngineOptions {
11
10
  authTokenName?: string;
12
11
  }
12
+ export declare function isAuthEngine(auth?: ClientAuthEngine | LocalStorageAuthEngineOptions | null): auth is ClientAuthEngine;
13
13
  export declare class LocalStorageAuthEngine implements ClientAuthEngine {
14
14
  private readonly _authTokenName;
15
15
  private readonly _internalStorage;
16
16
  readonly isLocalStorageEnabled: boolean;
17
17
  constructor({ authTokenName }?: LocalStorageAuthEngineOptions);
18
- private _checkLocalStorageEnabled;
18
+ private checkLocalStorageEnabled;
19
+ loadToken(): Promise<null | SignedAuthToken>;
20
+ removeToken(): Promise<null | SignedAuthToken>;
19
21
  saveToken(token: string): Promise<SignedAuthToken>;
20
- removeToken(): Promise<SignedAuthToken>;
21
- loadToken(): Promise<SignedAuthToken>;
22
22
  }
@@ -1,18 +1,21 @@
1
1
  export function isAuthEngine(auth) {
2
- return (typeof auth === 'object' && 'saveToken' in auth && 'removeToken' in auth && 'loadToken' in auth);
2
+ return (!!auth && typeof auth === 'object' && 'saveToken' in auth && 'removeToken' in auth && 'loadToken' in auth);
3
3
  }
4
4
  export class LocalStorageAuthEngine {
5
+ _authTokenName;
6
+ _internalStorage;
7
+ isLocalStorageEnabled;
5
8
  constructor({ authTokenName } = {}) {
6
9
  this._internalStorage = {};
7
- this.isLocalStorageEnabled = this._checkLocalStorageEnabled();
10
+ this.isLocalStorageEnabled = this.checkLocalStorageEnabled();
8
11
  this._authTokenName = authTokenName ?? 'socketmesh.authToken';
9
12
  }
10
- _checkLocalStorageEnabled() {
13
+ checkLocalStorageEnabled() {
11
14
  let err;
12
15
  try {
13
16
  // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
14
17
  // throw QuotaExceededError. We're going to detect this and avoid hard to debug edge cases.
15
- localStorage.setItem('__localStorageTest', "1");
18
+ localStorage.setItem('__localStorageTest', '1');
16
19
  localStorage.removeItem('__localStorageTest');
17
20
  }
18
21
  catch (e) {
@@ -20,17 +23,18 @@ export class LocalStorageAuthEngine {
20
23
  }
21
24
  return !err;
22
25
  }
23
- async saveToken(token) {
26
+ async loadToken() {
27
+ let token;
24
28
  if (this.isLocalStorageEnabled) {
25
- localStorage.setItem(this._authTokenName, token);
29
+ token = localStorage.getItem(this._authTokenName);
26
30
  }
27
31
  else {
28
- this._internalStorage[this._authTokenName] = token;
32
+ token = this._internalStorage[this._authTokenName] || null;
29
33
  }
30
34
  return token;
31
35
  }
32
36
  async removeToken() {
33
- let loadPromise = this.loadToken();
37
+ const loadPromise = this.loadToken();
34
38
  if (this.isLocalStorageEnabled) {
35
39
  localStorage.removeItem(this._authTokenName);
36
40
  }
@@ -39,13 +43,12 @@ export class LocalStorageAuthEngine {
39
43
  }
40
44
  return loadPromise;
41
45
  }
42
- async loadToken() {
43
- let token;
46
+ async saveToken(token) {
44
47
  if (this.isLocalStorageEnabled) {
45
- token = localStorage.getItem(this._authTokenName);
48
+ localStorage.setItem(this._authTokenName, token);
46
49
  }
47
50
  else {
48
- token = this._internalStorage[this._authTokenName] || null;
51
+ this._internalStorage[this._authTokenName] = token;
49
52
  }
50
53
  return token;
51
54
  }
@@ -1,20 +1,20 @@
1
- import { ChannelDetails, ChannelMap, Channels, ChannelsOptions } from "@socket-mesh/channels";
2
- import { ClientTransport } from "./client-transport.js";
3
- import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from "@socket-mesh/core";
1
+ import { ChannelDetails, ChannelMap, Channels, ChannelsOptions } from '@socket-mesh/channels';
2
+ import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap } from '@socket-mesh/core';
3
+ import { ClientTransport } from './client-transport.js';
4
4
  export interface ClientChannelsOptions extends ChannelsOptions {
5
5
  autoSubscribeOnConnect?: boolean;
6
6
  }
7
7
  export declare class ClientChannels<TChannel extends ChannelMap, TIncoming extends MethodMap, TService extends ServiceMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TState extends object> extends Channels<TChannel> {
8
- autoSubscribeOnConnect: boolean;
9
- protected readonly _transport: ClientTransport<TIncoming, TService, TOutgoing, TPrivateOutgoing, TState>;
10
8
  protected _preparingPendingSubscriptions: boolean;
9
+ protected readonly _transport: ClientTransport<TIncoming, TService, TOutgoing, TPrivateOutgoing, TState>;
10
+ autoSubscribeOnConnect: boolean;
11
11
  constructor(transport: ClientTransport<TIncoming, TService, TOutgoing, TPrivateOutgoing, TState>, options?: ClientChannelsOptions);
12
+ invokePublish<U extends keyof TChannel & string>(channelName: keyof TChannel & string, data: TChannel[U]): Promise<void>;
13
+ private processPendingSubscriptions;
12
14
  private suspendSubscriptions;
15
+ transmitPublish<U extends keyof TChannel & string>(channelName: U, data: TChannel[U]): Promise<void>;
16
+ private triggerChannelSubscribeFail;
13
17
  protected trySubscribe(channel: ChannelDetails): void;
14
- private processPendingSubscriptions;
15
- unsubscribe(channelName: keyof TChannel & string): void;
16
18
  protected tryUnsubscribe(channel: ChannelDetails): void;
17
- private triggerChannelSubscribeFail;
18
- transmitPublish<U extends keyof TChannel & string>(channelName: U, data: TChannel[U]): Promise<void>;
19
- invokePublish<U extends keyof TChannel & string>(channelName: keyof TChannel & string, data: TChannel[U]): Promise<void>;
19
+ unsubscribe(channelName: keyof TChannel & string): void;
20
20
  }
@@ -1,5 +1,8 @@
1
- import { Channels } from "@socket-mesh/channels";
1
+ import { Channels } from '@socket-mesh/channels';
2
2
  export class ClientChannels extends Channels {
3
+ _preparingPendingSubscriptions;
4
+ _transport;
5
+ autoSubscribeOnConnect;
3
6
  constructor(transport, options) {
4
7
  if (!options) {
5
8
  options = {};
@@ -9,20 +12,51 @@ export class ClientChannels extends Channels {
9
12
  this._transport = transport;
10
13
  this._preparingPendingSubscriptions = false;
11
14
  this._transport.plugins.push({
12
- type: 'channels',
13
15
  onAuthenticated: () => {
14
16
  if (!this._preparingPendingSubscriptions) {
15
17
  this.processPendingSubscriptions();
16
18
  }
17
19
  },
20
+ onClose: () => {
21
+ this.suspendSubscriptions();
22
+ },
18
23
  onReady: () => {
19
24
  if (this.autoSubscribeOnConnect) {
20
25
  this.processPendingSubscriptions();
21
26
  }
22
27
  },
23
- onClose: () => {
24
- this.suspendSubscriptions();
25
- },
28
+ type: 'channels'
29
+ });
30
+ }
31
+ invokePublish(channelName, data) {
32
+ const pubData = {
33
+ channel: this.decorateChannelName(channelName),
34
+ data
35
+ };
36
+ return this._transport.invoke('#publish', pubData)[0];
37
+ }
38
+ processPendingSubscriptions() {
39
+ this._preparingPendingSubscriptions = false;
40
+ const pendingChannels = [];
41
+ Object.keys(this._channelMap).forEach((channelName) => {
42
+ const channel = this._channelMap[channelName];
43
+ if (channel.state === 'pending') {
44
+ pendingChannels.push(channel);
45
+ }
46
+ });
47
+ pendingChannels.sort((a, b) => {
48
+ const ap = a.options.priority || 0;
49
+ const bp = b.options.priority || 0;
50
+ if (ap > bp) {
51
+ return -1;
52
+ }
53
+ if (ap < bp) {
54
+ return 1;
55
+ }
56
+ return 0;
57
+ });
58
+ pendingChannels.forEach((channel) => {
59
+ this.trySubscribe(channel);
26
60
  });
27
61
  }
28
62
  suspendSubscriptions() {
@@ -30,13 +64,37 @@ export class ClientChannels extends Channels {
30
64
  this.triggerChannelUnsubscribe(this._channelMap[channel], true);
31
65
  }
32
66
  }
67
+ transmitPublish(channelName, data) {
68
+ const pubData = {
69
+ channel: this.decorateChannelName(channelName),
70
+ data
71
+ };
72
+ return this._transport.transmit('#publish', pubData);
73
+ }
74
+ triggerChannelSubscribeFail(err, channel, options) {
75
+ const hasAuthRequirements = !channel.options.waitForAuth || !!this._transport.signedAuthToken;
76
+ const hasChannel = !!this._channelMap[channel.name];
77
+ if (hasChannel && hasAuthRequirements) {
78
+ delete this._channelMap[channel.name];
79
+ this._channelEventDemux.write(`${channel.name}/subscribeFail`, {
80
+ channel: channel.name,
81
+ error: err,
82
+ options
83
+ });
84
+ this.emit('subscribeFail', {
85
+ channel: channel.name,
86
+ error: err,
87
+ options
88
+ });
89
+ }
90
+ }
33
91
  trySubscribe(channel) {
34
- const meetsAuthRequirements = !channel.options.waitForAuth || !!this._transport.signedAuthToken;
92
+ const hasAuthRequirements = !channel.options.waitForAuth || !!this._transport.signedAuthToken;
35
93
  // We can only ever have one pending subscribe action at any given time on a channel
36
- if (this._transport.status === 'ready' &&
37
- !this._preparingPendingSubscriptions &&
38
- !channel.subscribePromise &&
39
- meetsAuthRequirements) {
94
+ if (this._transport.status === 'ready'
95
+ && !this._preparingPendingSubscriptions
96
+ && !channel.subscribePromise
97
+ && hasAuthRequirements) {
40
98
  const subscriptionOptions = {};
41
99
  if (channel.options.waitForAuth) {
42
100
  subscriptionOptions.waitForAuth = true;
@@ -44,7 +102,7 @@ export class ClientChannels extends Channels {
44
102
  if (channel.options.data) {
45
103
  subscriptionOptions.data = channel.options.data;
46
104
  }
47
- [channel.subscribePromise, channel.subscribeAbort] = this._transport.invoke({ method: '#subscribe', ackTimeoutMs: false }, {
105
+ [channel.subscribePromise, channel.subscribeAbort] = this._transport.invoke({ ackTimeoutMs: false, method: '#subscribe' }, {
48
106
  channel: this.decorateChannelName(channel.name),
49
107
  ...subscriptionOptions
50
108
  });
@@ -52,7 +110,7 @@ export class ClientChannels extends Channels {
52
110
  delete channel.subscribePromise;
53
111
  delete channel.subscribeAbort;
54
112
  this.triggerChannelSubscribe(channel, subscriptionOptions);
55
- }).catch(err => {
113
+ }).catch((err) => {
56
114
  if (err.name === 'BadConnectionError') {
57
115
  // In case of a failed connection, keep the subscription
58
116
  // as pending; it will try again on reconnect.
@@ -70,36 +128,6 @@ export class ClientChannels extends Channels {
70
128
  });
71
129
  }
72
130
  }
73
- processPendingSubscriptions() {
74
- this._preparingPendingSubscriptions = false;
75
- const pendingChannels = [];
76
- Object.keys(this._channelMap).forEach((channelName) => {
77
- const channel = this._channelMap[channelName];
78
- if (channel.state === 'pending') {
79
- pendingChannels.push(channel);
80
- }
81
- });
82
- pendingChannels.sort((a, b) => {
83
- const ap = a.options.priority || 0;
84
- const bp = b.options.priority || 0;
85
- if (ap > bp) {
86
- return -1;
87
- }
88
- if (ap < bp) {
89
- return 1;
90
- }
91
- return 0;
92
- });
93
- pendingChannels.forEach((channel) => {
94
- this.trySubscribe(channel);
95
- });
96
- }
97
- unsubscribe(channelName) {
98
- const channel = this._channelMap[channelName];
99
- if (channel) {
100
- this.tryUnsubscribe(channel);
101
- }
102
- }
103
131
  tryUnsubscribe(channel) {
104
132
  this.triggerChannelUnsubscribe(channel);
105
133
  if (this._transport.status === 'ready') {
@@ -112,38 +140,13 @@ export class ClientChannels extends Channels {
112
140
  // the operation on the server side.
113
141
  this._transport
114
142
  .transmit('#unsubscribe', decoratedChannelName)
115
- .catch(err => { });
143
+ .catch((err) => { });
116
144
  }
117
145
  }
118
- triggerChannelSubscribeFail(err, channel, options) {
119
- const meetsAuthRequirements = !channel.options.waitForAuth || !!this._transport.signedAuthToken;
120
- const hasChannel = !!this._channelMap[channel.name];
121
- if (hasChannel && meetsAuthRequirements) {
122
- delete this._channelMap[channel.name];
123
- this._channelEventDemux.write(`${channel.name}/subscribeFail`, {
124
- channel: channel.name,
125
- error: err,
126
- options
127
- });
128
- this.emit('subscribeFail', {
129
- error: err,
130
- channel: channel.name,
131
- options
132
- });
146
+ unsubscribe(channelName) {
147
+ const channel = this._channelMap[channelName];
148
+ if (channel) {
149
+ this.tryUnsubscribe(channel);
133
150
  }
134
151
  }
135
- transmitPublish(channelName, data) {
136
- const pubData = {
137
- channel: this.decorateChannelName(channelName),
138
- data
139
- };
140
- return this._transport.transmit('#publish', pubData);
141
- }
142
- invokePublish(channelName, data) {
143
- const pubData = {
144
- channel: this.decorateChannelName(channelName),
145
- data
146
- };
147
- return this._transport.invoke('#publish', pubData)[0];
148
- }
149
152
  }
@@ -1,24 +1,27 @@
1
- import ws from "isomorphic-ws";
2
- import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap, SocketOptions } from "@socket-mesh/core";
3
- import { ClientAuthEngine, LocalStorageAuthEngineOptions } from "./client-auth-engine.js";
4
- import { ClientPrivateMap } from "./maps/client-map.js";
5
- import { ServerPrivateMap } from "./maps/server-map.js";
1
+ import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap, SocketOptions } from '@socket-mesh/core';
2
+ import ws from 'isomorphic-ws';
3
+ import { ClientAuthEngine, LocalStorageAuthEngineOptions } from './client-auth-engine.js';
4
+ import { ClientPrivateMap } from './maps/client-map.js';
5
+ import { ServerPrivateMap } from './maps/server-map.js';
6
6
  export interface AutoReconnectOptions {
7
7
  initialDelay: number;
8
- randomness: number;
9
- multiplier: number;
10
8
  maxDelayMs: number;
9
+ multiplier: number;
10
+ randomness: number;
11
+ }
12
+ export interface ClientSocketOptions<TOutgoing extends PublicMethodMap = {}, TService extends ServiceMap = {}, TIncoming extends MethodMap = {}, TPrivateOutgoing extends PrivateMethodMap = {}, TState extends object = {}> extends SocketOptions<TIncoming & ClientPrivateMap, TOutgoing, TPrivateOutgoing & ServerPrivateMap, TService, TState> {
13
+ address: string | URL;
14
+ authEngine?: ClientAuthEngine | LocalStorageAuthEngineOptions | null;
15
+ autoConnect?: boolean;
16
+ autoReconnect?: boolean | Partial<AutoReconnectOptions>;
17
+ autoSubscribeOnConnect?: boolean;
18
+ channelPrefix?: string;
19
+ connectTimeoutMs?: number;
20
+ wsOptions?: ws.ClientOptions;
11
21
  }
12
22
  export interface ConnectOptions {
13
23
  address?: string | URL;
14
24
  connectTimeoutMs?: number;
15
25
  wsOptions?: ws.ClientOptions;
16
26
  }
17
- export interface ClientSocketOptions<TOutgoing extends PublicMethodMap = {}, TService extends ServiceMap = {}, TIncoming extends MethodMap = {}, TPrivateOutgoing extends PrivateMethodMap = {}, TState extends object = {}> extends SocketOptions<TIncoming & ClientPrivateMap, TOutgoing, TPrivateOutgoing & ServerPrivateMap, TService, TState>, ConnectOptions {
18
- autoConnect?: boolean;
19
- authEngine?: ClientAuthEngine | LocalStorageAuthEngineOptions | null;
20
- autoReconnect?: Partial<AutoReconnectOptions> | boolean;
21
- autoSubscribeOnConnect?: boolean;
22
- channelPrefix?: string;
23
- }
24
27
  export declare function parseClientOptions<TIncoming extends MethodMap, TService extends ServiceMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TState extends object>(options: ClientSocketOptions<TOutgoing, TService, TIncoming, TPrivateOutgoing, TState> | string | URL): ClientSocketOptions<TOutgoing, TService, TIncoming, TPrivateOutgoing, TState>;
@@ -2,5 +2,5 @@ export function parseClientOptions(options) {
2
2
  if (typeof options === 'string' || 'pathname' in options) {
3
3
  options = { address: options };
4
4
  }
5
- return Object.assign({}, options);
5
+ return { ...options };
6
6
  }
@@ -1,10 +1,10 @@
1
- import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from "./client-socket-options.js";
2
- import { SignedAuthToken } from "@socket-mesh/auth";
3
- import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap, Socket } from "@socket-mesh/core";
4
- import { ClientChannels } from "./client-channels.js";
5
- import { ClientPrivateMap } from "./maps/client-map.js";
6
- import { ChannelMap } from "@socket-mesh/channels";
7
- import { ServerPrivateMap } from "./maps/server-map.js";
1
+ import { SignedAuthToken } from '@socket-mesh/auth';
2
+ import { ChannelMap } from '@socket-mesh/channels';
3
+ import { MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap, Socket } from '@socket-mesh/core';
4
+ import { ClientChannels } from './client-channels.js';
5
+ import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from './client-socket-options.js';
6
+ import { ClientPrivateMap } from './maps/client-map.js';
7
+ import { ServerPrivateMap } from './maps/server-map.js';
8
8
  export declare class ClientSocket<TOutgoing extends PublicMethodMap = {}, TChannel extends ChannelMap = ChannelMap, TService extends ServiceMap = {}, TState extends object = {}, TIncoming extends MethodMap = {}, TPrivateOutgoing extends PrivateMethodMap = {}> extends Socket<TIncoming & ClientPrivateMap, TOutgoing, TPrivateOutgoing & ServerPrivateMap, TService, TState> {
9
9
  private readonly _clientTransport;
10
10
  readonly channels: ClientChannels<TChannel, TIncoming, TService, TOutgoing, TPrivateOutgoing, TState>;
@@ -12,7 +12,7 @@ export declare class ClientSocket<TOutgoing extends PublicMethodMap = {}, TChann
12
12
  constructor(options: ClientSocketOptions<TOutgoing, TService, TIncoming, TPrivateOutgoing, TState>);
13
13
  authenticate(signedAuthToken: SignedAuthToken): Promise<void>;
14
14
  get autoReconnect(): AutoReconnectOptions | false;
15
- set autoReconnect(value: Partial<AutoReconnectOptions> | boolean);
15
+ set autoReconnect(value: boolean | Partial<AutoReconnectOptions>);
16
16
  connect(options?: ConnectOptions): void;
17
17
  get connectTimeoutMs(): number;
18
18
  set connectTimeoutMs(timeoutMs: number);
@@ -1,21 +1,23 @@
1
- import { ClientTransport } from "./client-transport.js";
2
- import { parseClientOptions } from "./client-socket-options.js";
3
- import { setAuthTokenHandler } from "./handlers/set-auth-token.js";
4
- import { removeAuthTokenHandler } from "./handlers/remove-auth-token.js";
5
- import { hydrateError } from "@socket-mesh/errors";
6
- import { Socket, wait } from "@socket-mesh/core";
7
- import { ClientChannels } from "./client-channels.js";
8
- import { publishHandler } from "./handlers/publish.js";
9
- import { kickOutHandler } from "./handlers/kickout.js";
1
+ import { Socket, wait } from '@socket-mesh/core';
2
+ import { hydrateError } from '@socket-mesh/errors';
3
+ import { ClientChannels } from './client-channels.js';
4
+ import { parseClientOptions } from './client-socket-options.js';
5
+ import { ClientTransport } from './client-transport.js';
6
+ import { kickOutHandler } from './handlers/kickout.js';
7
+ import { publishHandler } from './handlers/publish.js';
8
+ import { removeAuthTokenHandler } from './handlers/remove-auth-token.js';
9
+ import { setAuthTokenHandler } from './handlers/set-auth-token.js';
10
10
  export class ClientSocket extends Socket {
11
+ _clientTransport;
12
+ channels;
11
13
  constructor(options) {
12
14
  options = parseClientOptions(options);
13
15
  options.handlers =
14
16
  Object.assign({
15
- "#kickOut": kickOutHandler,
16
- "#publish": publishHandler,
17
- "#setAuthToken": setAuthTokenHandler,
18
- "#removeAuthToken": removeAuthTokenHandler
17
+ '#kickOut': kickOutHandler,
18
+ '#publish': publishHandler,
19
+ '#removeAuthToken': removeAuthTokenHandler,
20
+ '#setAuthToken': setAuthTokenHandler
19
21
  }, options.handlers);
20
22
  const clientTransport = new ClientTransport(options);
21
23
  super(clientTransport, options);
@@ -68,7 +70,9 @@ export class ClientSocket extends Socket {
68
70
  this._clientTransport.onError(err);
69
71
  return;
70
72
  }
71
- this.emit('removeAuthToken', { oldAuthToken });
73
+ if (oldAuthToken) {
74
+ this.emit('removeAuthToken', { oldAuthToken });
75
+ }
72
76
  })();
73
77
  if (this.status !== 'closed') {
74
78
  await this._clientTransport.transmit('#removeAuthToken');
@@ -1,28 +1,35 @@
1
- import { FunctionReturnType, InvokeMethodOptions, InvokeServiceOptions, SocketTransport, SocketStatus, MethodMap, ServiceMap, PublicMethodMap, PrivateMethodMap } from "@socket-mesh/core";
2
- import ws from "isomorphic-ws";
3
- import { ClientAuthEngine } from "./client-auth-engine.js";
4
- import { ServerPrivateMap } from "./maps/server-map.js";
5
- import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from "./client-socket-options.js";
6
- import { AuthToken } from "@socket-mesh/auth";
7
- import { ClientPrivateMap } from "./maps/client-map.js";
1
+ import { AuthToken } from '@socket-mesh/auth';
2
+ import { FunctionReturnType, InvokeMethodOptions, InvokeServiceOptions, MethodMap, PrivateMethodMap, PublicMethodMap, ServiceMap, SocketStatus, SocketTransport } from '@socket-mesh/core';
3
+ import ws from 'isomorphic-ws';
4
+ import { ClientAuthEngine } from './client-auth-engine.js';
5
+ import { AutoReconnectOptions, ClientSocketOptions, ConnectOptions } from './client-socket-options.js';
6
+ import { ClientPrivateMap } from './maps/client-map.js';
7
+ import { ServerPrivateMap } from './maps/server-map.js';
8
8
  export declare class ClientTransport<TIncoming extends MethodMap, TService extends ServiceMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TState extends object> extends SocketTransport<TIncoming & ClientPrivateMap, TOutgoing, TPrivateOutgoing & ServerPrivateMap, TService, TState> {
9
- readonly authEngine: ClientAuthEngine;
10
- private _uri;
11
- private _wsOptions;
12
- connectTimeoutMs: number;
13
- private _connectTimeoutRef;
14
9
  private _autoReconnect;
15
10
  private _connectAttempts;
11
+ private _connectTimeoutRef;
16
12
  private _pendingReconnectTimeout;
17
13
  private _pingTimeoutMs;
14
+ private _uri;
15
+ private _wsOptions;
16
+ readonly authEngine: ClientAuthEngine;
17
+ connectTimeoutMs: number;
18
18
  isPingTimeoutDisabled: boolean;
19
+ type: 'client';
19
20
  constructor(options: ClientSocketOptions<TOutgoing, TService, TIncoming, TPrivateOutgoing, TState>);
20
21
  get autoReconnect(): AutoReconnectOptions | false;
21
- set autoReconnect(value: Partial<AutoReconnectOptions> | boolean);
22
+ set autoReconnect(value: boolean | Partial<AutoReconnectOptions>);
22
23
  connect(options?: ConnectOptions): void;
23
24
  get connectAttempts(): number;
24
25
  disconnect(code?: number, reason?: string): void;
25
26
  private handshake;
27
+ invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
28
+ invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod, (false | number)?], arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
29
+ invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: InvokeServiceOptions<TService, TServiceName, TMethod>, arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
30
+ invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
31
+ invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(method: TMethod, arg: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
32
+ invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(options: InvokeMethodOptions<(TPrivateOutgoing & ServerPrivateMap), TMethod>, arg?: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
26
33
  protected onClose(code: number, reason?: Buffer): void;
27
34
  protected onOpen(): void;
28
35
  protected onPingPong(): void;
@@ -31,21 +38,13 @@ export declare class ClientTransport<TIncoming extends MethodMap, TService exten
31
38
  set pingTimeoutMs(value: number);
32
39
  private resetReconnect;
33
40
  send(data: Buffer | string): Promise<void>;
34
- setAuthorization(authToken: AuthToken): Promise<boolean>;
35
41
  setAuthorization(signedAuthToken: string, authToken?: AuthToken): Promise<boolean>;
36
42
  get status(): SocketStatus;
37
- private tryReconnect;
38
- type: 'client';
39
- get uri(): URL;
40
- protected get webSocket(): ws.WebSocket | null;
41
- protected set webSocket(value: ws.WebSocket | null);
42
43
  transmit<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): Promise<void>;
43
44
  transmit<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod], arg?: Parameters<TService[TServiceName][TMethod]>[0]): Promise<void>;
44
45
  transmit<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(method: TMethod, arg?: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): Promise<void>;
45
- invoke<TMethod extends keyof TOutgoing>(method: TMethod, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
46
- invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: [TServiceName, TMethod, (number | false)?], arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
47
- invoke<TServiceName extends keyof TService, TMethod extends keyof TService[TServiceName]>(options: InvokeServiceOptions<TService, TServiceName, TMethod>, arg?: Parameters<TService[TServiceName][TMethod]>[0]): [Promise<FunctionReturnType<TService[TServiceName][TMethod]>>, () => void];
48
- invoke<TMethod extends keyof TOutgoing>(options: InvokeMethodOptions<TOutgoing, TMethod>, arg?: Parameters<TOutgoing[TMethod]>[0]): [Promise<FunctionReturnType<TOutgoing[TMethod]>>, () => void];
49
- invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(method: TMethod, arg: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
50
- invoke<TMethod extends keyof (TPrivateOutgoing & ServerPrivateMap)>(options: InvokeMethodOptions<(TPrivateOutgoing & ServerPrivateMap), TMethod>, arg?: Parameters<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>[0]): [Promise<FunctionReturnType<(TPrivateOutgoing & ServerPrivateMap)[TMethod]>>, () => void];
46
+ private tryReconnect;
47
+ get uri(): URL;
48
+ protected get webSocket(): null | ws.WebSocket;
49
+ protected set webSocket(value: null | ws.WebSocket);
51
50
  }