-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathconfiguration.ts
More file actions
905 lines (786 loc) · 24.8 KB
/
configuration.ts
File metadata and controls
905 lines (786 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
/**
* {@link PubNub} client configuration module.
*/
import { PubNubFileConstructor, PubNubFileInterface } from '../types/file';
import { RequestRetryPolicy } from '../components/retry-policy';
import { PubNubError } from '../../errors/pubnub-error';
import { ICryptoModule } from './crypto-module';
import { KeySet, Payload } from '../types/api';
import { Logger, LogLevel } from './logger';
import { LoggerManager } from '../components/logger-manager';
// --------------------------------------------------------
// ----------------------- Defaults -----------------------
// --------------------------------------------------------
// region Defaults
/**
* Whether secured connection should be used by or not.
*/
const USE_SSL = true;
/**
* Whether PubNub client should catch up subscription after network issues.
*/
const RESTORE = false;
/**
* Whether network availability change should be announced with `PNNetworkDownCategory` and
* `PNNetworkUpCategory` state or not.
*/
const AUTO_NETWORK_DETECTION = false;
/**
* Whether messages should be de-duplicated before announcement or not.
*/
const DEDUPE_ON_SUBSCRIBE = false;
/**
* Maximum cache which should be used for message de-duplication functionality.
*/
const DEDUPE_CACHE_SIZE = 100;
/**
* Maximum number of file message publish retries.
*/
const FILE_PUBLISH_RETRY_LIMIT = 5;
/**
* Whether subscription event engine should be used or not.
*/
const ENABLE_EVENT_ENGINE = false;
/**
* Whether configured user presence state should be maintained by the PubNub client or not.
*/
const MAINTAIN_PRESENCE_STATE = true;
/**
* Whether heartbeat should be postponed on successful subscribe response or not.
*/
const USE_SMART_HEARTBEAT = false;
/**
* Whether PubNub client should try to utilize existing TCP connection for new requests or not.
*/
const KEEP_ALIVE = false;
/**
* Whether leave events should be suppressed or not.
*/
const SUPPRESS_LEAVE_EVENTS = false;
/**
* Whether heartbeat request failure should be announced or not.
*/
const ANNOUNCE_HEARTBEAT_FAILURE = true;
/**
* Whether heartbeat request success should be announced or not.
*/
const ANNOUNCE_HEARTBEAT_SUCCESS = false;
/**
* Whether PubNub client instance id should be added to the requests or not.
*/
const USE_INSTANCE_ID = false;
/**
* Whether unique identifier should be added to the request or not.
*/
const USE_REQUEST_ID = true;
/**
* Transactional requests timeout.
*/
const TRANSACTIONAL_REQUEST_TIMEOUT = 15;
/**
* Subscription request timeout.
*/
const SUBSCRIBE_REQUEST_TIMEOUT = 310;
/**
* File upload / download request timeout.
*/
const FILE_REQUEST_TIMEOUT = 300;
/**
* Default user presence timeout.
*/
const PRESENCE_TIMEOUT = 300;
/**
* Maximum user presence timeout.
*/
const PRESENCE_TIMEOUT_MAXIMUM = 320;
// endregion
/**
* Base user-provided PubNub client configuration.
*/
export type UserConfiguration = {
/**
* Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing.
*/
subscribeKey: string;
/**
* Specifies the `subscribe_key` to be used for subscribing to a channel and message publishing.
*
* @deprecated Use the {@link subscribeKey} instead.
*/
subscribe_key?: string;
/**
* Specifies the `publishKey` to be used for publishing messages to a channel.
*/
publishKey?: string;
/**
* Specifies the `publish_key` to be used for publishing messages to a channel.
*
* @deprecated Use the {@link publishKey} instead.
*/
publish_key?: string;
/**
* Specifies the `secretKey` to be used for request signatures computation.
*/
secretKey?: string;
/**
* Specifies the `secret_key` to be used for request signatures computation.
*
* @deprecated Use the {@link secretKey} instead.
*/
secret_key?: string;
/**
* Unique PubNub client user identifier.
*
* Unique `userId` to identify the user or the device that connects to PubNub.
* It's a UTF-8 encoded string of up to 64 alphanumeric characters.
*
* If you don't set the `userId`, you won't be able to connect to PubNub.
*/
userId?: string;
/**
* If Access Manager enabled, this key will be used on all requests.
*/
authKey?: string | null;
/**
* Log HTTP information.
*
* @default `false`
*
* @deprecated Use {@link UserConfiguration.logLevel logLevel} and {@link UserConfiguration.loggers loggers} instead.
*/
logVerbosity?: boolean;
/**
* Minimum messages log level which should be passed to the logger.
*/
logLevel?: LogLevel;
/**
* List of additional custom {@link Logger loggers} to which logged messages will be passed.
*/
loggers?: Logger[];
/**
* If set to true, requests will be made over HTTPS.
*
* @default `true` for v4.20.0 onwards, `false` before v4.20.0
*/
ssl?: boolean;
/**
* If a custom domain is required, SDK accepts it here.
*
* @default `ps.pndsn.com`
*/
origin?: string | string[];
/**
* How long the server will consider the client alive for presence.The value is in seconds.
*
* @default `300`
*/
presenceTimeout?: number;
/**
* How often the client will announce itself to server. The value is in seconds.
*
* @default `not set`
*/
heartbeatInterval?: number;
/**
* Transactional requests timeout in milliseconds.
*
* Maximum duration for which PubNub client should wait for transactional request completion.
*
* @default `15` seconds
*/
transactionalRequestTimeout?: number;
/**
* Subscription requests timeout in milliseconds.
*
* Maximum duration for which PubNub client should wait for subscription request completion.
*
* @default `310` seconds
*/
subscribeRequestTimeout?: number;
/**
* File upload / download request timeout in milliseconds.
*
* Maximum duration for which PubNub client should wait for file upload / download request
* completion.
*
* @default `300` seconds
*/
fileRequestTimeout?: number;
/**
* `true` to allow catch up on the front-end applications.
*
* @default `false`
*/
restore?: boolean;
/**
* Whether to include the PubNub object instance ID in outgoing requests.
*
* @default `false`
*/
useInstanceId?: boolean;
/**
* When `true` the SDK doesn't send out the leave requests.
*
* @default `false`
*/
suppressLeaveEvents?: boolean;
/**
* `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the
* payload is above of `requestMessageCountThreshold`.
*
* @default `100`
*/
requestMessageCountThreshold?: number;
/**
* This flag announces when the network is down or up using the states `PNNetworkDownCategory`
* and `PNNetworkUpCategory`.
*
* @default `false`
*/
autoNetworkDetection?: boolean;
/**
* If the browser fails to detect the network changes from Wi-Fi to LAN and vice versa, or you
* get reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to
* take over.
*
* **Note:** This option is available only in the **browser** environment.
*
* @default `true`
*/
listenToBrowserNetworkEvents?: boolean;
/**
* Whether to use the standardized workflows for subscribe and presence.
*
* Note that the `maintainPresenceState` parameter is set to true by default, so make sure to
* disable it if you don't need to maintain presence state. For more information, refer to the
* param description in this table.
*
*
* @default `false`
*/
enableEventEngine?: boolean;
/**
* Custom reconnection configuration parameters.
*
* `retryConfiguration: policy` is the type of policy to be used.
*
* Available values:
* - `PubNub.LinearRetryPolicy({ delay, maximumRetry })`
* - `PubNub.ExponentialRetryPolicy({ minimumDelay, maximumDelay, maximumRetry })`
*
* For more information, refer to
* {@link /docs/general/setup/connection-management#reconnection-policy|Reconnection Policy}. JavaScript doesn't
* support excluding endpoints.
*
* @default `not set`
*/
retryConfiguration?: RequestRetryPolicy;
/**
* Whether the `state` set using `setState()` should be maintained for the current `userId`.
* This option works only when `enableEventEngine` is set to `true`.
*
* @default `true`
*/
maintainPresenceState?: boolean;
/**
* Whether heartbeat should be postponed on successful subscribe response.
*
* With implicit heartbeat each successful `subscribe` loop response is treated as `heartbeat`
* and there is no need to send another explicit heartbeat earlier than `heartbeatInterval`
* since moment of `subscribe` response.
*
* **Note:** With disabled implicit heartbeat this feature may cause `timeout` if there is
* constant activity on subscribed channels / groups.
*
* @default `true`
*/
useSmartHeartbeat?: boolean;
/**
* `UUID` to use. You should set a unique `UUID` to identify the user or the device that
* connects to PubNub.
* If you don't set the `UUID`, you won't be able to connect to PubNub.
*
* @deprecated Use {@link userId} instead.
*/
uuid?: string;
/**
* If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of
* opening a new one for each new request.
*
* @default `false`
*/
keepAlive?: boolean;
/**
* If the SDK is running as part of another SDK built atop of it, allow a custom `pnsdk` with
* name and version.
*/
sdkName?: string;
/**
* If the SDK is operated by a partner, allow a custom `pnsdk` item for them.
*/
partnerId?: string;
};
/**
* Extended client configuration.
*
* Extended configuration contains unannounced configuration options.
*
* @internal
*/
export type ExtendedConfiguration = UserConfiguration & {
/**
* PubNub Account key set.
*/
keySet: KeySet;
/**
* Real-time updates filtering expression.
*/
filterExpression?: string | null;
/**
* Whether messages should be de-duplicated on subscribe before announcement or not.
*
* @default `false`
*/
dedupeOnSubscribe: boolean;
/**
* Maximum size of deduplication manager cache.
*/
maximumCacheSize: number;
/**
* Whether unique request identifier should be used in request query or not.
*
* @default `false`
*/
useRequestId?: boolean;
/**
* Whether heartbeat request success should be announced or not.
*
* @default `false`
*/
announceSuccessfulHeartbeats: boolean;
/**
* Whether heartbeat request failure should be announced or not.
*
* @default `true`
*/
announceFailedHeartbeats: boolean;
/**
* How many times file message publish attempt should be retried.
*
* @default `5`
*/
fileUploadPublishRetryLimit: number;
};
/**
* Platform-specific PubNub client configuration.
*
* Part of configuration which is added by platform-specific PubNub client initialization code.
*
* @internal
*/
export type PlatformConfiguration = {
/**
* Track of the SDK family for identifier generator.
*/
sdkFamily: string;
/**
* The cryptography module used for encryption and decryption of messages and files. Takes the
* {@link cipherKey} and {@link useRandomIVs} parameters as arguments.
*
* For more information, refer to the
* {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section.
*
* @default `not set`
*/
cryptoModule?: ICryptoModule;
/**
* Platform-specific file representation
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
PubNubFile?: PubNubFileConstructor<PubNubFileInterface, any>;
// region Deprecated parameters
/**
* If passed, will encrypt the payloads.
*
* @deprecated Pass it to `cryptoModule` instead.
*/
cipherKey?: string;
/**
* When `true` the initialization vector (IV) is random for all requests (not just for file
* upload).
* When `false` the IV is hard-coded for all requests except for file upload.
*
* @default `true`
*
* @deprecated Pass it to `cryptoModule` instead.
*/
useRandomIVs?: boolean;
/**
* Custom data encryption method.
*
* @deprecated Instead use {@link cryptoModule} for data encryption.
*/
customEncrypt?: (data: string | Payload) => string;
/**
* Custom data decryption method.
*
* @deprecated Instead use {@link cryptoModule} for data decryption.
*/
customDecrypt?: (data: string) => string;
// endregion
};
/**
* User-provided configuration object interface.
*
* Interface contains limited set of settings manipulation and access.
*/
export interface ClientConfiguration {
/**
* Get a PubNub client user identifier.
*
* @returns Current PubNub client user identifier.
*/
getUserId(): string;
/**
* Change the current PubNub client user identifier.
*
* **Important:** Change won't affect ongoing REST API calls.
*
* @param value - New PubNub client user identifier.
*
* @throws Error empty user identifier has been provided.
*/
setUserId(value: string): void;
/**
* Change REST API endpoint access authorization key.
*
* @param authKey - New authorization key which should be used with new requests.
*/
setAuthKey(authKey: string | null): void;
/**
* Real-time updates filtering expression.
*
* @returns Filtering expression.
*/
getFilterExpression(): string | undefined | null;
/**
* Update real-time updates filtering expression.
*
* @param expression - New expression which should be used or `undefined` to disable filtering.
*/
setFilterExpression(expression: string | null | undefined): void;
/**
* Change data encryption / decryption key.
*
* @param key - New key which should be used for data encryption / decryption.
*/
setCipherKey(key: string | undefined): void;
/**
* Get PubNub SDK version.
*
* @returns Current SDK version.
*/
get version(): string;
/**
* Get PubNub SDK version.
*
* @returns Current SDK version.
*/
getVersion(): string;
/**
* Add framework's prefix.
*
* @param name - Name of the framework which would want to add own data into `pnsdk` suffix.
* @param suffix - Suffix with information about framework.
*/
_addPnsdkSuffix(name: string, suffix: string | number): void;
// --------------------------------------------------------
// ---------------------- Deprecated ----------------------
// --------------------------------------------------------
// region Deprecated
/**
* Get a PubNub client user identifier.
*
* @returns Current PubNub client user identifier.
*
* @deprecated Use the {@link getUserId} or {@link userId} getter instead.
*/
getUUID(): string;
/**
* Change the current PubNub client user identifier.
*
* **Important:** Change won't affect ongoing REST API calls.
*
* @param value - New PubNub client user identifier.
*
* @returns {Configuration} Reference to the configuration instance for easier chaining.
*
* @throws Error empty user identifier has been provided.
*
* @deprecated Use the {@link setUserId} or {@link userId} setter instead.
*/
setUUID(value: string): void;
// endregion
}
/**
* Internal PubNub client configuration object interface.
*
* @internal
*/
export interface PrivateClientConfiguration
extends ClientConfiguration,
Omit<ExtendedConfiguration, 'subscribe_key' | 'publish_key' | 'secret_key' | 'uuid'> {
/**
* Registered loggers manager.
*/
logger(): LoggerManager;
/**
* REST API endpoint access authorization key.
*
* It is required to have `authorization key` with required permissions to access REST API
* endpoints when `PAM` enabled for user key set.
*/
getAuthKey(): string | undefined | null;
/**
* Data encryption / decryption module.
*
* @returns Data processing crypto module (if set).
*/
getCryptoModule(): ICryptoModule | undefined;
/**
* Whether SDK client use `SharedWorker` or not.
*
* @returns `true` if SDK build for browser and SDK configured to use `SharedWorker`.
*/
isSharedWorkerEnabled(): boolean;
/**
* Whether `-pnpres` should not be filtered out from list of channels / groups in presence-related requests or not.
*
* This option required and set to `true` for Shared Worker setup to properly update client's state.
*
* @returns `true` if `-pnpres` channels and groups shouldn't be removed before sending request.
*/
getKeepPresenceChannelsInPresenceRequests(): boolean;
/**
* Retrieve user's presence timeout.
*
* @returns User's presence timeout value.
*/
getPresenceTimeout(): number;
/**
* Change user's presence timeout.
*
* @param timeout - New timeout for user's presence.
*/
setPresenceTimeout(timeout: number): void;
/**
* Retrieve heartbeat requests interval.
*
* @returns Heartbeat requests interval.
*/
getHeartbeatInterval(): number | undefined;
/**
* Change heartbeat requests interval.
*
* @param interval - New presence request heartbeat intervals.
*/
setHeartbeatInterval(interval: number): void;
/**
* Transactional request timeout.
*
* @returns Maximum duration in milliseconds for which PubNub client should wait for
* transactional request completion.
*/
getTransactionTimeout(): number;
/**
* Subscription requests timeout.
*
* @returns Maximum duration in milliseconds for which PubNub client should wait for
* subscription request completion.
*/
getSubscribeTimeout(): number;
/**
* File requests timeout.
*
* @returns Maximum duration in milliseconds for which PubNub client should wait for
* file upload / download request completion.
*/
getFileTimeout(): number;
/**
* PubNub file object constructor.
*/
get PubNubFile(): PubNubFileConstructor<PubNubFileInterface, unknown> | undefined;
/**
* Get PubNub client instance identifier.
*
* @returns Current PubNub client instance identifier.
*/
get instanceId(): string | undefined;
/**
* Get PubNub client instance identifier.
*
* @returns Current PubNub client instance identifier.
*/
getInstanceId(): string | undefined;
/**
* Get SDK family identifier.
*
* @returns Current SDK family identifier.
*/
get sdkFamily(): string;
/**
* Compose `pnsdk` suffix string.
*
* @param separator - String which will be used to join registered suffixes.
*
* @returns Concatenated `pnsdk` suffix string.
*/
_getPnsdkSuffix(separator: string): string;
// --------------------------------------------------------
// ---------------------- Deprecated ----------------------
// --------------------------------------------------------
// region Deprecated
/**
* If passed, will encrypt the payloads.
*
* @deprecated Pass it to `cryptoModule` instead.
*/
getCipherKey(): string | undefined;
/**
* When `true` the initialization vector (IV) is random for all requests (not just for file
* upload).
* When `false` the IV is hard-coded for all requests except for file upload.
*
* @default `true`
*
* @deprecated Pass it to `cryptoModule` instead.
*/
getUseRandomIVs(): boolean | undefined;
/**
* Custom data encryption method.
*
* @deprecated Instead use {@link cryptoModule} for data encryption.
*/
getCustomEncrypt(): ((data: string | Payload) => string) | undefined;
/**
* Custom data decryption method.
*
* @deprecated Instead use {@link cryptoModule} for data decryption.
*/
getCustomDecrypt(): ((data: string) => string) | undefined;
// endregion
}
/**
* Apply configuration default values.
*
* @param configuration - User-provided configuration.
*
* @internal
*/
export const setDefaults = (configuration: UserConfiguration): ExtendedConfiguration => {
// Copy configuration.
const configurationCopy = { ...configuration };
configurationCopy.ssl ??= USE_SSL;
configurationCopy.transactionalRequestTimeout ??= TRANSACTIONAL_REQUEST_TIMEOUT;
configurationCopy.subscribeRequestTimeout ??= SUBSCRIBE_REQUEST_TIMEOUT;
configurationCopy.fileRequestTimeout ??= FILE_REQUEST_TIMEOUT;
configurationCopy.restore ??= RESTORE;
configurationCopy.useInstanceId ??= USE_INSTANCE_ID;
configurationCopy.suppressLeaveEvents ??= SUPPRESS_LEAVE_EVENTS;
configurationCopy.requestMessageCountThreshold ??= DEDUPE_CACHE_SIZE;
configurationCopy.autoNetworkDetection ??= AUTO_NETWORK_DETECTION;
configurationCopy.enableEventEngine ??= ENABLE_EVENT_ENGINE;
configurationCopy.maintainPresenceState ??= MAINTAIN_PRESENCE_STATE;
configurationCopy.useSmartHeartbeat ??= USE_SMART_HEARTBEAT;
configurationCopy.keepAlive ??= KEEP_ALIVE;
if (configurationCopy.userId && configurationCopy.uuid)
throw new PubNubError("PubNub client configuration error: use only 'userId'");
configurationCopy.userId ??= configurationCopy.uuid;
if (!configurationCopy.userId) throw new PubNubError("PubNub client configuration error: 'userId' not set");
else if (configurationCopy.userId?.trim().length === 0)
throw new PubNubError("PubNub client configuration error: 'userId' is empty");
// Generate default origin subdomains.
if (!configurationCopy.origin)
configurationCopy.origin = Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`);
const keySet: KeySet = {
subscribeKey: configurationCopy.subscribeKey,
publishKey: configurationCopy.publishKey,
secretKey: configurationCopy.secretKey,
};
if (configurationCopy.presenceTimeout !== undefined) {
if (configurationCopy.presenceTimeout > PRESENCE_TIMEOUT_MAXIMUM) {
configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MAXIMUM;
// eslint-disable-next-line no-console
console.warn(
'WARNING: Presence timeout is larger than the maximum. Using maximum value: ',
PRESENCE_TIMEOUT_MAXIMUM,
);
} else if (configurationCopy.presenceTimeout <= 0) {
// eslint-disable-next-line no-console
console.warn('WARNING: Presence timeout should be larger than zero.');
delete configurationCopy.presenceTimeout;
}
}
if (configurationCopy.presenceTimeout !== undefined)
configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1;
else configurationCopy.presenceTimeout = PRESENCE_TIMEOUT;
// Apply extended configuration defaults.
let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS;
let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE;
let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT;
let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE;
let maximumCacheSize = DEDUPE_CACHE_SIZE;
let useRequestId = USE_REQUEST_ID;
// @ts-expect-error Not documented legacy configuration options.
if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') {
// @ts-expect-error Not documented legacy configuration options.
dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe;
}
// @ts-expect-error Not documented legacy configuration options.
if (configurationCopy.maximumCacheSize !== undefined && typeof configurationCopy.maximumCacheSize === 'number') {
// @ts-expect-error Not documented legacy configuration options.
maximumCacheSize = configurationCopy.maximumCacheSize;
}
// @ts-expect-error Not documented legacy configuration options.
if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') {
// @ts-expect-error Not documented legacy configuration options.
useRequestId = configurationCopy.useRequestId;
}
if (
// @ts-expect-error Not documented legacy configuration options.
configurationCopy.announceSuccessfulHeartbeats !== undefined &&
// @ts-expect-error Not documented legacy configuration options.
typeof configurationCopy.announceSuccessfulHeartbeats === 'boolean'
) {
// @ts-expect-error Not documented legacy configuration options.
announceSuccessfulHeartbeats = configurationCopy.announceSuccessfulHeartbeats;
}
if (
// @ts-expect-error Not documented legacy configuration options.
configurationCopy.announceFailedHeartbeats !== undefined &&
// @ts-expect-error Not documented legacy configuration options.
typeof configurationCopy.announceFailedHeartbeats === 'boolean'
) {
// @ts-expect-error Not documented legacy configuration options.
announceFailedHeartbeats = configurationCopy.announceFailedHeartbeats;
}
if (
// @ts-expect-error Not documented legacy configuration options.
configurationCopy.fileUploadPublishRetryLimit !== undefined &&
// @ts-expect-error Not documented legacy configuration options.
typeof configurationCopy.fileUploadPublishRetryLimit === 'number'
) {
// @ts-expect-error Not documented legacy configuration options.
fileUploadPublishRetryLimit = configurationCopy.fileUploadPublishRetryLimit;
}
return {
...configurationCopy,
keySet,
dedupeOnSubscribe,
maximumCacheSize,
useRequestId,
announceSuccessfulHeartbeats,
announceFailedHeartbeats,
fileUploadPublishRetryLimit,
};
};