From f447757cf5309fef106f26941d213ab726f32869 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 4 Oct 2023 23:11:01 -0300 Subject: [PATCH] pauseAudio when roomview is blur --- app/views/RoomView/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 9be544520..e0fbeab19 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -227,6 +227,7 @@ class RoomView extends React.Component { cancel: () => void; }; private sub?: RoomClass; + private unsubscribeBlur?: () => void; constructor(props: IRoomViewProps) { super(props); @@ -304,6 +305,7 @@ class RoomView extends React.Component { } componentDidMount() { + const { navigation } = this.props; this.mounted = true; this.didMountInteraction = InteractionManager.runAfterInteractions(() => { const { isAuthenticated } = this.props; @@ -330,6 +332,10 @@ class RoomView extends React.Component { } }); EventEmitter.addEventListener('ROOM_REMOVED', this.handleRoomRemoved); + // TODO: Refactor when audio becomes global + this.unsubscribeBlur = navigation.addListener('blur', () => { + audioPlayer.pauseCurrentAudio(); + }); } shouldComponentUpdate(nextProps: IRoomViewProps, nextState: IRoomViewState) { @@ -446,10 +452,11 @@ class RoomView extends React.Component { if (this.retryInitTimeout) { clearTimeout(this.retryInitTimeout); } + if (this.unsubscribeBlur) { + this.unsubscribeBlur(); + } EventEmitter.removeListener('connected', this.handleConnected); EventEmitter.removeListener('ROOM_REMOVED', this.handleRoomRemoved); - // TODO: Refactor when audio becomes global - await audioPlayer.pauseCurrentAudio(); } canForwardGuest = async () => { @@ -1161,9 +1168,6 @@ class RoomView extends React.Component { return; } - // TODO: Refactor when audio becomes global - await audioPlayer.pauseCurrentAudio(); - if (item.tmid) { let name = ''; let jumpToMessageId = '';