Skip to content

Commit

Permalink
Merge pull request #13626 from nextcloud/backport/13625/stable30
Browse files Browse the repository at this point in the history
  • Loading branch information
Antreesy authored Oct 24, 2024
2 parents 198a58e + e7a1dcf commit 7fe2722
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 39 deletions.
15 changes: 8 additions & 7 deletions src/components/CallView/CallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,19 @@ export default {
callParticipantModelsWithScreen(newValue, previousValue) {
// Everytime a new screen is shared, switch to promoted view
if (newValue.length > previousValue.length) {
this.callViewStore.startPresentation()
this.callViewStore.startPresentation(this.token)
} else if (newValue.length === 0 && previousValue.length > 0 && !this.hasLocalScreen && !this.selectedVideoPeerId) {
// last screen share stopped and no selected video, restoring previous state
this.callViewStore.stopPresentation()
this.callViewStore.stopPresentation(this.token)
}
},
showLocalScreen(showLocalScreen) {
// Everytime the local screen is shared, switch to promoted view
if (showLocalScreen) {
this.callViewStore.startPresentation()
this.callViewStore.startPresentation(this.token)
} else if (this.callParticipantModelsWithScreen.length === 0 && !this.selectedVideoPeerId) {
// last screen share stopped and no selected video, restoring previous state
this.callViewStore.stopPresentation()
this.callViewStore.stopPresentation(this.token)
}
},
hasLocalVideo(newValue) {
Expand Down Expand Up @@ -681,12 +681,13 @@ export default {

if (this.callViewStore.presentationStarted) {
this.callViewStore.setCallViewMode({
token: this.token,
isGrid: false,
isStripeOpen: false,
clearLast: false,
})
} else {
this.callViewStore.startPresentation()
this.callViewStore.startPresentation(this.token)
}
this.callViewStore.setSelectedVideoPeerId(null)
this.screens.splice(index, 1)
Expand Down Expand Up @@ -718,7 +719,7 @@ export default {
return
}
this.callViewStore.setSelectedVideoPeerId(peerId)
this.callViewStore.startPresentation()
this.callViewStore.startPresentation(this.token)
},
handleClickLocalVideo() {
// DO nothing if no video
Expand All @@ -727,7 +728,7 @@ export default {
}
// Deselect possible selected video
this.callViewStore.setSelectedVideoPeerId('local')
this.callViewStore.startPresentation()
this.callViewStore.startPresentation(this.token)
},

async fetchPeers() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/CallView/Grid/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export default {
return this.isStripe
},
set(value) {
this.callViewStore.setCallViewMode({ isGrid: !value, clearLast: false })
this.callViewStore.setCallViewMode({ token: this.token, isGrid: !value, clearLast: false })
},
},
},
Expand Down Expand Up @@ -853,7 +853,7 @@ export default {
},

handleClickStripeCollapse() {
this.callViewStore.setCallViewMode({ isStripeOpen: !this.stripeOpen, clearLast: false })
this.callViewStore.setCallViewMode({ token: this.token, isStripeOpen: !this.stripeOpen, clearLast: false })
},

