@100mslive/react-sdk 0.11.3-alpha.2 → 0.11.3-alpha.4
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/dist/hooks/types.d.ts +1 -1
- package/dist/hooks/useDevices.d.ts +1 -1
- package/dist/hooks/usePaginatedParticipants.d.ts +1 -1
- package/dist/hooks/useParticipants.d.ts +1 -1
- package/dist/index.cjs.js +2 -1
- package/dist/index.cjs.js.map +7 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +7 -1
- package/dist/primitives/HmsRoomProvider.d.ts +2 -2
- package/dist/primitives/store.d.ts +3 -1
- package/dist/utils/layout.d.ts +2 -2
- package/package.json +8 -15
- package/dist/hooks/useAVToggle.js +0 -2
- package/dist/hooks/useAVToggle.js.map +0 -1
- package/dist/hooks/useAudioLevelStyles.js +0 -2
- package/dist/hooks/useAudioLevelStyles.js.map +0 -1
- package/dist/hooks/useAudioMode.js +0 -2
- package/dist/hooks/useAudioMode.js.map +0 -1
- package/dist/hooks/useAutoplayError.js +0 -2
- package/dist/hooks/useAutoplayError.js.map +0 -1
- package/dist/hooks/useAwayNotifications.js +0 -2
- package/dist/hooks/useAwayNotifications.js.map +0 -1
- package/dist/hooks/useCustomEvent.js +0 -2
- package/dist/hooks/useCustomEvent.js.map +0 -1
- package/dist/hooks/useDevices.js +0 -2
- package/dist/hooks/useDevices.js.map +0 -1
- package/dist/hooks/useEmbedShare.js +0 -2
- package/dist/hooks/useEmbedShare.js.map +0 -1
- package/dist/hooks/usePDFShare.js +0 -2
- package/dist/hooks/usePDFShare.js.map +0 -1
- package/dist/hooks/usePaginatedParticipants.js +0 -2
- package/dist/hooks/usePaginatedParticipants.js.map +0 -1
- package/dist/hooks/useParticipantList.js +0 -2
- package/dist/hooks/useParticipantList.js.map +0 -1
- package/dist/hooks/useParticipants.js +0 -2
- package/dist/hooks/useParticipants.js.map +0 -1
- package/dist/hooks/usePreviewJoin.js +0 -2
- package/dist/hooks/usePreviewJoin.js.map +0 -1
- package/dist/hooks/useRecordingStreaming.js +0 -2
- package/dist/hooks/useRecordingStreaming.js.map +0 -1
- package/dist/hooks/useRemoteAVToggle.js +0 -2
- package/dist/hooks/useRemoteAVToggle.js.map +0 -1
- package/dist/hooks/useScreenShare.js +0 -2
- package/dist/hooks/useScreenShare.js.map +0 -1
- package/dist/hooks/useTranscript.js +0 -2
- package/dist/hooks/useTranscript.js.map +0 -1
- package/dist/hooks/useVideo.js +0 -2
- package/dist/hooks/useVideo.js.map +0 -1
- package/dist/hooks/useVideoList.js +0 -2
- package/dist/hooks/useVideoList.js.map +0 -1
- package/dist/hooks/useWhiteboard.js +0 -2
- package/dist/hooks/useWhiteboard.js.map +0 -1
- package/dist/node_modules/tslib/tslib.es6.mjs.js +0 -2
- package/dist/node_modules/tslib/tslib.es6.mjs.js.map +0 -1
- package/dist/packages/react-sdk/node_modules/zustand/esm/shallow.js +0 -2
- package/dist/packages/react-sdk/node_modules/zustand/esm/shallow.js.map +0 -1
- package/dist/primitives/HmsRoomProvider.js +0 -2
- package/dist/primitives/HmsRoomProvider.js.map +0 -1
- package/dist/primitives/store.js +0 -2
- package/dist/primitives/store.js.map +0 -1
- package/dist/utils/commons.js +0 -2
- package/dist/utils/commons.js.map +0 -1
- package/dist/utils/groupBy.js +0 -2
- package/dist/utils/groupBy.js.map +0 -1
- package/dist/utils/isBrowser.js +0 -2
- package/dist/utils/isBrowser.js.map +0 -1
- package/dist/utils/layout.js +0 -2
- package/dist/utils/layout.js.map +0 -1
- package/dist/utils/logger.js +0 -2
- package/dist/utils/logger.js.map +0 -1
- package/src/hooks/types.ts +0 -6
- package/src/hooks/useAVToggle.ts +0 -66
- package/src/hooks/useAudioLevelStyles.ts +0 -37
- package/src/hooks/useAudioMode.tsx +0 -11
- package/src/hooks/useAutoplayError.ts +0 -41
- package/src/hooks/useAwayNotifications.ts +0 -55
- package/src/hooks/useCustomEvent.ts +0 -121
- package/src/hooks/useDevices.ts +0 -96
- package/src/hooks/useEmbedShare.ts +0 -97
- package/src/hooks/usePDFShare.ts +0 -117
- package/src/hooks/usePaginatedParticipants.ts +0 -56
- package/src/hooks/useParticipantList.ts +0 -27
- package/src/hooks/useParticipants.ts +0 -72
- package/src/hooks/usePreviewJoin.ts +0 -166
- package/src/hooks/useRecordingStreaming.ts +0 -34
- package/src/hooks/useRemoteAVToggle.ts +0 -102
- package/src/hooks/useScreenShare.ts +0 -77
- package/src/hooks/useTranscript.ts +0 -50
- package/src/hooks/useVideo.ts +0 -87
- package/src/hooks/useVideoList.ts +0 -162
- package/src/hooks/useWhiteboard.ts +0 -50
- package/src/index.ts +0 -56
- package/src/primitives/HmsRoomProvider.ts +0 -221
- package/src/primitives/store.ts +0 -59
- package/src/primitives/types.ts +0 -6
- package/src/utils/commons.ts +0 -34
- package/src/utils/groupBy.ts +0 -29
- package/src/utils/isBrowser.ts +0 -1
- package/src/utils/layout.ts +0 -473
- package/src/utils/logger.ts +0 -62
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
selectAppData,
|
|
4
|
-
selectIsConnectedToRoom,
|
|
5
|
-
selectLocalPeer,
|
|
6
|
-
selectPermissions,
|
|
7
|
-
selectWhiteboard,
|
|
8
|
-
} from '@100mslive/hms-video-store';
|
|
9
|
-
import { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';
|
|
10
|
-
|
|
11
|
-
export const useWhiteboard = (isMobile = false) => {
|
|
12
|
-
const isConnected = useHMSStore(selectIsConnectedToRoom);
|
|
13
|
-
const localPeerUserId = useHMSStore(selectLocalPeer)?.customerUserId;
|
|
14
|
-
const whiteboard = useHMSStore(selectWhiteboard);
|
|
15
|
-
const isHeadless = useHMSStore(selectAppData('disableNotifications'));
|
|
16
|
-
const open = !!whiteboard?.open;
|
|
17
|
-
const isOwner = whiteboard?.owner === localPeerUserId;
|
|
18
|
-
const actions = useHMSActions();
|
|
19
|
-
const [isEnabled, setIsEnabled] = useState(false);
|
|
20
|
-
const permissions = useHMSStore(selectPermissions)?.whiteboard;
|
|
21
|
-
const isAdmin = !!permissions?.includes('admin');
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (isConnected) {
|
|
25
|
-
setIsEnabled(actions.interactivityCenter.whiteboard.isEnabled);
|
|
26
|
-
}
|
|
27
|
-
}, [isConnected, actions]);
|
|
28
|
-
|
|
29
|
-
const toggle = useCallback(async () => {
|
|
30
|
-
if (!isConnected || !isAdmin) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (open) {
|
|
35
|
-
isOwner && (await actions.interactivityCenter.whiteboard.close());
|
|
36
|
-
} else {
|
|
37
|
-
await actions.interactivityCenter.whiteboard.open();
|
|
38
|
-
}
|
|
39
|
-
}, [actions, isOwner, isAdmin, open, isConnected]);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
open,
|
|
43
|
-
token: whiteboard?.token,
|
|
44
|
-
endpoint: whiteboard?.addr,
|
|
45
|
-
isOwner,
|
|
46
|
-
isAdmin,
|
|
47
|
-
zoomToContent: isHeadless || isMobile,
|
|
48
|
-
toggle: isEnabled && isAdmin ? toggle : undefined,
|
|
49
|
-
};
|
|
50
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
HMSRoomProvider,
|
|
3
|
-
useHMSStore,
|
|
4
|
-
useHMSActions,
|
|
5
|
-
useHMSNotifications,
|
|
6
|
-
useHMSVanillaStore,
|
|
7
|
-
useHMSVanillaNotifications,
|
|
8
|
-
useHMSStatsStore,
|
|
9
|
-
} from './primitives/HmsRoomProvider';
|
|
10
|
-
export { usePreviewJoin } from './hooks/usePreviewJoin';
|
|
11
|
-
export { useAVToggle } from './hooks/useAVToggle';
|
|
12
|
-
export { useVideo } from './hooks/useVideo';
|
|
13
|
-
export { useScreenShare } from './hooks/useScreenShare';
|
|
14
|
-
export { useRemoteAVToggle } from './hooks/useRemoteAVToggle';
|
|
15
|
-
export { useVideoList } from './hooks/useVideoList';
|
|
16
|
-
export { useAudioLevelStyles } from './hooks/useAudioLevelStyles';
|
|
17
|
-
export { useDevices } from './hooks/useDevices';
|
|
18
|
-
export { useParticipantList } from './hooks/useParticipantList';
|
|
19
|
-
export { useRecordingStreaming } from './hooks/useRecordingStreaming';
|
|
20
|
-
export { useAutoplayError } from './hooks/useAutoplayError';
|
|
21
|
-
export { useCustomEvent } from './hooks/useCustomEvent';
|
|
22
|
-
export { useParticipants } from './hooks/useParticipants';
|
|
23
|
-
export { useEmbedShare } from './hooks/useEmbedShare';
|
|
24
|
-
export { usePDFShare } from './hooks/usePDFShare';
|
|
25
|
-
export { usePaginatedParticipants } from './hooks/usePaginatedParticipants';
|
|
26
|
-
export { useWhiteboard } from './hooks/useWhiteboard';
|
|
27
|
-
export { useAwayNotifications } from './hooks/useAwayNotifications';
|
|
28
|
-
export { useTranscript } from './hooks/useTranscript';
|
|
29
|
-
export { useAudioMode } from './hooks/useAudioMode';
|
|
30
|
-
|
|
31
|
-
// types
|
|
32
|
-
export type { hooksErrHandler } from './hooks/types';
|
|
33
|
-
export type { usePreviewInput, usePreviewResult } from './hooks/usePreviewJoin';
|
|
34
|
-
export type { useVideoListInput, useVideoResult, useVideoListTile } from './hooks/useVideoList';
|
|
35
|
-
export type { useAVToggleResult } from './hooks/useAVToggle';
|
|
36
|
-
export type { useDevicesResult } from './hooks/useDevices';
|
|
37
|
-
export type { useScreenShareResult } from './hooks/useScreenShare';
|
|
38
|
-
export type { useRemoteAVToggleResult } from './hooks/useRemoteAVToggle';
|
|
39
|
-
export type { useRecordingStreamingResult } from './hooks/useRecordingStreaming';
|
|
40
|
-
export type { useParticipantListResult } from './hooks/useParticipantList';
|
|
41
|
-
export type { useParticipantsResult, useParticipantsParams } from './hooks/useParticipants';
|
|
42
|
-
export type { useVideoInput, useVideoOutput } from './hooks/useVideo';
|
|
43
|
-
export type { useAutoplayErrorResult } from './hooks/useAutoplayError';
|
|
44
|
-
export type { useCustomEventInput, useCustomEventResult } from './hooks/useCustomEvent';
|
|
45
|
-
export type { useEmbedShareResult } from './hooks/useEmbedShare';
|
|
46
|
-
export type { usePDFShareResult } from './hooks/usePDFShare';
|
|
47
|
-
export type { TrackWithPeerAndDimensions } from './utils/layout';
|
|
48
|
-
export type { usePaginatedParticipantsResult, usePaginatedParticipantsInput } from './hooks/usePaginatedParticipants';
|
|
49
|
-
export type { HMSTranscript, useHMSTranscriptInput } from './hooks/useTranscript';
|
|
50
|
-
|
|
51
|
-
// helpers
|
|
52
|
-
export { throwErrorHandler } from './utils/commons';
|
|
53
|
-
|
|
54
|
-
export { getVideoTracksFromPeers as getPeersWithTiles } from './utils/layout';
|
|
55
|
-
// reexport everything from store so app can import everything directly from this
|
|
56
|
-
export * from '@100mslive/hms-video-store';
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import React, { createContext, PropsWithChildren, useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import create from 'zustand';
|
|
3
|
-
import {
|
|
4
|
-
HMSActions,
|
|
5
|
-
HMSGenericTypes,
|
|
6
|
-
HMSNotificationInCallback,
|
|
7
|
-
HMSNotifications,
|
|
8
|
-
HMSNotificationTypeParam,
|
|
9
|
-
HMSReactiveStore,
|
|
10
|
-
HMSStatsStore,
|
|
11
|
-
HMSStatsStoreWrapper,
|
|
12
|
-
HMSStore,
|
|
13
|
-
HMSStoreWrapper,
|
|
14
|
-
} from '@100mslive/hms-video-store';
|
|
15
|
-
import { HMSContextProviderProps, hooksErrorMessage, makeHMSStatsStoreHook, makeHMSStoreHook } from './store';
|
|
16
|
-
import { isBrowser } from '../utils/isBrowser';
|
|
17
|
-
|
|
18
|
-
export interface HMSRoomProviderProps<T extends HMSGenericTypes> {
|
|
19
|
-
actions?: HMSActions<T>;
|
|
20
|
-
store?: HMSStoreWrapper<T>;
|
|
21
|
-
notifications?: HMSNotifications;
|
|
22
|
-
stats?: HMSStatsStoreWrapper;
|
|
23
|
-
/**
|
|
24
|
-
* if true this will enable webrtc stats collection
|
|
25
|
-
*/
|
|
26
|
-
isHMSStatsOn?: boolean;
|
|
27
|
-
leaveOnUnload?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* only one context is being created currently. This would need to be changed if multiple
|
|
32
|
-
* rooms have to be supported, where every room will have its own context, provider, store and actions.
|
|
33
|
-
*/
|
|
34
|
-
const HMSContext = createContext<HMSContextProviderProps | null>(null);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* top level wrapper for using react sdk hooks. This doesn't have any mandatory arguments, if you are already
|
|
38
|
-
* initialising the sdk on your side, you can pass in the primitives from there as well to use hooks for
|
|
39
|
-
* react part of your code.
|
|
40
|
-
* @constructor
|
|
41
|
-
*/
|
|
42
|
-
// eslint-disable-next-line complexity
|
|
43
|
-
export const HMSRoomProvider = <T extends HMSGenericTypes = { sessionStore: Record<string, any> }>({
|
|
44
|
-
children,
|
|
45
|
-
actions,
|
|
46
|
-
store,
|
|
47
|
-
notifications,
|
|
48
|
-
stats,
|
|
49
|
-
isHMSStatsOn = false,
|
|
50
|
-
leaveOnUnload = true,
|
|
51
|
-
}: PropsWithChildren<HMSRoomProviderProps<T>>) => {
|
|
52
|
-
const providerProps: HMSContextProviderProps = useMemo(() => {
|
|
53
|
-
let providerProps: HMSContextProviderProps;
|
|
54
|
-
// adding a dummy function for setstate and destroy because zustan'd create expects them
|
|
55
|
-
// to be present but we don't expose them from the store.
|
|
56
|
-
const errFn = () => {
|
|
57
|
-
throw new Error('modifying store is not allowed');
|
|
58
|
-
};
|
|
59
|
-
if (actions && store) {
|
|
60
|
-
providerProps = {
|
|
61
|
-
actions: actions,
|
|
62
|
-
store: create<HMSStore<T>>({
|
|
63
|
-
...store,
|
|
64
|
-
setState: errFn,
|
|
65
|
-
destroy: errFn,
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
if (notifications) {
|
|
69
|
-
providerProps.notifications = notifications;
|
|
70
|
-
}
|
|
71
|
-
if (stats) {
|
|
72
|
-
providerProps.statsStore = create<HMSStatsStore>({
|
|
73
|
-
getState: stats.getState,
|
|
74
|
-
subscribe: stats.subscribe,
|
|
75
|
-
setState: errFn,
|
|
76
|
-
destroy: errFn,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
const hmsReactiveStore = new HMSReactiveStore<T>();
|
|
81
|
-
providerProps = {
|
|
82
|
-
actions: hmsReactiveStore.getActions(),
|
|
83
|
-
store: create<HMSStore<T>>({
|
|
84
|
-
...hmsReactiveStore.getStore(),
|
|
85
|
-
setState: errFn,
|
|
86
|
-
destroy: errFn,
|
|
87
|
-
}), // convert vanilla store in react hook
|
|
88
|
-
notifications: hmsReactiveStore.getNotifications(),
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
if (isHMSStatsOn) {
|
|
92
|
-
const stats = hmsReactiveStore.getStats();
|
|
93
|
-
providerProps.statsStore = create<HMSStatsStore>({
|
|
94
|
-
getState: stats.getState,
|
|
95
|
-
subscribe: stats.subscribe,
|
|
96
|
-
setState: errFn,
|
|
97
|
-
destroy: errFn,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
providerProps.actions.setFrameworkInfo({
|
|
104
|
-
type: 'react-web',
|
|
105
|
-
version: React.version,
|
|
106
|
-
sdkVersion: process.env.REACT_SDK_VERSION,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return providerProps;
|
|
110
|
-
}, [actions, store, notifications, stats, isHMSStatsOn]);
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (isBrowser && leaveOnUnload) {
|
|
114
|
-
const unloadCallback = () => providerProps.actions.leave();
|
|
115
|
-
window.addEventListener('unload', unloadCallback);
|
|
116
|
-
return () => {
|
|
117
|
-
window.removeEventListener('unload', unloadCallback);
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return () => {};
|
|
122
|
-
}, [leaveOnUnload, providerProps]);
|
|
123
|
-
|
|
124
|
-
return React.createElement(HMSContext.Provider, { value: providerProps }, children);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* `useHMSStore` is a read only hook which can be passed a selector to read data.
|
|
129
|
-
* The hook can only be used in a component if HMSRoomProvider is present in its ancestors.
|
|
130
|
-
*/
|
|
131
|
-
export const useHMSStore = makeHMSStoreHook(HMSContext);
|
|
132
|
-
|
|
133
|
-
export const useHMSStatsStore = makeHMSStatsStoreHook(HMSContext);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* `useHMSVanillaStore` is a read only hook which returns the vanilla HMSStore.
|
|
137
|
-
* Usage:
|
|
138
|
-
* ```
|
|
139
|
-
* const hmsStore = useHMSVanillaStore();
|
|
140
|
-
* const dominantSpeaker = hmsStore.getState(selectDominantSpeaker);
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
|
-
* Note: There's no need to use the vanilla hmsStore in React components.
|
|
144
|
-
* This is used in rare cases where the store needs to be accessed outside a React component.
|
|
145
|
-
* For almost every case, `useHMSStore` would get the job done.
|
|
146
|
-
*/
|
|
147
|
-
export const useHMSVanillaStore = () => {
|
|
148
|
-
const HMSContextConsumer = useContext(HMSContext);
|
|
149
|
-
if (!HMSContextConsumer) {
|
|
150
|
-
throw new Error(hooksErrorMessage);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return HMSContextConsumer.store;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/*
|
|
157
|
-
* `useHMSVanillaNotifications` returns the vanilla HMSNotifications object. This makes it a bit easier to ensure
|
|
158
|
-
* a notification is processed only once in your components. The other way is to use the hook version and put
|
|
159
|
-
* the component high enough in the chain.
|
|
160
|
-
* Usage:
|
|
161
|
-
* ```
|
|
162
|
-
* useEffect(() => {
|
|
163
|
-
* const unsub = notifications.onNotification((notification) => {
|
|
164
|
-
* console.log(notification);
|
|
165
|
-
* }, notificationType);
|
|
166
|
-
* return unsub;
|
|
167
|
-
* }, [])
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
export const useHMSVanillaNotifications = () => {
|
|
171
|
-
const HMSContextConsumer = useContext(HMSContext);
|
|
172
|
-
if (!HMSContextConsumer) {
|
|
173
|
-
throw new Error(hooksErrorMessage);
|
|
174
|
-
}
|
|
175
|
-
return HMSContextConsumer.notifications;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/*
|
|
179
|
-
* `useHMSActions` is a write only hook which can be used to dispatch actions.
|
|
180
|
-
*/
|
|
181
|
-
export const useHMSActions = () => {
|
|
182
|
-
const HMSContextConsumer = useContext(HMSContext);
|
|
183
|
-
if (!HMSContextConsumer) {
|
|
184
|
-
throw new Error(hooksErrorMessage);
|
|
185
|
-
}
|
|
186
|
-
return HMSContextConsumer.actions;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* `useHMSNotifications` is a read only hook which gives the latest notification(HMSNotification) received.
|
|
191
|
-
* @param type can be a string or an array of string for the types of notifications to listen to. If an array is passed
|
|
192
|
-
* either declare it outside the functional component or use a useMemo to make sure its reference stays same across
|
|
193
|
-
* rerenders for performance reasons.
|
|
194
|
-
*/
|
|
195
|
-
export const useHMSNotifications = <T extends HMSNotificationTypeParam>(
|
|
196
|
-
type?: T,
|
|
197
|
-
): HMSNotificationInCallback<T> | null => {
|
|
198
|
-
const HMSContextConsumer = useContext(HMSContext);
|
|
199
|
-
const [notification, setNotification] = useState<HMSNotificationInCallback<T> | null>(null);
|
|
200
|
-
|
|
201
|
-
if (!HMSContextConsumer) {
|
|
202
|
-
throw new Error(hooksErrorMessage);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
useEffect(() => {
|
|
206
|
-
if (!HMSContextConsumer.notifications) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
const unsubscribe = HMSContextConsumer.notifications.onNotification<T>(notification => {
|
|
210
|
-
setNotification(notification);
|
|
211
|
-
}, type);
|
|
212
|
-
return unsubscribe;
|
|
213
|
-
}, [HMSContextConsumer.notifications, type]);
|
|
214
|
-
|
|
215
|
-
return notification;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export const useIsHMSStatsOn = () => {
|
|
219
|
-
const HMSContextConsumer = useContext(HMSContext);
|
|
220
|
-
return Boolean(HMSContextConsumer?.statsStore);
|
|
221
|
-
};
|
package/src/primitives/store.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { EqualityChecker, StateSelector } from 'zustand';
|
|
3
|
-
import shallow from 'zustand/shallow';
|
|
4
|
-
import { HMSActions, HMSNotifications, HMSStatsStore, HMSStore, IStoreReadOnly } from '@100mslive/hms-video-store';
|
|
5
|
-
import HMSLogger from '../utils/logger';
|
|
6
|
-
|
|
7
|
-
export interface IHMSReactStore<S extends HMSStore | HMSStatsStore> extends IStoreReadOnly<S> {
|
|
8
|
-
<U>(selector: StateSelector<S, U>, equalityFn?: EqualityChecker<U>): U;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const hooksErrorMessage = `It seems like you forgot to add your component within a top level HMSRoomProvider, please refer to 100ms react docs(https://www.100ms.live/docs/javascript/v2/how-to-guides/install-the-sdk/integration#react-hooks) to check on the required steps for using this hook. If the provider is present
|
|
12
|
-
at the top level, check the yarn.lock/package-lock.json, if there are multiple versions of @100mslive/react-sdk. Please ensure the versions of @100mslive/react-sdk and @100mslive/roomkit-react are the same versions from the release notes(https://www.100ms.live/docs/javascript/v2/changelog/release-notes) that you are trying to update to.`;
|
|
13
|
-
|
|
14
|
-
export interface HMSContextProviderProps {
|
|
15
|
-
actions: HMSActions; // for actions which may also mutate store
|
|
16
|
-
store: IHMSReactStore<HMSStore>; // readonly store, don't mutate this
|
|
17
|
-
notifications?: HMSNotifications;
|
|
18
|
-
statsStore?: IHMSReactStore<HMSStatsStore>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function makeHMSStoreHook(hmsContext: React.Context<HMSContextProviderProps | null>) {
|
|
22
|
-
const useHMSStore = <StateSlice>(
|
|
23
|
-
selector: StateSelector<HMSStore, StateSlice>,
|
|
24
|
-
equalityFn: EqualityChecker<StateSlice> = shallow,
|
|
25
|
-
) => {
|
|
26
|
-
if (!selector) {
|
|
27
|
-
HMSLogger.w(
|
|
28
|
-
'fetching full store without passing any selector may have a heavy performance impact on your website.',
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
const HMSContextConsumer = useContext(hmsContext);
|
|
32
|
-
if (!HMSContextConsumer) {
|
|
33
|
-
throw new Error(hooksErrorMessage);
|
|
34
|
-
}
|
|
35
|
-
const useStore = HMSContextConsumer.store;
|
|
36
|
-
return useStore(selector, equalityFn);
|
|
37
|
-
};
|
|
38
|
-
return useHMSStore;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function makeHMSStatsStoreHook(hmsContext: React.Context<HMSContextProviderProps | null>) {
|
|
42
|
-
const useHMSStatsStore = <StateSlice>(
|
|
43
|
-
selector: StateSelector<HMSStatsStore, StateSlice>,
|
|
44
|
-
equalityFn: EqualityChecker<StateSlice> = shallow,
|
|
45
|
-
) => {
|
|
46
|
-
if (!selector) {
|
|
47
|
-
HMSLogger.w(
|
|
48
|
-
'fetching full store without passing any selector may have a heavy performance impact on your website.',
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
const HMSContextConsumer = useContext(hmsContext);
|
|
52
|
-
if (!HMSContextConsumer) {
|
|
53
|
-
throw new Error(hooksErrorMessage);
|
|
54
|
-
}
|
|
55
|
-
const useStore = HMSContextConsumer.statsStore;
|
|
56
|
-
return useStore?.(selector, equalityFn);
|
|
57
|
-
};
|
|
58
|
-
return useHMSStatsStore;
|
|
59
|
-
}
|
package/src/primitives/types.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EqualityChecker, StateSelector } from 'zustand';
|
|
2
|
-
import { HMSStatsStore, HMSStore, IStoreReadOnly } from '@100mslive/hms-video-store';
|
|
3
|
-
|
|
4
|
-
export interface IHMSReactStore<S extends HMSStore | HMSStatsStore> extends IStoreReadOnly<S> {
|
|
5
|
-
<U>(selector: StateSelector<S, U>, equalityFn?: EqualityChecker<U>): U;
|
|
6
|
-
}
|
package/src/utils/commons.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { parsedUserAgent } from '@100mslive/hms-video-store';
|
|
3
|
-
import HMSLogger from './logger';
|
|
4
|
-
import { hooksErrHandler } from '../hooks/types';
|
|
5
|
-
|
|
6
|
-
const TAG = 'react-sdk';
|
|
7
|
-
|
|
8
|
-
export const logErrorHandler: hooksErrHandler = (err: Error, method?: string) => HMSLogger.e(TAG, method, err);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* pass in this error handler to get the error thrown back to the UI for further handling, showing toast etc.
|
|
12
|
-
* @param err
|
|
13
|
-
*/
|
|
14
|
-
export const throwErrorHandler: hooksErrHandler = (err: Error) => {
|
|
15
|
-
throw err;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default function usePrevious<T>(state: T): T | undefined {
|
|
19
|
-
const ref = useRef<T>();
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
ref.current = state;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return ref.current;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const chromiumBasedBrowsers = ['blink'];
|
|
29
|
-
|
|
30
|
-
export const isChromiumBased = chromiumBasedBrowsers.some(
|
|
31
|
-
(value: string) => parsedUserAgent.getEngine()?.name?.toLowerCase() === value,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
export const pdfIframeURL = 'https://pdf-annotation.100ms.live/generic/web/viewer.html';
|
package/src/utils/groupBy.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { HMSPeer } from '@100mslive/hms-video-store';
|
|
2
|
-
/**
|
|
3
|
-
* Give array like [
|
|
4
|
-
* { name: 'peer1', id: 1, roleName: 'role1' },
|
|
5
|
-
* { name: 'peer2', id: 2, roleName: 'role2' }
|
|
6
|
-
*]
|
|
7
|
-
* the output will be
|
|
8
|
-
* {
|
|
9
|
-
* 'role1': [{'name': 'peer1', id: 1, roleName: 'role1'}],
|
|
10
|
-
* 'role2': [{ name: 'peer2', id: 2, roleName: 'role2' }]
|
|
11
|
-
* }
|
|
12
|
-
* @param {HMSPeer[]} peers
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export const groupByRoles = (peers: HMSPeer[]) => {
|
|
16
|
-
if (!peers || !Array.isArray(peers) || peers.length === 0) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
return peers.reduce((res: Record<string, HMSPeer[]>, peer) => {
|
|
20
|
-
if (!peer.roleName) {
|
|
21
|
-
return res;
|
|
22
|
-
}
|
|
23
|
-
if (!res[peer.roleName]) {
|
|
24
|
-
res[peer.roleName] = [];
|
|
25
|
-
}
|
|
26
|
-
res[peer.roleName].push(peer);
|
|
27
|
-
return res;
|
|
28
|
-
}, {});
|
|
29
|
-
};
|
package/src/utils/isBrowser.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isBrowser = typeof window !== 'undefined';
|