Skip to content

Commit

Permalink
fix(prebuilt): 🐛 instance is created and destroyed on meeting leave
Browse files Browse the repository at this point in the history
  • Loading branch information
stanwolverine committed Jan 8, 2024
1 parent 1aa1ffb commit c0707b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
20 changes: 18 additions & 2 deletions packages/react-native-room-kit/src/HMSContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import React from 'react';
import { useSelector } from 'react-redux';
import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';

import type { RootState } from './redux';
import { HMSInstanceSetup } from './HMSInstanceSetup';
import { HMSRoomSetup } from './HMSRoomSetup';
import { MeetingState } from './types';
import { clearStore } from './redux/actions';

export const HMSContainer = () => {
const dispatch = useDispatch();
const isHMSInstanceAvailable = useSelector(
(state: RootState) => !!state.user.hmsInstance
);
const outOfMeeting = useSelector(
(state: RootState) =>
state.app.meetingState === MeetingState.OUT_FROM_MEETING
);
const canCleanupAfter = isHMSInstanceAvailable && outOfMeeting;

React.useEffect(() => {
if (canCleanupAfter) {
return () => {
dispatch(clearStore());
};
}
}, [canCleanupAfter]);

if (isHMSInstanceAvailable) {
return <HMSRoomSetup />;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-room-kit/src/HMSRoomSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export const HMSRoomSetup = () => {
useEffect(() => {
return () => {
ignoreHLSStreamPromise.current = true;
prebuiltCleanUp();
// prebuiltCleanUp();
};
}, []);

Expand Down
5 changes: 2 additions & 3 deletions packages/react-native-room-kit/src/hooks-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2149,18 +2149,17 @@ export const useLeaveMethods = () => {
const onLeave = reduxStore.getState().user.onLeave;

if (typeof onLeave === 'function') {
dispatch(changeMeetingState(MeetingState.OUT_FROM_MEETING));
onLeave(reason);
dispatch(clearStore());
} else if (
navigation &&
typeof navigation.canGoBack === 'function' &&
navigation.canGoBack()
) {
dispatch(changeMeetingState(MeetingState.OUT_FROM_MEETING));
navigation.goBack();
dispatch(clearStore());
} else {
// Otherwise default action is to show "Meeting Ended" screen
dispatch(clearStore()); // TODO: We need different clearStore for MeetingEnded
dispatch(changeMeetingState(MeetingState.MEETING_ENDED));
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-room-kit/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum MeetingState {
NOT_JOINED,
IN_PREVIEW,
IN_MEETING,
OUT_FROM_MEETING,
MEETING_ENDED,
ERROR,
}
Expand Down

0 comments on commit c0707b1

Please sign in to comment.