1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/**
* @copyright Copyright (c) 2020 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import Vue from 'vue'
import BrowserStorage from '../services/BrowserStorage'
import {
CONVERSATION,
} from '../constants'
const state = {
isGrid: false,
isStripeOpen: true,
lastIsGrid: null,
lastIsStripeOpen: null,
presentationStarted: false,
selectedVideoPeerId: null,
videoBackgroundBlur: 1,
participantRaisedHands: {},
}
const getters = {
isGrid: (state) => state.isGrid,
isStripeOpen: (state) => state.isStripeOpen,
lastIsGrid: (state) => state.lastIsGrid,
lastIsStripeOpen: (state) => state.lastIsStripeOpen,
presentationStarted: (state) => state.presentationStarted,
selectedVideoPeerId: (state) => {
return state.selectedVideoPeerId
},
/**
* @param {object} state the width and height to calculate the radius from
* @returns {number} the blur radius to use, in pixels
*/
getBlurRadius: (state) => (width, height) => {
return (width * height * state.videoBackgroundBlur) / 1000
},
getParticipantRaisedHand: (state) => (sessionId) => {
return state.participantRaisedHands[sessionId] || { state: false, timestamp: null }
},
isParticipantRaisedHand: (state) => (sessionId) => {
return state.participantRaisedHands[sessionId]?.state
},
}
const mutations = {
isGrid(state, value) {
state.isGrid = value
},
isStripeOpen(state, value) {
state.isStripeOpen = value
},
lastIsGrid(state, value) {
state.lastIsGrid = value
},
lastIsStripeOpen(state, value) {
state.lastIsStripeOpen = value
},
selectedVideoPeerId(state, value) {
state.selectedVideoPeerId = value
},
presentationStarted(state, value) {
state.presentationStarted = value
},
setParticipantHandRaised(state, { sessionId, raisedHand }) {
if (!sessionId) {
throw new Error('Missing or empty sessionId argument in call to setParticipantHandRaised')
}
if (raisedHand && raisedHand.state) {
Vue.set(state.participantRaisedHands, sessionId, raisedHand)
} else {
Vue.delete(state.participantRaisedHands, sessionId)
}
},
clearParticipantHandRaised(state) {
state.participantRaisedHands = {}
},
}
const actions = {
selectedVideoPeerId(context, value) {
context.commit('selectedVideoPeerId', value)
},
joinCall(context, { token }) {
let isGrid = BrowserStorage.getItem('callprefs-' + token + '-isgrid')
if (isGrid === null) {
const conversationType = context.getters.conversations[token].type
// default to grid view for group/public calls, otherwise speaker view
isGrid = (conversationType === CONVERSATION.TYPE.GROUP
|| conversationType === CONVERSATION.TYPE.PUBLIC)
} else {
// BrowserStorage.getItem returns a string instead of a boolean
isGrid = (isGrid === 'true')
}
context.dispatch('setCallViewMode', { isGrid: isGrid, isStripeOpen: true })
},
leaveCall(context) {
// clear raised hands as they were specific to the call
context.commit('clearParticipantHandRaised')
},
/**
* Sets the current call view mode and saves it in preferences.
* If clearLast is false, also remembers it in separate properties.
*
* @param {object} context default store context;
* @param {bool} isGrid=null true for enabled grid mode, false for speaker view;
* @param {bool} isStripeOpen=null true for visible stripel mode, false for speaker view;
* @param {bool} clearLast=true set to false to not reset last temporary remembered state;
*/
setCallViewMode(context, { isGrid = null, isStripeOpen = null, clearLast = true }) {
if (clearLast) {
context.commit('lastIsGrid', null)
context.commit('lastIsStripeOpen', null)
} else {
context.commit('lastIsGrid', context.getters.isGrid)
context.commit('lastIsStripeOpen', context.getters.isStripeOpen)
}
if (isGrid !== null) {
BrowserStorage.setItem('callprefs-' + context.getters.getToken() + '-isgrid', isGrid)
context.commit('isGrid', isGrid)
}
if (isStripeOpen !== null) {
context.commit('isStripeOpen', isStripeOpen)
}
},
setParticipantHandRaised(context, { sessionId, raisedHand }) {
context.commit('setParticipantHandRaised', { sessionId, raisedHand })
},
/**
* Starts presentation mode.
*
* Switches off grid mode and closes the stripe.
* Remembers the call view state for after the end of the presentation.
*
* @param {object} context default store context;
*/
startPresentation(context) {
// don't start twice, this would prevent multiple
// screen shares to clear the last call view state
if (context.getters.presentationStarted) {
return
}
context.commit('presentationStarted', true)
// switch off grid mode during presentation and collapse
// the stripe to focus on the screen share, but continue remembering
// the last state
context.dispatch('setCallViewMode', {
isGrid: false,
isStripeOpen: false,
clearLast: false,
})
},
/**
* Stops presentation mode.
*
* Restores call view state from before starting the presentation, given
* that the last state was not cleared manually.
*
* @param {object} context default store context;
*/
stopPresentation(context) {
if (!context.getters.presentationStarted) {
return
}
// restore previous state
context.dispatch('setCallViewMode', {
isGrid: context.getters.lastIsGrid,
isStripeOpen: context.getters.lastIsStripeOpen,
})
context.commit('presentationStarted', false)
},
}
export default { state, mutations, getters, actions }
|