@stream-io/video-react-bindings 0.2.33 → 0.2.35

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/index.cjs.js +609 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.es.js +589 -0
  6. package/dist/index.es.js.map +1 -0
  7. package/dist/src/contexts/StreamI18nContext.d.ts +2 -2
  8. package/dist/src/i18n/StreamI18n.d.ts +29 -0
  9. package/dist/src/i18n/index.d.ts +3 -0
  10. package/dist/src/i18n/types.d.ts +7 -0
  11. package/dist/src/i18n/utils.d.ts +2 -0
  12. package/index.ts +2 -0
  13. package/package.json +13 -11
  14. package/src/contexts/StreamI18nContext.tsx +5 -3
  15. package/src/i18n/StreamI18n.ts +124 -0
  16. package/src/i18n/index.ts +3 -0
  17. package/src/i18n/types.ts +19 -0
  18. package/src/i18n/utils.ts +10 -0
  19. package/dist/index.js +0 -4
  20. package/dist/index.js.map +0 -1
  21. package/dist/src/contexts/StreamCallContext.js +0 -26
  22. package/dist/src/contexts/StreamCallContext.js.map +0 -1
  23. package/dist/src/contexts/StreamI18nContext.js +0 -40
  24. package/dist/src/contexts/StreamI18nContext.js.map +0 -1
  25. package/dist/src/contexts/StreamVideoContext.js +0 -23
  26. package/dist/src/contexts/StreamVideoContext.js.map +0 -1
  27. package/dist/src/contexts/index.js +0 -4
  28. package/dist/src/contexts/index.js.map +0 -1
  29. package/dist/src/hooks/callStateHooks.js +0 -311
  30. package/dist/src/hooks/callStateHooks.js.map +0 -1
  31. package/dist/src/hooks/index.js +0 -10
  32. package/dist/src/hooks/index.js.map +0 -1
  33. package/dist/src/hooks/permissions.js +0 -23
  34. package/dist/src/hooks/permissions.js.map +0 -1
  35. package/dist/src/hooks/store.js +0 -33
  36. package/dist/src/hooks/store.js.map +0 -1
  37. package/dist/src/hooks/useObservableValue.js +0 -17
  38. package/dist/src/hooks/useObservableValue.js.map +0 -1
  39. package/dist/src/wrappers/Restricted.js +0 -17
  40. package/dist/src/wrappers/Restricted.js.map +0 -1
  41. package/dist/src/wrappers/index.js +0 -2
  42. package/dist/src/wrappers/index.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ### [0.2.35](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-react-bindings-0.2.34...@stream-io/video-react-bindings-0.2.35) (2023-10-18)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `@stream-io/video-client` updated to version `0.3.34`
