-
Notifications
You must be signed in to change notification settings - Fork 144
refactor: Voice Player date structure #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HoonBaek
merged 14 commits into
develop/Voice-message
from
fix/UIKIT-3263/Use-reducer-for-voice-player-context-operation
Mar 2, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
285ee50
Apply dux to voice player state
EunSeo-Baek 91775e1
Remove event operation logic of voice player
EunSeo-Baek 1a6a018
Migrate useVoicePlayer to apply new structure
EunSeo-Baek e4ba6e3
Remove the voice player event operation legacy
EunSeo-Baek 182ac50
Add new VoicePlayerStatus IDLE
EunSeo-Baek e262f1b
Apply VoicePlayerStatus to UI components
EunSeo-Baek f712abe
Add validation check for playbackTime and duration of voicePlayerInit…
EunSeo-Baek fcb3081
Do not pause VoicePlayer when change channel or thread
EunSeo-Baek 30b23e7
Apply VoicePlayerStatus to change the state of VoiceMessageInput
EunSeo-Baek 6f9a1cf
Pause AudioPlayer in useEffect unmount scope using document
EunSeo-Baek dab7c35
Fix typo
EunSeo-Baek 8770a82
Use audio file first when play method is called with a real audio file
EunSeo-Baek 5530b0f
Replace the type definition of GroupKey to be with the related function
EunSeo-Baek 97b5c8a
Clean up voice player action types
EunSeo-Baek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const actionTypes = { | ||
INITIALIZE_AUDIO_UNIT: 'INITIALIZE_AUDIO_UNIT', | ||
SET_CURRENT_PLAYER: 'SET_CURRENT_PLAYER', | ||
ON_VOICE_PLAYER_PLAY: 'ON_VOICE_PLAYER_PLAY', | ||
ON_VOICE_PLAYER_PAUSE: 'ON_VOICE_PLAYER_PAUSE', | ||
ON_CURRENT_TIME_UPDATE: 'ON_CURRENT_TIME_UPDATE', | ||
} as const; | ||
|
||
type ObjectValues<T> = T[keyof T]; | ||
export type VoicePlayerActionType = ObjectValues<typeof actionTypes>; | ||
|
||
export const INITIALIZE_AUDIO_UNIT: VoicePlayerActionType = 'INITIALIZE_AUDIO_UNIT'; | ||
export const SET_CURRENT_PLAYER: VoicePlayerActionType = 'SET_CURRENT_PLAYER'; | ||
export const ON_VOICE_PLAYER_PLAY: VoicePlayerActionType = 'ON_VOICE_PLAYER_PLAY'; | ||
export const ON_VOICE_PLAYER_PAUSE: VoicePlayerActionType = 'ON_VOICE_PLAYER_PAUSE'; | ||
export const ON_CURRENT_TIME_UPDATE: VoicePlayerActionType = 'ON_CURRENT_TIME_UPDATE'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { GroupKey } from '../utils'; | ||
|
||
export const VoicePlayerStatus = { | ||
IDLE: 'IDLE', | ||
PREPARING: 'PREPARING', | ||
PLAYING: 'PLAYING', | ||
PAUSED: 'PAUSED', | ||
COMPLETED: 'COMPLETED', | ||
} as const; | ||
export type VoicePlayerStatus = typeof VoicePlayerStatus[keyof typeof VoicePlayerStatus]; | ||
|
||
export type AudioStorageUnit = { | ||
playingStatus: VoicePlayerStatus; | ||
audioFile: null | File; | ||
playbackTime: number; | ||
duration: number; | ||
} | ||
export const AudioUnitDefaultValue = (): AudioStorageUnit => ({ | ||
audioFile: null, | ||
playbackTime: 0, | ||
duration: 1000, | ||
playingStatus: VoicePlayerStatus.IDLE, | ||
}); | ||
|
||
export interface VoicePlayerInitialState { | ||
currentPlayer: null | HTMLAudioElement; | ||
currentGroupKey: string; | ||
audioStorage: Record<GroupKey, AudioStorageUnit>; | ||
} | ||
|
||
export const voicePlayerInitialState: VoicePlayerInitialState = { | ||
currentPlayer: null, | ||
currentGroupKey: '', | ||
audioStorage: {}, | ||
}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { | ||
INITIALIZE_AUDIO_UNIT, | ||
ON_CURRENT_TIME_UPDATE, | ||
ON_VOICE_PLAYER_PAUSE, | ||
ON_VOICE_PLAYER_PLAY, | ||
SET_CURRENT_PLAYER, | ||
} from "./actionTypes"; | ||
import { | ||
AudioStorageUnit, | ||
AudioUnitDefaultValue, | ||
VoicePlayerInitialState, | ||
VoicePlayerStatus, | ||
} from "./initialState"; | ||
|
||
type InitializeAudioUnitPayload = { groupKey: string }; | ||
type SetCurrentPlayerPayload = { audioPlayer: HTMLAudioElement, groupKey: string }; | ||
type OnVoicePlayerPlayPayload = { groupKey: string, audioFile: File }; | ||
type OnVoicePlayerPausePayload = { groupKey: string }; | ||
type OnCurrentTimeUpdatePayload = { groupKey: string }; | ||
type PayloadType = ( | ||
InitializeAudioUnitPayload | ||
| SetCurrentPlayerPayload | ||
| OnVoicePlayerPlayPayload | ||
| OnVoicePlayerPausePayload | ||
| OnCurrentTimeUpdatePayload | ||
); | ||
HoonBaek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type ActionType = { | ||
type: string; | ||
payload: PayloadType; | ||
} | ||
|
||
export default function voicePlayerReducer( | ||
state: VoicePlayerInitialState, | ||
action: ActionType, | ||
): VoicePlayerInitialState { | ||
switch (action.type) { | ||
case INITIALIZE_AUDIO_UNIT: { | ||
HoonBaek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { groupKey } = action.payload as InitializeAudioUnitPayload; | ||
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit; | ||
audioUnit.playingStatus = VoicePlayerStatus.PREPARING; | ||
return { | ||
...state, | ||
audioStorage: { | ||
...state.audioStorage, | ||
[groupKey]: audioUnit, | ||
}, | ||
}; | ||
} | ||
case SET_CURRENT_PLAYER: { | ||
const { audioPlayer, groupKey } = action.payload as SetCurrentPlayerPayload; | ||
return { | ||
...state, | ||
currentPlayer: audioPlayer, | ||
currentGroupKey: groupKey, | ||
}; | ||
} | ||
case ON_VOICE_PLAYER_PLAY: { | ||
const { groupKey, audioFile } = action.payload as OnVoicePlayerPlayPayload; | ||
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit; | ||
audioUnit.audioFile = audioFile; | ||
audioUnit.playingStatus = VoicePlayerStatus.PLAYING; | ||
return { | ||
...state, | ||
audioStorage: { | ||
...state.audioStorage, | ||
[groupKey]: audioUnit, | ||
}, | ||
}; | ||
} | ||
case ON_VOICE_PLAYER_PAUSE: { | ||
const { groupKey } = action.payload as OnVoicePlayerPausePayload; | ||
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit; | ||
audioUnit.playingStatus = VoicePlayerStatus.PAUSED; | ||
const { currentTime, duration } = state.currentPlayer as HTMLAudioElement; | ||
if (audioUnit.playbackTime === audioUnit.duration) { | ||
audioUnit.playbackTime = 0; | ||
} else if (currentTime > 0 && duration > 0) { | ||
audioUnit.playbackTime = currentTime; | ||
audioUnit.duration = duration; | ||
} | ||
return { | ||
...state, | ||
audioStorage: { | ||
...state.audioStorage, | ||
[groupKey]: audioUnit, | ||
}, | ||
}; | ||
} | ||
case ON_CURRENT_TIME_UPDATE: { | ||
const { groupKey } = action.payload as OnCurrentTimeUpdatePayload; | ||
const { currentTime, duration } = state.currentPlayer as HTMLAudioElement; | ||
const audioUnit = (state.audioStorage?.[groupKey] ? state.audioStorage[groupKey] : AudioUnitDefaultValue()) as AudioStorageUnit; | ||
if (currentTime > 0 && duration > 0) { | ||
audioUnit.playbackTime = currentTime; | ||
audioUnit.duration = duration; | ||
} | ||
return { | ||
...state, | ||
audioStorage: { | ||
...state.audioStorage, | ||
[groupKey]: audioUnit, | ||
}, | ||
}; | ||
} | ||
default: | ||
return state; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.