@stream-io/video-react-bindings 0.0.1-alpha.13

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 (56) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/LICENSE +219 -0
  3. package/README.md +3 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/contexts/StreamCallContext.d.ts +25 -0
  8. package/dist/src/contexts/StreamCallContext.js +24 -0
  9. package/dist/src/contexts/StreamCallContext.js.map +1 -0
  10. package/dist/src/contexts/StreamI18nContext.d.ts +19 -0
  11. package/dist/src/contexts/StreamI18nContext.js +40 -0
  12. package/dist/src/contexts/StreamI18nContext.js.map +1 -0
  13. package/dist/src/contexts/StreamVideoContext.d.ts +24 -0
  14. package/dist/src/contexts/StreamVideoContext.js +23 -0
  15. package/dist/src/contexts/StreamVideoContext.js.map +1 -0
  16. package/dist/src/contexts/index.d.ts +3 -0
  17. package/dist/src/contexts/index.js +4 -0
  18. package/dist/src/contexts/index.js.map +1 -0
  19. package/dist/src/hooks/call.d.ts +80 -0
  20. package/dist/src/hooks/call.js +116 -0
  21. package/dist/src/hooks/call.js.map +1 -0
  22. package/dist/src/hooks/client.d.ts +33 -0
  23. package/dist/src/hooks/client.js +36 -0
  24. package/dist/src/hooks/client.js.map +1 -0
  25. package/dist/src/hooks/helpers/useObservableValue.d.ts +6 -0
  26. package/dist/src/hooks/helpers/useObservableValue.js +17 -0
  27. package/dist/src/hooks/helpers/useObservableValue.js.map +1 -0
  28. package/dist/src/hooks/index.d.ts +6 -0
  29. package/dist/src/hooks/index.js +7 -0
  30. package/dist/src/hooks/index.js.map +1 -0
  31. package/dist/src/hooks/participants.d.ts +30 -0
  32. package/dist/src/hooks/participants.js +42 -0
  33. package/dist/src/hooks/participants.js.map +1 -0
  34. package/dist/src/hooks/permissions.d.ts +15 -0
  35. package/dist/src/hooks/permissions.js +24 -0
  36. package/dist/src/hooks/permissions.js.map +1 -0
  37. package/dist/src/hooks/store.d.ts +11 -0
  38. package/dist/src/hooks/store.js +28 -0
  39. package/dist/src/hooks/store.js.map +1 -0
  40. package/dist/src/hooks/user.d.ts +7 -0
  41. package/dist/src/hooks/user.js +13 -0
  42. package/dist/src/hooks/user.js.map +1 -0
  43. package/index.ts +2 -0
  44. package/package.json +43 -0
  45. package/src/contexts/StreamCallContext.tsx +41 -0
  46. package/src/contexts/StreamI18nContext.tsx +70 -0
  47. package/src/contexts/StreamVideoContext.tsx +54 -0
  48. package/src/contexts/index.ts +3 -0
  49. package/src/hooks/call.ts +126 -0
  50. package/src/hooks/client.ts +77 -0
  51. package/src/hooks/helpers/useObservableValue.ts +21 -0
  52. package/src/hooks/index.ts +6 -0
  53. package/src/hooks/participants.ts +57 -0
  54. package/src/hooks/permissions.ts +27 -0
  55. package/src/hooks/store.ts +33 -0
  56. package/src/hooks/user.ts +13 -0
