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

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 (256) 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 +191 -27
  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/userState.js +5 -1
  73. package/lib/commonjs/redux/reducers/userState.js.map +1 -1
  74. package/lib/commonjs/types.js +10 -1
  75. package/lib/commonjs/types.js.map +1 -1
  76. package/lib/commonjs/utils/types.js +11 -1
  77. package/lib/commonjs/utils/types.js.map +1 -1
  78. package/lib/commonjs/utils.js +1 -7
  79. package/lib/commonjs/utils.js.map +1 -1
  80. package/lib/module/HMSPrebuilt.js +16 -14
  81. package/lib/module/HMSPrebuilt.js.map +1 -1
  82. package/lib/module/HMSRoomSetup.js +81 -40
  83. package/lib/module/HMSRoomSetup.js.map +1 -1
  84. package/lib/module/Icons/Hand/assets/hand-off.png +0 -0
  85. package/lib/module/Icons/Hand/assets/hand-off@2x.png +0 -0
  86. package/lib/module/Icons/Hand/assets/hand-off@3x.png +0 -0
  87. package/lib/module/Icons/Hand/index.js +2 -1
  88. package/lib/module/Icons/Hand/index.js.map +1 -1
  89. package/lib/module/Icons/Recording/assets/recording-off.png +0 -0
  90. package/lib/module/Icons/Recording/assets/recording-off@2x.png +0 -0
  91. package/lib/module/Icons/Recording/assets/recording-off@3x.png +0 -0
  92. package/lib/module/Icons/Recording/index.js +2 -1
  93. package/lib/module/Icons/Recording/index.js.map +1 -1
  94. package/lib/module/components/DisplayView.js +3 -1
  95. package/lib/module/components/DisplayView.js.map +1 -1
  96. package/lib/module/components/EndRoomModal.js +20 -0
  97. package/lib/module/components/EndRoomModal.js.map +1 -0
  98. package/lib/module/components/EndRoomModalContent.js +9 -2
  99. package/lib/module/components/EndRoomModalContent.js.map +1 -1
  100. package/lib/module/components/Footer.js +9 -1
  101. package/lib/module/components/Footer.js.map +1 -1
  102. package/lib/module/components/HMSKeyboardAvoidingView.js +4 -19
  103. package/lib/module/components/HMSKeyboardAvoidingView.js.map +1 -1
  104. package/lib/module/components/HMSLocalScreenshareNotification.js +1 -1
  105. package/lib/module/components/HMSManageLeave.js +5 -181
  106. package/lib/module/components/HMSManageLeave.js.map +1 -1
  107. package/lib/module/components/HMSNotification.js +4 -3
  108. package/lib/module/components/HMSNotification.js.map +1 -1
  109. package/lib/module/components/HMSNotifications.js +28 -2
  110. package/lib/module/components/HMSNotifications.js.map +1 -1
  111. package/lib/module/components/HMSOverlayChatView.js +7 -1
  112. package/lib/module/components/HMSOverlayChatView.js.map +1 -1
  113. package/lib/module/components/HMSReconnectingNotification.js +24 -0
  114. package/lib/module/components/HMSReconnectingNotification.js.map +1 -0
  115. package/lib/module/components/HMSRecordingIndicator.js +1 -1
  116. package/lib/module/components/HMSRecordingIndicator.js.map +1 -1
  117. package/lib/module/components/HMSTerminalErrorNotification.js +57 -0
  118. package/lib/module/components/HMSTerminalErrorNotification.js.map +1 -0
  119. package/lib/module/components/LeaveRoomBottomSheet.js +167 -0
  120. package/lib/module/components/LeaveRoomBottomSheet.js.map +1 -0
  121. package/lib/module/components/Meeting.js +5 -1
  122. package/lib/module/components/Meeting.js.map +1 -1
  123. package/lib/module/components/MeetingScreenContent.js +3 -2
  124. package/lib/module/components/MeetingScreenContent.js.map +1 -1
  125. package/lib/module/components/PIPView.js +81 -16
  126. package/lib/module/components/PIPView.js.map +1 -1
  127. package/lib/module/components/Participants/ParticipantsItemOptions.js +24 -2
  128. package/lib/module/components/Participants/ParticipantsItemOptions.js.map +1 -1
  129. package/lib/module/components/PeerVideoTile/AvatarView.js +4 -4
  130. package/lib/module/components/PeerVideoTile/PeerAudioIndicator.js +3 -1
  131. package/lib/module/components/PeerVideoTile/PeerAudioIndicator.js.map +1 -1
  132. package/lib/module/components/PeerVideoTile/PeerVideoTileView.js +1 -1
  133. package/lib/module/components/PeerVideoTile/PeerVideoTileView.js.map +1 -1
  134. package/lib/module/components/PreviewForRoleChangeModal.js +1 -1
  135. package/lib/module/components/RoomSettingsModalContent.js +6 -9
  136. package/lib/module/components/RoomSettingsModalContent.js.map +1 -1
  137. package/lib/module/components/StopRecordingModalContent.js +4 -1
  138. package/lib/module/components/StopRecordingModalContent.js.map +1 -1
  139. package/lib/module/hooks-util.js +182 -24
  140. package/lib/module/hooks-util.js.map +1 -1
  141. package/lib/module/index.js +1 -0
  142. package/lib/module/index.js.map +1 -1
  143. package/lib/module/redux/actionTypes.js +6 -1
  144. package/lib/module/redux/actionTypes.js.map +1 -1
  145. package/lib/module/redux/actions/index.js +18 -0
  146. package/lib/module/redux/actions/index.js.map +1 -1
  147. package/lib/module/redux/reducers/appState.js +17 -1
  148. package/lib/module/redux/reducers/appState.js.map +1 -1
  149. package/lib/module/redux/reducers/userState.js +5 -1
  150. package/lib/module/redux/reducers/userState.js.map +1 -1
  151. package/lib/module/types.js +9 -0
  152. package/lib/module/types.js.map +1 -1
  153. package/lib/module/utils/types.js +11 -0
  154. package/lib/module/utils/types.js.map +1 -1
  155. package/lib/module/utils.js +0 -6
  156. package/lib/module/utils.js.map +1 -1
  157. package/lib/typescript/HMSPrebuilt.d.ts +2 -16
  158. package/lib/typescript/HMSPrebuilt.d.ts.map +1 -1
  159. package/lib/typescript/HMSRoomSetup.d.ts.map +1 -1
  160. package/lib/typescript/Icons/Hand/index.d.ts +1 -0
  161. package/lib/typescript/Icons/Hand/index.d.ts.map +1 -1
  162. package/lib/typescript/Icons/Recording/index.d.ts +1 -0
  163. package/lib/typescript/Icons/Recording/index.d.ts.map +1 -1
  164. package/lib/typescript/components/DisplayView.d.ts.map +1 -1
  165. package/lib/typescript/components/EndRoomModal.d.ts +6 -0
  166. package/lib/typescript/components/EndRoomModal.d.ts.map +1 -0
  167. package/lib/typescript/components/EndRoomModalContent.d.ts.map +1 -1
  168. package/lib/typescript/components/Footer.d.ts +1 -0
  169. package/lib/typescript/components/Footer.d.ts.map +1 -1
  170. package/lib/typescript/components/HMSKeyboardAvoidingView.d.ts +1 -0
  171. package/lib/typescript/components/HMSKeyboardAvoidingView.d.ts.map +1 -1
  172. package/lib/typescript/components/HMSManageLeave.d.ts.map +1 -1
  173. package/lib/typescript/components/HMSNotification.d.ts +1 -0
  174. package/lib/typescript/components/HMSNotification.d.ts.map +1 -1
  175. package/lib/typescript/components/HMSNotifications.d.ts +1 -0
  176. package/lib/typescript/components/HMSNotifications.d.ts.map +1 -1
  177. package/lib/typescript/components/HMSOverlayChatView.d.ts.map +1 -1
  178. package/lib/typescript/components/HMSReconnectingNotification.d.ts +5 -0
  179. package/lib/typescript/components/HMSReconnectingNotification.d.ts.map +1 -0
  180. package/lib/typescript/components/HMSTerminalErrorNotification.d.ts +10 -0
  181. package/lib/typescript/components/HMSTerminalErrorNotification.d.ts.map +1 -0
  182. package/lib/typescript/components/LeaveRoomBottomSheet.d.ts +6 -0
  183. package/lib/typescript/components/LeaveRoomBottomSheet.d.ts.map +1 -0
  184. package/lib/typescript/components/Meeting.d.ts.map +1 -1
  185. package/lib/typescript/components/PIPView.d.ts.map +1 -1
  186. package/lib/typescript/components/Participants/ParticipantsItemOptions.d.ts.map +1 -1
  187. package/lib/typescript/components/PeerVideoTile/PeerAudioIndicator.d.ts.map +1 -1
  188. package/lib/typescript/components/PeerVideoTile/PeerVideoTileView.d.ts.map +1 -1
  189. package/lib/typescript/components/RoomSettingsModalContent.d.ts.map +1 -1
  190. package/lib/typescript/components/StopRecordingModalContent.d.ts.map +1 -1
  191. package/lib/typescript/hooks-util.d.ts +20 -7
  192. package/lib/typescript/hooks-util.d.ts.map +1 -1
  193. package/lib/typescript/index.d.ts +2 -0
  194. package/lib/typescript/index.d.ts.map +1 -1
  195. package/lib/typescript/redux/actionTypes.d.ts +3 -0
  196. package/lib/typescript/redux/actionTypes.d.ts.map +1 -1
  197. package/lib/typescript/redux/actions/index.d.ts +23 -14
  198. package/lib/typescript/redux/actions/index.d.ts.map +1 -1
  199. package/lib/typescript/redux/index.d.ts +5 -7
  200. package/lib/typescript/redux/index.d.ts.map +1 -1
  201. package/lib/typescript/redux/reducers/appState.d.ts +4 -5
  202. package/lib/typescript/redux/reducers/appState.d.ts.map +1 -1
  203. package/lib/typescript/redux/reducers/index.d.ts +5 -7
  204. package/lib/typescript/redux/reducers/index.d.ts.map +1 -1
  205. package/lib/typescript/redux/reducers/userState.d.ts +2 -2
  206. package/lib/typescript/redux/reducers/userState.d.ts.map +1 -1
  207. package/lib/typescript/types.d.ts +79 -0
  208. package/lib/typescript/types.d.ts.map +1 -1
  209. package/lib/typescript/utils/types.d.ts +24 -0
  210. package/lib/typescript/utils/types.d.ts.map +1 -1
  211. package/lib/typescript/utils.d.ts +0 -5
  212. package/lib/typescript/utils.d.ts.map +1 -1
  213. package/package.json +2 -2
  214. package/src/HMSPrebuilt.tsx +32 -23
  215. package/src/HMSRoomSetup.tsx +105 -53
  216. package/src/Icons/Hand/assets/hand-off.png +0 -0
  217. package/src/Icons/Hand/assets/hand-off@2x.png +0 -0
  218. package/src/Icons/Hand/assets/hand-off@3x.png +0 -0
  219. package/src/Icons/Hand/index.tsx +13 -3
  220. package/src/Icons/Recording/assets/recording-off.png +0 -0
  221. package/src/Icons/Recording/assets/recording-off@2x.png +0 -0
  222. package/src/Icons/Recording/assets/recording-off@3x.png +0 -0
  223. package/src/Icons/Recording/index.tsx +9 -2
  224. package/src/components/DisplayView.tsx +6 -0
  225. package/src/components/EndRoomModal.tsx +24 -0
  226. package/src/components/EndRoomModalContent.tsx +9 -2
  227. package/src/components/Footer.tsx +18 -2
  228. package/src/components/HMSKeyboardAvoidingView.tsx +5 -23
  229. package/src/components/HMSLocalScreenshareNotification.tsx +1 -1
  230. package/src/components/HMSManageLeave.tsx +4 -228
  231. package/src/components/HMSNotification.tsx +4 -2
  232. package/src/components/HMSNotifications.tsx +41 -7
  233. package/src/components/HMSOverlayChatView.tsx +6 -1
  234. package/src/components/HMSReconnectingNotification.tsx +27 -0
  235. package/src/components/HMSRecordingIndicator.tsx +1 -1
  236. package/src/components/HMSTerminalErrorNotification.tsx +70 -0
  237. package/src/components/LeaveRoomBottomSheet.tsx +199 -0
  238. package/src/components/Meeting.tsx +7 -0
  239. package/src/components/MeetingScreenContent.tsx +2 -2
  240. package/src/components/PIPView.tsx +113 -25
  241. package/src/components/Participants/ParticipantsItemOptions.tsx +26 -4
  242. package/src/components/PeerVideoTile/AvatarView.tsx +4 -4
  243. package/src/components/PeerVideoTile/PeerAudioIndicator.tsx +6 -1
  244. package/src/components/PeerVideoTile/PeerVideoTileView.tsx +4 -2
  245. package/src/components/PreviewForRoleChangeModal.tsx +1 -1
  246. package/src/components/RoomSettingsModalContent.tsx +5 -9
  247. package/src/components/StopRecordingModalContent.tsx +3 -1
  248. package/src/hooks-util.ts +240 -23
  249. package/src/index.ts +2 -0
  250. package/src/redux/actionTypes.ts +7 -0
  251. package/src/redux/actions/index.ts +19 -7
  252. package/src/redux/reducers/appState.ts +18 -1
  253. package/src/redux/reducers/userState.ts +7 -3
  254. package/src/types.ts +71 -0
  255. package/src/utils/types.ts +27 -0
  256. 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!];
