centrifuge 5.0.0-beta.3 → 5.0.1

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.
package/README.md CHANGED
@@ -130,8 +130,8 @@ Supported transports are:
130
130
  * `websocket`
131
131
  * `http_stream`
132
132
  * `sse`
133
- * `sockjs` (SockJS can also be used as a fallback, but sticky session must be used on the backend in distributed case, SockJS is currently in DEPRECATED status in Centrifugal ecosystem).
134
- * `webtransport` (experimental, see details below)
133
+ * `sockjs` - SockJS can also be used as a fallback, SockJS is currently in DEPRECATED status in Centrifugal ecosystem. Also, sticky sessions must be used on the backend in distributed case with it. See more details below
134
+ * `webtransport` - this SDK also supports WebTransport in experimental form. See details below
135
135
 
136
136
  If you want to use sticky sessions on a load balancer level as an optimimization for Centrifugal bidirectional emulation layer keep in mind that we currently use `same-origin` credentials policy for emulation requests in `http_stream` and `sse` transport cases. So cookies will only be passed in same-origin case. Please open an issue in case you need to configure more relaxed credentials. Though in most cases stickyness based on client's IP may be sufficient enough.
137
137
 
@@ -168,7 +168,7 @@ Note, that in SockJS case endpoint starts with `http://`, not with `ws://` as we
168
168
 
