Skip to content

Commit c8ffe4c

Browse files
author
Sravan S
authored
fix: Pause voice when moved back (#606)
Is better not to handle this in Message Component because this is a layout edge case. Customer can decide the layout, so they should be able to dictate the UX Fixes: https://sendbird.atlassian.net/browse/UIKIT-4031
1 parent 6599a88 commit c8ffe4c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/hooks/VoicePlayer/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface VoicePlayerContext {
3737
voicePlayerStore: VoicePlayerInitialState;
3838
}
3939

40+
export const ALL = 'ALL';
41+
4042
const noop = () => { /* noop */ };
4143
const VoicePlayerStoreDefaultValue = {
4244
currentGroupKey: '',
@@ -70,11 +72,15 @@ export const VoicePlayerProvider = ({
7072
}
7173
};
7274

73-
const pause = (groupKey: string) => {
75+
const pause = (groupKey: string|null) => {
7476
if (currentGroupKey === groupKey && currentPlayer !== null) {
7577
logger.info('VoicePlayer: Pause playing(by group key).');
7678
currentPlayer?.pause();
7779
}
80+
if (groupKey === ALL) {
81+
logger.info('VoicePlayer: Pause playing(all).');
82+
currentPlayer?.pause();
83+
}
7884
};
7985

8086
const play = ({

src/modules/App/MobileLayout.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import MessageSearch from '../MessageSearch';
1414
import Thread from '../Thread';
1515
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext';
1616
import uuidv4 from '../../utils/uuid';
17+
import { ALL, useVoicePlayerContext } from '../../hooks/VoicePlayer';
1718

1819
enum PANELS {
1920
CHANNEL_LIST = 'CHANNEL_LIST',
@@ -49,6 +50,8 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
4950
const sdk = store?.stores?.sdkStore?.sdk as SendbirdGroupChat;
5051
const userId = store?.config?.userId;
5152

53+
const { pause } = useVoicePlayerContext();
54+
5255
const goToMessage = (message?: BaseMessage | null, timeoutCb?: (msgId: number | null) => void) => {
5356
setStartingPoint?.(message?.createdAt || null);
5457
setTimeout(() => {
@@ -118,6 +121,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
118121
}}
119122
onBackClick={() => {
120123
setPanel(PANELS.CHANNEL_LIST);
124+
pause(ALL);
121125
}}
122126
isReactionEnabled={isReactionEnabled}
123127
showSearchIcon={showSearchIcon}
@@ -185,6 +189,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
185189
message={threadTargetMessage}
186190
onHeaderActionClick={() => {
187191
setPanel(PANELS.CHANNEL);
192+
pause(ALL);
188193
}}
189194
onMoveToParentMessage={({ message, channel }) => {
190195
setCurrentChannel(channel);

src/ui/VoiceMessageItemBody/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const VoiceMessageItemBody = ({
2929
const [usingReaction, setUsingReaction] = useState(false);
3030
const {
3131
play,
32+
// do not pause on unmount, because on desktop layout
33+
// the component can be paused when it is played from
34+
// channel and same message is unmounted from the thread
3235
pause,
3336
playbackTime = 0,
3437
duration,

0 commit comments

Comments
 (0)