diff --git a/src/store/conference.js b/src/store/conference.js index 9c059130..34918041 100644 --- a/src/store/conference.js +++ b/src/store/conference.js @@ -206,22 +206,23 @@ export default { }, participantLeft(state, participant) { + state.participants = state.participants.filter(($participant) => { + return participant.getId() !== $participant; + }); + }, + setSelectedParticipant(state, participant){ if(state.selectedParticipant == 'local' && !state.joinState === RequestState.succeeded){ state.selectedParticipant = null; } - else if(state.selectedParticipant == participant.getId()){ + else if(state.selectedParticipant == participant){ state.selectedParticipant = 'local'; state.manualSelection = false; } - state.participants = state.participants.filter(($participant) => { - return participant.getId() !== $participant; - }); - Vue.delete(state.remoteMediaStreams, participant.getId()); + else{ + state.selectedParticipant = participant; + } }, - setSelectedParticipant(state, participant){ - state.selectedParticipant = participant; - }, setManualSelection(state, val){ state.manualSelection = val; } diff --git a/src/store/index.js b/src/store/index.js index 8d6ae845..521c10da 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -130,6 +130,7 @@ export const store = new Vuex.Store({ }).onConferenceParticipantLeft((participant)=>{ store.commit('conference/participantLeft', participant); store.commit('conference/removeRemoteMedia', participant.id); + store.commit('conference/setSelectedParticipant', 'local'); }).onConferenceEvent((event)=>{ store.commit('conference/event', event); }).onConferenceMessage((message)=>{ diff --git a/t/store/conference.js b/t/store/conference.js new file mode 100644 index 00000000..7cd62c53 --- /dev/null +++ b/t/store/conference.js @@ -0,0 +1,109 @@ + +'use strict'; + +import ConferenceModule from '../../src/store/conference'; +import { assert } from 'chai'; + +describe('ConferenceModule', function(){ + + it('should add a participant id to the store if not already stored', () => { + let state = { + participants: [] + }; + const participant = { + getId: () => { + return '123456789'; + } + }; + ConferenceModule.mutations.participantJoined(state, participant); + assert.include(state.participants, participant.getId()); + + }); + + it('should not add a participant id to the store if already stored', () => { + let state = { + participants: ['123456789'] + }; + const participant = { + getId: () => { + return '123456789'; + } + }; + ConferenceModule.mutations.participantJoined(state, participant); + assert.equal(state.participants.length, 1); + + }); + + it('should remove a participant id from the store', () => { + let state = { + participants: ['123456789'] + }; + const participant = { + getId: () => { + return '123456789'; + } + }; + ConferenceModule.mutations.participantLeft(state, participant); + assert.notInclude(state.participants, participant.getId()); + + }); + + it('should add a participant mediastream to the store', () => { + let state = { + remoteMediaStreams: {} + }; + const participantId = '123456789'; + + ConferenceModule.mutations.addRemoteMedia(state, participantId); + assert.exists(state.remoteMediaStreams[participantId]); + + }); + + it('should remove a participant mediastream from the store', () => { + let state = { + remoteMediaStreams: { + 123456789: '123456789' + } + }; + const participantId = '123456789'; + + ConferenceModule.mutations.removeRemoteMedia(state, participantId); + assert.notExists(state.remoteMediaStreams[participantId]); + + }); + + it('should store the selected remote participant as selected', () => { + let state = { + selectedParticipant: null + }; + const participantId = '123456789'; + + ConferenceModule.mutations.setSelectedParticipant(state, participantId); + assert.equal(state.selectedParticipant, participantId); + + }); + + it('should store the local participant as selected', () => { + let state = { + selectedParticipant: '123456789' + }; + const participantId = '123456789'; + + ConferenceModule.mutations.setSelectedParticipant(state, participantId); + assert.equal(state.selectedParticipant, 'local'); + + }); + + it('should reset the selected participant when conference ends', () => { + let state = { + selectedParticipant: 'local', + joinState: false + }; + + ConferenceModule.mutations.setSelectedParticipant(state); + assert.equal(state.selectedParticipant, null); + + }); + + +});