Skip to content

Commit

Permalink
fix: pass conversation to callView store via actions
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Oct 24, 2024
1 parent 2f19f82 commit 6bf5c09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/store/participantsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
8 changes: 8 additions & 0 deletions src/store/participantsStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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', {
Expand Down
12 changes: 10 additions & 2 deletions src/stores/__tests__/callView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,26 @@ 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)
expect(callViewStore.isGrid).toBe(state)
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')
Expand Down
12 changes: 7 additions & 5 deletions src/stores/callView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({
Expand Down Expand Up @@ -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 })
},

/**
Expand Down

0 comments on commit 6bf5c09

Please sign in to comment.