@@ -0,0 +1,116 @@
1
+ import { useObservableValue } from './helpers/useObservableValue';
2
+ import { useCallState, useStore } from './store';
3
+ /**
4
+ * Utility hook which provides information whether the current call is being recorded.
5
+ *
6
+ * @category Call State
7
+ */
8
+ export const useIsCallRecordingInProgress = () => {
9
+ const { callRecordingInProgress$ } = useCallState();
10
+ return useObservableValue(callRecordingInProgress$);
11
+ };
12
+ /**
13
+ * Utility hook which provides a boolean indicating whether there is
14
+ * a participant in the current call which shares their screen.
15
+ *
16
+ * @category Call State
17
+ */
18
+ export const useHasOngoingScreenShare = () => {
19
+ const { hasOngoingScreenShare$ } = useCallState();
20
+ return useObservableValue(hasOngoingScreenShare$);
21
+ };
22
+ /**
23
+ * Utility hook which provides the latest stats report of the current call.
24
+ *
25
+ * The latest stats report of the current call.
26
+ * When stats gathering is enabled, this observable will emit a new value
27
+ * at a regular (configurable) interval.
28
+ *
29
+ * Consumers of this observable can implement their own batching logic
30
+ * in case they want to show historical stats data.
31
+ *
32
+ * @category Call State
33
+ */
34
+ export const useCurrentCallStatsReport = () => {
35
+ const { callStatsReport$ } = useCallState();
36
+ return useObservableValue(callStatsReport$);
37
+ };
38
+ /**
39
+ * Utility hook which provides the dominant speaker of the current call.
40
+ *
41
+ * @category Call State
42
+ */
43
+ export const useDominantSpeaker = () => {
44
+ const { dominantSpeaker$ } = useCallState();
45
+ return useObservableValue(dominantSpeaker$);
46
+ };
47
+ /**
48
+ * Utility hook which provides a list of all notifications about created calls.
49
+ * In the ring call settings, these calls can be outgoing (I have called somebody)
50
+ * or incoming (somebody has called me).
51
+ *
52
+ * @category Client State
53
+ */
54
+ export const useCalls = () => {
55
+ const { calls$ } = useStore();
56
+ return useObservableValue(calls$);
57
+ };
58
+ /**
59
+ * Utility hook which provides a list of all incoming ring calls (somebody calls me).
60
+ *
61
+ * @deprecated derive from useCalls()/useCall() instead.
62
+ * @internal
63
+ * @category Client State
64
+ */
65
+ export const useIncomingCalls = () => {
66
+ const { incomingCalls$ } = useStore();
67
+ return useObservableValue(incomingCalls$);
68
+ };
69
+ /**
70
+ * Utility hook which provides a list of all outgoing ring calls (I call somebody).
71
+ *
72
+ * @deprecated derive from useCalls()/useCall() instead.
73
+ * @internal
74
+ * @category Client State
75
+ */
76
+ export const useOutgoingCalls = () => {
77
+ const { outgoingCalls$ } = useStore();
78
+ return useObservableValue(outgoingCalls$);
79
+ };
80
+ /**
81
+ * Utility hook which provides call metadata (such as blocked users and own capabilities).
82
+ *
83
+ * @category Call State
84
+ */
85
+ export const useCallMetadata = () => {
86
+ const { metadata$ } = useCallState();
87
+ return useObservableValue(metadata$);
88
+ };
89
+ /**
90
+ * Utility hook which provides a list of call members.
91
+ *
92
+ * @category Call State
93
+ */
94
+ export const useCallMembers = () => {
95
+ const { members$ } = useCallState();
96
+ return useObservableValue(members$);
97
+ };
98
+ /**
99
+ * Utility hook providing the latest list of recordings performed during the active call
100
+ *
101
+ * @category Call State
102
+ */
103
+ export const useCallRecordings = () => {
104
+ const { callRecordingList$ } = useCallState();
105
+ return useObservableValue(callRecordingList$);
106
+ };
107
+ /**
108
+ * Utility hook providing the current calling state of the call.
109
+ *
110
+ * @category Call State
111
+ */
112
+ export const useCallCallingState = () => {
113
+ const { callingState$ } = useCallState();
114
+ return useObservableValue(callingState$);
115
+ };
116
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.js","sourceRoot":"","sources":["../../../src/hooks/call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,MAAM,EAAE,wBAAwB,EAAE,GAAG,YAAY,EAAE,CAAC;IACpD,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,MAAM,EAAE,sBAAsB,EAAE,GAAG,YAAY,EAAE,CAAC;IAClD,OAAO,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC5C,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,MAAM,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC5C,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC9B,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtC,OAAO,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtC,OAAO,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAClC,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;IACrC,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,CAAC;IACpC,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,MAAM,EAAE,kBAAkB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC9C,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,EAAE,aAAa,EAAE,GAAG,YAAY,EAAE,CAAC;IACzC,OAAO,kBAAkB,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { StreamClientOptions, StreamVideoClient, TokenOrProvider, User } from '@stream-io/video-client';
2
+ /**
3
+ * Exclude types from documentation site, but we should still add doc comments
4
+ * @internal
5
+ */
6
+ export type StreamVideoClientInit = {
7
+ /**
8
+ * The Stream API key.
9
+ */
10
+ apiKey: string;
11
+ /**
12
+ * The token or token provider.
13
+ */
14
+ tokenOrProvider: TokenOrProvider;
15
+ /**
16
+ * The client options.
17
+ */
18
+ options?: StreamClientOptions;
19
+ /**
20
+ * The user to connect.
21
+ */
22
+ user: User;
23
+ /**
24
+ * Whether the user is anonymous. Defaults to `false`.
25
+ */
26
+ isAnonymous?: boolean;
27
+ };
28
+ /**
29
+ * Creates a new `StreamVideoClient` instance and connects the given user.
30
+ *
31
+ * @category Client State
32
+ */
33
+ export declare const useCreateStreamVideoClient: ({ apiKey, tokenOrProvider, user, options, isAnonymous, }: StreamVideoClientInit) => StreamVideoClient;
@@ -0,0 +1,36 @@
1
+ import { StreamVideoClient, } from '@stream-io/video-client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ /**
4
+ * Creates a new `StreamVideoClient` instance and connects the given user.
5
+ *
6
+ * @category Client State
7
+ */
8
+ export const useCreateStreamVideoClient = ({ apiKey, tokenOrProvider, user, options, isAnonymous = false, }) => {
9
+ const [client] = useState(() => new StreamVideoClient(apiKey, options));
10
+ const disconnectRef = useRef(Promise.resolve());
11
+ useEffect(() => {
12
+ const connectionPromise = disconnectRef.current.then(() => {
13
+ if (isAnonymous) {
14
+ return client
15
+ .connectAnonymousUser(user, tokenOrProvider)
16
+ .catch((err) => {
17
+ console.error(`Failed to establish connection`, err);
18
+ });
19
+ }
20
+ return client.connectUser(user, tokenOrProvider).catch((err) => {
21
+ console.error(`Failed to establish connection`, err);
22
+ });
23
+ });
24
+ return () => {
25
+ disconnectRef.current = connectionPromise
26
+ .then(() => client.disconnectUser())
27
+ .catch((err) => {
28
+ console.error(`Failed to disconnect`, err);
29
+ });
30
+ };
31
+ // we want to re-run this effect only in some special cases
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, [apiKey, tokenOrProvider, client, isAnonymous, user === null || user === void 0 ? void 0 : user.id]);
34
+ return client;
35
+ };
36
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/hooks/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAGlB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA6BpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,EACzC,MAAM,EACN,eAAe,EACf,IAAI,EACJ,OAAO,EACP,WAAW,GAAG,KAAK,GACG,EAAE,EAAE;IAC1B,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAChD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,iBAAiB,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YACxD,IAAI,WAAW,EAAE;gBACf,OAAO,MAAM;qBACV,oBAAoB,CAAC,IAAI,EAAE,eAAe,CAAC;qBAC3C,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACb,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;gBACvD,CAAC,CAAC,CAAC;aACN;YACD,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC7D,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,OAAO,GAAG,iBAAiB;iBACtC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;iBACnC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QACF,2DAA2D;QAC3D,uDAAuD;IACzD,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,CAAC,CAAC,CAAC;IAE7D,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Observable } from 'rxjs';
2
+ /**
3
+ *
4
+ * @internal
5
+ */
6
+ export declare const useObservableValue: <T>(observable$: Observable<T>) => T;
@@ -0,0 +1,17 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { RxUtils } from '@stream-io/video-client';
3
+ /**
4
+ *
5
+ * @internal
6
+ */
7
+ export const useObservableValue = (observable$) => {
8
+ const [value, setValue] = useState(() => RxUtils.getCurrentValue(observable$));
9
+ useEffect(() => {
10
+ const subscription = observable$.subscribe(setValue);
11
+ return () => {
12
+ subscription.unsubscribe();
13
+ };
14
+ }, [observable$]);
15
+ return value;
16
+ };
17
+ //# sourceMappingURL=useObservableValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useObservableValue.js","sourceRoot":"","sources":["../../../../src/hooks/helpers/useObservableValue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAI,WAA0B,EAAE,EAAE;IAClE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAI,GAAG,EAAE,CACzC,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CACrC,CAAC;IACF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACrD,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './call';
2
+ export * from './client';
3
+ export * from './participants';
4
+ export * from './permissions';
5
+ export * from './store';
6
+ export * from './user';
@@ -0,0 +1,7 @@
1
+ export * from './call';
2
+ export * from './client';
3
+ export * from './participants';
4
+ export * from './permissions';
5
+ export * from './store';
6
+ export * from './user';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Comparator, StreamVideoParticipant } from '@stream-io/video-client';
2
+ /**
3
+ * A hook which provides a list of all participants that have joined an active call.
4
+ *
5
+ * @category Call State
6
+ *
7
+ * @param options.sortBy - A comparator function to sort the participants by.
8
+ * Make sure to memoize output of the `combineComparators` function
9
+ * (or keep it out of component's scope if possible) before passing it down to this property.
10
+ */
11
+ export declare const useParticipants: ({ sortBy, }?: {
12
+ /**
13
+ * Make sure to memoize output of the `combineComparators` function
14
+ * (or keep it out of component's scope if possible) before passing it down to this property.
15
+ */
16
+ sortBy?: Comparator<StreamVideoParticipant> | undefined;
17
+ }) => (StreamVideoParticipant | import("@stream-io/video-client").StreamVideoLocalParticipant)[];
18
+ /**
19
+ * A hook which provides a StreamVideoLocalParticipant object.
20
+ * It signals that I have joined a call.
21
+ *
22
+ * @category Call State
23
+ */
24
+ export declare const useLocalParticipant: () => import("@stream-io/video-client").StreamVideoLocalParticipant | undefined;
25
+ /**
26
+ * A hook which provides a list of all other participants than me that have joined an active call.
27
+ *
28
+ * @category Call State
29
+ */
30
+ export declare const useRemoteParticipants: () => StreamVideoParticipant[];
@@ -0,0 +1,42 @@
1
+ import { useObservableValue } from './helpers/useObservableValue';
2
+ import { useCallState } from './store';
3
+ import { useMemo } from 'react';
4
+ /**
5
+ * A hook which provides a list of all participants that have joined an active call.
6
+ *
7
+ * @category Call State
8
+ *
9
+ * @param options.sortBy - A comparator function to sort the participants by.
10
+ * Make sure to memoize output of the `combineComparators` function
11
+ * (or keep it out of component's scope if possible) before passing it down to this property.
12
+ */
13
+ export const useParticipants = ({ sortBy, } = {}) => {
14
+ const { participants$ } = useCallState();
15
+ const participants = useObservableValue(participants$);
16
+ return useMemo(() => {
17
+ if (sortBy) {
18
+ return [...participants].sort(sortBy);
19
+ }
20
+ return participants;
21
+ }, [participants, sortBy]);
22
+ };
23
+ /**
24
+ * A hook which provides a StreamVideoLocalParticipant object.
25
+ * It signals that I have joined a call.
26
+ *
27
+ * @category Call State
28
+ */
29
+ export const useLocalParticipant = () => {
30
+ const { localParticipant$ } = useCallState();
31
+ return useObservableValue(localParticipant$);
32
+ };
33
+ /**
34
+ * A hook which provides a list of all other participants than me that have joined an active call.
35
+ *
36
+ * @category Call State
37
+ */
38
+ export const useRemoteParticipants = () => {
39
+ const { remoteParticipants$ } = useCallState();
40
+ return useObservableValue(remoteParticipants$);
41
+ };
42
+ //# sourceMappingURL=participants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"participants.js","sourceRoot":"","sources":["../../../src/hooks/participants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,MAAM,MAOJ,EAAE,EAAE,EAAE;IACR,MAAM,EAAE,aAAa,EAAE,GAAG,YAAY,EAAE,CAAC;IACzC,MAAM,YAAY,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;IAEvD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,MAAM,EAAE;YACV,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,EAAE,iBAAiB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC7C,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,MAAM,EAAE,mBAAmB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC/C,OAAO,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;AACjD,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { OwnCapability } from '@stream-io/video-client';
2
+ /**
3
+ * Hook that returns true if the current user has all the given permissions.
4
+ *
5
+ * @param permissions the permissions to check.
6
+ *
7
+ * @category Call State
8
+ */
9
+ export declare const useHasPermissions: (...permissions: OwnCapability[]) => boolean;
10
+ /**
11
+ * A hook which returns the current user's own capabilities.
12
+ *
13
+ * @category Call State
14
+ */
15
+ export declare const useOwnCapabilities: () => OwnCapability[];
@@ -0,0 +1,24 @@
1
+ import { useCallMetadata } from './call';
2
+ /**
3
+ * Hook that returns true if the current user has all the given permissions.
4
+ *
5
+ * @param permissions the permissions to check.
6
+ *
7
+ * @category Call State
8
+ */
9
+ export const useHasPermissions = (...permissions) => {
10
+ const metadata = useCallMetadata();
11
+ if (!metadata)
12
+ return false;
13
+ return permissions.every((permission) => metadata.own_capabilities.includes(permission));
14
+ };
15
+ /**
16
+ * A hook which returns the current user's own capabilities.
17
+ *
18
+ * @category Call State
19
+ */
20
+ export const useOwnCapabilities = () => {
21
+ const metadata = useCallMetadata();
22
+ return (metadata === null || metadata === void 0 ? void 0 : metadata.own_capabilities) || [];
23
+ };
24
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../src/hooks/permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,WAA4B,EAAE,EAAE;IACnE,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CACtC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAC/C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,gBAAgB,KAAI,EAAE,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { CallState } from '@stream-io/video-client';
2
+ /**
3
+ * Utility hook which provides access to client's state store.
4
+ */
5
+ export declare const useStore: () => import("@stream-io/video-client").StreamVideoReadOnlyStateStore;
6
+ /**
7
+ * Utility hook which provides the current call's state.
8
+ *
9
+ * @category Call State
10
+ */
11
+ export declare const useCallState: () => CallState;
@@ -0,0 +1,28 @@
1
+ import { CallState } from '@stream-io/video-client';
2
+ import { useCall, useStreamVideoClient } from '../contexts';
3
+ /**
4
+ * Utility hook which provides access to client's state store.
5
+ */
6
+ export const useStore = () => {
7
+ const client = useStreamVideoClient();
8
+ if (!client) {
9
+ throw new Error(`StreamVideoClient isn't initialized or this hook is called outside of <StreamVideo> context.`);
10
+ }
11
+ return client.readOnlyStateStore;
12
+ };
13
+ /**
14
+ * Utility hook which provides the current call's state.
15
+ *
16
+ * @category Call State
17
+ */
18
+ export const useCallState = () => {
19
+ const call = useCall();
20
+ // return an empty and unlinked CallState object if there is no call in the provider
21
+ // this ensures that the hooks always return a value and many null checks can be avoided
22
+ if (!call) {
23
+ console.warn(`You are using useCallState() outside a Call context. Please wrap your component in <StreamCallProvider />`);
24
+ return new CallState();
25
+ }
26
+ return call.state;
27
+ };
28
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/hooks/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;KACH;IACD,OAAO,MAAM,CAAC,kBAAkB,CAAC;AACnC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,oFAAoF;IACpF,wFAAwF;IACxF,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,CAAC,IAAI,CACV,2GAA2G,CAC5G,CAAC;QACF,OAAO,IAAI,SAAS,EAAE,CAAC;KACxB;IACD,OAAO,IAAI,CAAC,KAAK,CAAC;AACpB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @returns
4
+ *
5
+ * @category Client State
6
+ */
7
+ export declare const useConnectedUser: () => import("@stream-io/video-client").User | undefined;
@@ -0,0 +1,13 @@
1
+ import { useStore } from './store';
2
+ import { useObservableValue } from './helpers/useObservableValue';
3
+ /**
4
+ *
5
+ * @returns
6
+ *
7
+ * @category Client State
8
+ */
9
+ export const useConnectedUser = () => {
10
+ const { connectedUser$ } = useStore();
11
+ return useObservableValue(connectedUser$);
12
+ };
13
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/hooks/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtC,OAAO,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC5C,CAAC,CAAC"}
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/contexts';
2
+ export * from './src/hooks';
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@stream-io/video-react-bindings",
3
+ "packageManager": "yarn@3.2.4",
4
+ "main": "./dist/index.js",
5
+ "types": "./dist/index.d.ts",
6
+ "license": "See license in LICENSE",
7
+ "scripts": {
8
+ "clean": "rimraf dist",
9
+ "start": "tsc --project tsconfig.json --watch",
10
+ "build": "tsc --project tsconfig.production.json",
11
+ "generate-docs": "rimraf generated-docs && typedoc --options typedoc.json ./index.ts && replace-in-file '# @stream-io/video-react-bindings' '# Hooks' temp-docs/** && replace-in-file '.md' '' 'temp-docs/**' && mkdir generated-docs && cp temp-docs/modules.md generated-docs/hooks.md && rm -rf temp-docs"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "src",
16
+ "index.ts",
17
+ "package.json",
18
+ "README.md",
19
+ "LICENSE",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "dependencies": {
23
+ "rxjs": "~7.5.7"
24
+ },
25
+ "peerDependencies": {
26
+ "@stream-io/i18n": "^0.0.1-alpha.10",
27
+ "@stream-io/video-client": "^0.0.1-alpha.124",
28
+ "react": ">=17.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@stream-io/i18n": "^0.0.1-alpha.10",
32
+ "@stream-io/video-client": "^0.0.1-alpha.124",
33
+ "@types/react": "^18.0.26",
34
+ "@types/rimraf": "^3.0.2",
35
+ "react": "^18.2.0",
36
+ "replace-in-file": "^6.3.5",
37
+ "rimraf": "^3.0.2",
38
+ "typedoc": "^0.23.23",
39
+ "typedoc-plugin-markdown": "^3.13.6",
40
+ "typescript": "^4.9.5"
41
+ },
42
+ "version": "0.0.1-alpha.13"
43
+ }
@@ -0,0 +1,41 @@
1
+ import { createContext, PropsWithChildren, useContext } from 'react';
2
+ import { Call } from '@stream-io/video-client';
3
+
4
+ const StreamCallContext = createContext<Call | undefined>(undefined);
5
+
6
+ /**
7
+ *
8
+ * We don't expose types in our docs site but we should still add doc comments
9
+ * @internal
10
+ */
11
+ export interface StreamCallProviderProps {
12
+ call?: Call;
13
+ }
14
+
15
+ /**
16
+ *
17
+ * @param props
18
+ * @returns
19
+ *
20
+ * @category Call State
21
+ */
22
+ export const StreamCallProvider = (
23
+ props: PropsWithChildren<StreamCallProviderProps>,
24
+ ) => {
25
+ const { call, children } = props;
26
+ return (
27
+ <StreamCallContext.Provider value={call}>
28
+ {children}
29
+ </StreamCallContext.Provider>
30
+ );
31
+ };
32
+
33
+ /**
34
+ *
35
+ * @returns
36
+ *
37
+ * @category Call State
38
+ */
39
+ export const useCall = () => {
40
+ return useContext(StreamCallContext);
41
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ createContext,
3
+ PropsWithChildren,
4
+ useContext,
5
+ useEffect,
6
+ useState,
7
+ } from 'react';
8
+ import {
9
+ defaultTranslationFunction,
10
+ StreamI18n,
11
+ TranslationsMap,
12
+ } from '@stream-io/i18n';
13
+
14
+ type StreamI18nContextValue = {
15
+ t: StreamI18n['t'];
16
+ i18n?: StreamI18n;
17
+ };
18
+
19
+ const StreamI18nContext = createContext<StreamI18nContextValue>({
20
+ t: defaultTranslationFunction,
21
+ });
22
+
23
+ export type StreamI18nProviderProps = CreateI18nParams;
24
+
25
+ export const StreamI18nProvider = ({
26
+ children,
27
+ ...createI18nParams
28
+ }: PropsWithChildren<StreamI18nProviderProps>) => {
29
+ const { i18n, t } = useCreateI18n(createI18nParams);
30
+
31
+ return (
32
+ <StreamI18nContext.Provider value={{ t, i18n }}>
33
+ {children}
34
+ </StreamI18nContext.Provider>
35
+ );
36
+ };
37
+
38
+ type CreateI18nParams = {
39
+ i18nInstance?: StreamI18n;
40
+ language?: string;
41
+ translationsOverrides?: TranslationsMap;
42
+ };
43
+
44
+ export const useCreateI18n = ({
45
+ i18nInstance,
46
+ language,
47
+ translationsOverrides,
48
+ }: CreateI18nParams) => {
49
+ const [i18n] = useState<StreamI18n>(
50
+ () =>
51
+ i18nInstance ||
52
+ new StreamI18n({ currentLanguage: language, translationsOverrides }),
53
+ );
54
+ const [t, setTranslationFn] = useState<StreamI18n['t']>(
55
+ () => defaultTranslationFunction,
56
+ );
57
+
58
+ useEffect(() => {
59
+ if (i18n.isInitialized && language && i18n?.currentLanguage !== language) {
60
+ i18n.changeLanguage(language);
61
+ } else if (!i18n.isInitialized) {
62
+ if (!language) i18n.changeLanguage();
63
+ i18n.init().then((_i18n) => setTranslationFn(() => _i18n.i18nInstance.t));
64
+ }
65
+ }, [i18n, i18nInstance, language, translationsOverrides]);
66
+
67
+ return { i18n, t };
68
+ };
69
+
70
+ export const useI18n = () => useContext(StreamI18nContext);
@@ -0,0 +1,54 @@
1
+ import { createContext, PropsWithChildren, useContext } from 'react';
2
+ import { StreamVideoClient } from '@stream-io/video-client';
3
+ import {
4
+ StreamI18nProvider,
5
+ StreamI18nProviderProps,
6
+ } from './StreamI18nContext';
7
+
8
+ const StreamVideoContext = createContext<StreamVideoClient | undefined>(
9
+ undefined,
10
+ );
11
+
12
+ /**
13
+ * Exclude types from documentaiton site, but we should still add doc comments
14
+ * @internal
15
+ */
16
+ export type StreamVideoProps = StreamI18nProviderProps & {
17
+ client: StreamVideoClient;
18
+ };
19
+
20
+ /**
21
+ * StreamVideo is a provider component which should be used to wrap the entire application.
22
+ * It provides the client object to all children components and initializes the i18n instance.
23
+ * @param PropsWithChildren<StreamVideoProps>
24
+ * @category Client State
25
+ */
26
+ export const StreamVideo = ({
27
+ children,
28
+ client,
29
+ i18nInstance,
30
+ language,
31
+ translationsOverrides,
32
+ }: PropsWithChildren<StreamVideoProps>) => {
33
+ return (
34
+ <StreamVideoContext.Provider value={client}>
35
+ <StreamI18nProvider
36
+ i18nInstance={i18nInstance}
37
+ language={language}
38
+ translationsOverrides={translationsOverrides}
39
+ >
40
+ {children}
41
+ </StreamI18nProvider>
42
+ </StreamVideoContext.Provider>
43
+ );
44
+ };
45
+
46
+ /**
47
+ *
48
+ * @returns
49
+ *
50
+ * @category Client State
51
+ */
52
+ export const useStreamVideoClient = () => {
53
+ return useContext(StreamVideoContext);
54
+ };
@@ -0,0 +1,3 @@
1
+ export * from './StreamCallContext';
2
+ export * from './StreamI18nContext';
3
+ export * from './StreamVideoContext';