@@ -1886,13 +2001,13 @@ export const useShouldGoLive = () => {
1886
2001
  return shouldGoLive;
1887
2002
  };
1888
2003
 
1889
- export const useLeaveMethods = (isUnmounted: boolean) => {
2004
+ export const useLeaveMethods = () => {
1890
2005
  const navigation = useContext(NavigationContext);
1891
2006
  const hmsInstance = useHMSInstance();
1892
2007
  const dispatch = useDispatch();
1893
2008
  const reduxStore = useStore<RootState>();
1894
2009
 
1895
- const destroy = useCallback(() => {
2010
+ const destroy = useCallback((reason: Parameters<OnLeaveHandler>[0]) => {
1896
2011
  try {
1897
2012
  const s = hmsInstance.destroy();
1898
2013
  console.log('Destroy Success: ', s);
@@ -1919,9 +2034,13 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1919
2034
  const onLeave = reduxStore.getState().user.onLeave;
1920
2035
 
1921
2036
  if (typeof onLeave === 'function') {
1922
- onLeave();
2037
+ onLeave(reason);
1923
2038
  dispatch(clearStore());
1924
- } else if (navigation && navigation.canGoBack() && !isUnmounted) {
2039
+ } else if (
2040
+ navigation &&
2041
+ typeof navigation.canGoBack === 'function' &&
2042
+ navigation.canGoBack()
2043
+ ) {
1925
2044
  navigation.goBack();
1926
2045
  dispatch(clearStore());
1927
2046
  } else {
@@ -1941,7 +2060,7 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1941
2060
  }, [hmsInstance]);
1942
2061
 
1943
2062
  const leave = useCallback(
1944
- async (shouldEndStream: boolean = false) => {
2063
+ async (reason: OnLeaveReason, shouldEndStream: boolean = false) => {
1945
2064
  if (shouldEndStream) {
1946
2065
  hmsInstance.stopHLSStreaming().catch((error) => {
1947
2066
  console.log('Stop HLS Streaming Error: ', error);
@@ -1950,7 +2069,7 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1950
2069
  try {
1951
2070
  const d = await hmsInstance.leave();
1952
2071
  console.log('Leave Success: ', d);
1953
- await destroy();
2072
+ await destroy(reason);
1954
2073
  } catch (e) {
1955
2074
  console.log(`Leave Room Error: ${e}`);
1956
2075
  Toast.showWithGravity(`Leave Room Error: ${e}`, Toast.LONG, Toast.TOP);
@@ -1959,31 +2078,31 @@ export const useLeaveMethods = (isUnmounted: boolean) => {
1959
2078
  [destroy, hmsInstance]
1960
2079
  );
1961
2080
 
1962
- const goToPreview = useCallback(async () => {
2081
+ const prebuiltCleanUp = useCallback(async () => {
1963
2082
  try {
1964
2083
  await hmsInstance.leave();
1965
2084
  await hmsInstance.destroy();
1966
2085
  dispatch(clearStore());
1967
2086
  } catch (error) {
1968
2087
  Toast.showWithGravity(
1969
- `Unable to go to Preview: ${error}`,
2088
+ `Unable to leave or destroy: ${error}`,
1970
2089
  Toast.LONG,
1971
2090
  Toast.TOP
1972
2091
  );
1973
2092
  }
1974
2093
  }, [hmsInstance]);
1975
2094
 
1976
- const endRoom = useCallback(async () => {
2095
+ const endRoom = useCallback(async (reason: OnLeaveReason) => {
1977
2096
  try {
1978
2097
  const d = await hmsInstance.endRoom('Host ended the room');
1979
2098
  console.log('EndRoom Success: ', d);
1980
- await destroy();
2099
+ await destroy(reason);
1981
2100
  } catch (e) {
1982
2101
  console.log('EndRoom Error: ', e);
1983
2102
  }
1984
2103
  }, [destroy, hmsInstance]);
1985
2104
 
1986
- return { destroy, leave, endRoom, goToPreview };
2105
+ return { destroy, leave, endRoom, prebuiltCleanUp };
1987
2106
  };
1988
2107
 
1989
2108
  // Returns layout config as it is returned from server
@@ -2189,3 +2308,101 @@ export const useHMSConferencingScreenConfig = <Selected = unknown>(
2189
2308
  return selector(conferencingScreenConfig);
2190
2309
  }, equalityFn);
2191
2310
  };
2311
+
2312
+ export const useBackButtonPress = () => {
2313
+ const { handleModalVisibleType } = useModalType();
2314
+
2315
+ const handleBackPress = useSelector(
2316
+ (state: RootState) => state.app.handleBackButton
2317
+ );
2318
+
2319
+ useEffect(() => {
2320
+ if (handleBackPress) {
2321
+ const backPressHandler = () => {
2322
+ handleModalVisibleType(ModalTypes.LEAVE_ROOM);
2323
+
2324
+ /**
2325
+ * When true is returned the event will not be bubbled up
2326
+ * & no other back action will execute
2327
+ */
2328
+ return true;
2329
+
2330
+ /**
2331
+ * Returning false will let the event to bubble up & let other event listeners
2332
+ * or the system's default back action to be executed.
2333
+ */
2334
+ // return false;
2335
+ };
2336
+
2337
+ const subscription = BackHandler.addEventListener(
2338
+ 'hardwareBackPress',
2339
+ backPressHandler
2340
+ );
2341
+
2342
+ return () => {
2343
+ if (typeof subscription.remove === 'function') {
2344
+ subscription.remove();
2345
+ } else {
2346
+ BackHandler.removeEventListener(
2347
+ 'hardwareBackPress',
2348
+ backPressHandler
2349
+ );
2350
+ }
2351
+ };
2352
+ }
2353
+ }, [handleBackPress, handleModalVisibleType]);
2354
+ };
2355
+
2356
+ export const useSavePropsToStore = (
2357
+ props: HMSPrebuiltProps,
2358
+ dispatch: AppDispatch
2359
+ ) => {
2360
+ const { roomCode, options, onLeave, handleBackButton, autoEnterPipMode } =
2361
+ props;
2362
+
2363
+ useEffect(() => {
2364
+ dispatch(setPrebuiltData({ roomCode, options }));
2365
+ }, [roomCode, options]);
2366
+
2367
+ useEffect(() => {
2368
+ dispatch(setOnLeaveHandler(onLeave));
2369
+ }, [onLeave]);
2370
+
2371
+ useEffect(() => {
2372
+ if (Platform.OS === 'android') {
2373
+ dispatch(setHandleBackButton(handleBackButton));
2374
+ }
2375
+ }, [handleBackButton]);
2376
+
2377
+ useEffect(() => {
2378
+ if (Platform.OS === 'android') {
2379
+ dispatch(setAutoEnterPipMode(autoEnterPipMode));
2380
+ }
2381
+ }, [autoEnterPipMode]);
2382
+ };
2383
+
2384
+ export const useStartRecording = () => {
2385
+ const dispatch = useDispatch();
2386
+ const hmsInstance = useHMSInstance();
2387
+
2388
+ const startRecording = useCallback(() => {
2389
+ dispatch(setStartingOrStoppingRecording(true));
2390
+
2391
+ hmsInstance.startRTMPOrRecording({ record: true }).catch((error) => {
2392
+ batch(() => {
2393
+ dispatch(setStartingOrStoppingRecording(false));
2394
+ dispatch(
2395
+ addNotification({
2396
+ id: Math.random().toString(16).slice(2),
2397
+ type: NotificationTypes.ERROR,
2398
+ message: error.message
2399
+ })
2400
+ );
2401
+ });
2402
+ });
2403
+ }, [hmsInstance]);
2404
+
2405
+ return {
2406
+ startRecording,
2407
+ };
2408
+ };
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:
@@ -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:
package/src/types.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { HMSException, HMSPeer } from "@100mslive/react-native-hms";
2
+ import type { HMSIOSScreenShareConfig, OnLeaveHandler } from "./utils/types";
3
+
1
4
  export enum MeetingState {
2
5
  NOT_JOINED,
3
6
  IN_PREVIEW,
@@ -5,3 +8,71 @@ export enum MeetingState {
5
8
  MEETING_ENDED,
6
9
  ERROR,
7
10
  }
11
+ export interface HMSPrebuiltProps {
12
+ roomCode: string;
13
+ options?: {
14
+ userName?: string;
15
+ userId?: string;
16
+ endPoints?: {
17
+ init: string;
18
+ token: string;
19
+ layout: string;
20
+ };
21
+ debugMode?: boolean;
22
+ ios?: HMSIOSScreenShareConfig;
23
+ };
24
+ /**
25
+ * onLeave - Optional callback function
26
+ *
27
+ * It will be invoked when user leaves meeting or user is removed from the room
28
+ */
29
+ onLeave?: OnLeaveHandler;
30
+ /**
31
+ * [Android Only] handleBackButton - `Optional<Boolean>` | Default value - `false`
32
+ *
33
+ * When `true`, Leave modal will open on press of back button on android
34
+ * otherwise user will leave meeting immediately without any confirmation modal opening
35
+ *
36
+ * Example usage:
37
+ * ```jsx
38
+ * const isScreenFocused = useIsFocused();
39
+ *
40
+ * ...
41
+ *
42
+ * <HMSPrebuilt
43
+ * {...}
44
+ * handleBackButton={isScreenFocused}
45
+ * />
46
+ * ```
47
+ */
48
+ handleBackButton?: boolean;
49
+ /**
50
+ * [Android Only] autoEnterPipMode - `Optional<Boolean>` | Default value - `false`
51
+ *
52
+ * When `true`, App will go into PIP mode automatically when user tries to leave or minimize app while it is inside room
53
+ *
54
+ * Example usage:
55
+ * ```jsx
56
+ * <HMSPrebuilt
57
+ * {...}
58
+ * autoEnterPipMode={true}
59
+ * />
60
+ * ```
61
+ */
62
+ autoEnterPipMode?: boolean;
63
+ }
64
+
65
+ export enum NotificationTypes {
66
+ ROLE_CHANGE_DECLINED = 'role_change_declined',
67
+ RECONNECTING = 'reconnecting',
68
+ HAND_RAISE = 'hand_raise',
69
+ LOCAL_SCREENSHARE = 'local_screenshare',
70
+ ERROR = 'error',
71
+ TERMINAL_ERROR = 'terminal_error',
72
+ }
73
+
74
+ export type Notification =
75
+ | { id: string; type: NotificationTypes; }
76
+ | { id: string; type: NotificationTypes; message: string; }
77
+ | { id: string; type: NotificationTypes; peer: HMSPeer; }
78
+ | { id: string; type: NotificationTypes; exception: HMSException; }