@100mslive/react-sdk 0.0.1-alpha → 0.0.2-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/dist/hooks/useAudioLevel.d.ts +5 -0
- package/dist/hooks/usePreview.d.ts +1 -1
- package/dist/hooks/useVideo.d.ts +2 -0
- package/dist/hooks/useVideoList.d.ts +26 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/node_modules/react-intersection-observer/react-intersection-observer.m.js +244 -0
- package/dist/packages/react-sdk/src/hooks/HmsRoomProvider.js +131 -0
- package/dist/packages/react-sdk/src/hooks/store.js +25 -0
- package/dist/packages/react-sdk/src/hooks/useAVToggle.js +35 -0
- package/dist/packages/react-sdk/src/hooks/useAudioLevel.js +24 -0
- package/dist/packages/react-sdk/src/hooks/useDevices.js +62 -0
- package/dist/packages/react-sdk/src/hooks/usePreview.js +40 -0
- package/dist/packages/react-sdk/src/hooks/useVideo.js +44 -0
- package/dist/packages/react-sdk/src/hooks/useVideoListLayout.js +65 -0
- package/dist/packages/react-sdk/src/hooks/useVideoTile.js +36 -0
- package/dist/packages/react-sdk/src/index.js +9 -0
- package/dist/packages/react-sdk/src/utils/isBrowser.js +2 -0
- package/dist/packages/react-sdk/src/utils/layout.js +434 -0
- package/dist/packages/react-sdk/src/utils/logger.js +74 -0
- package/dist/src/hooks/useAudioLevel.js +1 -0
- package/dist/src/hooks/usePreview.js +1 -1
- package/dist/src/hooks/useVideo.js +1 -0
- package/dist/src/hooks/useVideoList.js +1 -0
- package/dist/src/hooks/useVideoListLayout.js +65 -1
- package/dist/src/index.js +1 -1
- package/package.json +2 -1
- package/CHANGELOG.md +0 -5
|
@@ -0,0 +1,44 @@
|
|
|
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 };
|
|
@@ -0,0 +1,65 @@
|
|
|
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 };
|
|
@@ -0,0 +1,36 @@
|
|
|
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 };
|
|
@@ -0,0 +1,9 @@
|
|
|
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';
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
const chunk = (elements, chunkSize, onlyOnePage) => elements.reduce((resultArray, tile, index) => {
|
|
4
|
+
const chunkIndex = Math.floor(index / chunkSize);
|
|
5
|
+
|
|
6
|
+
if (chunkIndex > 0 && onlyOnePage) {
|
|
7
|
+
return resultArray;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!resultArray[chunkIndex]) {
|
|
11
|
+
resultArray[chunkIndex] = []; // start a new chunk
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
resultArray[chunkIndex].push(tile);
|
|
15
|
+
return resultArray;
|
|
16
|
+
}, []);
|
|
17
|
+
/**
|
|
18
|
+
* Given a list of tracks/elements and some constraints, group the tracks in separate pages.
|
|
19
|
+
* @return 2D list for every page which has the original element and height and width
|
|
20
|
+
* for its tile.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const chunkElements = ({
|
|
25
|
+
elements,
|
|
26
|
+
tilesInFirstPage,
|
|
27
|
+
onlyOnePage,
|
|
28
|
+
isLastPageDifferentFromFirstPage,
|
|
29
|
+
defaultWidth,
|
|
30
|
+
defaultHeight,
|
|
31
|
+
lastPageWidth,
|
|
32
|
+
lastPageHeight
|
|
33
|
+
}) => {
|
|
34
|
+
const chunks = chunk(elements, tilesInFirstPage, onlyOnePage);
|
|
35
|
+
return chunks.map((ch, page) => ch.map(element => {
|
|
36
|
+
const isLastPage = page === chunks.length - 1;
|
|
37
|
+
const width = isLastPageDifferentFromFirstPage && isLastPage ? lastPageWidth : defaultWidth;
|
|
38
|
+
const height = isLastPageDifferentFromFirstPage && isLastPage ? lastPageHeight : defaultHeight;
|
|
39
|
+
return _extends({}, element, {
|
|
40
|
+
height,
|
|
41
|
+
width
|
|
42
|
+
});
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Mathematical mode - the element with the highest occurrence in an array
|
|
47
|
+
* @param array
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function mode(array) {
|
|
52
|
+
if (array.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const modeMap = {};
|
|
57
|
+
let maxEl = array[0];
|
|
58
|
+
let maxCount = 1;
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < array.length; i++) {
|
|
61
|
+
const el = array[i];
|
|
62
|
+
|
|
63
|
+
if (modeMap[el] === null) {
|
|
64
|
+
modeMap[el] = 1;
|
|
65
|
+
} else {
|
|
66
|
+
modeMap[el]++;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (modeMap[el] > maxCount) {
|
|
70
|
+
maxEl = el;
|
|
71
|
+
maxCount = modeMap[el];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return maxEl;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* get the aspect ration occurring with the highest frequency
|
|
79
|
+
* @param tracks - video tracks to infer aspect ratios from
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const getModeAspectRatio = tracks => mode(tracks.filter(track => {
|
|
84
|
+
var _track$track, _track$track2;
|
|
85
|
+
|
|
86
|
+
return ((_track$track = track.track) == null ? void 0 : _track$track.width) && ((_track$track2 = track.track) == null ? void 0 : _track$track2.height);
|
|
87
|
+
}).map(track => {
|
|
88
|
+
var _track$track3, _track$track4;
|
|
89
|
+
|
|
90
|
+
const width = (_track$track3 = track.track) == null ? void 0 : _track$track3.width;
|
|
91
|
+
const height = (_track$track4 = track.track) == null ? void 0 : _track$track4.height; // Default to 1 if there are no video tracks
|
|
92
|
+
|
|
93
|
+
return (width || 1) / (height || 1);
|
|
94
|
+
}));
|
|
95
|
+
/**
|
|
96
|
+
* Finds the largest rectangle area when trying to place N rectangle into a containing
|
|
97
|
+
* rectangle without rotation.
|
|
98
|
+
*
|
|
99
|
+
* @param {Number} containerWidth The width of the container.
|
|
100
|
+
* @param {Number} containerHeight The height of the container.
|
|
101
|
+
* @param {Number} numRects How many rectangles must fit within.
|
|
102
|
+
* @param {Number} width The unscaled width of the rectangles to be placed.
|
|
103
|
+
* @param {Number} height The unscaled height of the rectangles to be placed.
|
|
104
|
+
* @return {Object} The area and number of rows and columns that fit.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const largestRect = (containerWidth, containerHeight, numRects, width, height) => {
|
|
109
|
+
if (containerWidth < 0 || containerHeight < 0) {
|
|
110
|
+
throw new Error('Container must have a non-negative area');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (numRects < 1 || !Number.isInteger(numRects)) {
|
|
114
|
+
throw new Error('Number of shapes to place must be a positive integer');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const aspectRatio = width && height && width / height;
|
|
118
|
+
|
|
119
|
+
if (aspectRatio !== undefined && isNaN(aspectRatio)) {
|
|
120
|
+
throw new Error('Aspect ratio must be a number');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let best = {
|
|
124
|
+
area: 0,
|
|
125
|
+
cols: 0,
|
|
126
|
+
rows: 0,
|
|
127
|
+
width: 0,
|
|
128
|
+
height: 0
|
|
129
|
+
}; // TODO: Don't start with obviously-`ba`d candidates.
|
|
130
|
+
|
|
131
|
+
const startCols = numRects;
|
|
132
|
+
const colDelta = -1; // For each combination of rows + cols that can fit the number of rectangles,
|
|
133
|
+
// place them and see the area.
|
|
134
|
+
|
|
135
|
+
if (aspectRatio !== undefined) {
|
|
136
|
+
for (let cols = startCols; cols > 0; cols += colDelta) {
|
|
137
|
+
const rows = Math.ceil(numRects / cols);
|
|
138
|
+
const hScale = containerWidth / (cols * aspectRatio);
|
|
139
|
+
const vScale = containerHeight / rows;
|
|
140
|
+
|
|
141
|
+
let _width;
|
|
142
|
+
|
|
143
|
+
let _height; // Determine which axis is the constraint.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if (hScale <= vScale) {
|
|
147
|
+
_width = containerWidth / cols;
|
|
148
|
+
_height = _width / aspectRatio;
|
|
149
|
+
} else {
|
|
150
|
+
_height = containerHeight / rows;
|
|
151
|
+
_width = _height * aspectRatio;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const area = _width * _height;
|
|
155
|
+
|
|
156
|
+
if (area > best.area) {
|
|
157
|
+
best = {
|
|
158
|
+
area,
|
|
159
|
+
width: _width,
|
|
160
|
+
height: _height,
|
|
161
|
+
rows,
|
|
162
|
+
cols
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return best;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const getTileSizesWithColConstraint = ({
|
|
172
|
+
parentWidth,
|
|
173
|
+
parentHeight,
|
|
174
|
+
count,
|
|
175
|
+
maxCount,
|
|
176
|
+
aspectRatio
|
|
177
|
+
}) => {
|
|
178
|
+
let defaultWidth = 0;
|
|
179
|
+
let defaultHeight = 0;
|
|
180
|
+
let lastPageWidth = 0;
|
|
181
|
+
let lastPageHeight = 0;
|
|
182
|
+
let isLastPageDifferentFromFirstPage = false;
|
|
183
|
+
let tilesInFirstPage = 0;
|
|
184
|
+
let tilesinLastPage = 0;
|
|
185
|
+
const cols = Math.min(Math.ceil(Math.sqrt(count * (parentWidth / parentHeight) / (aspectRatio.width / aspectRatio.height))), maxCount);
|
|
186
|
+
const width = parentWidth / cols;
|
|
187
|
+
const height = width / (aspectRatio.width / aspectRatio.height);
|
|
188
|
+
const rows = Math.floor(parentHeight / height);
|
|
189
|
+
defaultHeight = height;
|
|
190
|
+
defaultWidth = width;
|
|
191
|
+
tilesInFirstPage = Math.min(count, rows * cols);
|
|
192
|
+
tilesinLastPage = count % (rows * cols);
|
|
193
|
+
isLastPageDifferentFromFirstPage = tilesinLastPage > 0 && count > rows * cols;
|
|
194
|
+
|
|
195
|
+
if (isLastPageDifferentFromFirstPage) {
|
|
196
|
+
const _cols = Math.min(Math.ceil(Math.sqrt(tilesinLastPage * (parentWidth / parentHeight) / (aspectRatio.width / aspectRatio.height))), maxCount);
|
|
197
|
+
|
|
198
|
+
const _width2 = parentWidth / _cols;
|
|
199
|
+
|
|
200
|
+
const _height2 = _width2 / (aspectRatio.width / aspectRatio.height);
|
|
201
|
+
|
|
202
|
+
lastPageHeight = _height2;
|
|
203
|
+
lastPageWidth = _width2;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
tilesInFirstPage,
|
|
208
|
+
defaultWidth,
|
|
209
|
+
defaultHeight,
|
|
210
|
+
lastPageWidth,
|
|
211
|
+
lastPageHeight,
|
|
212
|
+
isLastPageDifferentFromFirstPage
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const getTileSizesWithPageConstraint = ({
|
|
217
|
+
parentWidth,
|
|
218
|
+
parentHeight,
|
|
219
|
+
count,
|
|
220
|
+
maxCount,
|
|
221
|
+
aspectRatio
|
|
222
|
+
}) => {
|
|
223
|
+
let defaultWidth = 0;
|
|
224
|
+
let defaultHeight = 0;
|
|
225
|
+
let lastPageWidth = 0;
|
|
226
|
+
let lastPageHeight = 0;
|
|
227
|
+
let isLastPageDifferentFromFirstPage = false;
|
|
228
|
+
let tilesInFirstPage = 0;
|
|
229
|
+
let tilesinLastPage = 0;
|
|
230
|
+
const {
|
|
231
|
+
width: initialWidth,
|
|
232
|
+
height: initialHeight
|
|
233
|
+
} = largestRect(parentWidth, parentHeight, Math.min(count, maxCount), aspectRatio.width, aspectRatio.height);
|
|
234
|
+
defaultWidth = initialWidth;
|
|
235
|
+
defaultHeight = initialHeight;
|
|
236
|
+
tilesInFirstPage = Math.min(count, maxCount);
|
|
237
|
+
tilesinLastPage = count % maxCount;
|
|
238
|
+
isLastPageDifferentFromFirstPage = tilesinLastPage > 0 && count > maxCount;
|
|
239
|
+
|
|
240
|
+
if (isLastPageDifferentFromFirstPage) {
|
|
241
|
+
const {
|
|
242
|
+
width: remWidth,
|
|
243
|
+
height: remHeight
|
|
244
|
+
} = largestRect(parentWidth, parentHeight, tilesinLastPage, aspectRatio.width, aspectRatio.height);
|
|
245
|
+
lastPageWidth = remWidth;
|
|
246
|
+
lastPageHeight = remHeight;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
tilesInFirstPage,
|
|
251
|
+
defaultWidth,
|
|
252
|
+
defaultHeight,
|
|
253
|
+
lastPageWidth,
|
|
254
|
+
lastPageHeight,
|
|
255
|
+
isLastPageDifferentFromFirstPage
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const getTileSizesWithRowConstraint = ({
|
|
260
|
+
parentWidth,
|
|
261
|
+
parentHeight,
|
|
262
|
+
count,
|
|
263
|
+
maxCount,
|
|
264
|
+
aspectRatio
|
|
265
|
+
}) => {
|
|
266
|
+
let defaultWidth = 0;
|
|
267
|
+
let defaultHeight = 0;
|
|
268
|
+
let lastPageWidth = 0;
|
|
269
|
+
let lastPageHeight = 0;
|
|
270
|
+
let isLastPageDifferentFromFirstPage = false;
|
|
271
|
+
let tilesInFirstPage = 0;
|
|
272
|
+
let tilesinLastPage = 0;
|
|
273
|
+
const rows = Math.min(Math.ceil(Math.sqrt(count * (aspectRatio.width / aspectRatio.height) / (parentWidth / parentHeight))), maxCount);
|
|
274
|
+
const height = parentHeight / rows;
|
|
275
|
+
const width = height * (aspectRatio.width / aspectRatio.height);
|
|
276
|
+
const cols = Math.floor(parentWidth / width);
|
|
277
|
+
defaultWidth = width;
|
|
278
|
+
defaultHeight = height;
|
|
279
|
+
tilesInFirstPage = Math.min(count, rows * cols);
|
|
280
|
+
tilesinLastPage = count % (rows * cols);
|
|
281
|
+
isLastPageDifferentFromFirstPage = tilesinLastPage > 0 && count > rows * cols;
|
|
282
|
+
|
|
283
|
+
if (isLastPageDifferentFromFirstPage) {
|
|
284
|
+
const _rows = Math.min(Math.ceil(Math.sqrt(tilesinLastPage * (aspectRatio.width / aspectRatio.height) / (parentWidth / parentHeight))), maxCount);
|
|
285
|
+
|
|
286
|
+
const _height3 = parentHeight / _rows;
|
|
287
|
+
|
|
288
|
+
const _width3 = _height3 * (aspectRatio.width / aspectRatio.height);
|
|
289
|
+
|
|
290
|
+
lastPageHeight = _height3;
|
|
291
|
+
lastPageWidth = _width3;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
tilesInFirstPage,
|
|
296
|
+
defaultWidth,
|
|
297
|
+
defaultHeight,
|
|
298
|
+
lastPageWidth,
|
|
299
|
+
lastPageHeight,
|
|
300
|
+
isLastPageDifferentFromFirstPage
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
function calculateLayoutSizes({
|
|
305
|
+
count,
|
|
306
|
+
parentWidth,
|
|
307
|
+
parentHeight,
|
|
308
|
+
maxTileCount,
|
|
309
|
+
maxRowCount,
|
|
310
|
+
maxColCount,
|
|
311
|
+
aspectRatio
|
|
312
|
+
}) {
|
|
313
|
+
let defaultWidth = 0;
|
|
314
|
+
let defaultHeight = 0;
|
|
315
|
+
let lastPageWidth = 0;
|
|
316
|
+
let lastPageHeight = 0;
|
|
317
|
+
let isLastPageDifferentFromFirstPage = false;
|
|
318
|
+
let tilesInFirstPage = 0;
|
|
319
|
+
|
|
320
|
+
if (count === 0) {
|
|
321
|
+
// no tracks to show
|
|
322
|
+
return {
|
|
323
|
+
tilesInFirstPage,
|
|
324
|
+
defaultWidth,
|
|
325
|
+
defaultHeight,
|
|
326
|
+
lastPageWidth,
|
|
327
|
+
lastPageHeight,
|
|
328
|
+
isLastPageDifferentFromFirstPage
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (maxTileCount) {
|
|
333
|
+
({
|
|
334
|
+
tilesInFirstPage,
|
|
335
|
+
defaultWidth,
|
|
336
|
+
defaultHeight,
|
|
337
|
+
lastPageWidth,
|
|
338
|
+
lastPageHeight,
|
|
339
|
+
isLastPageDifferentFromFirstPage
|
|
340
|
+
} = getTileSizesWithPageConstraint({
|
|
341
|
+
parentWidth,
|
|
342
|
+
parentHeight,
|
|
343
|
+
count,
|
|
344
|
+
maxCount: maxTileCount,
|
|
345
|
+
aspectRatio
|
|
346
|
+
}));
|
|
347
|
+
} else if (maxRowCount) {
|
|
348
|
+
({
|
|
349
|
+
tilesInFirstPage,
|
|
350
|
+
defaultWidth,
|
|
351
|
+
defaultHeight,
|
|
352
|
+
lastPageWidth,
|
|
353
|
+
lastPageHeight,
|
|
354
|
+
isLastPageDifferentFromFirstPage
|
|
355
|
+
} = getTileSizesWithRowConstraint({
|
|
356
|
+
parentWidth,
|
|
357
|
+
parentHeight,
|
|
358
|
+
count,
|
|
359
|
+
maxCount: maxRowCount,
|
|
360
|
+
aspectRatio
|
|
361
|
+
}));
|
|
362
|
+
} else if (maxColCount) {
|
|
363
|
+
({
|
|
364
|
+
tilesInFirstPage,
|
|
365
|
+
defaultWidth,
|
|
366
|
+
defaultHeight,
|
|
367
|
+
lastPageWidth,
|
|
368
|
+
lastPageHeight,
|
|
369
|
+
isLastPageDifferentFromFirstPage
|
|
370
|
+
} = getTileSizesWithColConstraint({
|
|
371
|
+
parentWidth,
|
|
372
|
+
parentHeight,
|
|
373
|
+
count,
|
|
374
|
+
maxCount: maxColCount,
|
|
375
|
+
aspectRatio
|
|
376
|
+
}));
|
|
377
|
+
} else {
|
|
378
|
+
const {
|
|
379
|
+
width,
|
|
380
|
+
height
|
|
381
|
+
} = largestRect(parentWidth, parentHeight, count, aspectRatio.width, aspectRatio.height);
|
|
382
|
+
defaultWidth = width;
|
|
383
|
+
defaultHeight = height;
|
|
384
|
+
tilesInFirstPage = count;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
tilesInFirstPage,
|
|
389
|
+
defaultWidth,
|
|
390
|
+
defaultHeight,
|
|
391
|
+
lastPageWidth,
|
|
392
|
+
lastPageHeight,
|
|
393
|
+
isLastPageDifferentFromFirstPage
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const getVideoTracksFromPeers = (peers, tracks, showScreenFn) => {
|
|
398
|
+
if (!peers || !tracks || !showScreenFn) {
|
|
399
|
+
return [];
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const videoTracks = [];
|
|
403
|
+
|
|
404
|
+
for (const peer of peers) {
|
|
405
|
+
if (peer.videoTrack === undefined && peer.audioTrack && tracks[peer.audioTrack]) {
|
|
406
|
+
videoTracks.push({
|
|
407
|
+
peer
|
|
408
|
+
});
|
|
409
|
+
} else if (peer.videoTrack && tracks[peer.videoTrack]) {
|
|
410
|
+
videoTracks.push({
|
|
411
|
+
track: tracks[peer.videoTrack],
|
|
412
|
+
peer
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (showScreenFn(peer) && peer.auxiliaryTracks.length > 0) {
|
|
417
|
+
const screenShareTrackID = peer.auxiliaryTracks.find(trackID => {
|
|
418
|
+
const track = tracks[trackID];
|
|
419
|
+
return (track == null ? void 0 : track.type) === 'video' && (track == null ? void 0 : track.source) === 'screen';
|
|
420
|
+
}); // Don't show tile if screenshare only has audio
|
|
421
|
+
|
|
422
|
+
if (screenShareTrackID) {
|
|
423
|
+
videoTracks.push({
|
|
424
|
+
track: tracks[screenShareTrackID],
|
|
425
|
+
peer
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return videoTracks;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export { calculateLayoutSizes, chunk, chunkElements, getModeAspectRatio, getTileSizesWithColConstraint, getTileSizesWithPageConstraint, getTileSizesWithRowConstraint, getVideoTracksFromPeers, largestRect, mode };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var HMSLogLevel;
|
|
2
|
+
|
|
3
|
+
(function (HMSLogLevel) {
|
|
4
|
+
HMSLogLevel[HMSLogLevel["VERBOSE"] = 0] = "VERBOSE";
|
|
5
|
+
HMSLogLevel[HMSLogLevel["DEBUG"] = 1] = "DEBUG";
|
|
6
|
+
HMSLogLevel[HMSLogLevel["INFO"] = 2] = "INFO";
|
|
7
|
+
HMSLogLevel[HMSLogLevel["WARN"] = 3] = "WARN";
|
|
8
|
+
HMSLogLevel[HMSLogLevel["ERROR"] = 4] = "ERROR";
|
|
9
|
+
HMSLogLevel[HMSLogLevel["NONE"] = 5] = "NONE";
|
|
10
|
+
})(HMSLogLevel || (HMSLogLevel = {}));
|
|
11
|
+
|
|
12
|
+
class HMSLogger {
|
|
13
|
+
static v(tag, ...data) {
|
|
14
|
+
this.log(HMSLogLevel.VERBOSE, tag, ...data);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static d(tag, ...data) {
|
|
18
|
+
this.log(HMSLogLevel.DEBUG, tag, ...data);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static i(tag, ...data) {
|
|
22
|
+
this.log(HMSLogLevel.INFO, tag, ...data);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static w(tag, ...data) {
|
|
26
|
+
this.log(HMSLogLevel.WARN, tag, ...data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static e(tag, ...data) {
|
|
30
|
+
this.log(HMSLogLevel.ERROR, tag, ...data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static log(level, tag, ...data) {
|
|
34
|
+
if (this.level.valueOf() > level.valueOf()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch (level) {
|
|
39
|
+
case HMSLogLevel.VERBOSE:
|
|
40
|
+
{
|
|
41
|
+
console.log('HMSui-components: ', tag, ...data);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
case HMSLogLevel.DEBUG:
|
|
46
|
+
{
|
|
47
|
+
console.debug('HMSui-components: ', tag, ...data);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
case HMSLogLevel.INFO:
|
|
52
|
+
{
|
|
53
|
+
console.info('HMSui-components: ', tag, ...data);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case HMSLogLevel.WARN:
|
|
58
|
+
{
|
|
59
|
+
console.warn('HMSui-components: ', tag, ...data);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
case HMSLogLevel.ERROR:
|
|
64
|
+
{
|
|
65
|
+
console.error('HMSui-components: ', tag, ...data);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
HMSLogger.level = HMSLogLevel.VERBOSE;
|
|
74
|
+
export { HMSLogLevel, HMSLogger as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as r}from"react";import{selectTrackAudioByID as o}from"@100mslive/hms-video-store";import{useHMSVanillaStore as t}from"./HmsRoomProvider.js";function e({trackId:e,getStyle:s,ref:c}){const i=t();r((()=>i.subscribe((r=>{if(!c.current)return;const o=s(r);console.log(o,r);for(const r in o)c.current.style[r]=o[r]}),o(e))),[e])}export{e as useAudioLevel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isBrowser as
|
|
1
|
+
import{isBrowser as e}from"@100mslive/hms-video";import{selectLocalPeer as o,selectRoomState as r,selectIsLocalAudioEnabled as i,selectIsLocalVideoDisplayEnabled as s,selectIsAllowedToPublish as m,HMSRoomState as t}from"@100mslive/hms-video-store";import{useState as n,useEffect as a}from"react";import{useHMSActions as d,useHMSStore as l}from"./HmsRoomProvider.js";const v=(v,c="preview")=>{const[p,u]=n(!1),w=d(),P=l(o),b=l(r),f=l(i),h=l(s),E=l(m),T=p||b!==t.Preview;return a((()=>{b===t.Disconnected&&w.preview({userName:c,authToken:v}),e&&(window.onunload=()=>w.leave())}),[b,w,v]),{localPeer:P,roomState:b,audioEnabled:f,videoEnabled:h,isAllowedToPublish:E,disableJoin:T,actions:w,setInProgress:u}};export{v as usePreview};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{selectTrackByID as o}from"@100mslive/hms-video-store";import{useRef as e,useCallback as r,useEffect as i}from"react";import{useInView as t}from"react-intersection-observer";import{useHMSActions as n,useHMSStore as l}from"./HmsRoomProvider.js";const d=d=>{const c=n(),s=e(null),{ref:a,inView:m}=t({threshold:.5}),u=r((o=>{s.current=o,a(o)}),[a]),v=l(o(d));return i((()=>{(async()=>{s.current&&v&&(m&&v.enabled?(console.log("****** ENABLE VIDEO *******"),await c.attachVideo(v.id,s.current)):(console.log("****** DETACH VIDEO *******"),await c.detachVideo(v.id,s.current)))})()}),[m,s,null==v?void 0:v.id,null==v?void 0:v.enabled,null==v?void 0:v.deviceID,null==v?void 0:v.plugins]),u};export{d as useVideo};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{selectTracksMap as t}from"@100mslive/hms-video-store";import{useMemo as e}from"react";import{getVideoTracksFromPeers as o,getModeAspectRatio as a,calculateLayoutSizes as i,chunkElements as r}from"../utils/layout.js";import{useHMSVanillaStore as s}from"./HmsRoomProvider.js";const n=({maxTileCount:n,maxColCount:l,maxRowCount:h,width:m,height:g,showScreenFn:u=(()=>!1),peers:d,overflow:f="scroll-x",aspectRatio:P})=>{const c=s().getState(t),p=o(d,c,u),x=e((()=>{if(P)return P;return{width:a(p)||1,height:1}}),[P,p]),C=p.length,{tilesInFirstPage:F,defaultWidth:w,defaultHeight:H,lastPageWidth:W,lastPageHeight:R,isLastPageDifferentFromFirstPage:v}=e((()=>i({count:C,parentWidth:Math.floor(m),parentHeight:Math.floor(g),maxTileCount:n,maxRowCount:h,maxColCount:l,aspectRatio:x})),[C,m,g,n,h,l,x]);return{chunkedTracksWithPeer:e((()=>r({elements:p,tilesInFirstPage:F,onlyOnePage:"hidden"===f,isLastPageDifferentFromFirstPage:v,defaultWidth:w,defaultHeight:H,lastPageWidth:W,lastPageHeight:R})),[p,F,f,v,w,H,W,R])}};export{n as useVideoList};
|