@@ -7,6 +7,7 @@ import { defineStore } from 'pinia'
7
7
8
8
import { CONVERSATION } from '../constants.js'
9
9
import BrowserStorage from '../services/BrowserStorage.js'
10
+ import store from '../store/index.js'
10
11
11
12
export const useCallViewStore = defineStore ( 'callView' , {
12
13
state : ( ) => ( {
@@ -27,8 +28,6 @@ export const useCallViewStore = defineStore('callView', {
27
28
} ,
28
29
29
30
actions : {
30
- // Mutations
31
- // Actions
32
31
setForceCallView ( value ) {
33
32
this . forceCallView = value
34
33
} ,
@@ -37,43 +36,41 @@ export const useCallViewStore = defineStore('callView', {
37
36
this . isViewerOverlay = value
38
37
} ,
39
38
39
+ setIsEmptyCallView ( value ) {
40
+ this . isEmptyCallView = value
41
+ } ,
42
+
40
43
setSelectedVideoPeerId ( value ) {
41
44
this . selectedVideoPeerId = value
42
45
} ,
43
46
44
- joinCall ( context , { token } ) {
45
- let isGrid = BrowserStorage . getItem ( 'callprefs-' + token + '-isgrid' )
46
- if ( isGrid === null ) {
47
- const conversationType = context . getters . conversations [ token ] . type
48
- // default to grid view for group/public calls, otherwise speaker view
49
- isGrid = ( conversationType === CONVERSATION . TYPE . GROUP
50
- || conversationType === CONVERSATION . TYPE . PUBLIC )
51
- } else {
52
- // BrowserStorage.getItem returns a string instead of a boolean
53
- isGrid = ( isGrid === 'true' )
54
- }
55
- context . dispatch ( 'setCallViewMode' , { isGrid, isStripeOpen : true } )
47
+ handleJoinCall ( { token } ) {
48
+ const gridPreference = BrowserStorage . getItem ( `callprefs-${ token } -isgrid` )
49
+ const isGrid = gridPreference === null
50
+ // not defined yet, default to grid view for group/public calls, otherwise speaker view
51
+ ? [ CONVERSATION . TYPE . GROUP , CONVERSATION . TYPE . PUBLIC ] . includes ( store . getters . conversations [ token ] . type )
52
+ : gridPreference === 'true'
53
+ this . setCallViewMode ( { isGrid, isStripeOpen : true } )
56
54
} ,
57
55
58
56
/**
59
57
* Sets the current call view mode and saves it in preferences.
60
58
* If clearLast is false, also remembers it in separate properties.
61
59
*
62
- * @param {object } context default store context;
63
60
* @param {object } data the wrapping object;
64
61
* @param {boolean|null } [data.isGrid=null] true for enabled grid mode, false for speaker view;
65
62
* @param {boolean|null } [data.isStripeOpen=null] true for visible striped mode, false for speaker view;
66
63
* @param {boolean } [data.clearLast=true] set false to not reset last temporary remembered state;
67
64
*/
68
- setCallViewMode ( context , { isGrid = null , isStripeOpen = null , clearLast = true } ) {
65
+ setCallViewMode ( { isGrid = null , isStripeOpen = null , clearLast = true } ) {
69
66
if ( clearLast ) {
70
67
this . lastIsGrid = null
71
68
this . lastIsStripeOpen = null
72
69
}
73
70
74
71
if ( isGrid !== null ) {
75
72
this . lastIsGrid = this . isGrid
76
- BrowserStorage . setItem ( ' callprefs-' + context . getters . getToken ( ) + ' -isgrid' , isGrid )
73
+ BrowserStorage . setItem ( ` callprefs-${ store . getters . getToken ( ) } -isgrid` , isGrid )
77
74
this . isGrid = isGrid
78
75
}
79
76
@@ -88,53 +85,33 @@ export const useCallViewStore = defineStore('callView', {
88
85
*
89
86
* Switches off grid mode and closes the stripe.
90
87
* Remembers the call view state for after the end of the presentation.
91
- *
92
- * @param {object } context default store context;
93
88
*/
94
- startPresentation ( context ) {
95
- // don't start twice, this would prevent multiple
96
- // screen shares to clear the last call view state
89
+ startPresentation ( ) {
90
+ // don't start twice, this would prevent multiple screen shares to clear the last call view state
97
91
if ( this . presentationStarted ) {
98
92
return
99
93
}
100
-
101
94
this . presentationStarted = true
102
- // switch off grid mode during presentation and collapse
103
- // the stripe to focus on the screen share, but continue remembering
104
- // the last state
105
- context . dispatch ( 'setCallViewMode' , {
106
- isGrid : false ,
107
- isStripeOpen : false ,
108
- clearLast : false ,
109
- } )
95
+
96
+ this . setCallViewMode ( { isGrid : false , isStripeOpen : false , clearLast : false } )
110
97
} ,
111
98
112
99
/**
113
100
* Stops presentation mode.
114
101
*
115
- * Restores call view state from before starting the presentation, given
116
- * that the last state was not cleared manually.
117
- *
118
- * @param {object } context default store context;
102
+ * Restores call view state from before starting the presentation,
103
+ * given that the last state was not cleared manually.
119
104
*/
120
- stopPresentation ( context ) {
105
+ stopPresentation ( ) {
121
106
if ( ! this . presentationStarted ) {
122
107
return
123
108
}
124
- if ( ! this . isGrid && ! this . isStripeOpen ) {
125
- // User didn't pick grid view during presentation
126
- // restore previous state
127
- context . dispatch ( 'setCallViewMode' , {
128
- isGrid : this . lastIsGrid ,
129
- isStripeOpen : this . lastIsStripeOpen ,
130
- clearLast : false ,
131
- } )
132
- }
133
109
this . presentationStarted = false
134
- } ,
135
110
136
- setIsEmptyCallView ( value ) {
137
- this . isEmptyCallView = value
111
+ if ( ! this . isGrid && ! this . isStripeOpen ) {
112
+ // User didn't pick grid view during presentation, restore previous state
113
+ this . setCallViewMode ( { isGrid : this . lastIsGrid , isStripeOpen : this . lastIsStripeOpen , clearLast : false } )
114
+ }
138
115
} ,
139
116
140
117
/**
0 commit comments