@100mslive/react-native-room-kit 1.0.1 → 1.0.2-beta.1

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.
Files changed (262) hide show
  1. package/lib/commonjs/HMSPrebuilt.js +16 -14
  2. package/lib/commonjs/HMSPrebuilt.js.map +1 -1
  3. package/lib/commonjs/HMSRoomSetup.js +85 -44
  4. package/lib/commonjs/HMSRoomSetup.js.map +1 -1
  5. package/lib/commonjs/Icons/Hand/assets/hand-off.png +0 -0
  6. package/lib/commonjs/Icons/Hand/assets/hand-off@2x.png +0 -0
  7. package/lib/commonjs/Icons/Hand/assets/hand-off@3x.png +0 -0
  8. package/lib/commonjs/Icons/Hand/index.js +2 -1
  9. package/lib/commonjs/Icons/Hand/index.js.map +1 -1
  10. package/lib/commonjs/Icons/Recording/assets/recording-off.png +0 -0
  11. package/lib/commonjs/Icons/Recording/assets/recording-off@2x.png +0 -0
  12. package/lib/commonjs/Icons/Recording/assets/recording-off@3x.png +0 -0
  13. package/lib/commonjs/Icons/Recording/index.js +2 -1
  14. package/lib/commonjs/Icons/Recording/index.js.map +1 -1
  15. package/lib/commonjs/components/DisplayView.js +3 -1
  16. package/lib/commonjs/components/DisplayView.js.map +1 -1
  17. package/lib/commonjs/components/EndRoomModal.js +29 -0
  18. package/lib/commonjs/components/EndRoomModal.js.map +1 -0
  19. package/lib/commonjs/components/EndRoomModalContent.js +9 -2
  20. package/lib/commonjs/components/EndRoomModalContent.js.map +1 -1
  21. package/lib/commonjs/components/Footer.js +9 -1
  22. package/lib/commonjs/components/Footer.js.map +1 -1
  23. package/lib/commonjs/components/HMSKeyboardAvoidingView.js +3 -18
  24. package/lib/commonjs/components/HMSKeyboardAvoidingView.js.map +1 -1
  25. package/lib/commonjs/components/HMSLocalScreenshareNotification.js +2 -2
  26. package/lib/commonjs/components/HMSLocalScreenshareNotification.js.map +1 -1
  27. package/lib/commonjs/components/HMSManageLeave.js +3 -178
  28. package/lib/commonjs/components/HMSManageLeave.js.map +1 -1
  29. package/lib/commonjs/components/HMSNotification.js +4 -3
  30. package/lib/commonjs/components/HMSNotification.js.map +1 -1
  31. package/lib/commonjs/components/HMSNotifications.js +32 -6
  32. package/lib/commonjs/components/HMSNotifications.js.map +1 -1
  33. package/lib/commonjs/components/HMSOverlayChatView.js +7 -1
  34. package/lib/commonjs/components/HMSOverlayChatView.js.map +1 -1
  35. package/lib/commonjs/components/HMSReconnectingNotification.js +33 -0
  36. package/lib/commonjs/components/HMSReconnectingNotification.js.map +1 -0
  37. package/lib/commonjs/components/HMSRecordingIndicator.js +1 -1
  38. package/lib/commonjs/components/HMSRecordingIndicator.js.map +1 -1
  39. package/lib/commonjs/components/HMSTerminalErrorNotification.js +66 -0
  40. package/lib/commonjs/components/HMSTerminalErrorNotification.js.map +1 -0
  41. package/lib/commonjs/components/LeaveRoomBottomSheet.js +175 -0
  42. package/lib/commonjs/components/LeaveRoomBottomSheet.js.map +1 -0
  43. package/lib/commonjs/components/Meeting.js +4 -0
  44. package/lib/commonjs/components/Meeting.js.map +1 -1
  45. package/lib/commonjs/components/MeetingScreenContent.js +3 -2
  46. package/lib/commonjs/components/MeetingScreenContent.js.map +1 -1
  47. package/lib/commonjs/components/PIPView.js +80 -15
  48. package/lib/commonjs/components/PIPView.js.map +1 -1
  49. package/lib/commonjs/components/Participants/ParticipantsItemOptions.js +23 -1
  50. package/lib/commonjs/components/Participants/ParticipantsItemOptions.js.map +1 -1
  51. package/lib/commonjs/components/PeerVideoTile/AvatarView.js +4 -4
  52. package/lib/commonjs/components/PeerVideoTile/PeerAudioIndicator.js +3 -1
  53. package/lib/commonjs/components/PeerVideoTile/PeerAudioIndicator.js.map +1 -1
  54. package/lib/commonjs/components/PeerVideoTile/PeerVideoTileView.js +1 -1
  55. package/lib/commonjs/components/PeerVideoTile/PeerVideoTileView.js.map +1 -1
  56. package/lib/commonjs/components/PreviewForRoleChangeModal.js +2 -2
  57. package/lib/commonjs/components/PreviewForRoleChangeModal.js.map +1 -1
  58. package/lib/commonjs/components/RoomSettingsModalContent.js +4 -7
  59. package/lib/commonjs/components/RoomSettingsModalContent.js.map +1 -1
  60. package/lib/commonjs/components/StopRecordingModalContent.js +4 -1
  61. package/lib/commonjs/components/StopRecordingModalContent.js.map +1 -1
  62. package/lib/commonjs/hooks-util.js +193 -28
  63. package/lib/commonjs/hooks-util.js.map +1 -1
  64. package/lib/commonjs/index.js +11 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/redux/actionTypes.js +6 -1
  67. package/lib/commonjs/redux/actionTypes.js.map +1 -1
  68. package/lib/commonjs/redux/actions/index.js +22 -1
  69. package/lib/commonjs/redux/actions/index.js.map +1 -1
  70. package/lib/commonjs/redux/reducers/appState.js +17 -1
  71. package/lib/commonjs/redux/reducers/appState.js.map +1 -1
  72. package/lib/commonjs/redux/reducers/hmsStates.js +15 -4
  73. package/lib/commonjs/redux/reducers/hmsStates.js.map +1 -1
  74. package/lib/commonjs/redux/reducers/userState.js +5 -1
  75. package/lib/commonjs/redux/reducers/userState.js.map +1 -1
  76. package/lib/commonjs/types.js +10 -1
  77. package/lib/commonjs/types.js.map +1 -1
  78. package/lib/commonjs/utils/types.js +11 -1
  79. package/lib/commonjs/utils/types.js.map +1 -1
  80. package/lib/commonjs/utils.js +1 -7
  81. package/lib/commonjs/utils.js.map +1 -1
  82. package/lib/module/HMSPrebuilt.js +16 -14
  83. package/lib/module/HMSPrebuilt.js.map +1 -1
  84. package/lib/module/HMSRoomSetup.js +81 -40
  85. package/lib/module/HMSRoomSetup.js.map +1 -1
  86. package/lib/module/Icons/Hand/assets/hand-off.png +0 -0
  87. package/lib/module/Icons/Hand/assets/hand-off@2x.png +0 -0
  88. package/lib/module/Icons/Hand/assets/hand-off@3x.png +0 -0
  89. package/lib/module/Icons/Hand/index.js +2 -1
  90. package/lib/module/Icons/Hand/index.js.map +1 -1
  91. package/lib/module/Icons/Recording/assets/recording-off.png +0 -0
  92. package/lib/module/Icons/Recording/assets/recording-off@2x.png +0 -0
  93. package/lib/module/Icons/Recording/assets/recording-off@3x.png +0 -0
  94. package/lib/module/Icons/Recording/index.js +2 -1
  95. package/lib/module/Icons/Recording/index.js.map +1 -1
  96. package/lib/module/components/DisplayView.js +3 -1
  97. package/lib/module/components/DisplayView.js.map +1 -1
  98. package/lib/module/components/EndRoomModal.js +20 -0
  99. package/lib/module/components/EndRoomModal.js.map +1 -0
  100. package/lib/module/components/EndRoomModalContent.js +9 -2
  101. package/lib/module/components/EndRoomModalContent.js.map +1 -1
  102. package/lib/module/components/Footer.js +9 -1
  103. package/lib/module/components/Footer.js.map +1 -1
  104. package/lib/module/components/HMSKeyboardAvoidingView.js +4 -19
  105. package/lib/module/components/HMSKeyboardAvoidingView.js.map +1 -1
  106. package/lib/module/components/HMSLocalScreenshareNotification.js +1 -1
  107. package/lib/module/components/HMSManageLeave.js +5 -181
  108. package/lib/module/components/HMSManageLeave.js.map +1 -1
  109. package/lib/module/components/HMSNotification.js +4 -3
  110. package/lib/module/components/HMSNotification.js.map +1 -1
  111. package/lib/module/components/HMSNotifications.js +28 -2
  112. package/lib/module/components/HMSNotifications.js.map +1 -1
  113. package/lib/module/components/HMSOverlayChatView.js +7 -1
  114. package/lib/module/components/HMSOverlayChatView.js.map +1 -1
  115. package/lib/module/components/HMSReconnectingNotification.js +24 -0
  116. package/lib/module/components/HMSReconnectingNotification.js.map +1 -0
  117. package/lib/module/components/HMSRecordingIndicator.js +1 -1
  118. package/lib/module/components/HMSRecordingIndicator.js.map +1 -1
  119. package/lib/module/components/HMSTerminalErrorNotification.js +57 -0
  120. package/lib/module/components/HMSTerminalErrorNotification.js.map +1 -0
  121. package/lib/module/components/LeaveRoomBottomSheet.js +167 -0
  122. package/lib/module/components/LeaveRoomBottomSheet.js.map +1 -0
  123. package/lib/module/components/Meeting.js +5 -1
  124. package/lib/module/components/Meeting.js.map +1 -1
  125. package/lib/module/components/MeetingScreenContent.js +3 -2
  126. package/lib/module/components/MeetingScreenContent.js.map +1 -1
  127. package/lib/module/components/PIPView.js +81 -16
  128. package/lib/module/components/PIPView.js.map +1 -1
  129. package/lib/module/components/Participants/ParticipantsItemOptions.js +24 -2
  130. package/lib/module/components/Participants/ParticipantsItemOptions.js.map +1 -1
  131. package/lib/module/components/PeerVideoTile/AvatarView.js +4 -4
  132. package/lib/module/components/PeerVideoTile/PeerAudioIndicator.js +3 -1
  133. package/lib/module/components/PeerVideoTile/PeerAudioIndicator.js.map +1 -1
  134. package/lib/module/components/PeerVideoTile/PeerVideoTileView.js +1 -1
  135. package/lib/module/components/PeerVideoTile/PeerVideoTileView.js.map +1 -1
  136. package/lib/module/components/PreviewForRoleChangeModal.js +1 -1
  137. package/lib/module/components/RoomSettingsModalContent.js +6 -9
  138. package/lib/module/components/RoomSettingsModalContent.js.map +1 -1
  139. package/lib/module/components/StopRecordingModalContent.js +4 -1
  140. package/lib/module/components/StopRecordingModalContent.js.map +1 -1
  141. package/lib/module/hooks-util.js +184 -25
  142. package/lib/module/hooks-util.js.map +1 -1
  143. package/lib/module/index.js +1 -0
  144. package/lib/module/index.js.map +1 -1
  145. package/lib/module/redux/actionTypes.js +6 -1
  146. package/lib/module/redux/actionTypes.js.map +1 -1
  147. package/lib/module/redux/actions/index.js +18 -0
  148. package/lib/module/redux/actions/index.js.map +1 -1
  149. package/lib/module/redux/reducers/appState.js +17 -1
  150. package/lib/module/redux/reducers/appState.js.map +1 -1
  151. package/lib/module/redux/reducers/hmsStates.js +15 -4
  152. package/lib/module/redux/reducers/hmsStates.js.map +1 -1
  153. package/lib/module/redux/reducers/userState.js +5 -1
  154. package/lib/module/redux/reducers/userState.js.map +1 -1
  155. package/lib/module/types.js +9 -0
  156. package/lib/module/types.js.map +1 -1
  157. package/lib/module/utils/types.js +11 -0
  158. package/lib/module/utils/types.js.map +1 -1
  159. package/lib/module/utils.js +0 -6
  160. package/lib/module/utils.js.map +1 -1
  161. package/lib/typescript/HMSPrebuilt.d.ts +2 -16
  162. package/lib/typescript/HMSPrebuilt.d.ts.map +1 -1
  163. package/lib/typescript/HMSRoomSetup.d.ts.map +1 -1
  164. package/lib/typescript/Icons/Hand/index.d.ts +1 -0
  165. package/lib/typescript/Icons/Hand/index.d.ts.map +1 -1
  166. package/lib/typescript/Icons/Recording/index.d.ts +1 -0
  167. package/lib/typescript/Icons/Recording/index.d.ts.map +1 -1
  168. package/lib/typescript/components/DisplayView.d.ts.map +1 -1
  169. package/lib/typescript/components/EndRoomModal.d.ts +6 -0
  170. package/lib/typescript/components/EndRoomModal.d.ts.map +1 -0
  171. package/lib/typescript/components/EndRoomModalContent.d.ts.map +1 -1
  172. package/lib/typescript/components/Footer.d.ts +1 -0
  173. package/lib/typescript/components/Footer.d.ts.map +1 -1
  174. package/lib/typescript/components/HMSKeyboardAvoidingView.d.ts +1 -0
  175. package/lib/typescript/components/HMSKeyboardAvoidingView.d.ts.map +1 -1
  176. package/lib/typescript/components/HMSManageLeave.d.ts.map +1 -1
  177. package/lib/typescript/components/HMSNotification.d.ts +1 -0
  178. package/lib/typescript/components/HMSNotification.d.ts.map +1 -1
  179. package/lib/typescript/components/HMSNotifications.d.ts +1 -0
  180. package/lib/typescript/components/HMSNotifications.d.ts.map +1 -1
  181. package/lib/typescript/components/HMSOverlayChatView.d.ts.map +1 -1
  182. package/lib/typescript/components/HMSReconnectingNotification.d.ts +5 -0
  183. package/lib/typescript/components/HMSReconnectingNotification.d.ts.map +1 -0
  184. package/lib/typescript/components/HMSTerminalErrorNotification.d.ts +10 -0
  185. package/lib/typescript/components/HMSTerminalErrorNotification.d.ts.map +1 -0
  186. package/lib/typescript/components/LeaveRoomBottomSheet.d.ts +6 -0
  187. package/lib/typescript/components/LeaveRoomBottomSheet.d.ts.map +1 -0
  188. package/lib/typescript/components/Meeting.d.ts.map +1 -1
  189. package/lib/typescript/components/PIPView.d.ts.map +1 -1
  190. package/lib/typescript/components/Participants/ParticipantsItemOptions.d.ts.map +1 -1
  191. package/lib/typescript/components/PeerVideoTile/PeerAudioIndicator.d.ts.map +1 -1
  192. package/lib/typescript/components/PeerVideoTile/PeerVideoTileView.d.ts.map +1 -1
  193. package/lib/typescript/components/RoomSettingsModalContent.d.ts.map +1 -1
  194. package/lib/typescript/components/StopRecordingModalContent.d.ts.map +1 -1
  195. package/lib/typescript/hooks-util.d.ts +20 -7
  196. package/lib/typescript/hooks-util.d.ts.map +1 -1
  197. package/lib/typescript/index.d.ts +2 -0
  198. package/lib/typescript/index.d.ts.map +1 -1
  199. package/lib/typescript/redux/actionTypes.d.ts +3 -0
  200. package/lib/typescript/redux/actionTypes.d.ts.map +1 -1
  201. package/lib/typescript/redux/actions/index.d.ts +23 -14
  202. package/lib/typescript/redux/actions/index.d.ts.map +1 -1
  203. package/lib/typescript/redux/index.d.ts +5 -7
  204. package/lib/typescript/redux/index.d.ts.map +1 -1
  205. package/lib/typescript/redux/reducers/appState.d.ts +4 -5
  206. package/lib/typescript/redux/reducers/appState.d.ts.map +1 -1
  207. package/lib/typescript/redux/reducers/hmsStates.d.ts.map +1 -1
  208. package/lib/typescript/redux/reducers/index.d.ts +5 -7
  209. package/lib/typescript/redux/reducers/index.d.ts.map +1 -1
  210. package/lib/typescript/redux/reducers/userState.d.ts +2 -2
  211. package/lib/typescript/redux/reducers/userState.d.ts.map +1 -1
  212. package/lib/typescript/types.d.ts +79 -0
  213. package/lib/typescript/types.d.ts.map +1 -1
  214. package/lib/typescript/utils/types.d.ts +24 -0
  215. package/lib/typescript/utils/types.d.ts.map +1 -1
  216. package/lib/typescript/utils.d.ts +0 -5
  217. package/lib/typescript/utils.d.ts.map +1 -1
  218. package/package.json +2 -2
  219. package/src/HMSPrebuilt.tsx +32 -23
  220. package/src/HMSRoomSetup.tsx +105 -53
  221. package/src/Icons/Hand/assets/hand-off.png +0 -0
  222. package/src/Icons/Hand/assets/hand-off@2x.png +0 -0
  223. package/src/Icons/Hand/assets/hand-off@3x.png +0 -0
  224. package/src/Icons/Hand/index.tsx +13 -3
  225. package/src/Icons/Recording/assets/recording-off.png +0 -0
  226. package/src/Icons/Recording/assets/recording-off@2x.png +0 -0
  227. package/src/Icons/Recording/assets/recording-off@3x.png +0 -0
  228. package/src/Icons/Recording/index.tsx +9 -2
  229. package/src/components/DisplayView.tsx +6 -0
  230. package/src/components/EndRoomModal.tsx +24 -0
  231. package/src/components/EndRoomModalContent.tsx +9 -2
  232. package/src/components/Footer.tsx +18 -2
  233. package/src/components/HMSKeyboardAvoidingView.tsx +5 -23
  234. package/src/components/HMSLocalScreenshareNotification.tsx +1 -1
  235. package/src/components/HMSManageLeave.tsx +4 -228
  236. package/src/components/HMSNotification.tsx +4 -2
  237. package/src/components/HMSNotifications.tsx +41 -7
  238. package/src/components/HMSOverlayChatView.tsx +6 -1
  239. package/src/components/HMSReconnectingNotification.tsx +27 -0
  240. package/src/components/HMSRecordingIndicator.tsx +1 -1
  241. package/src/components/HMSTerminalErrorNotification.tsx +70 -0
  242. package/src/components/LeaveRoomBottomSheet.tsx +199 -0
  243. package/src/components/Meeting.tsx +7 -0
  244. package/src/components/MeetingScreenContent.tsx +2 -2
  245. package/src/components/PIPView.tsx +113 -25
  246. package/src/components/Participants/ParticipantsItemOptions.tsx +26 -4
  247. package/src/components/PeerVideoTile/AvatarView.tsx +4 -4
  248. package/src/components/PeerVideoTile/PeerAudioIndicator.tsx +6 -1
  249. package/src/components/PeerVideoTile/PeerVideoTileView.tsx +4 -2
  250. package/src/components/PreviewForRoleChangeModal.tsx +1 -1
  251. package/src/components/RoomSettingsModalContent.tsx +5 -9
  252. package/src/components/StopRecordingModalContent.tsx +3 -1
  253. package/src/hooks-util.ts +243 -25
  254. package/src/index.ts +2 -0
  255. package/src/redux/actionTypes.ts +7 -0
  256. package/src/redux/actions/index.ts +19 -7
  257. package/src/redux/reducers/appState.ts +18 -1
  258. package/src/redux/reducers/hmsStates.ts +19 -7
  259. package/src/redux/reducers/userState.ts +7 -3
  260. package/src/types.ts +71 -0
  261. package/src/utils/types.ts +27 -0
  262. package/src/utils.ts +0 -6
