@100mslive/roomkit-react 0.3.2-alpha.0 → 0.3.2-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ import { match, P } from 'ts-pattern';
2
+ import { HMSPeer, selectPermissions, useHMSActions, useHMSStore } from '@100mslive/react-sdk';
3
+ import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
4
+
5
+ export const useGroupOnStageActions = ({ peers }: { peers: HMSPeer[] }) => {
6
+ const hmsActions = useHMSActions();
7
+ const { elements } = useRoomLayoutConferencingScreen();
8
+ const {
9
+ bring_to_stage_label,
10
+ remove_from_stage_label,
11
+ on_stage_role,
12
+ off_stage_roles = [],
13
+ skip_preview_for_role_change = false,
14
+ } = elements.on_stage_exp || {};
15
+ const canChangeRole = useHMSStore(selectPermissions)?.changeRole;
16
+
17
+ const offStageRolePeers = peers.filter(peer =>
18
+ match({ on_stage_role, bring_to_stage_label, roleName: peer.roleName })
19
+ .with(
20
+ {
21
+ on_stage_role: P.when(role => !!role),
22
+ bring_to_stage_label: P.when(label => !!label),
23
+ roleName: P.when(role => !!role && off_stage_roles.includes(role)),
24
+ },
25
+ () => true,
26
+ )
27
+ .otherwise(() => false),
28
+ );
29
+
30
+ const lowerAllHands = async () => {
31
+ return Promise.all(peers.map(peer => hmsActions.lowerRemotePeerHand(peer.id)));
32
+ };
33
+
34
+ const bringAllToStage = () => {
35
+ if (!canChangeRole || !on_stage_role) {
36
+ return;
37
+ }
38
+ return Promise.all(
39
+ offStageRolePeers.map(peer => {
40
+ return hmsActions.changeRoleOfPeer(peer.id, on_stage_role, skip_preview_for_role_change).then(() => {
41
+ return skip_preview_for_role_change ? hmsActions.lowerRemotePeerHand(peer.id) : null;
42
+ });
43
+ }),
44
+ );
45
+ };
46
+
47
+ return {
48
+ lowerAllHands,
49
+ bringAllToStage,
50
+ canBringToStage: canChangeRole && offStageRolePeers.length > 0,
51
+ bring_to_stage_label,
52
+ remove_from_stage_label,
53
+ };
54
+ };
@@ -0,0 +1,49 @@
1
+ import { useState } from 'react';
2
+ import { selectPeerMetadata, selectPermissions, useHMSActions, useHMSStore } from '@100mslive/react-sdk';
3
+ import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
4
+
5
+ export const usePeerOnStageActions = ({ peerId, role }: { peerId: string; role: string }) => {
6
+ const hmsActions = useHMSActions();
7
+ const { elements } = useRoomLayoutConferencingScreen();
8
+ const {
9
+ bring_to_stage_label,
10
+ remove_from_stage_label,
11
+ on_stage_role,
12
+ off_stage_roles = [],
13
+ skip_preview_for_role_change = false,
14
+ } = elements.on_stage_exp || {};
15
+ const isInStage = role === on_stage_role;
16
+ const canChangeRole = useHMSStore(selectPermissions)?.changeRole;
17
+ const shouldShowStageRoleChange =
18
+ canChangeRole &&
19
+ ((isInStage && remove_from_stage_label) || (off_stage_roles?.includes(role) && bring_to_stage_label));
20
+ const prevRole = useHMSStore(selectPeerMetadata(peerId))?.prevRole;
21
+ const [open, setOpen] = useState(false);
22
+
23
+ const lowerPeerHand = async () => {
24
+ await hmsActions.lowerRemotePeerHand(peerId);
25
+ };
26
+
27
+ const handleStageAction = async () => {
28
+ if (isInStage) {
29
+ prevRole && hmsActions.changeRoleOfPeer(peerId, prevRole, true);
30
+ } else if (on_stage_role) {
31
+ await hmsActions.changeRoleOfPeer(peerId, on_stage_role, skip_preview_for_role_change);
32
+ if (skip_preview_for_role_change) {
33
+ await lowerPeerHand();
34
+ }
35
+ }
36
+ setOpen(false);
37
+ };
38
+
39
+ return {
40
+ open,
41
+ setOpen,
42
+ lowerPeerHand,
43
+ handleStageAction,
44
+ shouldShowStageRoleChange,
45
+ isInStage,
46
+ bring_to_stage_label,
47
+ remove_from_stage_label,
48
+ };
49
+ };
@@ -193,7 +193,6 @@ const SidePane = ({
193
193
  });
194
194
 
195
195
  if (!trackId && !SidepaneComponent) {
196
- console.log('sidepane not rendered', { trackId, SidepaneComponent });
197
196
  return null;
198
197
  }
199
198