handleMovement() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/LocalVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export default {

handleStopFollowing() {
this.callViewStore.setSelectedVideoPeerId(null)
this.callViewStore.stopPresentation()
this.callViewStore.stopPresentation(this.token)
},

updateContainerAspectRatio([{ target }]) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/VideoBottomBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ describe('VideoBottomBar.vue', () => {

test('method is called after click', async () => {
callViewStore.setSelectedVideoPeerId(PEER_ID)
callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)
expect(callViewStore.selectedVideoPeerId).toBe(PEER_ID)
expect(callViewStore.presentationStarted).toBeTruthy()

Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/VideoBottomBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default {
},

handleStopFollowing() {
this.callViewStore.stopPresentation()
this.callViewStore.stopPresentation(this.token)
this.callViewStore.setSelectedVideoPeerId(null)
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar/TopBarMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export default {
},

changeView() {
this.callViewStore.setCallViewMode({ isGrid: !this.isGrid, clearLast: false })
this.callViewStore.setCallViewMode({ token: this.token, isGrid: !this.isGrid, clearLast: false })
this.callViewStore.setSelectedVideoPeerId(null)
},

Expand Down
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
46 changes: 32 additions & 14 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 All @@ -72,9 +80,8 @@ describe('callViewStore', () => {
})

it('switching call view mode saves in local storage', () => {
vuexStore.dispatch('updateToken', TOKEN)

callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: false,
})
Expand All @@ -83,6 +90,7 @@ describe('callViewStore', () => {
expect(BrowserStorage.setItem).toHaveBeenCalledWith(BROWSER_STORAGE_KEY, true)

callViewStore.setCallViewMode({
token: TOKEN,
isGrid: false,
isStripeOpen: true,
})
Expand All @@ -93,37 +101,41 @@ describe('callViewStore', () => {

it('start presentation switches off grid view and restores when it ends', () => {
[{
token: TOKEN,
isGrid: true,
isStripeOpen: true,
}, {
token: TOKEN,
isGrid: false,
isStripeOpen: false,
}].forEach((testState) => {
callViewStore.setCallViewMode(testState)

callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)
expect(callViewStore.isGrid).toBeFalsy()
expect(callViewStore.isStripeOpen).toBeFalsy()

callViewStore.stopPresentation()
callViewStore.stopPresentation(TOKEN)
expect(callViewStore.isGrid).toEqual(testState.isGrid)
expect(callViewStore.isStripeOpen).toEqual(testState.isStripeOpen)
})
})

it('switching modes during presentation does not resets it after it ends', () => {
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: true,
})
callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)

// switch during presentation
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: true,
})
callViewStore.stopPresentation()
callViewStore.stopPresentation(TOKEN)

// state kept, not restored
expect(callViewStore.isGrid).toBeTruthy()
Expand All @@ -132,26 +144,28 @@ describe('callViewStore', () => {

it('starting presentation twice does not mess up remembered state', () => {
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: true,
})
expect(callViewStore.presentationStarted).toBeFalsy()

callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)
expect(callViewStore.presentationStarted).toBeTruthy()

// switch during presentation
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: true,
})
callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)
// state kept
expect(callViewStore.presentationStarted).toBeTruthy()
expect(callViewStore.isGrid).toBeTruthy()
expect(callViewStore.isStripeOpen).toBeTruthy()

callViewStore.stopPresentation()
callViewStore.stopPresentation(TOKEN)
expect(callViewStore.presentationStarted).toBeFalsy()
// state kept, not restored
expect(callViewStore.isGrid).toBeTruthy()
Expand All @@ -160,24 +174,26 @@ describe('callViewStore', () => {

it('stopping presentation twice does not mess up remembered state', () => {
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: true,
})
expect(callViewStore.presentationStarted).toBeFalsy()

callViewStore.startPresentation()
callViewStore.startPresentation(TOKEN)
expect(callViewStore.presentationStarted).toBeTruthy()

callViewStore.stopPresentation()
callViewStore.stopPresentation(TOKEN)
expect(callViewStore.presentationStarted).toBeFalsy()
expect(callViewStore.isGrid).toBeTruthy()
expect(callViewStore.isStripeOpen).toBeTruthy()

callViewStore.setCallViewMode({
token: TOKEN,
isGrid: false,
isStripeOpen: false,
})
callViewStore.stopPresentation()
callViewStore.stopPresentation(TOKEN)
expect(callViewStore.presentationStarted).toBeFalsy()
// state kept, not reset
expect(callViewStore.isGrid).toBeFalsy()
Expand All @@ -188,13 +204,15 @@ describe('callViewStore', () => {
expect(callViewStore.lastIsGrid).toEqual(null)
expect(callViewStore.lastIsStripeOpen).toEqual(null)
callViewStore.setCallViewMode({
token: TOKEN,
isGrid: true,
isStripeOpen: false,
})
expect(callViewStore.lastIsGrid).toBeFalsy()
expect(callViewStore.lastIsStripeOpen).toBeTruthy()

callViewStore.setCallViewMode({
token: TOKEN,
clearLast: false,
})
expect(callViewStore.lastIsGrid).toBeFalsy()
Expand Down
Loading

0 comments on commit 7fe2722

Please sign in to comment.