diff --git a/src/store/participantsStore.js b/src/store/participantsStore.js index 66b3ef4ca3b..09fc6f91f93 100644 --- a/src/store/participantsStore.js +++ b/src/store/participantsStore.js @@ -845,7 +845,7 @@ const actions = { }, 10000) const callViewStore = useCallViewStore() - callViewStore.handleJoinCall({ token }) + callViewStore.handleJoinCall(getters.conversation(token)) }, async leaveCall({ commit, getters }, { token, participantIdentifier, all = false }) { diff --git a/src/store/participantsStore.spec.js b/src/store/participantsStore.spec.js index 36fd7494d88..70dc8baac55 100644 --- a/src/store/participantsStore.spec.js +++ b/src/store/participantsStore.spec.js @@ -540,6 +540,10 @@ describe('participantsStore', () => { const flags = PARTICIPANT.CALL_FLAG.WITH_AUDIO | PARTICIPANT.CALL_FLAG.WITH_VIDEO beforeEach(async () => { + testStoreConfig.getters.conversation = () => jest.fn().mockReturnValue({ + token: TOKEN, + type: 3, + }) store = new Vuex.Store(testStoreConfig) store.dispatch('addParticipant', { token: TOKEN, @@ -876,6 +880,10 @@ describe('participantsStore', () => { attendeeId: 1, sessionId: 'session-id-1', }) + testStoreConfig.getters.conversation = () => jest.fn().mockReturnValue({ + token: TOKEN, + type: 3, + }) store = new Vuex.Store(testStoreConfig) store.dispatch('addParticipant', { diff --git a/src/stores/__tests__/callView.spec.js b/src/stores/__tests__/callView.spec.js index 922cb831880..6231c864582 100644 --- a/src/stores/__tests__/callView.spec.js +++ b/src/stores/__tests__/callView.spec.js @@ -38,11 +38,12 @@ describe('callViewStore', () => { function testDefaultGridState(type, state, browserStorageState = null) { // Arrange BrowserStorage.getItem.mockReturnValueOnce(browserStorageState) + const conversation = { token: TOKEN, type } // using commit instead of dispatch because the action also processes participants - vuexStore.commit('addConversation', { token: TOKEN, type }) + vuexStore.commit('addConversation', conversation) // Act - callViewStore.handleJoinCall({ token: TOKEN }) + callViewStore.handleJoinCall(conversation) // Assert expect(BrowserStorage.getItem).toHaveBeenCalledWith(BROWSER_STORAGE_KEY) @@ -50,6 +51,13 @@ describe('callViewStore', () => { expect(callViewStore.isStripeOpen).toBeTruthy() } + it('does not proceed without conversation object', () => { + // Act + callViewStore.handleJoinCall() + // Assert + expect(BrowserStorage.getItem).not.toHaveBeenCalledWith(BROWSER_STORAGE_KEY) + }) + it('restores grid state from BrowserStorage when joining call (true)', () => { // Arrange testDefaultGridState(CONVERSATION.TYPE.GROUP, true, 'true') diff --git a/src/stores/callView.js b/src/stores/callView.js index 7202755febd..360be6eafcf 100644 --- a/src/stores/callView.js +++ b/src/stores/callView.js @@ -7,7 +7,6 @@ import { defineStore } from 'pinia' import { CONVERSATION } from '../constants.js' import BrowserStorage from '../services/BrowserStorage.js' -import store from '../store/index.js' export const useCallViewStore = defineStore('callView', { state: () => ({ @@ -44,13 +43,16 @@ export const useCallViewStore = defineStore('callView', { this.selectedVideoPeerId = value }, - handleJoinCall({ token }) { - const gridPreference = BrowserStorage.getItem(`callprefs-${token}-isgrid`) + handleJoinCall(conversation) { + if (!conversation) { + return + } + const gridPreference = BrowserStorage.getItem(`callprefs-${conversation.token}-isgrid`) const isGrid = gridPreference === null // not defined yet, default to grid view for group/public calls, otherwise speaker view - ? [CONVERSATION.TYPE.GROUP, CONVERSATION.TYPE.PUBLIC].includes(store.getters.conversations[token].type) + ? [CONVERSATION.TYPE.GROUP, CONVERSATION.TYPE.PUBLIC].includes(conversation.type) : gridPreference === 'true' - this.setCallViewMode({ isGrid, isStripeOpen: true }) + this.setCallViewMode({ token: conversation.token, isGrid, isStripeOpen: true }) }, /**