169
169
  WebTransport is experimental and is only supported by Centrifugo at the moment (i.e. it's not available in Centrifuge library for Go out of the box).
170
170
 
171
- See information about it in [Centrifugo WebTransport docs](https://centrifugal.dev/docs/transports/webtransport).
171
+ Server must be additionally configured to work with WebTransport connections – see information in [Centrifugo WebTransport docs](https://centrifugal.dev/docs/transports/webtransport).
172
172
 
173
173
  ## Client API
174
174
 
@@ -1,161 +1,161 @@
1
- import { Subscription } from './subscription';
2
- import { State, Options, SubscriptionState, ClientEvents, TypedEventEmitter, RpcResult, SubscriptionOptions, HistoryOptions, HistoryResult, PublishResult, PresenceResult, PresenceStatsResult, TransportEndpoint } from './types';
3
- export declare class UnauthorizedError extends Error {
4
- constructor(message: any);
5
- }
6
- declare const Centrifuge_base: new () => TypedEventEmitter<ClientEvents>;
7
- /** Centrifuge is a Centrifuge/Centrifugo bidirectional client. */
8
- export declare class Centrifuge extends Centrifuge_base {
9
- state: State;
10
- private _endpoint;
11
- private _emulation;
12
- private _transports;
13
- private _currentTransportIndex;
14
- private _triedAllTransports;
15
- private _transportWasOpen;
16
- private _transport?;
17
- private _transportId;
18
- private _deviceWentOffline;
19
- private _transportClosed;
20
- private _reconnecting;
21
- private _reconnectTimeout?;
22
- private _reconnectAttempts;
23
- private _client;
24
- private _session;
25
- private _node;
26
- private _subs;
27
- private _serverSubs;
28
- private _commandId;
29
- private _commands;
30
- private _batching;
31
- private _refreshRequired;
32
- private _refreshTimeout?;
33
- private _callbacks;
34
- private _token;
35
- private _data;
36
- private _dispatchPromise;
37
- private _serverPing;
38
- private _serverPingTimeout?;
39
- private _sendPong;
40
- private _promises;
41
- private _promiseId;
42
- private _networkEventsSet;
43
- private _debugEnabled;
44
- private _config;
45
- protected _codec: any;
46
- static SubscriptionState: typeof SubscriptionState;
47
- static State: typeof State;
48
- static UnauthorizedError: typeof UnauthorizedError;
49
- /** Constructs Centrifuge client. Call connect() method to start connecting. */
50
- constructor(endpoint: string | Array<TransportEndpoint>, options?: Partial<Options>);
51
- /** newSubscription allocates new Subscription to a channel. Since server only allows
52
- * one subscription per channel per client this method throws if client already has
53
- * channel subscription in internal registry.
54
- * */
55
- newSubscription(channel: string, options?: Partial<SubscriptionOptions>): Subscription;
56
- /** getSubscription returns Subscription if it's registered in the internal
57
- * registry or null. */
58
- getSubscription(channel: string): Subscription | null;
59
- /** removeSubscription allows removing Subcription from the internal registry. Subscrption
60
- * must be in unsubscribed state. */
61
- removeSubscription(sub: Subscription | null): void;
62
- /** Get a map with all current client-side subscriptions. */
63
- subscriptions(): Record<string, Subscription>;
64
- /** ready returns a Promise which resolves upon client goes to Connected
65
- * state and rejects in case of client goes to Disconnected or Failed state.
66
- * Users can provide optional timeout in milliseconds. */
67
- ready(timeout?: number): Promise<void>;
68
- /** connect to a server. */
69
- connect(): void;
70
- /** disconnect from a server. */
71
- disconnect(): void;
72
- /** setToken allows setting connection token. Or resetting used token to be empty. */
73
- setToken(token: string): void;
74
- /** send asynchronous data to a server (without any response from a server
75
- * expected, see rpc method if you need response). */
76
- send(data: any): Promise<void>;
77
- /** rpc to a server - i.e. a call which waits for a response with data. */
78
- rpc(method: string, data: any): Promise<RpcResult>;
79
- /** publish data to a channel. */
80
- publish(channel: string, data: any): Promise<PublishResult>;
81
- /** history for a channel. By default it does not return publications (only current
82
- * StreamPosition data) – provide an explicit limit > 0 to load publications.*/
83
- history(channel: string, options?: HistoryOptions): Promise<HistoryResult>;
84
- /** presence for a channel. */
85
- presence(channel: string): Promise<PresenceResult>;
86
- /** presence stats for a channel. */
87
- presenceStats(channel: string): Promise<PresenceStatsResult>;
88
- /** start command batching (collect into temporary buffer without sending to a server)
89
- * until stopBatching called.*/
90
- startBatching(): void;
91
- /** stop batching commands and flush collected commands to the
92
- * network (all in one request/frame).*/
93
- stopBatching(): void;
94
- private _debug;
95
- private _configure;
96
- private _setState;
97
- private _isDisconnected;
98
- private _isConnecting;
99
- private _isConnected;
100
- private _nextCommandId;
101
- private _setNetworkEvents;
102
- private _getReconnectDelay;
103
- private _clearOutgoingRequests;
104
- private _clearConnectedState;
105
- private _handleWriteError;
106
- private _transportSendCommands;
107
- private _initializeTransport;
108
- private _sendConnect;
109
- private _startReconnecting;
110
- private _connectError;
111
- private _scheduleReconnect;
112
- private _constructConnectCommand;
113
- private _getHistoryRequest;
114
- private _methodCall;
115
- private _callPromise;
116
- private _dataReceived;
117
- private _dispatchSynchronized;
118
- private _dispatchReply;
119
- private _call;
120
- private _startConnecting;
121
- private _disconnect;
122
- private _failUnauthorized;
123
- private _getToken;
124
- private _refresh;
125
- private _refreshError;
126
- private _getRefreshRetryDelay;
127
- private _refreshResponse;
128
- private _removeSubscription;
129
- protected _unsubscribe(sub: Subscription): void;
130
- private _getSub;
131
- private _isServerSub;
132
- private _sendSubscribeCommands;
133
- private _connectResponse;
134
- private _processServerSubs;
135
- private _clearRefreshTimeout;
136
- private _clearReconnectTimeout;
137
- private _clearServerPingTimeout;
138
- private _waitServerPing;
139
- private _getSubscribeContext;
140
- private _handleReply;
141
- private _handleJoin;
142
- private _handleLeave;
143
- private _handleUnsubscribe;
144
- private _handleSubscribe;
145
- private _handleDisconnect;
146
- private _getPublicationContext;
147
- private _getJoinLeaveContext;
148
- private _handlePublication;
149
- private _handleMessage;
150
- private _handleServerPing;
151
- private _handlePush;
152
- private _flush;
153
- private _createErrorObject;
154
- private _registerCall;
155
- private _addCommand;
156
- private _nextPromiseId;
157
- private _nextTransportId;
158
- private _resolvePromises;
159
- private _rejectPromises;
160
- }
161
- export {};
1
+ import { Subscription } from './subscription';
2
+ import { State, Options, SubscriptionState, ClientEvents, TypedEventEmitter, RpcResult, SubscriptionOptions, HistoryOptions, HistoryResult, PublishResult, PresenceResult, PresenceStatsResult, TransportEndpoint } from './types';
3
+ export declare class UnauthorizedError extends Error {
4
+ constructor(message: any);
5
+ }
6
+ declare const Centrifuge_base: new () => TypedEventEmitter<ClientEvents>;
7
+ /** Centrifuge is a Centrifuge/Centrifugo bidirectional client. */
8
+ export declare class Centrifuge extends Centrifuge_base {
9
+ state: State;
10
+ private _endpoint;
11
+ private _emulation;
12
+ private _transports;
13
+ private _currentTransportIndex;
14
+ private _triedAllTransports;
15
+ private _transportWasOpen;
16
+ private _transport?;
17
+ private _transportId;
18
+ private _deviceWentOffline;
19
+ private _transportClosed;
20
+ private _reconnecting;
21
+ private _reconnectTimeout?;
22
+ private _reconnectAttempts;
23
+ private _client;
24
+ private _session;
25
+ private _node;
26
+ private _subs;
27
+ private _serverSubs;
28
+ private _commandId;
29
+ private _commands;
30
+ private _batching;
31
+ private _refreshRequired;
32
+ private _refreshTimeout?;
33
+ private _callbacks;
34
+ private _token;
35
+ private _data;
36
+ private _dispatchPromise;
37
+ private _serverPing;
38
+ private _serverPingTimeout?;
39
+ private _sendPong;
40
+ private _promises;
41
+ private _promiseId;
42
+ private _networkEventsSet;
43
+ private _debugEnabled;
44
+ private _config;
45
+ protected _codec: any;
46
+ static SubscriptionState: typeof SubscriptionState;
47
+ static State: typeof State;
48
+ static UnauthorizedError: typeof UnauthorizedError;
49
+ /** Constructs Centrifuge client. Call connect() method to start connecting. */
50
+ constructor(endpoint: string | Array<TransportEndpoint>, options?: Partial<Options>);
51
+ /** newSubscription allocates new Subscription to a channel. Since server only allows
52
+ * one subscription per channel per client this method throws if client already has
53
+ * channel subscription in internal registry.
54
+ * */
55
+ newSubscription(channel: string, options?: Partial<SubscriptionOptions>): Subscription;
56
+ /** getSubscription returns Subscription if it's registered in the internal
57
+ * registry or null. */
58
+ getSubscription(channel: string): Subscription | null;
59
+ /** removeSubscription allows removing Subcription from the internal registry. Subscrption
60
+ * must be in unsubscribed state. */
61
+ removeSubscription(sub: Subscription | null): void;
62
+ /** Get a map with all current client-side subscriptions. */
63
+ subscriptions(): Record<string, Subscription>;
64
+ /** ready returns a Promise which resolves upon client goes to Connected
65
+ * state and rejects in case of client goes to Disconnected or Failed state.
66
+ * Users can provide optional timeout in milliseconds. */
67
+ ready(timeout?: number): Promise<void>;
68
+ /** connect to a server. */
69
+ connect(): void;
70
+ /** disconnect from a server. */
71
+ disconnect(): void;
72
+ /** setToken allows setting connection token. Or resetting used token to be empty. */
73
+ setToken(token: string): void;
74
+ /** send asynchronous data to a server (without any response from a server
75
+ * expected, see rpc method if you need response). */
76
+ send(data: any): Promise<void>;
77
+ /** rpc to a server - i.e. a call which waits for a response with data. */
78
+ rpc(method: string, data: any): Promise<RpcResult>;
79
+ /** publish data to a channel. */
80
+ publish(channel: string, data: any): Promise<PublishResult>;
81
+ /** history for a channel. By default it does not return publications (only current
82
+ * StreamPosition data) – provide an explicit limit > 0 to load publications.*/
83
+ history(channel: string, options?: HistoryOptions): Promise<HistoryResult>;
84
+ /** presence for a channel. */
85
+ presence(channel: string): Promise<PresenceResult>;
86
+ /** presence stats for a channel. */
87
+ presenceStats(channel: string): Promise<PresenceStatsResult>;
88
+ /** start command batching (collect into temporary buffer without sending to a server)
89
+ * until stopBatching called.*/
90
+ startBatching(): void;
91
+ /** stop batching commands and flush collected commands to the
92
+ * network (all in one request/frame).*/
93
+ stopBatching(): void;
94
+ private _debug;
95
+ private _configure;
96
+ private _setState;
97
+ private _isDisconnected;
98
+ private _isConnecting;
99
+ private _isConnected;
100
+ private _nextCommandId;
101
+ private _setNetworkEvents;
102
+ private _getReconnectDelay;
103
+ private _clearOutgoingRequests;
104
+ private _clearConnectedState;
105
+ private _handleWriteError;
106
+ private _transportSendCommands;
107
+ private _initializeTransport;
108
+ private _sendConnect;
109
+ private _startReconnecting;
110
+ private _connectError;
111
+ private _scheduleReconnect;
112
+ private _constructConnectCommand;
113
+ private _getHistoryRequest;
114
+ private _methodCall;
115
+ private _callPromise;
116
+ private _dataReceived;
117
+ private _dispatchSynchronized;
118
+ private _dispatchReply;
119
+ private _call;
120
+ private _startConnecting;
121
+ private _disconnect;
122
+ private _failUnauthorized;
123
+ private _getToken;
124
+ private _refresh;
125
+ private _refreshError;
126
+ private _getRefreshRetryDelay;
127
+ private _refreshResponse;
128
+ private _removeSubscription;
129
+ protected _unsubscribe(sub: Subscription): void;
130
+ private _getSub;
131
+ private _isServerSub;
132
+ private _sendSubscribeCommands;
133
+ private _connectResponse;
134
+ private _processServerSubs;
135
+ private _clearRefreshTimeout;
136
+ private _clearReconnectTimeout;
137
+ private _clearServerPingTimeout;
138
+ private _waitServerPing;
139
+ private _getSubscribeContext;
140
+ private _handleReply;
141
+ private _handleJoin;
142
+ private _handleLeave;
143
+ private _handleUnsubscribe;
144
+ private _handleSubscribe;
145
+ private _handleDisconnect;
146
+ private _getPublicationContext;
147
+ private _getJoinLeaveContext;
148
+ private _handlePublication;
149
+ private _handleMessage;
150
+ private _handleServerPing;
151
+ private _handlePush;
152
+ private _flush;
153
+ private _createErrorObject;
154
+ private _registerCall;
155
+ private _addCommand;
156
+ private _nextPromiseId;
157
+ private _nextTransportId;
158
+ private _resolvePromises;
159
+ private _rejectPromises;
160
+ }
161
+ export {};
package/build/codes.d.ts CHANGED
@@ -1,36 +1,36 @@
1
- export declare enum errorCodes {
2
- timeout = 1,
3
- transportClosed = 2,
4
- clientDisconnected = 3,
5
- clientClosed = 4,
6
- clientConnectToken = 5,
7
- clientRefreshToken = 6,
8
- subscriptionUnsubscribed = 7,
9
- subscriptionSubscribeToken = 8,
10
- subscriptionRefreshToken = 9,
11
- transportWriteError = 10,
12
- connectionClosed = 11,
13
- badConfiguration = 12
14
- }
15
- export declare enum connectingCodes {
16
- connectCalled = 0,
17
- transportClosed = 1,
18
- noPing = 2,
19
- subscribeTimeout = 3,
20
- unsubscribeError = 4
21
- }
22
- export declare enum disconnectedCodes {
23
- disconnectCalled = 0,
24
- unauthorized = 1,
25
- badProtocol = 2,
26
- messageSizeLimit = 3
27
- }
28
- export declare enum subscribingCodes {
29
- subscribeCalled = 0,
30
- transportClosed = 1
31
- }
32
- export declare enum unsubscribedCodes {
33
- unsubscribeCalled = 0,
34
- unauthorized = 1,
35
- clientClosed = 2
36
- }
1
+ export declare enum errorCodes {
2
+ timeout = 1,
3
+ transportClosed = 2,
4
+ clientDisconnected = 3,
5
+ clientClosed = 4,
6
+ clientConnectToken = 5,
7
+ clientRefreshToken = 6,
8
+ subscriptionUnsubscribed = 7,
9
+ subscriptionSubscribeToken = 8,
10
+ subscriptionRefreshToken = 9,
11
+ transportWriteError = 10,
12
+ connectionClosed = 11,
13
+ badConfiguration = 12
14
+ }
15
+ export declare enum connectingCodes {
16
+ connectCalled = 0,
17
+ transportClosed = 1,
18
+ noPing = 2,
19
+ subscribeTimeout = 3,
20
+ unsubscribeError = 4
21
+ }
22
+ export declare enum disconnectedCodes {
23
+ disconnectCalled = 0,
24
+ unauthorized = 1,
25
+ badProtocol = 2,
26
+ messageSizeLimit = 3
27
+ }
28
+ export declare enum subscribingCodes {
29
+ subscribeCalled = 0,
30
+ transportClosed = 1
31
+ }
32
+ export declare enum unsubscribedCodes {
33
+ unsubscribeCalled = 0,
34
+ unauthorized = 1,
35
+ clientClosed = 2
36
+ }
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Centrifuge, UnauthorizedError } from './centrifuge';
2
- import { Subscription } from './subscription';
3
- export * from "./types";
4
- export * from "./codes";
5
- export { Centrifuge, UnauthorizedError, Subscription };
1
+ import { Centrifuge, UnauthorizedError } from './centrifuge';
2
+ import { Subscription } from './subscription';
3
+ export * from "./types";
4
+ export * from "./codes";
5
+ export { Centrifuge, UnauthorizedError, Subscription };