Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/hooks/VoicePlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface VoicePlayerContext {
voicePlayerStore: VoicePlayerInitialState;
}

export const ALL = 'ALL';

const noop = () => { /* noop */ };
const VoicePlayerStoreDefaultValue = {
currentGroupKey: '',
Expand Down Expand Up @@ -70,11 +72,15 @@ export const VoicePlayerProvider = ({
}
};

const pause = (groupKey: string) => {
const pause = (groupKey: string|null) => {
if (currentGroupKey === groupKey && currentPlayer !== null) {
logger.info('VoicePlayer: Pause playing(by group key).');
currentPlayer?.pause();
}
if (groupKey === ALL) {
logger.info('VoicePlayer: Pause playing(all).');
currentPlayer?.pause();
}
};

const play = ({
Expand Down
5 changes: 5 additions & 0 deletions src/modules/App/MobileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import MessageSearch from '../MessageSearch';
import Thread from '../Thread';
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext';
import uuidv4 from '../../utils/uuid';
import { ALL, useVoicePlayerContext } from '../../hooks/VoicePlayer';

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

const { pause } = useVoicePlayerContext();

const goToMessage = (message?: BaseMessage | null, timeoutCb?: (msgId: number | null) => void) => {
setStartingPoint?.(message?.createdAt || null);
setTimeout(() => {
Expand Down Expand Up @@ -118,6 +121,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
}}
onBackClick={() => {
setPanel(PANELS.CHANNEL_LIST);
pause(ALL);
}}
isReactionEnabled={isReactionEnabled}
showSearchIcon={showSearchIcon}
Expand Down Expand Up @@ -185,6 +189,7 @@ export const MobileLayout: React.FC<MobileLayoutProps> = (
message={threadTargetMessage}
onHeaderActionClick={() => {
setPanel(PANELS.CHANNEL);
pause(ALL);
}}
onMoveToParentMessage={({ message, channel }) => {
setCurrentChannel(channel);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/VoiceMessageItemBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const VoiceMessageItemBody = ({
const [usingReaction, setUsingReaction] = useState(false);
const {
play,
// do not pause on unmount, because on desktop layout
// the component can be paused when it is played from
// channel and same message is unmounted from the thread
pause,
playbackTime = 0,
duration,
Expand Down