@100mslive/react-sdk 0.0.2-alpha → 0.0.3-alpha
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/package.json +2 -3
- package/dist/hooks/HmsRoomProvider.d.ts +0 -32
- package/dist/hooks/store.d.ts +0 -11
- package/dist/hooks/types.d.ts +0 -5
- package/dist/hooks/useAVToggle.d.ts +0 -7
- package/dist/hooks/useAudioLevel.d.ts +0 -5
- package/dist/hooks/useDevices.d.ts +0 -12
- package/dist/hooks/usePreview.d.ts +0 -11
- package/dist/hooks/useVideo.d.ts +0 -2
- package/dist/hooks/useVideoList.d.ts +0 -26
- package/dist/hooks/useVideoListLayout.d.ts +0 -26
- package/dist/hooks/useVideoTile.d.ts +0 -13
- package/dist/index.cjs.js +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/node_modules/react-intersection-observer/react-intersection-observer.m.js +0 -244
- package/dist/node_modules/zustand/esm/shallow.js +0 -1
- package/dist/packages/react-sdk/src/hooks/HmsRoomProvider.js +0 -131
- package/dist/packages/react-sdk/src/hooks/store.js +0 -25
- package/dist/packages/react-sdk/src/hooks/useAVToggle.js +0 -35
- package/dist/packages/react-sdk/src/hooks/useAudioLevel.js +0 -24
- package/dist/packages/react-sdk/src/hooks/useDevices.js +0 -62
- package/dist/packages/react-sdk/src/hooks/usePreview.js +0 -40
- package/dist/packages/react-sdk/src/hooks/useVideo.js +0 -44
- package/dist/packages/react-sdk/src/hooks/useVideoListLayout.js +0 -65
- package/dist/packages/react-sdk/src/hooks/useVideoTile.js +0 -36
- package/dist/packages/react-sdk/src/index.js +0 -9
- package/dist/packages/react-sdk/src/utils/isBrowser.js +0 -2
- package/dist/packages/react-sdk/src/utils/layout.js +0 -434
- package/dist/packages/react-sdk/src/utils/logger.js +0 -74
- package/dist/src/hooks/HmsRoomProvider.js +0 -1
- package/dist/src/hooks/store.js +0 -1
- package/dist/src/hooks/useAVToggle.js +0 -1
- package/dist/src/hooks/useAudioLevel.js +0 -1
- package/dist/src/hooks/useDevices.js +0 -1
- package/dist/src/hooks/usePreview.js +0 -1
- package/dist/src/hooks/useVideo.js +0 -1
- package/dist/src/hooks/useVideoList.js +0 -1
- package/dist/src/hooks/useVideoListLayout.js +0 -65
- package/dist/src/hooks/useVideoTile.js +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/utils/isBrowser.js +0 -1
- package/dist/src/utils/layout.js +0 -1
- package/dist/src/utils/logger.js +0 -1
- package/dist/utils/groupBy.d.ts +0 -2
- package/dist/utils/isBrowser.d.ts +0 -1
- package/dist/utils/layout.d.ts +0 -109
- package/dist/utils/logger.d.ts +0 -17
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { selectTrackAudioByID } from '@100mslive/hms-video-store';
|
|
3
|
-
import { useHMSVanillaStore } from './HmsRoomProvider.js';
|
|
4
|
-
|
|
5
|
-
function useAudioLevel({
|
|
6
|
-
trackId,
|
|
7
|
-
getStyle,
|
|
8
|
-
ref
|
|
9
|
-
}) {
|
|
10
|
-
const store = useHMSVanillaStore();
|
|
11
|
-
useEffect(() => store.subscribe(level => {
|
|
12
|
-
if (!ref.current) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const styles = getStyle(level);
|
|
17
|
-
|
|
18
|
-
for (const key in styles) {
|
|
19
|
-
ref.current.style[key] = styles[key];
|
|
20
|
-
}
|
|
21
|
-
}, selectTrackAudioByID(trackId)), [trackId]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { useAudioLevel };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { selectDevices, selectLocalMediaSettings, selectIsAllowedToPublish, selectIsAllowedToSubscribe } from '@100mslive/hms-video-store';
|
|
2
|
-
import { useHMSActions, useHMSStore } from './HmsRoomProvider.js';
|
|
3
|
-
|
|
4
|
-
const useDevices = () => {
|
|
5
|
-
const hmsActions = useHMSActions();
|
|
6
|
-
const devices = useHMSStore(selectDevices);
|
|
7
|
-
const selectedDevices = useHMSStore(selectLocalMediaSettings);
|
|
8
|
-
const {
|
|
9
|
-
video: showVideo,
|
|
10
|
-
audio: showAudio
|
|
11
|
-
} = useHMSStore(selectIsAllowedToPublish);
|
|
12
|
-
const isSubscribing = useHMSStore(selectIsAllowedToSubscribe); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
|
|
14
|
-
const handleInputChange = event => {
|
|
15
|
-
const selectedDevice = event.currentTarget.value;
|
|
16
|
-
const {
|
|
17
|
-
name
|
|
18
|
-
} = event.currentTarget;
|
|
19
|
-
|
|
20
|
-
if (selectedDevice !== selectedDevices[name]) {
|
|
21
|
-
switch (name) {
|
|
22
|
-
case 'audioInputDeviceId':
|
|
23
|
-
hmsActions.setAudioSettings({
|
|
24
|
-
deviceId: selectedDevice
|
|
25
|
-
});
|
|
26
|
-
break;
|
|
27
|
-
|
|
28
|
-
case 'videoInputDeviceId':
|
|
29
|
-
hmsActions.setVideoSettings({
|
|
30
|
-
deviceId: selectedDevice
|
|
31
|
-
});
|
|
32
|
-
break;
|
|
33
|
-
|
|
34
|
-
case 'audioOutputDeviceId':
|
|
35
|
-
hmsActions.setAudioOutputDevice(selectedDevice);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const videoInput = devices.videoInput || [];
|
|
42
|
-
const audioInput = devices.audioInput || [];
|
|
43
|
-
const audioOutput = devices.audioOutput || [];
|
|
44
|
-
const showSettings = [showVideo, showAudio, isSubscribing].some(val => !!val);
|
|
45
|
-
|
|
46
|
-
if (!showSettings) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
showVideo,
|
|
52
|
-
videoInput,
|
|
53
|
-
showAudio,
|
|
54
|
-
audioInput,
|
|
55
|
-
audioOutput,
|
|
56
|
-
isSubscribing,
|
|
57
|
-
selectedDevices,
|
|
58
|
-
handleInputChange
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export { useDevices };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isBrowser } from '@100mslive/hms-video';
|
|
2
|
-
import { selectLocalPeer, selectRoomState, selectIsLocalAudioEnabled, selectIsLocalVideoDisplayEnabled, selectIsAllowedToPublish, HMSRoomState } from '@100mslive/hms-video-store';
|
|
3
|
-
import { useState, useEffect } from 'react';
|
|
4
|
-
import { useHMSActions, useHMSStore } from './HmsRoomProvider.js';
|
|
5
|
-
|
|
6
|
-
const usePreview = (authToken, userName) => {
|
|
7
|
-
const [inProgress, setInProgress] = useState(false);
|
|
8
|
-
const actions = useHMSActions();
|
|
9
|
-
const localPeer = useHMSStore(selectLocalPeer);
|
|
10
|
-
const roomState = useHMSStore(selectRoomState);
|
|
11
|
-
const audioEnabled = useHMSStore(selectIsLocalAudioEnabled);
|
|
12
|
-
const videoEnabled = useHMSStore(selectIsLocalVideoDisplayEnabled);
|
|
13
|
-
const isAllowedToPublish = useHMSStore(selectIsAllowedToPublish);
|
|
14
|
-
const disableJoin = inProgress || roomState !== HMSRoomState.Preview;
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
// Call preview only when roomState is in disconnected state
|
|
17
|
-
if (roomState === HMSRoomState.Disconnected) {
|
|
18
|
-
actions.preview({
|
|
19
|
-
userName,
|
|
20
|
-
authToken
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (isBrowser) {
|
|
25
|
-
window.onunload = () => actions.leave();
|
|
26
|
-
}
|
|
27
|
-
}, [roomState, actions, authToken]);
|
|
28
|
-
return {
|
|
29
|
-
localPeer,
|
|
30
|
-
roomState,
|
|
31
|
-
audioEnabled,
|
|
32
|
-
videoEnabled,
|
|
33
|
-
isAllowedToPublish,
|
|
34
|
-
disableJoin,
|
|
35
|
-
actions,
|
|
36
|
-
setInProgress
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export { usePreview };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { selectTrackByID } from '@100mslive/hms-video-store';
|
|
2
|
-
import { useRef, useCallback, useEffect } from 'react';
|
|
3
|
-
import { useInView } from '../../../../node_modules/react-intersection-observer/react-intersection-observer.m.js';
|
|
4
|
-
import { useHMSActions, useHMSStore } from './HmsRoomProvider.js';
|
|
5
|
-
|
|
6
|
-
const useVideo = trackId => {
|
|
7
|
-
const actions = useHMSActions();
|
|
8
|
-
const videoRef = useRef(null);
|
|
9
|
-
const {
|
|
10
|
-
ref: inViewRef,
|
|
11
|
-
inView
|
|
12
|
-
} = useInView({
|
|
13
|
-
threshold: 0.5
|
|
14
|
-
});
|
|
15
|
-
const setRefs = useCallback(node => {
|
|
16
|
-
videoRef.current = node;
|
|
17
|
-
inViewRef(node);
|
|
18
|
-
}, [inViewRef]);
|
|
19
|
-
const hmsStoreVideoTrack = useHMSStore(selectTrackByID(trackId));
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
(async () => {
|
|
22
|
-
if (videoRef.current && hmsStoreVideoTrack) {
|
|
23
|
-
if (inView) {
|
|
24
|
-
if (hmsStoreVideoTrack.enabled) {
|
|
25
|
-
console.log('****** ENABLE VIDEO *******'); // attach when in view and enabled
|
|
26
|
-
|
|
27
|
-
await actions.attachVideo(hmsStoreVideoTrack.id, videoRef.current);
|
|
28
|
-
} else {
|
|
29
|
-
console.log('****** DETACH VIDEO *******'); // detach when in view but not enabled
|
|
30
|
-
|
|
31
|
-
await actions.detachVideo(hmsStoreVideoTrack.id, videoRef.current);
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
// detach when not in view
|
|
35
|
-
console.log('****** DETACH VIDEO *******');
|
|
36
|
-
await actions.detachVideo(hmsStoreVideoTrack.id, videoRef.current);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
})();
|
|
40
|
-
}, [inView, videoRef, hmsStoreVideoTrack == null ? void 0 : hmsStoreVideoTrack.id, hmsStoreVideoTrack == null ? void 0 : hmsStoreVideoTrack.enabled, hmsStoreVideoTrack == null ? void 0 : hmsStoreVideoTrack.deviceID, hmsStoreVideoTrack == null ? void 0 : hmsStoreVideoTrack.plugins]);
|
|
41
|
-
return setRefs;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { useVideo };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { selectTracksMap } from '@100mslive/hms-video-store';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { getVideoTracksFromPeers, getModeAspectRatio, calculateLayoutSizes, chunkElements } from '../utils/layout.js';
|
|
4
|
-
import { useHMSVanillaStore } from './HmsRoomProvider.js';
|
|
5
|
-
|
|
6
|
-
const useVideoList = ({
|
|
7
|
-
maxTileCount,
|
|
8
|
-
maxColCount,
|
|
9
|
-
maxRowCount,
|
|
10
|
-
width,
|
|
11
|
-
height,
|
|
12
|
-
showScreenFn,
|
|
13
|
-
peers,
|
|
14
|
-
overflow,
|
|
15
|
-
aspectRatio
|
|
16
|
-
}) => {
|
|
17
|
-
const store = useHMSVanillaStore();
|
|
18
|
-
const tracksMap = store.getState(selectTracksMap);
|
|
19
|
-
const tracksWithPeer = getVideoTracksFromPeers(peers, tracksMap, showScreenFn);
|
|
20
|
-
const finalAspectRatio = useMemo(() => {
|
|
21
|
-
if (aspectRatio) {
|
|
22
|
-
return aspectRatio;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const modeAspectRatio = getModeAspectRatio(tracksWithPeer); // Default to 1 if there are no video tracks
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
width: modeAspectRatio || 1,
|
|
29
|
-
height: 1
|
|
30
|
-
};
|
|
31
|
-
}, [aspectRatio, tracksWithPeer]);
|
|
32
|
-
const count = tracksWithPeer.length;
|
|
33
|
-
const {
|
|
34
|
-
tilesInFirstPage,
|
|
35
|
-
defaultWidth,
|
|
36
|
-
defaultHeight,
|
|
37
|
-
lastPageWidth,
|
|
38
|
-
lastPageHeight,
|
|
39
|
-
isLastPageDifferentFromFirstPage
|
|
40
|
-
} = useMemo(() => // Flooring since there's a bug in react-slick where it converts widdh into a number
|
|
41
|
-
calculateLayoutSizes({
|
|
42
|
-
count,
|
|
43
|
-
parentWidth: Math.floor(width),
|
|
44
|
-
parentHeight: Math.floor(height),
|
|
45
|
-
maxTileCount,
|
|
46
|
-
maxRowCount,
|
|
47
|
-
maxColCount,
|
|
48
|
-
aspectRatio: finalAspectRatio
|
|
49
|
-
}), [count, width, height, maxTileCount, maxRowCount, maxColCount, finalAspectRatio]);
|
|
50
|
-
const chunkedTracksWithPeer = useMemo(() => chunkElements({
|
|
51
|
-
elements: tracksWithPeer,
|
|
52
|
-
tilesInFirstPage,
|
|
53
|
-
onlyOnePage: overflow === 'hidden',
|
|
54
|
-
isLastPageDifferentFromFirstPage,
|
|
55
|
-
defaultWidth,
|
|
56
|
-
defaultHeight,
|
|
57
|
-
lastPageWidth,
|
|
58
|
-
lastPageHeight
|
|
59
|
-
}), [tracksWithPeer, tilesInFirstPage, overflow, isLastPageDifferentFromFirstPage, defaultWidth, defaultHeight, lastPageWidth, lastPageHeight]);
|
|
60
|
-
return {
|
|
61
|
-
chunkedTracksWithPeer
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export { useVideoList };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { selectVideoTrackByPeerID, selectIsPeerAudioEnabled, selectIsPeerVideoEnabled, selectPeerAudioByID } from '@100mslive/hms-video-store';
|
|
2
|
-
import { useRef, useEffect } from 'react';
|
|
3
|
-
import { useHMSActions, useHMSStore } from './HmsRoomProvider.js';
|
|
4
|
-
|
|
5
|
-
const useVideoTile = peer => {
|
|
6
|
-
const actions = useHMSActions();
|
|
7
|
-
const videoRef = useRef(null);
|
|
8
|
-
const videoTrack = useHMSStore(selectVideoTrackByPeerID(peer.id));
|
|
9
|
-
const isAudioOn = useHMSStore(selectIsPeerAudioEnabled(peer.id));
|
|
10
|
-
const isVideoOn = useHMSStore(selectIsPeerVideoEnabled(peer.id));
|
|
11
|
-
const {
|
|
12
|
-
isLocal,
|
|
13
|
-
name
|
|
14
|
-
} = peer;
|
|
15
|
-
const audioLevel = useHMSStore(selectPeerAudioByID(peer.id)) > 0;
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (videoRef.current && videoTrack) {
|
|
18
|
-
if (videoTrack.enabled) {
|
|
19
|
-
actions.attachVideo(videoTrack.id, videoRef.current);
|
|
20
|
-
} else {
|
|
21
|
-
actions.detachVideo(videoTrack.id, videoRef.current);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}, [videoTrack, actions]);
|
|
25
|
-
return {
|
|
26
|
-
videoRef,
|
|
27
|
-
isAudioOn,
|
|
28
|
-
isVideoOn,
|
|
29
|
-
actions,
|
|
30
|
-
isLocal,
|
|
31
|
-
name,
|
|
32
|
-
audioLevel
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export { useVideoTile };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { HMSRoomProvider, useHMSActions, useHMSNotifications, useHMSStore, useHMSVanillaStore } from './hooks/HmsRoomProvider.js';
|
|
2
|
-
export { calculateLayoutSizes, chunkElements, getModeAspectRatio } from './utils/layout.js';
|
|
3
|
-
export { usePreview } from './hooks/usePreview.js';
|
|
4
|
-
export { useVideoTile } from './hooks/useVideoTile.js';
|
|
5
|
-
export { useVideoList } from './hooks/useVideoListLayout.js';
|
|
6
|
-
export { useAVToggle } from './hooks/useAVToggle.js';
|
|
7
|
-
export { useDevices } from './hooks/useDevices.js';
|
|
8
|
-
export { useVideo } from './hooks/useVideo.js';
|
|
9
|
-
export { useAudioLevel } from './hooks/useAudioLevel.js';
|