@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,166 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
HMSConfigInitialSettings,
|
|
4
|
-
HMSICEServer,
|
|
5
|
-
HMSPreviewConfig,
|
|
6
|
-
HMSRoomState,
|
|
7
|
-
selectIsConnectedToRoom,
|
|
8
|
-
selectRoomState,
|
|
9
|
-
} from '@100mslive/hms-video-store';
|
|
10
|
-
import { hooksErrHandler } from './types';
|
|
11
|
-
import { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';
|
|
12
|
-
import { logErrorHandler } from '../utils/commons';
|
|
13
|
-
|
|
14
|
-
export interface usePreviewInput {
|
|
15
|
-
/**
|
|
16
|
-
* name of user who is joining, this is only required if join is called
|
|
17
|
-
*/
|
|
18
|
-
name?: string;
|
|
19
|
-
/**
|
|
20
|
-
* app side authentication token
|
|
21
|
-
*/
|
|
22
|
-
token: string;
|
|
23
|
-
/**
|
|
24
|
-
* any extra metadata info for the peer
|
|
25
|
-
*/
|
|
26
|
-
metadata?: string;
|
|
27
|
-
/**
|
|
28
|
-
* function to handle errors happening during preview
|
|
29
|
-
*/
|
|
30
|
-
handleError?: hooksErrHandler;
|
|
31
|
-
initEndpoint?: string;
|
|
32
|
-
/**
|
|
33
|
-
* initial settings for audio/video and device to be used.
|
|
34
|
-
*/
|
|
35
|
-
initialSettings?: HMSConfigInitialSettings;
|
|
36
|
-
/**
|
|
37
|
-
* Enable to get a network quality score while in preview. The score ranges from -1 to 5.
|
|
38
|
-
* -1 when we are not able to connect to 100ms servers within an expected time limit
|
|
39
|
-
* 0 when there is a timeout/failure when measuring the quality
|
|
40
|
-
* 1-5 ranges from poor to good quality.
|
|
41
|
-
*/
|
|
42
|
-
captureNetworkQualityInPreview?: boolean;
|
|
43
|
-
asRole?: string;
|
|
44
|
-
/**
|
|
45
|
-
* if this flag is enabled, the SDK takes care of unsubscribing to the video when it goes out of view.
|
|
46
|
-
* Additionally if simulcast is enabled, it takes care of auto managing simulcast layers based on the
|
|
47
|
-
* dimensions of the video element to conserve bandwidth.
|
|
48
|
-
*/
|
|
49
|
-
autoManageVideo?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* if this flag is enabled, wake lock will be acquired automatically(if supported) when joining the room, so the device
|
|
52
|
-
* will be kept awake.
|
|
53
|
-
*/
|
|
54
|
-
autoManageWakeLock?: boolean;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* use custom STUN/TURN servers for media connection (advanced)
|
|
58
|
-
*/
|
|
59
|
-
iceServers?: HMSICEServer[];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface usePreviewResult {
|
|
63
|
-
/**
|
|
64
|
-
* enable the join button for the user only when this is true
|
|
65
|
-
*/
|
|
66
|
-
enableJoin: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* call this function to join the room
|
|
69
|
-
*/
|
|
70
|
-
join: () => Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* once the user has joined the room, till leave happens this flag will be true. It can be used
|
|
73
|
-
* to decide to show between preview form and conferencing component/video tiles.
|
|
74
|
-
*/
|
|
75
|
-
isConnected: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* call this function to join the room
|
|
78
|
-
*/
|
|
79
|
-
preview: () => Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* This hook can be used to build a preview UI component, this lets you call preview every time the passed in
|
|
84
|
-
* token changes. This hook is best used in combination with useDevices for changing devices, useAVToggle for
|
|
85
|
-
* muting/unmuting and useAudioLevelStyles for showing mic audio level to the user.
|
|
86
|
-
* Any device change or mute/unmute will be carried across to join.
|
|
87
|
-
*/
|
|
88
|
-
export const usePreviewJoin = ({
|
|
89
|
-
name = '',
|
|
90
|
-
token,
|
|
91
|
-
metadata,
|
|
92
|
-
handleError = logErrorHandler,
|
|
93
|
-
initEndpoint,
|
|
94
|
-
initialSettings,
|
|
95
|
-
captureNetworkQualityInPreview,
|
|
96
|
-
asRole,
|
|
97
|
-
autoManageVideo,
|
|
98
|
-
autoManageWakeLock,
|
|
99
|
-
iceServers,
|
|
100
|
-
}: usePreviewInput): usePreviewResult => {
|
|
101
|
-
const actions = useHMSActions();
|
|
102
|
-
const roomState = useHMSStore(selectRoomState);
|
|
103
|
-
const isConnected = useHMSStore(selectIsConnectedToRoom) || false;
|
|
104
|
-
const enableJoin = roomState === HMSRoomState.Preview;
|
|
105
|
-
|
|
106
|
-
const config: HMSPreviewConfig = useMemo(() => {
|
|
107
|
-
return {
|
|
108
|
-
userName: name,
|
|
109
|
-
authToken: token,
|
|
110
|
-
metaData: metadata,
|
|
111
|
-
rememberDeviceSelection: true,
|
|
112
|
-
settings: initialSettings,
|
|
113
|
-
initEndpoint: initEndpoint,
|
|
114
|
-
asRole,
|
|
115
|
-
captureNetworkQualityInPreview,
|
|
116
|
-
autoManageVideo,
|
|
117
|
-
autoManageWakeLock,
|
|
118
|
-
iceServers,
|
|
119
|
-
};
|
|
120
|
-
}, [
|
|
121
|
-
name,
|
|
122
|
-
token,
|
|
123
|
-
metadata,
|
|
124
|
-
initEndpoint,
|
|
125
|
-
initialSettings,
|
|
126
|
-
captureNetworkQualityInPreview,
|
|
127
|
-
asRole,
|
|
128
|
-
autoManageVideo,
|
|
129
|
-
autoManageWakeLock,
|
|
130
|
-
iceServers,
|
|
131
|
-
]);
|
|
132
|
-
|
|
133
|
-
const preview = useCallback(async () => {
|
|
134
|
-
if (!token) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
if (isConnected || roomState !== HMSRoomState.Disconnected) {
|
|
139
|
-
await actions.leave().catch(() => {
|
|
140
|
-
// Do nothing as this might lead to leave called before join
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
await actions.preview(config);
|
|
144
|
-
} catch (err) {
|
|
145
|
-
handleError(err as Error, 'preview');
|
|
146
|
-
}
|
|
147
|
-
}, [token, isConnected, roomState, actions, config, handleError]);
|
|
148
|
-
|
|
149
|
-
const join = useCallback(async () => {
|
|
150
|
-
if (!token) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
await actions.join(config);
|
|
155
|
-
} catch (err) {
|
|
156
|
-
handleError(err as Error, 'join');
|
|
157
|
-
}
|
|
158
|
-
}, [actions, config, handleError, token]);
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
enableJoin,
|
|
162
|
-
join,
|
|
163
|
-
isConnected,
|
|
164
|
-
preview,
|
|
165
|
-
};
|
|
166
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { selectHLSState, selectRecordingState, selectRTMPState } from '@100mslive/hms-video-store';
|
|
2
|
-
import { useHMSStore } from '../primitives/HmsRoomProvider';
|
|
3
|
-
|
|
4
|
-
export interface useRecordingStreamingResult {
|
|
5
|
-
isServerRecordingOn: boolean;
|
|
6
|
-
isBrowserRecordingOn: boolean;
|
|
7
|
-
isHLSRecordingOn: boolean;
|
|
8
|
-
isStreamingOn: boolean;
|
|
9
|
-
isHLSRunning: boolean;
|
|
10
|
-
isRTMPRunning: boolean;
|
|
11
|
-
isRecordingOn: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useRecordingStreaming = (): useRecordingStreamingResult => {
|
|
15
|
-
const recording = useHMSStore(selectRecordingState);
|
|
16
|
-
const rtmp = useHMSStore(selectRTMPState);
|
|
17
|
-
const hls = useHMSStore(selectHLSState);
|
|
18
|
-
|
|
19
|
-
const isServerRecordingOn = recording.server.running;
|
|
20
|
-
const isBrowserRecordingOn = recording.browser.running;
|
|
21
|
-
const isHLSRecordingOn = recording.hls.running;
|
|
22
|
-
const isStreamingOn = hls.running || rtmp.running;
|
|
23
|
-
const isRecordingOn = isServerRecordingOn || isBrowserRecordingOn || isHLSRecordingOn;
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
isServerRecordingOn,
|
|
27
|
-
isBrowserRecordingOn,
|
|
28
|
-
isHLSRecordingOn,
|
|
29
|
-
isStreamingOn,
|
|
30
|
-
isHLSRunning: hls.running,
|
|
31
|
-
isRTMPRunning: rtmp.running,
|
|
32
|
-
isRecordingOn,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
HMSActions,
|
|
5
|
-
HMSTrack,
|
|
6
|
-
HMSTrackID,
|
|
7
|
-
selectAudioTrackByID,
|
|
8
|
-
selectAudioTrackVolume,
|
|
9
|
-
selectPermissions,
|
|
10
|
-
selectVideoTrackByID,
|
|
11
|
-
} from '@100mslive/hms-video-store';
|
|
12
|
-
import { hooksErrHandler } from './types';
|
|
13
|
-
import { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';
|
|
14
|
-
import { logErrorHandler } from '../utils/commons';
|
|
15
|
-
|
|
16
|
-
export interface useRemoteAVToggleResult {
|
|
17
|
-
/**
|
|
18
|
-
* true if unmuted and vice versa
|
|
19
|
-
*/
|
|
20
|
-
isAudioEnabled: boolean;
|
|
21
|
-
isVideoEnabled: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* current volume of the audio track
|
|
24
|
-
*/
|
|
25
|
-
volume?: number;
|
|
26
|
-
/**
|
|
27
|
-
* use this function to toggle audio state, the function will only be present if the user
|
|
28
|
-
* has permission to mute/unmute remote audio
|
|
29
|
-
*/
|
|
30
|
-
toggleAudio?: () => void;
|
|
31
|
-
/**
|
|
32
|
-
* use this function to toggle video state, the function will only be present if the user
|
|
33
|
-
* has permission to mute/unmute remote video
|
|
34
|
-
*/
|
|
35
|
-
toggleVideo?: () => void;
|
|
36
|
-
/**
|
|
37
|
-
* use this function to set the volume of peer's audio track for the local user, the function will
|
|
38
|
-
* only be present if the remote peer has an audio track to change volume for
|
|
39
|
-
*/
|
|
40
|
-
setVolume?: (volume: number) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const toggleTrackEnabled = async (
|
|
44
|
-
actions: HMSActions,
|
|
45
|
-
track: HMSTrack | undefined | null,
|
|
46
|
-
handleError: hooksErrHandler,
|
|
47
|
-
) => {
|
|
48
|
-
if (track) {
|
|
49
|
-
try {
|
|
50
|
-
await actions.setRemoteTrackEnabled(track.id, !track.enabled);
|
|
51
|
-
} catch (err) {
|
|
52
|
-
handleError(err as Error, 'remoteToggle');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* This hook can be used to implement remote mute/unmute + audio volume changer on tile level.
|
|
59
|
-
* @param peerId of the peer whose tracks need to be managed
|
|
60
|
-
* @param audioTrackId of the peer whose tracks need to be managed
|
|
61
|
-
* @param videoTrackId of the peer whose tracks need to be managed
|
|
62
|
-
* @param handleError to handle any error during toggle of audio/video
|
|
63
|
-
*/
|
|
64
|
-
export const useRemoteAVToggle = (
|
|
65
|
-
audioTrackId: HMSTrackID,
|
|
66
|
-
videoTrackId: HMSTrackID,
|
|
67
|
-
handleError: hooksErrHandler = logErrorHandler,
|
|
68
|
-
): useRemoteAVToggleResult => {
|
|
69
|
-
const actions = useHMSActions();
|
|
70
|
-
const audioTrack = useHMSStore(selectAudioTrackByID(audioTrackId));
|
|
71
|
-
const videoTrack = useHMSStore(selectVideoTrackByID(videoTrackId));
|
|
72
|
-
const volume = useHMSStore(selectAudioTrackVolume(audioTrack?.id));
|
|
73
|
-
const permissions = useHMSStore(selectPermissions);
|
|
74
|
-
const canToggleVideo = videoTrack?.enabled ? permissions?.mute : permissions?.unmute;
|
|
75
|
-
const canToggleAudio = audioTrack?.enabled ? permissions?.mute : permissions?.unmute;
|
|
76
|
-
|
|
77
|
-
const toggleAudio = useCallback(async () => {
|
|
78
|
-
await toggleTrackEnabled(actions, audioTrack, handleError);
|
|
79
|
-
}, [actions, audioTrack, handleError]);
|
|
80
|
-
|
|
81
|
-
const toggleVideo = useCallback(async () => {
|
|
82
|
-
await toggleTrackEnabled(actions, videoTrack, handleError);
|
|
83
|
-
}, [actions, handleError, videoTrack]);
|
|
84
|
-
|
|
85
|
-
const setVolume = useCallback(
|
|
86
|
-
(volume: number) => {
|
|
87
|
-
if (audioTrack) {
|
|
88
|
-
actions.setVolume(volume, audioTrack.id);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
[actions, audioTrack],
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
isAudioEnabled: !!audioTrack?.enabled,
|
|
96
|
-
isVideoEnabled: !!videoTrack?.enabled,
|
|
97
|
-
volume,
|
|
98
|
-
toggleAudio: audioTrack && canToggleAudio ? toggleAudio : undefined,
|
|
99
|
-
toggleVideo: videoTrack?.source === 'regular' && canToggleVideo ? toggleVideo : undefined,
|
|
100
|
-
setVolume: audioTrack ? setVolume : undefined,
|
|
101
|
-
};
|
|
102
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
HMSPeerID,
|
|
4
|
-
HMSScreenShareConfig,
|
|
5
|
-
HMSTrackID,
|
|
6
|
-
selectIsLocalScreenShared,
|
|
7
|
-
selectPeerScreenSharing,
|
|
8
|
-
selectScreenSharesByPeerId,
|
|
9
|
-
} from '@100mslive/hms-video-store';
|
|
10
|
-
import { hooksErrHandler } from '../hooks/types';
|
|
11
|
-
import { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';
|
|
12
|
-
import { logErrorHandler } from '../utils/commons';
|
|
13
|
-
|
|
14
|
-
export interface useScreenShareResult {
|
|
15
|
-
/**
|
|
16
|
-
* true if the local user is sharing screen, false otherwise
|
|
17
|
-
*/
|
|
18
|
-
amIScreenSharing: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* toggle screenshare for the local user, will only be present if the user has the permission to toggle
|
|
21
|
-
*/
|
|
22
|
-
toggleScreenShare?: (config?: HMSScreenShareConfig) => Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* the id of the peer who is currently sharing screen, will only be present if there is a screenshare in the room.
|
|
25
|
-
* In case of multiple screenshares, the behaviour of which one is picked is not defined.
|
|
26
|
-
*/
|
|
27
|
-
screenSharingPeerId?: HMSPeerID;
|
|
28
|
-
/**
|
|
29
|
-
* the name of the peer who is currently sharing screen. Will be undefined if no one is sharing the screen.
|
|
30
|
-
* In case of multiple screenshares, the behavior of which one is picked is not defined.
|
|
31
|
-
*/
|
|
32
|
-
screenSharingPeerName?: string;
|
|
33
|
-
/**
|
|
34
|
-
* screenShare audio track id, will only be present if there is a screenshare with video track
|
|
35
|
-
*/
|
|
36
|
-
screenShareVideoTrackId?: HMSTrackID;
|
|
37
|
-
/**
|
|
38
|
-
* screenShare audio track id, will only be present if there is a screenshare with audio track
|
|
39
|
-
*/
|
|
40
|
-
screenShareAudioTrackId?: HMSTrackID;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* This hook can be used to implement a screenshare toggle button as well as know about the screenshare in the room.
|
|
45
|
-
* This works best if your application only needs to show one screenshare in large view at a time with other screenshares
|
|
46
|
-
* similar to normal user tiles.
|
|
47
|
-
* For any complicated requirement with multiple screenshares it's best to use the store directly.
|
|
48
|
-
* For viewing the screenshare this hook is best used in combination with useVideo.
|
|
49
|
-
* For implementing control bar for local peer, this is used based with useAVToggle.
|
|
50
|
-
* @param handleError to handle any errors during screenshare toggle
|
|
51
|
-
*/
|
|
52
|
-
export const useScreenShare = (handleError: hooksErrHandler = logErrorHandler): useScreenShareResult => {
|
|
53
|
-
const actions = useHMSActions();
|
|
54
|
-
const amIScreenSharing = useHMSStore(selectIsLocalScreenShared);
|
|
55
|
-
const screenSharePeer = useHMSStore(selectPeerScreenSharing);
|
|
56
|
-
const screenShare = useHMSStore(selectScreenSharesByPeerId(screenSharePeer?.id));
|
|
57
|
-
|
|
58
|
-
const toggleScreenShare = useCallback(
|
|
59
|
-
async (config?: HMSScreenShareConfig) => {
|
|
60
|
-
try {
|
|
61
|
-
await actions.setScreenShareEnabled(!amIScreenSharing, config);
|
|
62
|
-
} catch (err) {
|
|
63
|
-
handleError(err as Error, 'toggleScreenShare');
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
[actions, amIScreenSharing, handleError],
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
amIScreenSharing,
|
|
71
|
-
screenSharingPeerId: screenSharePeer?.id,
|
|
72
|
-
screenSharingPeerName: screenSharePeer?.name,
|
|
73
|
-
screenShareVideoTrackId: screenShare?.video?.id,
|
|
74
|
-
screenShareAudioTrackId: screenShare?.audio?.id,
|
|
75
|
-
toggleScreenShare,
|
|
76
|
-
};
|
|
77
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { HMSNotificationTypes } from '@100mslive/hms-video-store';
|
|
3
|
-
import { hooksErrHandler } from './types';
|
|
4
|
-
import { useHMSVanillaNotifications } from '../primitives/HmsRoomProvider';
|
|
5
|
-
import { logErrorHandler } from '../utils/commons';
|
|
6
|
-
|
|
7
|
-
export interface HMSTranscript {
|
|
8
|
-
start: number;
|
|
9
|
-
end: number;
|
|
10
|
-
peer_id: string;
|
|
11
|
-
final: boolean;
|
|
12
|
-
transcript: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface useHMSTranscriptInput {
|
|
16
|
-
onTranscript?: (data: HMSTranscript[]) => void;
|
|
17
|
-
handleError?: hooksErrHandler;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A generic function to implement [custom events](https://www.100ms.live/docs/javascript/v2/features/chat#custom-events) in your UI.
|
|
22
|
-
* The data to be sent to remote is expected to be a serializable JSON. The serialization
|
|
23
|
-
* and deserialization is taken care of by the hook.
|
|
24
|
-
*/
|
|
25
|
-
export const useTranscript = ({ onTranscript, handleError = logErrorHandler }: useHMSTranscriptInput) => {
|
|
26
|
-
const type = 'hms_transcript';
|
|
27
|
-
const notifications = useHMSVanillaNotifications();
|
|
28
|
-
|
|
29
|
-
// this is to handle messages from remote peers
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (!notifications) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const unsubscribe = notifications.onNotification(notification => {
|
|
35
|
-
const msg = notification.data;
|
|
36
|
-
if (msg && msg.type === type) {
|
|
37
|
-
try {
|
|
38
|
-
const message = JSON.parse(msg.message);
|
|
39
|
-
const data = message.results as HMSTranscript[];
|
|
40
|
-
onTranscript?.(data);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
handleError(err as Error, 'handleCaptionEvent');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, HMSNotificationTypes.NEW_MESSAGE);
|
|
46
|
-
return unsubscribe;
|
|
47
|
-
}, [notifications, type, handleError, onTranscript]);
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
};
|
package/src/hooks/useVideo.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
|
-
import { HMSTrackID, selectVideoTrackByID } from '@100mslive/hms-video-store';
|
|
3
|
-
import { useHMSActions, useHMSStore } from '../primitives/HmsRoomProvider';
|
|
4
|
-
import HMSLogger from '../utils/logger';
|
|
5
|
-
|
|
6
|
-
export interface useVideoInput {
|
|
7
|
-
/**
|
|
8
|
-
* TrackId that is to be rendered
|
|
9
|
-
*/
|
|
10
|
-
trackId?: HMSTrackID;
|
|
11
|
-
/**
|
|
12
|
-
* Boolean stating whether to override the internal behaviour.
|
|
13
|
-
* when attach is false, even if tile is inView or enabled, it won't be rendered
|
|
14
|
-
*/
|
|
15
|
-
attach?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export interface useVideoOutput {
|
|
18
|
-
videoRef: React.RefCallback<HTMLVideoElement>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* This hooks can be used to implement a video tile component. Given a track id it will return a ref.
|
|
22
|
-
* The returned ref can be used to set on a video element meant to display the video.
|
|
23
|
-
* The hook will take care of attaching and detaching video, and will automatically detach when the video
|
|
24
|
-
* goes out of view to save on bandwidth.
|
|
25
|
-
*/
|
|
26
|
-
export const useVideo = ({ trackId, attach }: useVideoInput): useVideoOutput => {
|
|
27
|
-
const actions = useHMSActions();
|
|
28
|
-
const videoRef = useRef<HTMLVideoElement | null>(null);
|
|
29
|
-
const track = useHMSStore(selectVideoTrackByID(trackId));
|
|
30
|
-
const prevTrackId = useRef<HMSTrackID | undefined>();
|
|
31
|
-
|
|
32
|
-
const setRefs = useCallback((node: HTMLVideoElement) => {
|
|
33
|
-
if (node) {
|
|
34
|
-
videoRef.current = node;
|
|
35
|
-
}
|
|
36
|
-
}, []);
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (!prevTrackId.current) {
|
|
40
|
-
prevTrackId.current = track?.id;
|
|
41
|
-
} else if (track?.id && prevTrackId.current !== track?.id) {
|
|
42
|
-
// Remove video element reference from previous track by detaching
|
|
43
|
-
(async () => {
|
|
44
|
-
if (videoRef.current) {
|
|
45
|
-
try {
|
|
46
|
-
HMSLogger.d('detaching because different track is passed');
|
|
47
|
-
await actions.detachVideo(prevTrackId.current!, videoRef.current);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
HMSLogger.w('detach video error for track', prevTrackId.current, err);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
prevTrackId.current = track?.id;
|
|
53
|
-
})();
|
|
54
|
-
}
|
|
55
|
-
}, [track?.id, actions]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
(async () => {
|
|
59
|
-
if (track?.id && videoRef.current) {
|
|
60
|
-
if (attach !== false) {
|
|
61
|
-
await actions.attachVideo(track.id, videoRef.current);
|
|
62
|
-
} else {
|
|
63
|
-
await actions.detachVideo(track.id, videoRef.current);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
})();
|
|
67
|
-
}, [track, attach, actions]);
|
|
68
|
-
|
|
69
|
-
// detach on unmount
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
return () => {
|
|
72
|
-
(async () => {
|
|
73
|
-
if (videoRef.current && track) {
|
|
74
|
-
try {
|
|
75
|
-
// detach on unmount
|
|
76
|
-
await actions.detachVideo(track.id, videoRef.current);
|
|
77
|
-
} catch (err) {
|
|
78
|
-
HMSLogger.w('detach video error for track', track.id, err);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
|
-
};
|
|
83
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
-
}, []);
|
|
85
|
-
|
|
86
|
-
return { videoRef: setRefs };
|
|
87
|
-
};
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import { useResizeDetector } from 'react-resize-detector';
|
|
3
|
-
import { HMSPeer, HMSTrack, HMSTrackID, selectTracksMap } from '@100mslive/hms-video-store';
|
|
4
|
-
import { useHMSVanillaStore } from '../primitives/HmsRoomProvider';
|
|
5
|
-
import {
|
|
6
|
-
calculateLayoutSizes,
|
|
7
|
-
chunkElements,
|
|
8
|
-
getModeAspectRatio,
|
|
9
|
-
getVideoTracksFromPeers,
|
|
10
|
-
TrackWithPeer,
|
|
11
|
-
} from '../utils/layout';
|
|
12
|
-
|
|
13
|
-
export interface useVideoListInput {
|
|
14
|
-
/**
|
|
15
|
-
* peers is the list of all peers you need to display
|
|
16
|
-
*/
|
|
17
|
-
peers: HMSPeer[];
|
|
18
|
-
/**
|
|
19
|
-
* Max tiles in a page. Overrides maxRowCount and maxColCount
|
|
20
|
-
*/
|
|
21
|
-
maxTileCount?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Max rows in a page. Only applied if maxTileCount is not present
|
|
24
|
-
*/
|
|
25
|
-
maxRowCount?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Max columns in a page. Only applied if maxTileCount and maxRowCount are not present
|
|
28
|
-
*/
|
|
29
|
-
maxColCount?: number;
|
|
30
|
-
/**
|
|
31
|
-
* A function which tells whether to show the screenshare for a peer who is sharing their screen. A peer is passed
|
|
32
|
-
* and a boolean value is expected.
|
|
33
|
-
* This can be useful if there are multiple screenShares in the room where you may want to show the main one in the
|
|
34
|
-
* center view and others in video list along side other tiles. No screenShare is included by default.
|
|
35
|
-
* for example. includeScreenShare = (peer) => return peer.id !== mainScreenSharingPeer.id
|
|
36
|
-
*/
|
|
37
|
-
includeScreenShareForPeer?: (peer: HMSPeer) => boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Aspect ratio of VideoTiles, ideally this should be the same as the aspect ratio selected for
|
|
40
|
-
* capture in the dashboard template.
|
|
41
|
-
*/
|
|
42
|
-
aspectRatio?: { width: number; height: number };
|
|
43
|
-
/**
|
|
44
|
-
* By default this will be true. Only publishing(audio/video/screen) peers in the passed in peer list
|
|
45
|
-
* will be filtered. If you wish to show all peers, pass false for this.
|
|
46
|
-
*/
|
|
47
|
-
filterNonPublishingPeers?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Height that would be subtracted from the parent's height to give the available height, use case: if your pagination is inside the parent component then offsetY would be the height of pagination
|
|
50
|
-
*/
|
|
51
|
-
offsetY?: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface useVideoListTile extends TrackWithPeer {
|
|
55
|
-
width: number;
|
|
56
|
-
height: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface useVideoResult {
|
|
60
|
-
/**
|
|
61
|
-
* This returns a list of all pages with every page containing the list of all tiles on it.
|
|
62
|
-
*/
|
|
63
|
-
pagesWithTiles: useVideoListTile[][];
|
|
64
|
-
/**
|
|
65
|
-
* add the ref to the element going to render the video list, this is used to measure the available
|
|
66
|
-
* space/dimensions in order to calculate the best fit
|
|
67
|
-
*/
|
|
68
|
-
ref: React.MutableRefObject<any>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const DEFAULTS = {
|
|
72
|
-
aspectRatio: {
|
|
73
|
-
width: 1,
|
|
74
|
-
height: 1,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* This hook can be used to build a paginated gallery view of video tiles. You can give the hook
|
|
80
|
-
* a list of all the peers which need to be shown and it tells you how to structure the UI by giving
|
|
81
|
-
* a list of pages with every page having a list of video tiles.
|
|
82
|
-
* Please check the documentation of input and output types for more details.
|
|
83
|
-
*/
|
|
84
|
-
export const useVideoList = ({
|
|
85
|
-
peers,
|
|
86
|
-
maxTileCount,
|
|
87
|
-
maxColCount,
|
|
88
|
-
maxRowCount,
|
|
89
|
-
includeScreenShareForPeer = () => false,
|
|
90
|
-
aspectRatio = DEFAULTS.aspectRatio,
|
|
91
|
-
filterNonPublishingPeers = true,
|
|
92
|
-
offsetY = 0,
|
|
93
|
-
}: useVideoListInput): useVideoResult => {
|
|
94
|
-
const { width = 0, height = 0, ref } = useResizeDetector();
|
|
95
|
-
const store = useHMSVanillaStore();
|
|
96
|
-
// using vanilla store as we don't need re-rendering every time something in a track changes
|
|
97
|
-
const tracksMap: Record<HMSTrackID, HMSTrack> = store.getState(selectTracksMap);
|
|
98
|
-
const tracksWithPeer: TrackWithPeer[] = getVideoTracksFromPeers(
|
|
99
|
-
peers,
|
|
100
|
-
tracksMap,
|
|
101
|
-
includeScreenShareForPeer,
|
|
102
|
-
filterNonPublishingPeers,
|
|
103
|
-
);
|
|
104
|
-
const finalAspectRatio = useMemo(() => {
|
|
105
|
-
if (aspectRatio) {
|
|
106
|
-
return aspectRatio;
|
|
107
|
-
}
|
|
108
|
-
const modeAspectRatio = getModeAspectRatio(tracksWithPeer);
|
|
109
|
-
// Default to 1 if there are no video tracks
|
|
110
|
-
return {
|
|
111
|
-
width: modeAspectRatio || 1,
|
|
112
|
-
height: 1,
|
|
113
|
-
};
|
|
114
|
-
}, [aspectRatio, tracksWithPeer]);
|
|
115
|
-
const count = tracksWithPeer.length;
|
|
116
|
-
const {
|
|
117
|
-
tilesInFirstPage,
|
|
118
|
-
defaultWidth,
|
|
119
|
-
defaultHeight,
|
|
120
|
-
lastPageWidth,
|
|
121
|
-
lastPageHeight,
|
|
122
|
-
isLastPageDifferentFromFirstPage,
|
|
123
|
-
} = useMemo(
|
|
124
|
-
() =>
|
|
125
|
-
calculateLayoutSizes({
|
|
126
|
-
count,
|
|
127
|
-
parentWidth: Math.floor(width),
|
|
128
|
-
parentHeight: Math.floor(height) - Math.min(height, offsetY),
|
|
129
|
-
maxTileCount,
|
|
130
|
-
maxRowCount,
|
|
131
|
-
maxColCount,
|
|
132
|
-
aspectRatio: finalAspectRatio,
|
|
133
|
-
}),
|
|
134
|
-
[count, width, height, maxTileCount, maxRowCount, maxColCount, finalAspectRatio, offsetY],
|
|
135
|
-
);
|
|
136
|
-
const chunkedTracksWithPeer = useMemo(
|
|
137
|
-
() =>
|
|
138
|
-
chunkElements<TrackWithPeer>({
|
|
139
|
-
elements: tracksWithPeer,
|
|
140
|
-
tilesInFirstPage,
|
|
141
|
-
onlyOnePage: false,
|
|
142
|
-
isLastPageDifferentFromFirstPage,
|
|
143
|
-
defaultWidth,
|
|
144
|
-
defaultHeight,
|
|
145
|
-
lastPageWidth,
|
|
146
|
-
lastPageHeight,
|
|
147
|
-
}),
|
|
148
|
-
[
|
|
149
|
-
tracksWithPeer,
|
|
150
|
-
tilesInFirstPage,
|
|
151
|
-
isLastPageDifferentFromFirstPage,
|
|
152
|
-
defaultWidth,
|
|
153
|
-
defaultHeight,
|
|
154
|
-
lastPageWidth,
|
|
155
|
-
lastPageHeight,
|
|
156
|
-
],
|
|
157
|
-
);
|
|
158
|
-
return {
|
|
159
|
-
pagesWithTiles: chunkedTracksWithPeer,
|
|
160
|
-
ref,
|
|
161
|
-
};
|
|
162
|
-
};
|