@ -1,4 +1,3 @@
import Vue from 'vue'
import Vue from 'vue'
import {
import {
RequestState
RequestState
@ -26,7 +25,7 @@ export default {
leaveState : RequestState . initiated ,
leaveState : RequestState . initiated ,
leaveError : null ,
leaveError : null ,
participants : [ ] ,
participants : [ ] ,
remoteMediaStreams : []
remoteMediaStreams : {}
} ,
} ,
getters : {
getters : {
username ( state , getters , rootState , rootGetters ) {
username ( state , getters , rootState , rootGetters ) {
@ -70,7 +69,7 @@ export default {
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ;
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ;
} ,
} ,
localMediaStream ( state ) {
localMediaStream ( state ) {
if ( ( state . localMediaState === RequestState . succeeded ||
if ( ( state . localMediaState === RequestState . succeeded ||
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ) {
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ) {
return Vue . $conference . getLocalMediaStreamNative ( ) ;
return Vue . $conference . getLocalMediaStreamNative ( ) ;
}
}
@ -81,16 +80,16 @@ export default {
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ;
state . localMediaState === RequestState . requesting ) && Vue . $conference . hasLocalMediaStream ( ) ;
} ,
} ,
localParticipant ( state ) {
localParticipant ( state ) {
if ( state . joinState === RequestState . succeeded ) {
if ( state . joinState === RequestState . succeeded ) {
return Vue . $conference . getLocalParticipant ( ) ;
return Vue . $conference . getLocalParticipant ( ) ;
}
}
} ,
} ,
remoteParticipant : ( ) => ( participantId ) => {
remoteParticipant : ( ) => ( participantId ) => {
return Vue . $conference . getRemoteParticipant ( participantId ) ;
return Vue . $conference . getRemoteParticipant ( participantId ) ;
} ,
} ,
remoteMediaStream : ( state ) => ( participantId ) => {
remoteMediaStream : ( ) => ( participantId ) => {
if ( state . remoteMediaStreams . includes ( participantId ) ) {
const participant = Vue . $conference . getRemoteParticipant ( participantId ) ;
const participant = Vue . $conference . getRemoteParticipant ( participantId ) ;
if ( participant !== null ) {
return participant . mediaStream ? participant . mediaStream . getStream ( ) : null ;
return participant . mediaStream ? participant . mediaStream . getStream ( ) : null ;
}
}
return null ;
return null ;
@ -102,10 +101,13 @@ export default {
remoteMediaStreams ( state ) {
remoteMediaStreams ( state ) {
return state . remoteMediaStreams ;
return state . remoteMediaStreams ;
} ,
} ,
hasRemoteMediaStream : ( state ) => ( participantId ) => {
hasRemoteVideo : ( ) => ( participantId ) => {
return state . remoteMediaStreams . includes ( participantId )
const participant = Vue . $conference . getRemoteParticipant ( participantId ) ;
if ( participant !== null ) {
return participant . mediaStream ? participant . mediaStream . hasVideo ( ) : false ;
}
return false ;
}
}
} ,
} ,
mutations : {
mutations : {
enableConferencing ( state ) {
enableConferencing ( state ) {
@ -154,18 +156,10 @@ export default {
state . screenEnabled = false ;
state . screenEnabled = false ;
} ,
} ,
addRemoteMedia ( state , participantId ) {
addRemoteMedia ( state , participantId ) {
if ( state . remoteMediaStreams . includes ( participantId ) ) {
Vue . set ( state . remoteMediaStreams , participantId , participantId ) ;
state . remoteMediaStreams = state . remoteMediaStreams . filter ( ( $participant ) => {
return participantId !== $participant ;
} ) ;
}
state . remoteMediaStreams . push ( participantId ) ;
} ,
} ,
removeRemoteMedia ( state , participant ) {
removeRemoteMedia ( state , participantId ) {
state . remoteMediaStreams = state . remoteMediaStreams . filter ( ( $participant ) => {
Vue . delete ( state . remoteMediaStreams , participantId ) ;
return participant !== $participant ;
} ) ;
} ,
} ,
joinRequesting ( state ) {
joinRequesting ( state ) {
state . joinState = RequestState . requesting ;
state . joinState = RequestState . requesting ;
@ -196,24 +190,26 @@ export default {
state . leaveError = error ;
state . leaveError = error ;
} ,
} ,
participantJoined ( state , participant ) {
participantJoined ( state , participant ) {
if ( state . participants . includes ( participant . getId ( ) ) ) {
if ( state . participants . includes ( participant . getId ( ) ) ) {
state . participants = state . participants . filter ( ( $participant ) => {
state . participants = state . participants . filter ( ( $participant ) => {
return participant . getId ( ) !== $participant ;
return participant . getId ( ) !== $participant ;
} ) ;
} ) ;
}
}
state . participants . push ( participant . getId ( ) )
state . participants . push ( participant . getId ( ) ) ;
} ,
} ,
participantLeft ( state , participant ) {
participantLeft ( state , participant ) {
state . participants = state . participants . filter ( ( $participant ) => {
state . participants = state . participants . filter ( ( $participant ) => {
return participant . getId ( ) !== $participant ;
return participant . getId ( ) !== $participant ;
} ) ;
} ) ;
Vue . delete ( state . remoteMediaStreams , participant . getId ( ) ) ;
}
}
} ,
} ,
actions : {
actions : {
createLocalMedia ( context , type ) {
createLocalMedia ( context , type ) {
let media = Vue . $rtcEngine . createMedia ( ) ;
let media = Vue . $rtcEngine . createMedia ( ) ;
context . commit ( 'localMediaRequesting' ) ;
context . commit ( 'localMediaRequesting' ) ;
switch ( type ) {
switch ( type ) {
default :
default :
case MediaTypes . mic :
case MediaTypes . mic :
media . enableMicrophone ( ) ;
media . enableMicrophone ( ) ;
@ -234,13 +230,13 @@ export default {
break ;
break ;
}
}
let localMediaStream ;
let localMediaStream ;
return media . build ( ) . then ( ( $localMediaStream ) => {
return media . build ( ) . then ( ( $localMediaStream ) => {
localMediaStream = $localMediaStream ;
localMediaStream = $localMediaStream ;
localMediaStream . onVideoEnded ( ( ) => {
localMediaStream . onVideoEnded ( ( ) => {
context . dispatch ( 'createLocalMedia' , MediaTypes . mic ) ;
context . dispatch ( 'createLocalMedia' , MediaTypes . mic ) ;
} ) ;
} ) ;
Vue . $conference . setLocalMediaStream ( localMediaStream ) ;
Vue . $conference . setLocalMediaStream ( localMediaStream ) ;
switch ( type ) {
switch ( type ) {
default :
default :
case MediaTypes . mic :
case MediaTypes . mic :
context . commit ( 'enableMicrophone' ) ;
context . commit ( 'enableMicrophone' ) ;
@ -269,43 +265,43 @@ export default {
break ;
break ;
}
}
return Promise . resolve ( ) ;
return Promise . resolve ( ) ;
} ) . then ( ( ) => {
} ) . then ( ( ) => {
if ( context . getters . isJoined ) {
if ( context . getters . isJoined ) {
return Vue . $conference . changeConferenceMedia ( ) ;
return Vue . $conference . changeConferenceMedia ( ) ;
}
}
else {
else {
return Promise . resolve ( ) ;
return Promise . resolve ( ) ;
}
}
} ) . then ( ( ) => {
} ) . then ( ( ) => {
context . commit ( 'localMediaSucceeded' , localMediaStream ) ;
context . commit ( 'localMediaSucceeded' , localMediaStream ) ;
} ) . catch ( ( err ) => {
} ) . catch ( ( err ) => {
if ( ! context . getters . hasLocalMediaStream ) {
if ( ! context . getters . hasLocalMediaStream ) {
context . commit ( 'localMediaFailed' , err . message ) ;
context . commit ( 'localMediaFailed' , err . message ) ;
}
}
} ) ;
} ) ;
} ,
} ,
async enableMicrophone ( context ) {
async enableMicrophone ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
let mediaType = MediaTypes . mic ;
let mediaType = MediaTypes . mic ;
if ( context . getters . isCameraEnabled ) {
if ( context . getters . isCameraEnabled ) {
mediaType = MediaTypes . micCam ;
mediaType = MediaTypes . micCam ;
}
}
else if ( context . getters . isScreenEnabled ) {
else if ( context . getters . isScreenEnabled ) {
mediaType = MediaTypes . micScreen ;
mediaType = MediaTypes . micScreen ;
}
}
await context . dispatch ( 'createLocalMedia' , mediaType ) ;
await context . dispatch ( 'createLocalMedia' , mediaType ) ;
}
}
} ,
} ,
disableMicrophone ( context ) {
disableMicrophone ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
let mediaType = null ;
let mediaType = null ;
if ( context . getters . isCameraEnabled ) {
if ( context . getters . isCameraEnabled ) {
mediaType = MediaTypes . cam ;
mediaType = MediaTypes . cam ;
}
}
else if ( context . getters . isScreenEnabled ) {
else if ( context . getters . isScreenEnabled ) {
mediaType = MediaTypes . screen ;
mediaType = MediaTypes . screen ;
}
}
if ( mediaType === null ) {
if ( mediaType === null ) {
context . commit ( 'disposeLocalMedia' ) ;
context . commit ( 'disposeLocalMedia' ) ;
}
}
else {
else {
@ -314,7 +310,7 @@ export default {
}
}
} ,
} ,
toggleMicrophone ( context ) {
toggleMicrophone ( context ) {
if ( ! context . getters . isMicrophoneEnabled ) {
if ( ! context . getters . isMicrophoneEnabled ) {
context . dispatch ( 'enableMicrophone' ) ;
context . dispatch ( 'enableMicrophone' ) ;
}
}
else {
else {
@ -322,17 +318,17 @@ export default {
}
}
} ,
} ,
enableCamera ( context ) {
enableCamera ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
context . dispatch ( 'createLocalMedia' , MediaTypes . micCam ) ;
context . dispatch ( 'createLocalMedia' , MediaTypes . micCam ) ;
}
}
} ,
} ,
disableCamera ( context ) {
disableCamera ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
let mediaType = null ;
let mediaType = null ;
if ( context . getters . isMicrophoneEnabled ) {
if ( context . getters . isMicrophoneEnabled ) {
mediaType = MediaTypes . mic ;
mediaType = MediaTypes . mic ;
}
}
if ( mediaType === null ) {
if ( mediaType === null ) {
context . commit ( 'disposeLocalMedia' ) ;
context . commit ( 'disposeLocalMedia' ) ;
}
}
else {
else {
@ -341,7 +337,7 @@ export default {
}
}
} ,
} ,
toggleCamera ( context ) {
toggleCamera ( context ) {
if ( ! context . getters . isCameraEnabled ) {
if ( ! context . getters . isCameraEnabled ) {
context . dispatch ( 'enableCamera' ) ;
context . dispatch ( 'enableCamera' ) ;
}
}
else {
else {
@ -349,17 +345,17 @@ export default {
}
}
} ,
} ,
enableScreen ( context ) {
enableScreen ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
context . dispatch ( 'createLocalMedia' , MediaTypes . micScreen ) ;
context . dispatch ( 'createLocalMedia' , MediaTypes . micScreen ) ;
}
}
} ,
} ,
disableScreen ( context ) {
disableScreen ( context ) {
if ( ! context . getters . isLocalMediaRequesting ) {
if ( ! context . getters . isLocalMediaRequesting ) {
let mediaType = null ;
let mediaType = null ;
if ( context . getters . isMicrophoneEnabled ) {
if ( context . getters . isMicrophoneEnabled ) {
mediaType = MediaTypes . mic ;
mediaType = MediaTypes . mic ;
}
}
if ( mediaType === null ) {
if ( mediaType === null ) {
context . commit ( 'disposeLocalMedia' ) ;
context . commit ( 'disposeLocalMedia' ) ;
}
}
else {
else {
@ -368,7 +364,7 @@ export default {
}
}
} ,
} ,
toggleScreen ( context ) {
toggleScreen ( context ) {
if ( ! context . getters . isScreenEnabled ) {
if ( ! context . getters . isScreenEnabled ) {
context . dispatch ( 'enableScreen' ) ;
context . dispatch ( 'enableScreen' ) ;
}
}
else {
else {
@ -376,25 +372,25 @@ export default {
}
}
} ,
} ,
join ( context , conferenceId ) {
join ( context , conferenceId ) {
if ( context . getters . hasLocalMediaStream ) {
if ( context . getters . hasLocalMediaStream ) {
context . commit ( 'joinRequesting' ) ;
context . commit ( 'joinRequesting' ) ;
Vue . $conference . joinConference ( {
Vue . $conference . joinConference ( {
conferenceName : conferenceId ,
conferenceName : conferenceId ,
displayName : context . getters . username
displayName : context . getters . username
} ) . then ( ( ) => {
} ) . then ( ( ) => {
context . commit ( 'joinSucceeded' ) ;
context . commit ( 'joinSucceeded' ) ;
} ) . catch ( ( err ) => {
} ) . catch ( ( err ) => {
context . commit ( 'joinFailed' , err . message ) ;
context . commit ( 'joinFailed' , err . message ) ;
} ) ;
} ) ;
}
}
} ,
} ,
leave ( context ) {
leave ( context ) {
if ( context . getters . isJoined ) {
if ( context . getters . isJoined ) {
context . commit ( 'leaveRequesting' ) ;
context . commit ( 'leaveRequesting' ) ;
Vue . $conference . leaveConference ( ) . then ( ( ) => {
Vue . $conference . leaveConference ( ) . then ( ( ) => {
context . commit ( 'leaveSucceeded' ) ;
context . commit ( 'leaveSucceeded' ) ;
context . commit ( 'disposeLocalMedia' ) ;
context . commit ( 'disposeLocalMedia' ) ;
} ) . catch ( ( err ) => {
} ) . catch ( ( err ) => {
context . commit ( 'leaveFailed' , err . message ) ;
context . commit ( 'leaveFailed' , err . message ) ;
} ) ;
} ) ;
}
}