centrifuge 4.0.1 → 4.1.0

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
@@ -305,6 +305,10 @@ centrifuge.presenceStats("channel").then(function(resp) {
305
305
 
306
306
  Returns a Promise which will be resolved upon connection establishement (i.e. when Client goes to `connected` state).
307
307
 
308
+ #### setToken method
309
+
310
+ `setToken` may be useful to dynamically change the connection token. For example when you need to implement login/logout workflow. See an example in [blog post](https://centrifugal.dev/blog/2023/06/29/centrifugo-v5-released#token-behaviour-adjustments-in-sdks).
311
+
308
312
  #### error event
309
313
 
310
314
  To listen asynchronous error happening internally while Centrifuge client works you can set an `error` handler:
@@ -333,7 +337,7 @@ In case of Centrifugo on a server side this may be a JSON Web Token - see [authe
333
337
 
334
338
  **Connection token must come to the frontend from application backend - i.e. must be generated on the backend side**. The way to deliver token to the application frontend is up to the developer. Usually you can pass it in template rendering context or issue a separate call to request a connection token from the backend.
335
339
 
336
- If the token sets connection expiration then the client SDK will keep the token refreshed. It does this by calling a special callback function. This callback must return a new token. If a new token with updated connection expiration is returned from callback then it's sent to Centrifugo. If your callback returns an empty string this means the user has no permission to connect to Centrifugo and the Client will move to a disconnected state. In case of error returned by your callback SDK will retry the operation after some jittered time.
340
+ If the token sets connection expiration then the client SDK will keep the token refreshed. It does this by calling a special callback function. This callback must return a new token. If a new token with updated connection expiration is returned from callback then it's sent to Centrifugo. In case of error returned by your callback SDK will retry the operation after some jittered time. You can throw a special error (`throw new Centrifuge.UnauthorizedError();`) from `getToken` function to move the client into disconnected state (for example, when there is no permission to connect anymore).
337
341
 
338
342
  An example of possible `getToken` function implementation:
339
343
 
package/build/types.d.ts CHANGED
@@ -148,7 +148,7 @@ export interface PublicationContext {
148
148
  data: any;
149
149
  info?: ClientInfo;
150
150
  offset?: number;
151
- tags?: Map<string, string>;
151
+ tags?: Record<string, string>;
152
152
  }
153
153
  export interface ClientInfo {
154
154
  client: string;
@@ -209,7 +209,7 @@ export interface ServerPublicationContext {
209
209
  data: any;
210
210
  info?: ClientInfo;
211
211
  offset?: number;
212
- tags?: Map<string, string>;
212
+ tags?: Record<string, string>;
213
213
  }
214
214
  export interface ServerJoinContext {
215
215
  channel: string;
@@ -244,7 +244,7 @@ export interface RpcResult {
244
244
  data: any;
245
245
  }
246
246
  export interface PresenceResult {
247
- clients: Map<string, ClientInfo>;
247
+ clients: Record<string, ClientInfo>;
248
248
  }
249
249
  export interface PresenceStatsResult {
250
250
  numClients: number;