Skip to content

Commit

Permalink
feat(call): sidebar audio/video mute state fix & chat online state fi…
Browse files Browse the repository at this point in the history
…xes continued
  • Loading branch information
Drew Ewing committed May 12, 2022
1 parent 7339fa3 commit df6616d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default Vue.extend({
'conversation.participants': {
handler() {},
deep: true,
immediate: true,
},
},
methods: {
Expand Down
22 changes: 13 additions & 9 deletions components/views/navigation/sidebar/controls/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default Vue.extend({
computed: {
...mapState(['audio', 'video', 'webrtc', 'accounts']),
audioMuted(): boolean {
return this.webrtc.streamMuted[p2p.id]?.audio
return this.audio.muted || this.webrtc.streamMuted[p2p.id]?.audio
},
videoMuted(): boolean {
return this.webrtc.streamMuted[p2p.id]?.video
return this.video.disabled || this.webrtc.streamMuted[p2p.id]?.video
},
screenMuted(): boolean {
return this.webrtc.streamMuted[p2p.id]?.screen
Expand All @@ -49,13 +49,17 @@ export default Vue.extend({
* @example
*/
async toggleMute(kind = 'audio') {
this.isLoading = true
this.$store.dispatch(
'webrtc/toggleMute',
{ kind, peerId: p2p.id },
{ root: true },
)
this.isLoading = false
if (kind === 'audio') {
this.$store.dispatch('audio/toggleMute')
return
}
if (kind === 'video') {
this.$store.dispatch('video/toggle')
return
}
this.$store.dispatch('webrtc/toggleMute', { kind })
},
async toggleDeafen() {
this.isLoading = true
Expand Down
3 changes: 3 additions & 0 deletions libraries/WebRTC/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ export class Call extends Emitter<CallEventListeners> {
* await call.sendPeerCallRequest(peerId)
*/
async sendPeerCallRequest(peerId: string, force = false) {
if (!peerId) {
return
}
if (
!force &&
(this.peerConnected[peerId] || this.peerDialingDisabled[peerId])
Expand Down
26 changes: 16 additions & 10 deletions store/audio/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ export default {
* @description Toggles mute for outgoing audio
* @example @click="toggleMute"
*/
toggleMute({ dispatch, muted, rootState }: any) {
toggleMute({
state,
commit,
dispatch,
muted = !state.muted,
rootState,
}: any) {
const { activeCall } = rootState.webrtc
const call = $WebRTC.getCall(activeCall.callId)
const call = activeCall && $WebRTC.getCall(activeCall.callId)

if (call) {
if (muted) {
call.unmute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.UNMUTE, { root: true })
return
}
call.mute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.MUTE, { root: true })
commit('setMuted', muted)

if (muted) {
if (call) call.unmute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.UNMUTE, { root: true })
return
}
if (call) call.mute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.MUTE, { root: true })
},
/**
* @method toggleDeafen
Expand Down
2 changes: 1 addition & 1 deletion store/friends/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default {
},
{ root: true },
)
commit('conversation/addParticipant', friend.address, { root: true })
dispatch('conversation/addParticipant', friend.address, { root: true })
return
}
commit(
Expand Down
26 changes: 26 additions & 0 deletions store/video/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { VideoState } from './types'
import { ActionsArguments } from '~/types/store/store'
import { Sounds } from '~/libraries/SoundManager/SoundManager'
import { $WebRTC } from '~/libraries/WebRTC/WebRTC'

const videoActions = {
toggle(
{ state, commit, dispatch, rootState }: ActionsArguments<VideoState>,
disabled = !state.disabled,
) {
const { activeCall } = rootState.webrtc
const call = activeCall && $WebRTC.getCall(activeCall.callId)

commit('setDisabled', disabled)

if (disabled) {
if (call) call.unmute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.UNMUTE, { root: true })
return
}
if (call) call.mute({ kind: 'audio' })
dispatch('sounds/playSound', Sounds.MUTE, { root: true })
},
}

export default videoActions
6 changes: 3 additions & 3 deletions store/webrtc/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const webRTCActions = {
setInterval(() => {
if (rootState.conversation) {
rootState.conversation.participants
.filter((p) => p.peerId !== $Peer2Peer.id)
.filter((p) => p.peerId && p.peerId !== $Peer2Peer.id)
.forEach((p) => {
$Peer2Peer.sendMessage(
{
Expand Down Expand Up @@ -279,8 +279,8 @@ const webRTCActions = {
{ state }: ActionsArguments<WebRTCState>,
{ peerId, kind }: { peerId: string; kind: 'audio' | 'video' | 'screen' },
) {
if (!state.activeCall) {
throw new Error('mute: no active call')
if (!state.activeCall || !peerId) {
return
}
const call = $WebRTC.getCall(state.activeCall.callId)
if (!call) {
Expand Down

0 comments on commit df6616d

Please sign in to comment.