10
+
11
+ ### Features
12
+
13
+ * **build:** ESM and CJS bundles ([#1144](https://github.com/GetStream/stream-video-js/issues/1144)) ([58b60ee](https://github.com/GetStream/stream-video-js/commit/58b60eee4b1cd667d2eef8f17ed4e6da74876a51)), closes [#1025](https://github.com/GetStream/stream-video-js/issues/1025)
14
+
15
+ ### [0.2.34](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-react-bindings-0.2.33...@stream-io/video-react-bindings-0.2.34) (2023-10-13)
16
+
17
+ ### Dependency Updates
18
+
19
+ * `@stream-io/video-client` updated to version `0.3.33`
5
20
  ### [0.2.33](https://github.com/GetStream/stream-video-js/compare/@stream-io/video-react-bindings-0.2.32...@stream-io/video-react-bindings-0.2.33) (2023-10-13)
6
21
 
7
22
  ### Dependency Updates
@@ -0,0 +1,609 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var i18next = require('i18next');
6
+ var videoClient = require('@stream-io/video-client');
7
+
8
+ const StreamCallContext = react.createContext(undefined);
9
+ /**
10
+ *
11
+ * @param props
12
+ * @returns
13
+ *
14
+ * @category Call State
15
+ *
16
+ * @react If you're using the React SDK we recommend using the `StreamCall` component that wraps the `StreamCallProvider`. You only need to use the `StreamCallProvider` for advanced use-cases.
17
+ */
18
+ const StreamCallProvider = (props) => {
19
+ const { call, children } = props;
20
+ return (jsxRuntime.jsx(StreamCallContext.Provider, { value: call, children: children }));
21
+ };
22
+ /**
23
+ *
24
+ * @returns
25
+ *
26
+ * @category Call State
27
+ */
28
+ const useCall = () => {
29
+ return react.useContext(StreamCallContext);
30
+ };
31
+
32
+ const mapToRegistry = (translationsMap, namespace) => Object.entries(translationsMap).reduce((acc, [lng, translations]) => {
33
+ acc[lng] = { [namespace]: translations };
34
+ return acc;
35
+ }, {});
36
+
37
+ const DEFAULT_LANGUAGE = 'en';
38
+ const DEFAULT_NAMESPACE = 'stream-video';
39
+ const DEFAULT_CONFIG = {
40
+ debug: false,
41
+ currentLanguage: DEFAULT_LANGUAGE,
42
+ };
43
+ const DEFAULT_TRANSLATIONS_REGISTRY = mapToRegistry({}, DEFAULT_NAMESPACE);
44
+ const defaultTranslationFunction = (key) => key;
45
+ class StreamI18n {
46
+ /** Simple logger function */
47
+ constructor(options = {}) {
48
+ /** Translator function that converts the provided string into its equivalent in the current language. */
49
+ this.t = defaultTranslationFunction;
50
+ this.init = async () => {
51
+ try {
52
+ this.t = await this.i18nInstance.init();
53
+ }
54
+ catch (e) {
55
+ console.error(`Failed to initialize translations: ${JSON.stringify(e)}`);
56
+ }
57
+ return this;
58
+ };
59
+ this.changeLanguage = async (language, onChange) => {
60
+ if (!this._checkIsInitialized())
61
+ return;
62
+ // i18next detects the language, if none provided, but it is better
63
+ // to show this detection here explicitly
64
+ const browserLanguage = typeof window !== 'undefined' && window.navigator
65
+ ? window.navigator.language
66
+ : undefined;
67
+ await this.i18nInstance.changeLanguage(language || browserLanguage);
68
+ onChange?.(this.currentLanguage);
69
+ };
70
+ this.registerTranslationsForLanguage = ({ lng, translations, }) => {
71
+ if (!this._checkIsInitialized())
72
+ return;
73
+ this.i18nInstance.addResourceBundle(lng, DEFAULT_NAMESPACE, translations, true, true);
74
+ };
75
+ this._checkIsInitialized = () => {
76
+ if (!this.i18nInstance.isInitialized) {
77
+ console.warn('I18n instance is not initialized. Call yourStreamI18nInstance.init().');
78
+ }
79
+ return this.i18nInstance.isInitialized;
80
+ };
81
+ const { debug = DEFAULT_CONFIG.debug, currentLanguage = DEFAULT_CONFIG.currentLanguage, translationsOverrides, } = options;
82
+ this.i18nInstance = i18next.createInstance({
83
+ debug,
84
+ defaultNS: DEFAULT_NAMESPACE,
85
+ fallbackLng: false,
86
+ interpolation: { escapeValue: false },
87
+ keySeparator: false,
88
+ lng: currentLanguage,
89
+ nsSeparator: false,
90
+ parseMissingKeyHandler: (key) => {
91
+ return key;
92
+ },
93
+ resources: DEFAULT_TRANSLATIONS_REGISTRY,
94
+ });
95
+ if (translationsOverrides) {
96
+ this.i18nInstance.on('initialized', () => {
97
+ Object.entries(translationsOverrides).forEach(([lng, translations]) => {
98
+ this.registerTranslationsForLanguage({ lng, translations });
99
+ });
100
+ });
101
+ }
102
+ }
103
+ get currentLanguage() {
104
+ this._checkIsInitialized();
105
+ return this.i18nInstance.language;
106
+ }
107
+ get isInitialized() {
108
+ return this.i18nInstance.isInitialized;
109
+ }
110
+ }
111
+
112
+ const StreamI18nContext = react.createContext({
113
+ t: defaultTranslationFunction,
114
+ });
115
+ const StreamI18nProvider = ({ children, ...createI18nParams }) => {
116
+ const { i18n, t } = useCreateI18n(createI18nParams);
117
+ return (jsxRuntime.jsx(StreamI18nContext.Provider, { value: { t, i18n }, children: children }));
118
+ };
119
+ const useCreateI18n = ({ i18nInstance, language, translationsOverrides, }) => {
120
+ const [i18n] = react.useState(() => i18nInstance ||
121
+ new StreamI18n({ currentLanguage: language, translationsOverrides }));
122
+ const [t, setTranslationFn] = react.useState(() => defaultTranslationFunction);
123
+ react.useEffect(() => {
124
+ const { isInitialized } = i18n;
125
+ if (!isInitialized) {
126
+ i18n.init().then((_i18n) => setTranslationFn(() => _i18n.i18nInstance.t));
127
+ return;
128
+ }
129
+ if (language && i18n?.currentLanguage !== language) {
130
+ i18n.changeLanguage(language).catch((err) => {
131
+ console.log('Error while changing language', err);
132
+ });
133
+ }
134
+ }, [i18n, i18nInstance, language, translationsOverrides]);
135
+ return { i18n, t };
136
+ };
137
+ const useI18n = () => react.useContext(StreamI18nContext);
138
+
139
+ const StreamVideoContext = react.createContext(undefined);
140
+ /**
141
+ * StreamVideo is a provider component which should be used to wrap the entire application.
142
+ * It provides the client object to all children components and initializes the i18n instance.
143
+ * @param PropsWithChildren<StreamVideoProps>
144
+ * @category Client State
145
+ */
146
+ const StreamVideoProvider = ({ children, client, i18nInstance, language, translationsOverrides, }) => {
147
+ return (jsxRuntime.jsx(StreamVideoContext.Provider, { value: client, children: jsxRuntime.jsx(StreamI18nProvider, { i18nInstance: i18nInstance, language: language, translationsOverrides: translationsOverrides, children: children }) }));
148
+ };
149
+ /**
150
+ *
151
+ * @returns
152
+ *
153
+ * @category Client State
154
+ */
155
+ const useStreamVideoClient = () => {
156
+ return react.useContext(StreamVideoContext);
157
+ };
158
+
159
+ /**
160
+ * Utility hook which provides the current value of the given observable.
161
+ * @internal
162
+ */
163
+ const useObservableValue = (observable$) => {
164
+ const [value, setValue] = react.useState(() => videoClient.RxUtils.getCurrentValue(observable$));
165
+ react.useEffect(() => {
166
+ const subscription = observable$.subscribe(setValue);
167
+ return () => {
168
+ subscription.unsubscribe();
169
+ };
170
+ }, [observable$]);
171
+ return value;
172
+ };
173
+
174
+ /**
175
+ * Utility hook, which provides the current call's state.
176
+ *
177
+ * @category Call State
178
+ */
179
+ const useCallState = () => {
180
+ const call = useCall();
181
+ // return an empty and unlinked CallState object if there is no call in the provider
182
+ // this ensures that the hooks always return a value and many null checks can be avoided
183
+ if (!call) {
184
+ const message = 'You are using useCallState() outside a Call context. ' +
185
+ 'Please wrap your component in <StreamCall /> and provide a "call" instance.';
186
+ console.warn(message);
187
+ return new videoClient.CallState();
188
+ }
189
+ return call.state;
190
+ };
191
+ /**
192
+ * Utility hook which provides information whether the current call is being recorded. It will return `true` if the call is being recorded.
193
+ *
194
+ * @category Call State
195
+ */
196
+ const useIsCallRecordingInProgress = () => {
197
+ const { recording$ } = useCallState();
198
+ return useObservableValue(recording$);
199
+ };
200
+ /**
201
+ * Utility hook which provides information whether the current call is broadcasting.
202
+ *
203
+ * @category Call State
204
+ */
205
+ const useIsCallBroadcastingInProgress = () => {
206
+ const { egress$ } = useCallState();
207
+ const egress = useObservableValue(egress$);
208
+ if (!egress)
209
+ return false;
210
+ return egress.broadcasting;
211
+ };
212
+ /**
213
+ * Utility hook which provides information whether the current call is live.
214
+ *
215
+ * @category Call State
216
+ */
217
+ const useIsCallLive = () => {
218
+ const { backstage$ } = useCallState();
219
+ const isBackstageOn = useObservableValue(backstage$);
220
+ return !isBackstageOn;
221
+ };
222
+ /**
223
+ * Returns the list of blocked users in the current call.
224
+ */
225
+ const useCallBlockedUserIds = () => {
226
+ const { blockedUserIds$ } = useCallState();
227
+ return useObservableValue(blockedUserIds$);
228
+ };
229
+ /**
230
+ * Returns the timestamp when this call was created.
231
+ */
232
+ const useCallCreatedAt = () => {
233
+ const { createdAt$ } = useCallState();
234
+ return useObservableValue(createdAt$);
235
+ };
236
+ /**
237
+ * Returns the timestamp when this call was ended.
238
+ */
239
+ const useCallEndedAt = () => {
240
+ const { endedAt$ } = useCallState();
241
+ return useObservableValue(endedAt$);
242
+ };
243
+ /**
244
+ * Returns the timestamp telling when the call is scheduled to start.
245
+ */
246
+ const useCallStartsAt = () => {
247
+ const { startsAt$ } = useCallState();
248
+ return useObservableValue(startsAt$);
249
+ };
250
+ /**
251
+ * Returns the timestamp when this call was updated.
252
+ */
253
+ const useCallUpdatedAt = () => {
254
+ const { updatedAt$ } = useCallState();
255
+ return useObservableValue(updatedAt$);
256
+ };
257
+ /**
258
+ * Returns the information about the call's creator.
259
+ */
260
+ const useCallCreatedBy = () => {
261
+ const { createdBy$ } = useCallState();
262
+ return useObservableValue(createdBy$);
263
+ };
264
+ /**
265
+ * Returns the call's custom data.
266
+ */
267
+ const useCallCustomData = () => {
268
+ const { custom$ } = useCallState();
269
+ return useObservableValue(custom$);
270
+ };
271
+ /**
272
+ * Returns the call's Egress information.
273
+ */
274
+ const useCallEgress = () => {
275
+ const { egress$ } = useCallState();
276
+ return useObservableValue(egress$);
277
+ };
278
+ /**
279
+ * Returns the call's Ingress information.
280
+ */
281
+ const useCallIngress = () => {
282
+ const { ingress$ } = useCallState();
283
+ return useObservableValue(ingress$);
284
+ };
285
+ /**
286
+ * Returns the data for the current call session.
287
+ */
288
+ const useCallSession = () => {
289
+ const { session$ } = useCallState();
290
+ return useObservableValue(session$);
291
+ };
292
+ /**
293
+ * Returns the call's settings.
294
+ */
295
+ const useCallSettings = () => {
296
+ const { settings$ } = useCallState();
297
+ return useObservableValue(settings$);
298
+ };
299
+ /**
300
+ * Returns whether the call has transcribing enabled.
301
+ */
302
+ const useIsCallTranscribingInProgress = () => {
303
+ const { transcribing$ } = useCallState();
304
+ return useObservableValue(transcribing$);
305
+ };
306
+ /**
307
+ * Returns information about the user who has marked this call as ended.
308
+ */
309
+ const useCallEndedBy = () => {
310
+ const { endedBy$ } = useCallState();
311
+ return useObservableValue(endedBy$);
312
+ };
313
+ /**
314
+ * Utility hook which provides a boolean indicating whether there is
315
+ * a participant in the current call which shares their screen.
316
+ *
317
+ * @category Call State
318
+ */
319
+ const useHasOngoingScreenShare = () => {
320
+ const { hasOngoingScreenShare$ } = useCallState();
321
+ return useObservableValue(hasOngoingScreenShare$);
322
+ };
323
+ /**
324
+ * Utility hook which provides the latest stats report of the current call.
325
+ *
326
+ * The latest stats report of the current call.
327
+ * When stats gathering is enabled, this observable will emit a new value
328
+ * at a regular (configurable) interval.
329
+ *
330
+ * Consumers of this observable can implement their own batching logic
331
+ * in case they want to show historical stats data.
332
+ *
333
+ * @category Call State
334
+ */
335
+ const useCallStatsReport = () => {
336
+ const { callStatsReport$ } = useCallState();
337
+ return useObservableValue(callStatsReport$);
338
+ };
339
+ /**
340
+ * Utility hook which provides the dominant speaker of the current call.
341
+ *
342
+ * @category Call State
343
+ */
344
+ const useDominantSpeaker = () => {
345
+ const { dominantSpeaker$ } = useCallState();
346
+ return useObservableValue(dominantSpeaker$);
347
+ };
348
+ /**
349
+ * Utility hook which provides a list of call members.
350
+ *
351
+ * @category Call State
352
+ */
353
+ const useCallMembers = () => {
354
+ const { members$ } = useCallState();
355
+ return useObservableValue(members$);
356
+ };
357
+ /**
358
+ * Utility hook providing the current calling state of the call. For example, `RINGING` or `JOINED`.
359
+ *
360
+ * @category Call State
361
+ */
362
+ const useCallCallingState = () => {
363
+ const { callingState$ } = useCallState();
364
+ return useObservableValue(callingState$);
365
+ };
366
+ /**
367
+ * Utility hook providing the actual start time of the current session.
368
+ * Useful for calculating the call duration.
369
+ *
370
+ * @category Call State
371
+ */
372
+ const useCallStartedAt = () => {
373
+ const { startedAt$ } = useCallState();
374
+ return useObservableValue(startedAt$);
375
+ };
376
+ /**
377
+ * A hook which provides a list of all participants that have joined an active call.
378
+ *
379
+ * @category Call State
380
+ *
381
+ * @param options.sortBy - A comparator function to sort the participants by.
382
+ * Make sure to memoize output of the `combineComparators` function
383
+ * (or keep it out of component's scope if possible) before passing it down to this property.
384
+ */
385
+ const useParticipants = ({ sortBy, } = {}) => {
386
+ const { participants$ } = useCallState();
387
+ const participants = useObservableValue(participants$);
388
+ return react.useMemo(() => {
389
+ if (sortBy) {
390
+ return [...participants].sort(sortBy);
391
+ }
392
+ return participants;
393
+ }, [participants, sortBy]);
394
+ };
395
+ /**
396
+ * A hook which provides a StreamVideoLocalParticipant object.
397
+ * It signals that I have joined a call.
398
+ *
399
+ * @category Call State
400
+ */
401
+ const useLocalParticipant = () => {
402
+ const { localParticipant$ } = useCallState();
403
+ return useObservableValue(localParticipant$);
404
+ };
405
+ /**
406
+ * A hook which provides a list of all other participants than me that have joined an active call.
407
+ *
408
+ * @category Call State
409
+ */
410
+ const useRemoteParticipants = () => {
411
+ const { remoteParticipants$ } = useCallState();
412
+ return useObservableValue(remoteParticipants$);
413
+ };
414
+ /**
415
+ * Returns the approximate participant count of the active call.
416
+ * This includes the anonymous users as well, and it is computed on the server.
417
+ *
418
+ * @category Call State
419
+ */
420
+ const useParticipantCount = () => {
421
+ const { participantCount$ } = useCallState();
422
+ return useObservableValue(participantCount$);
423
+ };
424
+ /**
425
+ * Returns the approximate anonymous participant count of the active call.
426
+ * The regular participants are not included in this count. It is computed on the server.
427
+ *
428
+ * @category Call State
429
+ */
430
+ const useAnonymousParticipantCount = () => {
431
+ const { anonymousParticipantCount$ } = useCallState();
432
+ return useObservableValue(anonymousParticipantCount$);
433
+ };
434
+ /**
435
+ * Returns the generated thumbnail of the current call, if enabled in settings.
436
+ */
437
+ const useCallThumbnail = () => {
438
+ const { thumbnails$ } = useCallState();
439
+ return useObservableValue(thumbnails$);
440
+ };
441
+ /**
442
+ * Returns the camera state of the current call.
443
+ *
444
+ * @category Camera Manager State
445
+ *
446
+ */
447
+ const useCameraState = () => {
448
+ const call = useCall();
449
+ const { camera } = call;
450
+ const status = useObservableValue(camera.state.status$);
451
+ const direction = useObservableValue(camera.state.direction$);
452
+ return {
453
+ status,
454
+ direction,
455
+ };
456
+ };
457
+ /**
458
+ * Returns the microphone state of the current call.
459
+ *
460
+ * @category Microphone Manager State
461
+ */
462
+ const useMicrophoneState = () => {
463
+ const call = useCall();
464
+ const { microphone } = call;
465
+ const status = useObservableValue(microphone.state.status$);
466
+ const selectedDevice = useObservableValue(microphone.state.selectedDevice$);
467
+ return {
468
+ status,
469
+ selectedDevice,
470
+ };
471
+ };
472
+ const useScreenShareState = () => {
473
+ const call = useCall();
474
+ const { screenShare } = call;
475
+ const status = useObservableValue(screenShare.state.status$);
476
+ return {
477
+ status,
478
+ };
479
+ };
480
+
481
+ var CallStateHooks = /*#__PURE__*/Object.freeze({
482
+ __proto__: null,
483
+ useAnonymousParticipantCount: useAnonymousParticipantCount,
484
+ useCallBlockedUserIds: useCallBlockedUserIds,
485
+ useCallCallingState: useCallCallingState,
486
+ useCallCreatedAt: useCallCreatedAt,
487
+ useCallCreatedBy: useCallCreatedBy,
488
+ useCallCustomData: useCallCustomData,
489
+ useCallEgress: useCallEgress,
490
+ useCallEndedAt: useCallEndedAt,
491
+ useCallEndedBy: useCallEndedBy,
492
+ useCallIngress: useCallIngress,
493
+ useCallMembers: useCallMembers,
494
+ useCallSession: useCallSession,
495
+ useCallSettings: useCallSettings,
496
+ useCallStartedAt: useCallStartedAt,
497
+ useCallStartsAt: useCallStartsAt,
498
+ useCallState: useCallState,
499
+ useCallStatsReport: useCallStatsReport,
500
+ useCallThumbnail: useCallThumbnail,
501
+ useCallUpdatedAt: useCallUpdatedAt,
502
+ useCameraState: useCameraState,
503
+ useDominantSpeaker: useDominantSpeaker,
504
+ useHasOngoingScreenShare: useHasOngoingScreenShare,
505
+ useIsCallBroadcastingInProgress: useIsCallBroadcastingInProgress,
506
+ useIsCallLive: useIsCallLive,
507
+ useIsCallRecordingInProgress: useIsCallRecordingInProgress,
508
+ useIsCallTranscribingInProgress: useIsCallTranscribingInProgress,
509
+ useLocalParticipant: useLocalParticipant,
510
+ useMicrophoneState: useMicrophoneState,
511
+ useParticipantCount: useParticipantCount,
512
+ useParticipants: useParticipants,
513
+ useRemoteParticipants: useRemoteParticipants,
514
+ useScreenShareState: useScreenShareState
515
+ });
516
+
517
+ /**
518
+ * Hook that returns true if the local participant has all the given permissions.
519
+ *
520
+ * @param permissions the permissions to check.
521
+ *
522
+ * @category Call State
523
+ */
524
+ const useHasPermissions = (...permissions) => {
525
+ const capabilities = useOwnCapabilities();
526
+ return permissions.every((permission) => capabilities?.includes(permission));
527
+ };
528
+ /**
529
+ * A hook which returns the local participant's own capabilities.
530
+ *
531
+ * @category Call State
532
+ */
533
+ const useOwnCapabilities = () => {
534
+ const { ownCapabilities$ } = useCallState();
535
+ return useObservableValue(ownCapabilities$);
536
+ };
537
+
538
+ /**
539
+ * Utility hook which provides access to client's state store.
540
+ */
541
+ const useStore = () => {
542
+ const client = useStreamVideoClient();
543
+ if (!client) {
544
+ throw new Error(`StreamVideoClient isn't initialized or this hook is called outside of <StreamVideo> context.`);
545
+ }
546
+ return client.readOnlyStateStore;
547
+ };
548
+ /**
549
+ * Utility hook which provides a list of all notifications about created calls.
550
+ * In the ring call settings, these calls can be outgoing (I have called somebody)
551
+ * or incoming (somebody has called me).
552
+ *
553
+ * @category Client State
554
+ */
555
+ const useCalls = () => {
556
+ const { calls$ } = useStore();
557
+ return useObservableValue(calls$);
558
+ };
559
+ /**
560
+ * Returns the current connected user.
561
+ *
562
+ * @category Client State
563
+ */
564
+ const useConnectedUser = () => {
565
+ const { connectedUser$ } = useStore();
566
+ return useObservableValue(connectedUser$);
567
+ };
568
+
569
+ /**
570
+ * A hook-alike function that exposes all call state hooks.
571
+ *
572
+ * @category Call State
573
+ */
574
+ const useCallStateHooks = () => CallStateHooks;
575
+
576
+ const Restricted = ({ canRequestOnly, hasPermissionsOnly, requiredGrants, requireAll = true, children, }) => {
577
+ const call = useCall();
578
+ const ownCapabilities = useOwnCapabilities();
579
+ const hasPermissions = requiredGrants[requireAll ? 'every' : 'some']((capability) => ownCapabilities?.includes(capability));
580
+ if (hasPermissionsOnly)
581
+ return hasPermissions ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: children }) : null;
582
+ const canRequest = requiredGrants.some((capability) => !!call && call.permissionsContext.canRequest(capability));
583
+ if (canRequestOnly)
584
+ return canRequest ? jsxRuntime.jsx(jsxRuntime.Fragment, { children: children }) : null;
585
+ if (hasPermissions || canRequest)
586
+ return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
587
+ return null;
588
+ };
589
+
590
+ exports.DEFAULT_LANGUAGE = DEFAULT_LANGUAGE;
591
+ exports.DEFAULT_NAMESPACE = DEFAULT_NAMESPACE;
592
+ exports.Restricted = Restricted;
593
+ exports.StreamCallProvider = StreamCallProvider;
594
+ exports.StreamI18n = StreamI18n;
595
+ exports.StreamI18nProvider = StreamI18nProvider;
596
+ exports.StreamVideoProvider = StreamVideoProvider;
597
+ exports.defaultTranslationFunction = defaultTranslationFunction;
598
+ exports.mapToRegistry = mapToRegistry;
599
+ exports.useCall = useCall;
600
+ exports.useCallStateHooks = useCallStateHooks;
601
+ exports.useCalls = useCalls;
602
+ exports.useConnectedUser = useConnectedUser;
603
+ exports.useCreateI18n = useCreateI18n;
604
+ exports.useHasPermissions = useHasPermissions;
605
+ exports.useI18n = useI18n;
606
+ exports.useOwnCapabilities = useOwnCapabilities;
607
+ exports.useStore = useStore;
608
+ exports.useStreamVideoClient = useStreamVideoClient;
609
+ //# sourceMappingURL=index.cjs.js.map