Skip to content

Commit

Permalink
Merge pull request #4396 from traPtitech/feat/save_mute_state
Browse files Browse the repository at this point in the history
ミュート状態を保持するように
  • Loading branch information
nokhnaton authored Oct 28, 2024
2 parents a121b28 + 790d540 commit 9c8a0e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/store/app/rtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ const useAppRtcPinia = defineStore('app/rtc', () => {
}

/** マイクミュート */
const isMicMuted = ref(false)
const muteLocalStream = () => {
if (!localStreamManager.value) return
localStreamManager.value.mute()
isMicMuted.value = true
rtcSettings.isMute.value = true
}
const unmuteLocalStream = () => {
if (!localStreamManager.value) return
localStreamManager.value.unmute()
isMicMuted.value = false
rtcSettings.isMute.value = false
}

/** 現在発話しているユーザーを判定するsetIntervalのID */
Expand Down Expand Up @@ -283,7 +282,7 @@ const useAppRtcPinia = defineStore('app/rtc', () => {
setUserVolume(userId, 0.5)
})

if (isMicMuted.value) {
if (rtcSettings.isMute.value) {
mute()
} else {
unmute()
Expand Down Expand Up @@ -352,7 +351,7 @@ const useAppRtcPinia = defineStore('app/rtc', () => {

return {
isCurrentDevice,
isMicMuted,
isMicMuted: rtcSettings.isMute,
talkingUsersState,
startQall,
endQall,
Expand Down
12 changes: 10 additions & 2 deletions src/store/app/rtcSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type State = {
voicePitch: number
voiceRate: number
voiceVolume: number
isMute: boolean
}

const useRtcSettingsPinia = defineStore('app/rtcSettings', () => {
Expand All @@ -33,12 +34,13 @@ const useRtcSettingsPinia = defineStore('app/rtcSettings', () => {
voiceName: '',
voicePitch: 1,
voiceRate: 1.2,
voiceVolume: 1
voiceVolume: 1,
isMute: false
}

const [state, restoring, restoringPromise] = useIndexedDbValue(
'store/app/rtcSettings',
2,
3,
{
// migrate from vuex
1: async getStore => {
Expand All @@ -64,6 +66,12 @@ const useRtcSettingsPinia = defineStore('app/rtcSettings', () => {
delete state?.isNoiseReductionEnabled
const setReq = store.put(state, key)
await promisifyRequest(setReq)
},

3: async getStore => {
const store = getStore()
const setReq = store.put({ isMute: false }, key)
await promisifyRequest(setReq)
}
},
initialValue
Expand Down

0 comments on commit 9c8a0e7

Please sign in to comment.