@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.
- package/CHANGELOG.md +93 -0
- package/LICENSE +219 -0
- package/README.md +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/src/contexts/StreamCallContext.d.ts +25 -0
- package/dist/src/contexts/StreamCallContext.js +24 -0
- package/dist/src/contexts/StreamCallContext.js.map +1 -0
- package/dist/src/contexts/StreamI18nContext.d.ts +19 -0
- package/dist/src/contexts/StreamI18nContext.js +40 -0
- package/dist/src/contexts/StreamI18nContext.js.map +1 -0
- package/dist/src/contexts/StreamVideoContext.d.ts +24 -0
- package/dist/src/contexts/StreamVideoContext.js +23 -0
- package/dist/src/contexts/StreamVideoContext.js.map +1 -0
- package/dist/src/contexts/index.d.ts +3 -0
- package/dist/src/contexts/index.js +4 -0
- package/dist/src/contexts/index.js.map +1 -0
- package/dist/src/hooks/call.d.ts +80 -0
- package/dist/src/hooks/call.js +116 -0
- package/dist/src/hooks/call.js.map +1 -0
- package/dist/src/hooks/client.d.ts +33 -0
- package/dist/src/hooks/client.js +36 -0
- package/dist/src/hooks/client.js.map +1 -0
- package/dist/src/hooks/helpers/useObservableValue.d.ts +6 -0
- package/dist/src/hooks/helpers/useObservableValue.js +17 -0
- package/dist/src/hooks/helpers/useObservableValue.js.map +1 -0
- package/dist/src/hooks/index.d.ts +6 -0
- package/dist/src/hooks/index.js +7 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/participants.d.ts +30 -0
- package/dist/src/hooks/participants.js +42 -0
- package/dist/src/hooks/participants.js.map +1 -0
- package/dist/src/hooks/permissions.d.ts +15 -0
- package/dist/src/hooks/permissions.js +24 -0
- package/dist/src/hooks/permissions.js.map +1 -0
- package/dist/src/hooks/store.d.ts +11 -0
- package/dist/src/hooks/store.js +28 -0
- package/dist/src/hooks/store.js.map +1 -0
- package/dist/src/hooks/user.d.ts +7 -0
- package/dist/src/hooks/user.js +13 -0
- package/dist/src/hooks/user.js.map +1 -0
- package/index.ts +2 -0
- package/package.json +43 -0
- package/src/contexts/StreamCallContext.tsx +41 -0
- package/src/contexts/StreamI18nContext.tsx +70 -0
- package/src/contexts/StreamVideoContext.tsx +54 -0
- package/src/contexts/index.ts +3 -0
- package/src/hooks/call.ts +126 -0
- package/src/hooks/client.ts +77 -0
- package/src/hooks/helpers/useObservableValue.ts +21 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/participants.ts +57 -0
- package/src/hooks/permissions.ts +27 -0
- package/src/hooks/store.ts +33 -0
- package/src/hooks/user.ts +13 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useObservableValue } from './helpers/useObservableValue';
|
|
2
|
+
import { useCallState, useStore } from './store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility hook which provides information whether the current call is being recorded.
|
|
6
|
+
*
|
|
7
|
+
* @category Call State
|
|
8
|
+
*/
|
|
9
|
+
export const useIsCallRecordingInProgress = () => {
|
|
10
|
+
const { callRecordingInProgress$ } = useCallState();
|
|
11
|
+
return useObservableValue(callRecordingInProgress$);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Utility hook which provides a boolean indicating whether there is
|
|
16
|
+
* a participant in the current call which shares their screen.
|
|
17
|
+
*
|
|
18
|
+
* @category Call State
|
|
19
|
+
*/
|
|
20
|
+
export const useHasOngoingScreenShare = () => {
|
|
21
|
+
const { hasOngoingScreenShare$ } = useCallState();
|
|
22
|
+
return useObservableValue(hasOngoingScreenShare$);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Utility hook which provides the latest stats report of the current call.
|
|
27
|
+
*
|
|
28
|
+
* The latest stats report of the current call.
|
|
29
|
+
* When stats gathering is enabled, this observable will emit a new value
|
|
30
|
+
* at a regular (configurable) interval.
|
|
31
|
+
*
|
|
32
|
+
* Consumers of this observable can implement their own batching logic
|
|
33
|
+
* in case they want to show historical stats data.
|
|
34
|
+
*
|
|
35
|
+
* @category Call State
|
|
36
|
+
*/
|
|
37
|
+
export const useCurrentCallStatsReport = () => {
|
|
38
|
+
const { callStatsReport$ } = useCallState();
|
|
39
|
+
return useObservableValue(callStatsReport$);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Utility hook which provides the dominant speaker of the current call.
|
|
44
|
+
*
|
|
45
|
+
* @category Call State
|
|
46
|
+
*/
|
|
47
|
+
export const useDominantSpeaker = () => {
|
|
48
|
+
const { dominantSpeaker$ } = useCallState();
|
|
49
|
+
return useObservableValue(dominantSpeaker$);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Utility hook which provides a list of all notifications about created calls.
|
|
54
|
+
* In the ring call settings, these calls can be outgoing (I have called somebody)
|
|
55
|
+
* or incoming (somebody has called me).
|
|
56
|
+
*
|
|
57
|
+
* @category Client State
|
|
58
|
+
*/
|
|
59
|
+
export const useCalls = () => {
|
|
60
|
+
const { calls$ } = useStore();
|
|
61
|
+
return useObservableValue(calls$);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Utility hook which provides a list of all incoming ring calls (somebody calls me).
|
|
66
|
+
*
|
|
67
|
+
* @deprecated derive from useCalls()/useCall() instead.
|
|
68
|
+
* @internal
|
|
69
|
+
* @category Client State
|
|
70
|
+
*/
|
|
71
|
+
export const useIncomingCalls = () => {
|
|
72
|
+
const { incomingCalls$ } = useStore();
|
|
73
|
+
return useObservableValue(incomingCalls$);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Utility hook which provides a list of all outgoing ring calls (I call somebody).
|
|
78
|
+
*
|
|
79
|
+
* @deprecated derive from useCalls()/useCall() instead.
|
|
80
|
+
* @internal
|
|
81
|
+
* @category Client State
|
|
82
|
+
*/
|
|
83
|
+
export const useOutgoingCalls = () => {
|
|
84
|
+
const { outgoingCalls$ } = useStore();
|
|
85
|
+
return useObservableValue(outgoingCalls$);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Utility hook which provides call metadata (such as blocked users and own capabilities).
|
|
90
|
+
*
|
|
91
|
+
* @category Call State
|
|
92
|
+
*/
|
|
93
|
+
export const useCallMetadata = () => {
|
|
94
|
+
const { metadata$ } = useCallState();
|
|
95
|
+
return useObservableValue(metadata$);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Utility hook which provides a list of call members.
|
|
100
|
+
*
|
|
101
|
+
* @category Call State
|
|
102
|
+
*/
|
|
103
|
+
export const useCallMembers = () => {
|
|
104
|
+
const { members$ } = useCallState();
|
|
105
|
+
return useObservableValue(members$);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Utility hook providing the latest list of recordings performed during the active call
|
|
110
|
+
*
|
|
111
|
+
* @category Call State
|
|
112
|
+
*/
|
|
113
|
+
export const useCallRecordings = () => {
|
|
114
|
+
const { callRecordingList$ } = useCallState();
|
|
115
|
+
return useObservableValue(callRecordingList$);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Utility hook providing the current calling state of the call.
|
|
120
|
+
*
|
|
121
|
+
* @category Call State
|
|
122
|
+
*/
|
|
123
|
+
export const useCallCallingState = () => {
|
|
124
|
+
const { callingState$ } = useCallState();
|
|
125
|
+
return useObservableValue(callingState$);
|
|
126
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StreamClientOptions,
|
|
3
|
+
StreamVideoClient,
|
|
4
|
+
TokenOrProvider,
|
|
5
|
+
User,
|
|
6
|
+
} from '@stream-io/video-client';
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Exclude types from documentation site, but we should still add doc comments
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export type StreamVideoClientInit = {
|
|
14
|
+
/**
|
|
15
|
+
* The Stream API key.
|
|
16
|
+
*/
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/**
|
|
19
|
+
* The token or token provider.
|
|
20
|
+
*/
|
|
21
|
+
tokenOrProvider: TokenOrProvider;
|
|
22
|
+
/**
|
|
23
|
+
* The client options.
|
|
24
|
+
*/
|
|
25
|
+
options?: StreamClientOptions;
|
|
26
|
+
/**
|
|
27
|
+
* The user to connect.
|
|
28
|
+
*/
|
|
29
|
+
user: User;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the user is anonymous. Defaults to `false`.
|
|
32
|
+
*/
|
|
33
|
+
isAnonymous?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new `StreamVideoClient` instance and connects the given user.
|
|
38
|
+
*
|
|
39
|
+
* @category Client State
|
|
40
|
+
*/
|
|
41
|
+
export const useCreateStreamVideoClient = ({
|
|
42
|
+
apiKey,
|
|
43
|
+
tokenOrProvider,
|
|
44
|
+
user,
|
|
45
|
+
options,
|
|
46
|
+
isAnonymous = false,
|
|
47
|
+
}: StreamVideoClientInit) => {
|
|
48
|
+
const [client] = useState(() => new StreamVideoClient(apiKey, options));
|
|
49
|
+
|
|
50
|
+
const disconnectRef = useRef(Promise.resolve());
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const connectionPromise = disconnectRef.current.then(() => {
|
|
53
|
+
if (isAnonymous) {
|
|
54
|
+
return client
|
|
55
|
+
.connectAnonymousUser(user, tokenOrProvider)
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
console.error(`Failed to establish connection`, err);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return client.connectUser(user, tokenOrProvider).catch((err) => {
|
|
61
|
+
console.error(`Failed to establish connection`, err);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return () => {
|
|
66
|
+
disconnectRef.current = connectionPromise
|
|
67
|
+
.then(() => client.disconnectUser())
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error(`Failed to disconnect`, err);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
// we want to re-run this effect only in some special cases
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
|
+
}, [apiKey, tokenOrProvider, client, isAnonymous, user?.id]);
|
|
75
|
+
|
|
76
|
+
return client;
|
|
77
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { RxUtils } from '@stream-io/video-client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const useObservableValue = <T>(observable$: Observable<T>) => {
|
|
10
|
+
const [value, setValue] = useState<T>(() =>
|
|
11
|
+
RxUtils.getCurrentValue(observable$),
|
|
12
|
+
);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const subscription = observable$.subscribe(setValue);
|
|
15
|
+
return () => {
|
|
16
|
+
subscription.unsubscribe();
|
|
17
|
+
};
|
|
18
|
+
}, [observable$]);
|
|
19
|
+
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useObservableValue } from './helpers/useObservableValue';
|
|
2
|
+
import { useCallState } from './store';
|
|
3
|
+
import type {
|
|
4
|
+
Comparator,
|
|
5
|
+
StreamVideoParticipant,
|
|
6
|
+
} from '@stream-io/video-client';
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A hook which provides a list of all participants that have joined an active call.
|
|
11
|
+
*
|
|
12
|
+
* @category Call State
|
|
13
|
+
*
|
|
14
|
+
* @param options.sortBy - A comparator function to sort the participants by.
|
|
15
|
+
* Make sure to memoize output of the `combineComparators` function
|
|
16
|
+
* (or keep it out of component's scope if possible) before passing it down to this property.
|
|
17
|
+
*/
|
|
18
|
+
export const useParticipants = ({
|
|
19
|
+
sortBy,
|
|
20
|
+
}: {
|
|
21
|
+
/**
|
|
22
|
+
* Make sure to memoize output of the `combineComparators` function
|
|
23
|
+
* (or keep it out of component's scope if possible) before passing it down to this property.
|
|
24
|
+
*/
|
|
25
|
+
sortBy?: Comparator<StreamVideoParticipant>;
|
|
26
|
+
} = {}) => {
|
|
27
|
+
const { participants$ } = useCallState();
|
|
28
|
+
const participants = useObservableValue(participants$);
|
|
29
|
+
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
if (sortBy) {
|
|
32
|
+
return [...participants].sort(sortBy);
|
|
33
|
+
}
|
|
34
|
+
return participants;
|
|
35
|
+
}, [participants, sortBy]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A hook which provides a StreamVideoLocalParticipant object.
|
|
40
|
+
* It signals that I have joined a call.
|
|
41
|
+
*
|
|
42
|
+
* @category Call State
|
|
43
|
+
*/
|
|
44
|
+
export const useLocalParticipant = () => {
|
|
45
|
+
const { localParticipant$ } = useCallState();
|
|
46
|
+
return useObservableValue(localParticipant$);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A hook which provides a list of all other participants than me that have joined an active call.
|
|
51
|
+
*
|
|
52
|
+
* @category Call State
|
|
53
|
+
*/
|
|
54
|
+
export const useRemoteParticipants = () => {
|
|
55
|
+
const { remoteParticipants$ } = useCallState();
|
|
56
|
+
return useObservableValue(remoteParticipants$);
|
|
57
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OwnCapability } from '@stream-io/video-client';
|
|
2
|
+
import { useCallMetadata } from './call';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook that returns true if the current user has all the given permissions.
|
|
6
|
+
*
|
|
7
|
+
* @param permissions the permissions to check.
|
|
8
|
+
*
|
|
9
|
+
* @category Call State
|
|
10
|
+
*/
|
|
11
|
+
export const useHasPermissions = (...permissions: OwnCapability[]) => {
|
|
12
|
+
const metadata = useCallMetadata();
|
|
13
|
+
if (!metadata) return false;
|
|
14
|
+
return permissions.every((permission) =>
|
|
15
|
+
metadata.own_capabilities.includes(permission),
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A hook which returns the current user's own capabilities.
|
|
21
|
+
*
|
|
22
|
+
* @category Call State
|
|
23
|
+
*/
|
|
24
|
+
export const useOwnCapabilities = () => {
|
|
25
|
+
const metadata = useCallMetadata();
|
|
26
|
+
return metadata?.own_capabilities || [];
|
|
27
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CallState } from '@stream-io/video-client';
|
|
2
|
+
import { useCall, useStreamVideoClient } from '../contexts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility hook which provides access to client's state store.
|
|
6
|
+
*/
|
|
7
|
+
export const useStore = () => {
|
|
8
|
+
const client = useStreamVideoClient();
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`StreamVideoClient isn't initialized or this hook is called outside of <StreamVideo> context.`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return client.readOnlyStateStore;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Utility hook which provides the current call's state.
|
|
19
|
+
*
|
|
20
|
+
* @category Call State
|
|
21
|
+
*/
|
|
22
|
+
export const useCallState = () => {
|
|
23
|
+
const call = useCall();
|
|
24
|
+
// return an empty and unlinked CallState object if there is no call in the provider
|
|
25
|
+
// this ensures that the hooks always return a value and many null checks can be avoided
|
|
26
|
+
if (!call) {
|
|
27
|
+
console.warn(
|
|
28
|
+
`You are using useCallState() outside a Call context. Please wrap your component in <StreamCallProvider />`,
|
|
29
|
+
);
|
|
30
|
+
return new CallState();
|
|
31
|
+
}
|
|
32
|
+
return call.state;
|
|
33
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
import { useObservableValue } from './helpers/useObservableValue';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @returns
|
|
7
|
+
*
|
|
8
|
+
* @category Client State
|
|
9
|
+
*/
|
|
10
|
+
export const useConnectedUser = () => {
|
|
11
|
+
const { connectedUser$ } = useStore();
|
|
12
|
+
return useObservableValue(connectedUser$);
|
|
13
|
+
};
|