package/src/hooks-util.ts CHANGED
@@ -18,10 +18,13 @@ import {
18
18
  HMSTrackUpdate,
19
19
  HMSUpdateListenerActions,
20
20
  HMSMessageRecipient,
21
+ useHMSHLSPlayerResolution,
22
+ useHmsViewsResolutionsState,
21
23
  // useHMSPeerUpdates,
22
24
  } from '@100mslive/react-native-hms';
23
25
  import type { Chat as ChatConfig } from '@100mslive/types-prebuilt/elements/chat';
24
26
  import type {
27
+ HMSPIPConfig,
25
28
  HMSRole,
26
29
  HMSSessionStore,
27
30
  HMSSessionStoreValue,
@@ -49,10 +52,11 @@ import type { DependencyList } from 'react';
49
52
  import {
50
53
  MaxTilesInOnePage,
51
54
  ModalTypes,
55
+ OnLeaveReason,
52
56
  PeerListRefreshInterval,
53
57
  PipModes,
54
58
  } from './utils/types';
55
- import type { ChatBroadcastFilter, PeerTrackNode } from './utils/types';
59
+ import type { ChatBroadcastFilter, OnLeaveHandler, PeerTrackNode } from './utils/types';
56
60
  import { createPeerTrackNode } from './utils/functions';
57
61
  import {
58
62
  batch,
@@ -61,7 +65,7 @@ import {
61
65
  useSelector,
62
66
  useStore,
63
67
  } from 'react-redux';
64
- import type { RootState } from './redux';
68
+ import type { AppDispatch, RootState } from './redux';
65
69
  import {
66
70
  addMessage,
67
71
  addNotification,
@@ -82,16 +86,20 @@ import {
82
86
  saveUserData,
83
87
  setActiveChatBottomSheetTab,
84
88
  setActiveSpeakers,
89
+ setAutoEnterPipMode,
85
90
  setFullScreenPeerTrackNode,
86
91
  setHMSLocalPeerState,
87
92
  setHMSRoleState,
88
93
  setHMSRoomState,
94
+ setHandleBackButton,
89
95
  setIsLocalAudioMutedState,
90
96
  setIsLocalVideoMutedState,
91
97
  setLayoutConfig,
92
98
  setLocalPeerTrackNode,
93
99
  setMiniViewPeerTrackNode,
94
100
  setModalType,
101
+ setOnLeaveHandler,
102
+ setPrebuiltData,
95
103
  setReconnecting,
96
104
  setRoleChangeRequest,
97
105
  setStartingOrStoppingRecording,
@@ -111,7 +119,13 @@ import {
111
119
  replacePeerTrackNodesWithTrack,
112
120
  } from './peerTrackNodeUtils';
113
121
  import { MeetingState } from './types';
114
- import { InteractionManager, Keyboard, Platform } from 'react-native';
122
+ import type { HMSPrebuiltProps } from './types';
123
+ import {
124
+ BackHandler,
125
+ InteractionManager,
126
+ Keyboard,
127
+ Platform,
128
+ } from 'react-native';
115
129
  import type { ImageStyle, StyleProp, ViewStyle, TextStyle } from 'react-native';
116
130
  import { NavigationContext } from '@react-navigation/native';
117
131
  import {
@@ -129,7 +143,7 @@ import {
129
143
  import type { GridViewRefAttrs } from './components/GridView';
130
144
  import { getRoomLayout } from './modules/HMSManager';
131
145
  import { DEFAULT_THEME, DEFAULT_TYPOGRAPHY } from './utils/theme';
132
- import { NotificationTypes } from './utils';
146
+ import { NotificationTypes } from './types';
133
147
 
134
148
  export const useHMSListeners = (
135
149
  setPeerTrackNodes: React.Dispatch<React.SetStateAction<PeerTrackNode[]>>
@@ -1240,12 +1254,21 @@ export const useHMSReconnection = () => {
1240
1254
 
1241
1255
  hmsInstance.addEventListener(HMSUpdateListenerActions.RECONNECTING, () => {
1242
1256
  if (mounted) {
1243
- dispatch(setReconnecting(true));
1257
+ batch(() => {
1258
+ dispatch(setReconnecting(true));
1259
+ dispatch(addNotification({
1260
+ id: NotificationTypes.RECONNECTING,
1261
+ type: NotificationTypes.RECONNECTING
1262
+ }))
1263
+ });
1244
1264
  }
1245
1265
  });
1246
1266
  hmsInstance.addEventListener(HMSUpdateListenerActions.RECONNECTED, () => {
1247
1267
  if (mounted) {
1248
- dispatch(setReconnecting(false));
1268
+ batch(() => {
1269
+ dispatch(setReconnecting(false));
1270
+ dispatch(removeNotification(NotificationTypes.RECONNECTING));
1271
+ })
1249
1272
  }
1250
1273
  });
1251
1274
 
@@ -1259,11 +1282,11 @@ export const useHMSReconnection = () => {
1259
1282
 
1260
1283
  export const useHMSPIPRoomLeave = () => {
1261
1284
  const hmsInstance = useHMSInstance();
1262
- const { destroy } = useLeaveMethods(true);
1285
+ const { destroy } = useLeaveMethods();
1263
1286
 
1264
1287
  useEffect(() => {
1265
1288
  const pipRoomLeaveHandler = () => {
1266
- destroy();
1289
+ destroy(OnLeaveReason.PIP);
1267
1290
  };
1268
1291
 
1269
1292
  hmsInstance.addEventListener(
@@ -1279,11 +1302,17 @@ export const useHMSPIPRoomLeave = () => {
1279
1302
 
1280
1303
  export const useHMSRemovedFromRoomUpdate = () => {
1281
1304
  const hmsInstance = useHMSInstance();
1282
- const { destroy } = useLeaveMethods(true);
1305
+ const { destroy } = useLeaveMethods();
1283
1306
 
1284
1307
  useEffect(() => {
1285
- const removedFromRoomHandler = () => {
1286
- destroy();
1308
+ const removedFromRoomHandler = (data: {
1309
+ requestedBy?: HMSPeer | null;
1310
+ reason?: string;
1311
+ roomEnded?: boolean;
1312
+ }) => {
1313
+ destroy(
1314
+ data.roomEnded ? OnLeaveReason.ROOM_END : OnLeaveReason.PEER_KICKED
1315
+ );
1287
1316
  };
1288
1317
 
1289
1318
  hmsInstance.addEventListener(
@@ -1360,6 +1389,93 @@ export const useHMSNetworkQualityUpdate = () => {
1360
1389
  }, [hmsInstance]);
1361
1390
  };
1362
1391
 
1392
+ export type PIPConfig = Omit<HMSPIPConfig, 'autoEnterPipMode'>;
1393
+
1394
+ export const useEnableAutoPip = () => {
1395
+ const hmsInstance = useHMSInstance();
1396
+
1397
+ const enableAutoPip = useCallback(
1398
+ (data?: PIPConfig) => {
1399
+ hmsInstance.setPipParams({ ...data, autoEnterPipMode: true });
1400
+ },
1401
+ [hmsInstance]
1402
+ );
1403
+
1404
+ return enableAutoPip;
1405
+ };
1406
+
1407
+ export const useDisableAutoPip = () => {
1408
+ const hmsInstance = useHMSInstance();
1409
+
1410
+ const disableAutoPip = useCallback(
1411
+ (data?: PIPConfig) => {
1412
+ hmsInstance.setPipParams({ ...data, autoEnterPipMode: false });
1413
+ },
1414
+ [hmsInstance]
1415
+ );
1416
+
1417
+ return disableAutoPip;
1418
+ };
1419
+
1420
+ export const useAutoPip = (oneToOneCall: boolean) => {
1421
+ const enableAutoPip = useEnableAutoPip();
1422
+ const disableAutoPip = useDisableAutoPip();
1423
+
1424
+ const autoEnterPipMode = useSelector(
1425
+ (state: RootState) => state.app.autoEnterPipMode
1426
+ );
1427
+ const [numerator, denominator] = usePipAspectRatio(oneToOneCall);
1428
+
1429
+ useEffect(() => {
1430
+ if (autoEnterPipMode) {
1431
+ enableAutoPip({ aspectRatio: [numerator, denominator] });
1432
+
1433
+ return disableAutoPip;
1434
+ }
1435
+ }, [
1436
+ numerator,
1437
+ denominator,
1438
+ autoEnterPipMode,
1439
+ enableAutoPip,
1440
+ disableAutoPip,
1441
+ ]);
1442
+ };
1443
+
1444
+ export const usePipAspectRatio = (oneToOneCall: boolean): [number, number] => {
1445
+ const isHLSViewer = useIsHLSViewer();
1446
+ const hlsPlayerResolution = useHMSHLSPlayerResolution();
1447
+
1448
+ const firstSSNodeId = useSelector((state: RootState) => {
1449
+ const ssPeerTrackNode = state.app.screensharePeerTrackNodes[0];
1450
+ return ssPeerTrackNode?.track?.trackId;
1451
+ });
1452
+
1453
+ const ssResolution = useHmsViewsResolutionsState(firstSSNodeId);
1454
+
1455
+ const aspectRatio = useMemo((): [number, number] => {
1456
+ // When user is hlsviewer and we have stream resolution
1457
+ if (isHLSViewer && hlsPlayerResolution) {
1458
+ return [hlsPlayerResolution.width, hlsPlayerResolution.height];
1459
+ }
1460
+ // When user is hlsviewer and we don't have stream resolution
1461
+ if (isHLSViewer) {
1462
+ return [9, 16];
1463
+ }
1464
+ // When we have screenshare resolution, use it
1465
+ if (ssResolution) {
1466
+ return [ssResolution.width, ssResolution.height];
1467
+ }
1468
+ // When there is no screenshare and one-to-one call is happening
1469
+ if (!firstSSNodeId && oneToOneCall) {
1470
+ return [9, 16];
1471
+ }
1472
+ // default aspect ratio
1473
+ return [16, 9];
1474
+ }, [isHLSViewer, firstSSNodeId, oneToOneCall, ssResolution, hlsPlayerResolution]);
1475
+
1476
+ return aspectRatio;
1477
+ }
1478
+
1363
1479
  export const useHMSActiveSpeakerUpdates = (
1364
1480
  setPeerTrackNodes: React.Dispatch<React.SetStateAction<PeerTrackNode[]>>,
1365
1481
  active?: boolean
@@ -1821,7 +1937,6 @@ export const useFilteredParticipants = (filterText: string) => {
1821
1937
  : list;
1822
1938
 
1823
1939
  if (Array.isArray(filteredList) && filteredList.length > 0) {
1824
-
1825
1940
  filteredHandRaisedPeers.push(filteredList);
1826
1941
  const offStageRoleTotalCount =
1827
1942
  offStageParticipantsTotalCounts[role.name!];
@@ -1831,8 +1946,9 @@ export const useFilteredParticipants = (filterText: string) => {
1831
1946
  t.push({
1832
1947
  id: role.name!,
1833
1948
  label: `${role.name!} (${
1834
- typeof offStageRoleTotalCount === 'number'
1835
- ? offStageRoleTotalCount
1949
+ typeof offStageRoleTotalCount === 'number' &&
1950
+ offStageRoleTotalCount > filteredList.length
1951
+ ? offStageRoleTotalCount // only use `offStageRoleTotalCount` when it is number and more than list length
1836
1952
  : filteredList.length
1837
1953
  })`,
1838
1954
  showViewAll:
@@ -1886,13 +2002,13 @@ export const useShouldGoLive = () => {
1886
2002
  return shouldGoLive;
1887
2003
  };
1888
2004
 
1889
- export const useLeaveMethods = (isUnmounted: boolean) => {
2005
+ export const useLeaveMethods = () => {
1890
2006
  const navigation = useContext(NavigationContext);
1891
2007
  const hmsInstance = useHMSInstance();
1892
2008
  const dispatch = useDispatch();
1893
2009
  const reduxStore = useStore<RootState>();
1894
2010
 
1895
- const destroy = useCallback(() => {
2011
+ const destroy = useCallback((reason: Parameters<OnLeaveHandler>[0]) => {
1896
2012
  try {
1897
2013
  const s = hmsInstance.destroy();
1898
2014
  console.log('Destroy Success: ', s);
@@ -1919,9 +2035,13 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1919
2035
  const onLeave = reduxStore.getState().user.onLeave;
1920
2036
 
1921
2037
  if (typeof onLeave === 'function') {
1922
- onLeave();
2038
+ onLeave(reason);
1923
2039
  dispatch(clearStore());
1924
- } else if (navigation && navigation.canGoBack() && !isUnmounted) {
2040
+ } else if (
2041
+ navigation &&
2042
+ typeof navigation.canGoBack === 'function' &&
2043
+ navigation.canGoBack()
2044
+ ) {
1925
2045
  navigation.goBack();
1926
2046
  dispatch(clearStore());
1927
2047
  } else {
@@ -1941,7 +2061,7 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1941
2061
  }, [hmsInstance]);
1942
2062
 
1943
2063
  const leave = useCallback(
1944
- async (shouldEndStream: boolean = false) => {
2064
+ async (reason: OnLeaveReason, shouldEndStream: boolean = false) => {
1945
2065
  if (shouldEndStream) {
1946
2066
  hmsInstance.stopHLSStreaming().catch((error) => {
1947
2067
  console.log('Stop HLS Streaming Error: ', error);
@@ -1950,7 +2070,7 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1950
2070
  try {
1951
2071
  const d = await hmsInstance.leave();
1952
2072
  console.log('Leave Success: ', d);
1953
- await destroy();
2073
+ await destroy(reason);
1954
2074
  } catch (e) {
1955
2075
  console.log(`Leave Room Error: ${e}`);
1956
2076
  Toast.showWithGravity(`Leave Room Error: ${e}`, Toast.LONG, Toast.TOP);
@@ -1959,31 +2079,31 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1959
2079
  [destroy, hmsInstance]
1960
2080
  );
1961
2081
 
1962
- const goToPreview = useCallback(async () => {
2082
+ const prebuiltCleanUp = useCallback(async () => {
1963
2083
  try {
1964
2084
  await hmsInstance.leave();
1965
2085
  await hmsInstance.destroy();
1966
2086
  dispatch(clearStore());
1967
2087
  } catch (error) {
1968
2088
  Toast.showWithGravity(
1969
- `Unable to go to Preview: ${error}`,
2089
+ `Unable to leave or destroy: ${error}`,
1970
2090
  Toast.LONG,
1971
2091
  Toast.TOP
1972
2092
  );
1973
2093
  }
1974
2094
  }, [hmsInstance]);
1975
2095
 
1976
- const endRoom = useCallback(async () => {
2096
+ const endRoom = useCallback(async (reason: OnLeaveReason) => {
1977
2097
  try {
1978
2098
  const d = await hmsInstance.endRoom('Host ended the room');
1979
2099
  console.log('EndRoom Success: ', d);
1980
- await destroy();
2100
+ await destroy(reason);
1981
2101
  } catch (e) {
1982
2102
  console.log('EndRoom Error: ', e);
1983
2103
  }
1984
2104
  }, [destroy, hmsInstance]);
1985
2105
 
1986
- return { destroy, leave, endRoom, goToPreview };
2106
+ return { destroy, leave, endRoom, prebuiltCleanUp };
1987
2107
  };
1988
2108
 
1989
2109
  // Returns layout config as it is returned from server
@@ -2189,3 +2309,101 @@ export const useHMSConferencingScreenConfig = <Selected = unknown>(
2189
2309
  return selector(conferencingScreenConfig);
2190
2310
  }, equalityFn);
2191
2311
  };
2312
+
2313
+ export const useBackButtonPress = () => {
2314
+ const { handleModalVisibleType } = useModalType();
2315
+
2316
+ const handleBackPress = useSelector(
2317
+ (state: RootState) => state.app.handleBackButton
2318
+ );
2319
+
2320
+ useEffect(() => {
2321
+ if (handleBackPress) {
2322
+ const backPressHandler = () => {
2323
+ handleModalVisibleType(ModalTypes.LEAVE_ROOM);
2324
+
2325
+ /**
2326
+ * When true is returned the event will not be bubbled up
2327
+ * & no other back action will execute
2328
+ */
2329
+ return true;
2330
+
2331
+ /**
2332
+ * Returning false will let the event to bubble up & let other event listeners
2333
+ * or the system's default back action to be executed.
2334
+ */
2335
+ // return false;
2336
+ };
2337
+
2338
+ const subscription = BackHandler.addEventListener(
2339
+ 'hardwareBackPress',
2340
+ backPressHandler
2341
+ );
2342
+
2343
+ return () => {
2344
+ if (typeof subscription.remove === 'function') {
2345
+ subscription.remove();
2346
+ } else {
2347
+ BackHandler.removeEventListener(
2348
+ 'hardwareBackPress',
2349
+ backPressHandler
2350
+ );
2351
+ }
2352
+ };
2353
+ }
2354
+ }, [handleBackPress, handleModalVisibleType]);
2355
+ };
2356
+
2357
+ export const useSavePropsToStore = (
2358
+ props: HMSPrebuiltProps,
2359
+ dispatch: AppDispatch
2360
+ ) => {
2361
+ const { roomCode, options, onLeave, handleBackButton, autoEnterPipMode } =
2362
+ props;
2363
+
2364
+ useEffect(() => {
2365
+ dispatch(setPrebuiltData({ roomCode, options }));
2366
+ }, [roomCode, options]);
2367
+
2368
+ useEffect(() => {
2369
+ dispatch(setOnLeaveHandler(onLeave));
2370
+ }, [onLeave]);
2371
+
2372
+ useEffect(() => {
2373
+ if (Platform.OS === 'android') {
2374
+ dispatch(setHandleBackButton(handleBackButton));
2375
+ }
2376
+ }, [handleBackButton]);
2377
+
2378
+ useEffect(() => {
2379
+ if (Platform.OS === 'android') {
2380
+ dispatch(setAutoEnterPipMode(autoEnterPipMode));
2381
+ }
2382
+ }, [autoEnterPipMode]);
2383
+ };
2384
+
2385
+ export const useStartRecording = () => {
2386
+ const dispatch = useDispatch();
2387
+ const hmsInstance = useHMSInstance();
2388
+
2389
+ const startRecording = useCallback(() => {
2390
+ dispatch(setStartingOrStoppingRecording(true));
2391
+
2392
+ hmsInstance.startRTMPOrRecording({ record: true }).catch((error) => {
2393
+ batch(() => {
2394
+ dispatch(setStartingOrStoppingRecording(false));
2395
+ dispatch(
2396
+ addNotification({
2397
+ id: Math.random().toString(16).slice(2),
2398
+ type: NotificationTypes.ERROR,
2399
+ message: error.message
2400
+ })
2401
+ );
2402
+ });
2403
+ });
2404
+ }, [hmsInstance]);
2405
+
2406
+ return {
2407
+ startRecording,
2408
+ };
2409
+ };
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './HMSPrebuilt';
2
+ export { OnLeaveReason } from './utils/types';
3
+ export type { OnLeaveHandler, HMSIOSScreenShareConfig } from './utils/types';
@@ -84,6 +84,10 @@ const SET_ACTIVE_CHAT_BOTTOM_SHEET_TAB = 'SET_ACTIVE_CHAT_BOTTOM_SHEET_TAB';
84
84
 
85
85
  const SET_CHAT_FILTER_SHEET_VISIBLE = 'SET_CHAT_FILTER_SHEET_VISIBLE';
86
86
 
87
+ const SET_HANDLE_BACK_BUTTON = 'SET_HANDLE_BACK_BUTTON';
88
+
89
+ const SET_AUTO_ENTER_PIP_MODE = 'SET_AUTO_ENTER_PIP_MODE';
90
+
87
91
  export default {
88
92
  ADD_PINNED_MESSAGE,
89
93
  ADD_MESSAGE,
@@ -123,11 +127,14 @@ export default {
123
127
  REMOVE_NOTIFICATION,
124
128
  SET_ACTIVE_CHAT_BOTTOM_SHEET_TAB,
125
129
  SET_CHAT_FILTER_SHEET_VISIBLE,
130
+ SET_HANDLE_BACK_BUTTON,
131
+ SET_AUTO_ENTER_PIP_MODE,
126
132
  };
127
133
 
128
134
  export enum HmsStateActionTypes {
129
135
  CLEAR_STATES = 'CLEAR_STATES',
130
136
  SET_PREBUILT_DATA = 'SET_PREBUILT_DATA',
137
+ SET_ON_LEAVE_HANDLER = 'SET_ON_LEAVE_HANDLER',
131
138
  SET_ROOM_STATE = 'SET_ROOM_STATE',
132
139
  SET_LOCAL_PEER_STATE = 'SET_LOCAL_PEER_STATE',
133
140
  SET_ROLES_STATE = 'SET_ROLES_STATE',
@@ -18,11 +18,13 @@ import type {
18
18
  ChatBottomSheetTabs,
19
19
  HMSIOSScreenShareConfig,
20
20
  ModalTypes,
21
+ OnLeaveHandler,
21
22
  PeerTrackNode,
22
23
  PipModes,
23
24
  } from '../../utils/types';
24
25
  import actionTypes, { HmsStateActionTypes } from '../actionTypes';
25
26
  import { MeetingState } from '../../types';
27
+ import type { Notification } from '../../types';
26
28
 
27
29
  export const setPrebuiltData = (data: {
28
30
  roomCode: string;
@@ -37,12 +39,16 @@ export const setPrebuiltData = (data: {
37
39
  };
38
40
  ios?: HMSIOSScreenShareConfig;
39
41
  };
40
- onLeave?: () => void;
41
42
  }) => ({
42
43
  type: HmsStateActionTypes.SET_PREBUILT_DATA,
43
44
  payload: data,
44
45
  });
45
46
 
47
+ export const setOnLeaveHandler = (onLeave?: OnLeaveHandler) => ({
48
+ type: HmsStateActionTypes.SET_ON_LEAVE_HANDLER,
49
+ payload: { onLeave },
50
+ });
51
+
46
52
  export const clearStore = () => ({
47
53
  type: HmsStateActionTypes.CLEAR_STATES,
48
54
  });
@@ -306,16 +312,12 @@ export const updateScreenshareTile = (
306
312
  payload: data,
307
313
  });
308
314
 
309
- export const addNotification = (notification: {
310
- id: string;
311
- type: string;
312
- peer: HMSPeer;
313
- }) => ({
315
+ export const addNotification = (notification: Notification) => ({
314
316
  type: actionTypes.ADD_NOTIFICATION,
315
317
  payload: { notification },
316
318
  });
317
319
 
318
- export const removeNotification = (notificationId: string) => ({
320
+ export const removeNotification = (notificationId: Notification['id']) => ({
319
321
  type: actionTypes.REMOVE_NOTIFICATION,
320
322
  payload: { id: notificationId },
321
323
  });
@@ -379,3 +381,13 @@ export const setReconnecting = (reconnecting: boolean) => ({
379
381
  type: HmsStateActionTypes.SET_RECONNECTING,
380
382
  reconnecting,
381
383
  });
384
+
385
+ export const setHandleBackButton = (handleBackButton?: boolean) => ({
386
+ type: actionTypes.SET_HANDLE_BACK_BUTTON,
387
+ payload: { handleBackButton },
388
+ });
389
+
390
+ export const setAutoEnterPipMode = (autoEnterPipMode?: boolean) => ({
391
+ type: actionTypes.SET_AUTO_ENTER_PIP_MODE,
392
+ payload: { autoEnterPipMode },
393
+ });
@@ -11,6 +11,7 @@ import {
11
11
  HMSRemoteVideoStats,
12
12
  } from '@100mslive/react-native-hms';
13
13
  import { MeetingState } from '../../types';
14
+ import type { Notification } from '../../types';
14
15
 
15
16
  type ActionType = {
16
17
  payload: { [key: string]: any };
@@ -48,9 +49,11 @@ type IntialStateType = {
48
49
  startingOrStoppingRecording: boolean;
49
50
  fullScreenPeerTrackNode: null | PeerTrackNode;
50
51
  screensharePeerTrackNodes: PeerTrackNode[];
51
- notifications: { id: string; type: string; peer: HMSPeer }[];
52
+ notifications: Notification[];
52
53
  activeChatBottomSheetTab: (typeof ChatBottomSheetTabs)[number];
53
54
  chatFilterSheetVisible: boolean;
55
+ handleBackButton: boolean;
56
+ autoEnterPipMode: boolean;
54
57
  };
55
58
 
56
59
  const INITIAL_STATE: IntialStateType = {
@@ -80,6 +83,8 @@ const INITIAL_STATE: IntialStateType = {
80
83
  notifications: [],
81
84
  activeChatBottomSheetTab: ChatBottomSheetTabs[0],
82
85
  chatFilterSheetVisible: false,
86
+ handleBackButton: false,
87
+ autoEnterPipMode: false,
83
88
  };
84
89
 
85
90
  const appReducer = (
@@ -283,6 +288,18 @@ const appReducer = (
283
288
  chatFilterSheetVisible: action.payload.chatFilterSheetVisible,
284
289
  };
285
290
  }
291
+ case ActionTypes.SET_HANDLE_BACK_BUTTON: {
292
+ return {
293
+ ...state,
294
+ handleBackButton: action.payload.handleBackButton ?? INITIAL_STATE.handleBackButton,
295
+ };
296
+ }
297
+ case ActionTypes.SET_AUTO_ENTER_PIP_MODE: {
298
+ return {
299
+ ...state,
300
+ autoEnterPipMode: action.payload.autoEnterPipMode ?? INITIAL_STATE.autoEnterPipMode,
301
+ };
302
+ }
286
303
  case HmsStateActionTypes.CLEAR_STATES:
287
304
  return INITIAL_STATE;
288
305
  default:
@@ -402,17 +402,29 @@ const hmsStatesReducer = (
402
402
  };
403
403
  }
404
404
  case HmsStateActionTypes.UPDATE_PARTICIPANT: {
405
- const previousParticipant = Object.values(state.groupedParticipants)
406
- .flat()
407
- .find(
408
- (participant) => participant.peerID === action.participant.peerID
409
- );
405
+ let previousRoleName: HMSRole['name'] | null = null;
406
+
407
+ for (const groupName in state.groupedParticipants) {
408
+ if (Object.prototype.hasOwnProperty.call(state.groupedParticipants, groupName)) {
409
+ const participantsList = state.groupedParticipants[groupName];
410
+
411
+ if (Array.isArray(participantsList)) {
412
+ const result = participantsList.find(
413
+ (participant) => participant.peerID === action.participant.peerID
414
+ );
415
+
416
+ if (result) {
417
+ previousRoleName = groupName;
418
+ break;
419
+ }
420
+ }
421
+ }
422
+ }
410
423
 
411
- if (!previousParticipant) {
424
+ if (!previousRoleName) {
412
425
  return state;
413
426
  }
414
427
 
415
- const previousRoleName = previousParticipant.role?.name!;
416
428
  const currentRoleName = action.participant.role?.name!;
417
429
 
418
430
  // check if role change
@@ -5,7 +5,7 @@ import type {
5
5
  } from '@100mslive/react-native-hms';
6
6
  import { getMeetingCode, getMeetingUrl } from '../../utils/functions';
7
7
  import ActionTypes, { HmsStateActionTypes } from '../actionTypes';
8
- import type { HMSIOSScreenShareConfig } from '../../utils/types';
8
+ import type { HMSIOSScreenShareConfig, OnLeaveHandler } from '../../utils/types';
9
9
 
10
10
  type ActionType = {
11
11
  payload: any;
@@ -25,7 +25,7 @@ type IntialStateType = {
25
25
  isHLSFlow: boolean;
26
26
  roles: HMSRole[];
27
27
  iosBuildConfig: HMSIOSScreenShareConfig | null;
28
- onLeave: (() => void) | undefined;
28
+ onLeave: OnLeaveHandler | undefined;
29
29
  };
30
30
 
31
31
  const INITIAL_STATE: IntialStateType = {
@@ -78,9 +78,13 @@ const userReducer = (
78
78
  state.endPoints = action.payload.options.endPoints;
79
79
  state.debugMode = action.payload.options.debugMode ?? false;
80
80
  state.iosBuildConfig = action.payload.options.ios ?? null;
81
- state.onLeave = action.payload.onLeave;
82
81
 
83
82
  return state;
83
+ case HmsStateActionTypes.SET_ON_LEAVE_HANDLER:
84
+ return {
85
+ ...state,
86
+ onLeave: action.payload.onLeave,
87
+ };
84
88
  case HmsStateActionTypes.CLEAR_STATES:
85
89
  return INITIAL_STATE;
86
90
  default: