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

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 (64) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +219 -0
  3. package/README.md +3 -0
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/contexts/StreamCallContext.d.ts +27 -0
  8. package/dist/src/contexts/StreamCallContext.js +26 -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 +99 -0
  20. package/dist/src/hooks/call.js +144 -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 +44 -0
  32. package/dist/src/hooks/participants.js +62 -0
  33. package/dist/src/hooks/participants.js.map +1 -0
  34. package/dist/src/hooks/permissions.d.ts +21 -0
  35. package/dist/src/hooks/permissions.js +32 -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 +30 -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/dist/src/wrappers/Restricted.d.ts +19 -0
  44. package/dist/src/wrappers/Restricted.js +14 -0
  45. package/dist/src/wrappers/Restricted.js.map +1 -0
  46. package/dist/src/wrappers/index.d.ts +1 -0
  47. package/dist/src/wrappers/index.js +2 -0
  48. package/dist/src/wrappers/index.js.map +1 -0
  49. package/index.ts +3 -0
  50. package/package.json +43 -0
  51. package/src/contexts/StreamCallContext.tsx +43 -0
  52. package/src/contexts/StreamI18nContext.tsx +70 -0
  53. package/src/contexts/StreamVideoContext.tsx +54 -0
  54. package/src/contexts/index.ts +3 -0
  55. package/src/hooks/call.ts +157 -0
  56. package/src/hooks/client.ts +77 -0
  57. package/src/hooks/helpers/useObservableValue.ts +21 -0
  58. package/src/hooks/index.ts +6 -0
  59. package/src/hooks/participants.ts +79 -0
  60. package/src/hooks/permissions.ts +37 -0
  61. package/src/hooks/store.ts +34 -0
  62. package/src/hooks/user.ts +13 -0
  63. package/src/wrappers/Restricted.tsx +40 -0
  64. package/src/wrappers/index.ts +1 -0
@@ -0,0 +1,144 @@
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 metadata = useCallMetadata();
10
+ return !!(metadata === null || metadata === void 0 ? void 0 : metadata.recording);
11
+ };
12
+ /**
13
+ * Utility hook which provides information whether the current call is broadcasting.
14
+ *
15
+ * @category Call State
16
+ */
17
+ export const useIsCallBroadcastingInProgress = () => {
18
+ const metadata = useCallMetadata();
19
+ return !!(metadata === null || metadata === void 0 ? void 0 : metadata.broadcasting);
20
+ };
21
+ /**
22
+ * Utility hook which provides information whether the current call is live.
23
+ *
24
+ * @category Call State
25
+ */
26
+ export const useIsCallLive = () => {
27
+ const metadata = useCallMetadata();
28
+ return !(metadata === null || metadata === void 0 ? void 0 : metadata.backstage);
29
+ };
30
+ /**
31
+ * Utility hook which provides a boolean indicating whether there is
32
+ * a participant in the current call which shares their screen.
33
+ *
34
+ * @category Call State
35
+ */
36
+ export const useHasOngoingScreenShare = () => {
37
+ const { hasOngoingScreenShare$ } = useCallState();
38
+ return useObservableValue(hasOngoingScreenShare$);
39
+ };
40
+ /**
41
+ * Utility hook which provides the latest stats report of the current call.
42
+ *
43
+ * The latest stats report of the current call.
44
+ * When stats gathering is enabled, this observable will emit a new value
45
+ * at a regular (configurable) interval.
46
+ *
47
+ * Consumers of this observable can implement their own batching logic
48
+ * in case they want to show historical stats data.
49
+ *
50
+ * @category Call State
51
+ */
52
+ export const useCallStatsReport = () => {
53
+ const { callStatsReport$ } = useCallState();
54
+ return useObservableValue(callStatsReport$);
55
+ };
56
+ /**
57
+ * Utility hook which provides the dominant speaker of the current call.
58
+ *
59
+ * @category Call State
60
+ */
61
+ export const useDominantSpeaker = () => {
62
+ const { dominantSpeaker$ } = useCallState();
63
+ return useObservableValue(dominantSpeaker$);
64
+ };
65
+ /**
66
+ * Utility hook which provides a list of all notifications about created calls.
67
+ * In the ring call settings, these calls can be outgoing (I have called somebody)
68
+ * or incoming (somebody has called me).
69
+ *
70
+ * @category Client State
71
+ */
72
+ export const useCalls = () => {
73
+ const { calls$ } = useStore();
74
+ return useObservableValue(calls$);
75
+ };
76
+ /**
77
+ * Utility hook which provides a list of all incoming ring calls (somebody calls me).
78
+ *
79
+ * @deprecated derive from useCalls()/useCall() instead.
80
+ * @internal
81
+ * @category Client State
82
+ */
83
+ export const useIncomingCalls = () => {
84
+ const { incomingCalls$ } = useStore();
85
+ return useObservableValue(incomingCalls$);
86
+ };
87
+ /**
88
+ * Utility hook which provides a list of all outgoing ring calls (I call somebody).
89
+ *
90
+ * @deprecated derive from useCalls()/useCall() instead.
91
+ * @internal
92
+ * @category Client State
93
+ */
94
+ export const useOutgoingCalls = () => {
95
+ const { outgoingCalls$ } = useStore();
96
+ return useObservableValue(outgoingCalls$);
97
+ };
98
+ /**
99
+ * Utility hook which provides call metadata (such as blocked users and own capabilities).
100
+ *
101
+ * @category Call State
102
+ */
103
+ export const useCallMetadata = () => {
104
+ const { metadata$ } = useCallState();
105
+ return useObservableValue(metadata$);
106
+ };
107
+ /**
108
+ * Utility hook which provides a list of call members.
109
+ *
110
+ * @category Call State
111
+ */
112
+ export const useCallMembers = () => {
113
+ const { members$ } = useCallState();
114
+ return useObservableValue(members$);
115
+ };
116
+ /**
117
+ * Utility hook providing the latest list of recordings performed during the active call
118
+ *
119
+ * @category Call State
120
+ */
121
+ export const useCallRecordings = () => {
122
+ const { callRecordingList$ } = useCallState();
123
+ return useObservableValue(callRecordingList$);
124
+ };
125
+ /**
126
+ * Utility hook providing the current calling state of the call.
127
+ *
128
+ * @category Call State
129
+ */
130
+ export const useCallCallingState = () => {
131
+ const { callingState$ } = useCallState();
132
+ return useObservableValue(callingState$);
133
+ };
134
+ /**
135
+ * Utility hook providing the actual start time of the call.
136
+ * Useful for calculating the call duration.
137
+ *
138
+ * @category Call State
139
+ */
140
+ export const useCallStartedAt = () => {
141
+ const { startedAt$ } = useCallState();
142
+ return useObservableValue(startedAt$);
143
+ };
144
+ //# 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,QAAQ,GAAG,eAAe,EAA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G,EAAE;IACnC,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,EAAE,CAAC;IACtC,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;AACxC,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,44 @@
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[];
31
+ /**
32
+ * Returns the approximate participant count of the active call.
33
+ * This includes the anonymous users as well, and it is computed on the server.
34
+ *
35
+ * @category Call State
36
+ */
37
+ export declare const useParticipantCount: () => number;
38
+ /**
39
+ * Returns the approximate anonymous participant count of the active call.
40
+ * The regular participants are not included in this count. It is computed on the server.
41
+ *
42
+ * @category Call State
43
+ */
44
+ export declare const useAnonymousParticipantCount: () => number;
@@ -0,0 +1,62 @@
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
+ /**
43
+ * Returns the approximate participant count of the active call.
44
+ * This includes the anonymous users as well, and it is computed on the server.
45
+ *
46
+ * @category Call State
47
+ */
48
+ export const useParticipantCount = () => {
49
+ const { participantCount$ } = useCallState();
50
+ return useObservableValue(participantCount$);
51
+ };
52
+ /**
53
+ * Returns the approximate anonymous participant count of the active call.
54
+ * The regular participants are not included in this count. It is computed on the server.
55
+ *
56
+ * @category Call State
57
+ */
58
+ export const useAnonymousParticipantCount = () => {
59
+ const { anonymousParticipantCount$ } = useCallState();
60
+ return useObservableValue(anonymousParticipantCount$);
61
+ };
62
+ //# 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;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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,MAAM,EAAE,0BAA0B,EAAE,GAAG,YAAY,EAAE,CAAC;IACtD,OAAO,kBAAkB,CAAC,0BAA0B,CAAC,CAAC;AACxD,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { OwnCapability, PermissionRequestEvent } 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[];
16
+ /**
17
+ * A hook which returns the latest call permission request.
18
+ *
19
+ * @category Call State
20
+ */
21
+ export declare const useCallPermissionRequest: () => PermissionRequestEvent | undefined;
@@ -0,0 +1,32 @@
1
+ import { useCallState } from './store';
2
+ import { useObservableValue } from './helpers/useObservableValue';
3
+ /**
4
+ * Hook that returns true if the current user has all the given permissions.
5
+ *
6
+ * @param permissions the permissions to check.
7
+ *
8
+ * @category Call State
9
+ */
10
+ export const useHasPermissions = (...permissions) => {
11
+ const capabilities = useOwnCapabilities();
12
+ return permissions.every((permission) => capabilities.includes(permission));
13
+ };
14
+ /**
15
+ * A hook which returns the current user's own capabilities.
16
+ *
17
+ * @category Call State
18
+ */
19
+ export const useOwnCapabilities = () => {
20
+ const { ownCapabilities$ } = useCallState();
21
+ return useObservableValue(ownCapabilities$);
22
+ };
23
+ /**
24
+ * A hook which returns the latest call permission request.
25
+ *
26
+ * @category Call State
27
+ */
28
+ export const useCallPermissionRequest = () => {
29
+ const { callPermissionRequest$ } = useCallState();
30
+ return useObservableValue(callPermissionRequest$);
31
+ };
32
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../src/hooks/permissions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,WAA4B,EAAW,EAAE;IAC5E,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAoB,EAAE;IACtD,MAAM,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC5C,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAE1B,EAAE;IACd,MAAM,EAAE,sBAAsB,EAAE,GAAG,YAAY,EAAE,CAAC;IAClD,OAAO,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;AACpD,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,30 @@
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
+ const message = 'You are using useCallState() outside a Call context. ' +
24
+ 'Please wrap your component in <StreamCallProvider /> and provide a non-null "call" instance.';
25
+ console.warn(message);
26
+ return new CallState();
27
+ }
28
+ return call.state;
29
+ };
30
+ //# 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,MAAM,OAAO,GACX,uDAAuD;YACvD,8FAA8F,CAAC;QACjG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,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"}
@@ -0,0 +1,19 @@
1
+ import { OwnCapability } from '@stream-io/video-client';
2
+ import { PropsWithChildren } from 'react';
3
+ type RestrictedProps = PropsWithChildren<{
4
+ /**
5
+ * OwnCapabilities of the participant - grants they have available
6
+ */
7
+ availableGrants?: OwnCapability[];
8
+ /**
9
+ * Required grants for the component to be able to render supplied children elements
10
+ */
11
+ requiredGrants: OwnCapability[];
12
+ /**
13
+ * Require all grants specified in `requiredGrants` to be available in the `availableGrants`,
14
+ * component by default requires only one grant to appear in both arrays to render its children
15
+ */
16
+ requireAll?: boolean;
17
+ }>;
18
+ export declare const Restricted: ({ availableGrants: availableGrantsFromProps, requiredGrants, requireAll, children, }: RestrictedProps) => JSX.Element | null;
19
+ export {};
@@ -0,0 +1,14 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCall } from '../contexts';
3
+ import { useOwnCapabilities } from '../hooks';
4
+ export const Restricted = ({ availableGrants: availableGrantsFromProps, requiredGrants, requireAll = true, children, }) => {
5
+ const call = useCall();
6
+ const ownCapabilities = useOwnCapabilities();
7
+ const availableGrants = availableGrantsFromProps !== null && availableGrantsFromProps !== void 0 ? availableGrantsFromProps : ownCapabilities;
8
+ const hasPermissions = requiredGrants[requireAll ? 'every' : 'some']((capability) => availableGrants.includes(capability));
9
+ const canRequest = requiredGrants.some((capability) => !!call && call.permissionsContext.canRequest(capability));
10
+ if (hasPermissions || canRequest)
11
+ return _jsx(_Fragment, { children: children });
12
+ return null;
13
+ };
14
+ //# sourceMappingURL=Restricted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Restricted.js","sourceRoot":"","sources":["../../../src/wrappers/Restricted.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAkB9C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,eAAe,EAAE,wBAAwB,EACzC,cAAc,EACd,UAAU,GAAG,IAAI,EACjB,QAAQ,GACQ,EAAE,EAAE;IACpB,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;IAC7C,MAAM,eAAe,GAAG,wBAAwB,aAAxB,wBAAwB,cAAxB,wBAAwB,GAAI,eAAe,CAAC;IACpE,MAAM,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAClE,CAAC,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,CACrD,CAAC;IACF,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CACpC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CACzE,CAAC;IACF,IAAI,cAAc,IAAI,UAAU;QAAE,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACzD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './Restricted';
@@ -0,0 +1,2 @@
1
+ export * from './Restricted';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wrappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './src/contexts';
2
+ export * from './src/hooks';
3
+ export * from './src/wrappers';
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.8.1"
24
+ },
25
+ "peerDependencies": {
26
+ "@stream-io/i18n": "^0.0.1-alpha.89",
27
+ "@stream-io/video-client": "^0.0.2-alpha.18",
28
+ "react": ">=17.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@stream-io/i18n": "^0.0.1-alpha.89",
32
+ "@stream-io/video-client": "^0.0.2-alpha.18",
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.24.7",
39
+ "typedoc-plugin-markdown": "^3.15.3",
40
+ "typescript": "^4.9.5"
41
+ },
42
+ "version": "0.0.1-alpha.100"
43
+ }