From 9ad2fedf39e6c0bc80cb23be6fcb5c3c9274e16b Mon Sep 17 00:00:00 2001 From: Atir Nayab <91016903+nayabatir1@users.noreply.github.com> Date: Thu, 5 Jan 2023 12:40:09 +0530 Subject: [PATCH] fix(client): set fcc-sound value in local storage (#48762) --- client/src/redux/fetch-user-saga.js | 9 ++++++++- client/src/utils/tone/index.ts | 12 ++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/client/src/redux/fetch-user-saga.js b/client/src/redux/fetch-user-saga.js index 6e9dadac818..20b4d65ddae 100644 --- a/client/src/redux/fetch-user-saga.js +++ b/client/src/redux/fetch-user-saga.js @@ -1,5 +1,5 @@ import { call, put, takeEvery } from 'redux-saga/effects'; - +import store from 'store'; import { getSessionUser, getUserProfile } from '../utils/ajax'; import { fetchProfileForUserComplete, @@ -19,6 +19,13 @@ function* fetchSessionUser() { data: { user = {}, result = '', sessionMeta = {} } } = yield call(getSessionUser); const appUser = user[result] || {}; + + const [userId] = Object.keys(user); + + const sound = user[userId].sound; + + store.set('fcc-sound', sound); + yield put( fetchUserComplete({ user: appUser, username: result, sessionMeta }) ); diff --git a/client/src/utils/tone/index.ts b/client/src/utils/tone/index.ts index e146073809e..103ea6c46d2 100644 --- a/client/src/utils/tone/index.ts +++ b/client/src/utils/tone/index.ts @@ -62,20 +62,16 @@ type ToneStates = keyof typeof toneUrls; export async function playTone(state: ToneStates): Promise { const playSound = !!store.get('fcc-sound'); if (playSound && toneUrls[state]) { - const tone = await import('tone'); + const Tone = await import('tone'); - if (tone.context.state !== 'running') { - tone.context.resume().catch(err => { - console.error('Error resuming audio context', err); - }); - } - const player = new tone.Player(toneUrls[state]).toDestination(); + const player = new Tone.Player(toneUrls[state]).toDestination(); const storedVolume = (store.get('soundVolume') as number) ?? 50; const calculateDecibel = -60 * (1 - storedVolume / 100); player.volume.value = calculateDecibel; - player.autostart = true; + await Tone.loaded(); + player.start(); } }