|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+/*
|
|
|
2
|
+ * Copyright @ 2015 Atlassian Pty Ltd
|
|
|
3
|
+ *
|
|
|
4
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5
|
+ * you may not use this file except in compliance with the License.
|
|
|
6
|
+ * You may obtain a copy of the License at
|
|
|
7
|
+ *
|
|
|
8
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9
|
+ *
|
|
|
10
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
11
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13
|
+ * See the License for the specific language governing permissions and
|
|
|
14
|
+ * limitations under the License.
|
|
|
15
|
+ */
|
|
|
16
|
+
|
|
|
17
|
+import UIEvents from '../service/UI/UIEvents';
|
|
|
18
|
+import VideoLayout from './UI/videolayout/VideoLayout';
|
|
|
19
|
+import FilmStrip from './UI/videolayout/FilmStrip';
|
|
|
20
|
+
|
|
|
21
|
+/**
|
|
|
22
|
+ * The (name of the) command which transports the state (represented by
|
|
|
23
|
+ * {State} for the local state at the time of this writing) of a {FollowMe}
|
|
|
24
|
+ * (instance) between participants.
|
|
|
25
|
+ */
|
|
|
26
|
+const _COMMAND = "follow-me";
|
|
|
27
|
+
|
|
|
28
|
+/**
|
|
|
29
|
+ * Represents the set of {FollowMe}-related states (properties and their
|
|
|
30
|
+ * respective values) which are to be followed by a participant. {FollowMe}
|
|
|
31
|
+ * will send {_COMMAND} whenever a property of {State} changes (if the local
|
|
|
32
|
+ * participant is in her right to issue such a command, of course).
|
|
|
33
|
+ */
|
|
|
34
|
+class State {
|
|
|
35
|
+ /**
|
|
|
36
|
+ * Initializes a new {State} instance.
|
|
|
37
|
+ *
|
|
|
38
|
+ * @param propertyChangeCallback {Function} which is to be called when a
|
|
|
39
|
+ * property of the new instance has its value changed from an old value
|
|
|
40
|
+ * into a (different) new value. The function is supplied with the name of
|
|
|
41
|
+ * the property, the old value of the property before the change, and the
|
|
|
42
|
+ * new value of the property after the change.
|
|
|
43
|
+ */
|
|
|
44
|
+ constructor (propertyChangeCallback) {
|
|
|
45
|
+ this._propertyChangeCallback = propertyChangeCallback;
|
|
|
46
|
+ }
|
|
|
47
|
+
|
|
|
48
|
+ get filmStripVisible () { return this._filmStripVisible; }
|
|
|
49
|
+
|
|
|
50
|
+ set filmStripVisible (b) {
|
|
|
51
|
+ var oldValue = this._filmStripVisible;
|
|
|
52
|
+ if (oldValue !== b) {
|
|
|
53
|
+ this._filmStripVisible = b;
|
|
|
54
|
+ this._firePropertyChange('filmStripVisible', oldValue, b);
|
|
|
55
|
+ }
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ get nextOnStage() { return this._nextOnStage; }
|
|
|
59
|
+
|
|
|
60
|
+ set nextOnStage(id) {
|
|
|
61
|
+ var oldValue = this._nextOnStage;
|
|
|
62
|
+ if (oldValue !== id) {
|
|
|
63
|
+ this._nextOnStage = id;
|
|
|
64
|
+ this._firePropertyChange('nextOnStage', oldValue, id);
|
|
|
65
|
+ }
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ get sharedDocumentVisible () { return this._sharedDocumentVisible; }
|
|
|
69
|
+
|
|
|
70
|
+ set sharedDocumentVisible (b) {
|
|
|
71
|
+ var oldValue = this._sharedDocumentVisible;
|
|
|
72
|
+ if (oldValue !== b) {
|
|
|
73
|
+ this._sharedDocumentVisible = b;
|
|
|
74
|
+ this._firePropertyChange('sharedDocumentVisible', oldValue, b);
|
|
|
75
|
+ }
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ /**
|
|
|
79
|
+ * Invokes {_propertyChangeCallback} to notify it that {property} had its
|
|
|
80
|
+ * value changed from {oldValue} to {newValue}.
|
|
|
81
|
+ *
|
|
|
82
|
+ * @param property the name of the property which had its value changed
|
|
|
83
|
+ * from {oldValue} to {newValue}
|
|
|
84
|
+ * @param oldValue the value of {property} before the change
|
|
|
85
|
+ * @param newValue the value of {property} after the change
|
|
|
86
|
+ */
|
|
|
87
|
+ _firePropertyChange (property, oldValue, newValue) {
|
|
|
88
|
+ var propertyChangeCallback = this._propertyChangeCallback;
|
|
|
89
|
+ if (propertyChangeCallback)
|
|
|
90
|
+ propertyChangeCallback(property, oldValue, newValue);
|
|
|
91
|
+ }
|
|
|
92
|
+}
|
|
|
93
|
+
|
|
|
94
|
+/**
|
|
|
95
|
+ * Represents the "Follow Me" feature which enables a moderator to
|
|
|
96
|
+ * (partially) control the user experience/interface (e.g. film strip
|
|
|
97
|
+ * visibility) of (other) non-moderator particiapnts.
|
|
|
98
|
+ *
|
|
|
99
|
+ * @author Lyubomir Marinov
|
|
|
100
|
+ */
|
|
|
101
|
+class FollowMe {
|
|
|
102
|
+ /**
|
|
|
103
|
+ * Initializes a new {FollowMe} instance.
|
|
|
104
|
+ *
|
|
|
105
|
+ * @param conference the {conference} which is to transport
|
|
|
106
|
+ * {FollowMe}-related information between participants
|
|
|
107
|
+ * @param UI the {UI} which is the source (model/state) to be sent to
|
|
|
108
|
+ * remote participants if the local participant is the moderator or the
|
|
|
109
|
+ * destination (model/state) to receive from the remote moderator if the
|
|
|
110
|
+ * local participant is not the moderator
|
|
|
111
|
+ */
|
|
|
112
|
+ constructor (conference, UI) {
|
|
|
113
|
+ this._conference = conference;
|
|
|
114
|
+ this._UI = UI;
|
|
|
115
|
+
|
|
|
116
|
+ // The states of the local participant which are to be followed (by the
|
|
|
117
|
+ // remote participants when the local participant is in her right to
|
|
|
118
|
+ // issue such commands).
|
|
|
119
|
+ this._local = new State(this._localPropertyChange.bind(this));
|
|
|
120
|
+
|
|
|
121
|
+ // Listen to "Follow Me" commands. I'm not sure whether a moderator can
|
|
|
122
|
+ // (in lib-jitsi-meet and/or Meet) become a non-moderator. If that's
|
|
|
123
|
+ // possible, then it may be easiest to always listen to commands. The
|
|
|
124
|
+ // listener will validate received commands before acting on them.
|
|
|
125
|
+ conference.commands.addCommandListener(
|
|
|
126
|
+ _COMMAND,
|
|
|
127
|
+ this._onFollowMeCommand.bind(this));
|
|
|
128
|
+ }
|
|
|
129
|
+
|
|
|
130
|
+ /**
|
|
|
131
|
+ * Adds listeners for the UI states of the local participant which are
|
|
|
132
|
+ * to be followed (by the remote participants). A non-moderator (very
|
|
|
133
|
+ * likely) can become a moderator so it may be easiest to always track
|
|
|
134
|
+ * the states of interest.
|
|
|
135
|
+ * @private
|
|
|
136
|
+ */
|
|
|
137
|
+ _addFollowMeListeners () {
|
|
|
138
|
+ this.filmStripEventHandler = this._filmStripToggled.bind(this);
|
|
|
139
|
+ this._UI.addListener(UIEvents.TOGGLED_FILM_STRIP,
|
|
|
140
|
+ this.filmStripEventHandler);
|
|
|
141
|
+
|
|
|
142
|
+ var self = this;
|
|
|
143
|
+ this.pinnedEndpointEventHandler = function (smallVideo, isPinned) {
|
|
|
144
|
+ self._nextOnStage(smallVideo, isPinned);
|
|
|
145
|
+ };
|
|
|
146
|
+ this._UI.addListener(UIEvents.PINNED_ENDPOINT,
|
|
|
147
|
+ this.pinnedEndpointEventHandler);
|
|
|
148
|
+
|
|
|
149
|
+ this.sharedDocEventHandler = this._sharedDocumentToggled.bind(this);
|
|
|
150
|
+ this._UI.addListener( UIEvents.TOGGLED_SHARED_DOCUMENT,
|
|
|
151
|
+ this.sharedDocEventHandler);
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
|
154
|
+ /**
|
|
|
155
|
+ * Removes all follow me listeners.
|
|
|
156
|
+ * @private
|
|
|
157
|
+ */
|
|
|
158
|
+ _removeFollowMeListeners () {
|
|
|
159
|
+ this._UI.removeListener(UIEvents.TOGGLED_FILM_STRIP,
|
|
|
160
|
+ this.filmStripEventHandler);
|
|
|
161
|
+ this._UI.removeListener(UIEvents.TOGGLED_SHARED_DOCUMENT,
|
|
|
162
|
+ this.sharedDocEventHandler);
|
|
|
163
|
+ this._UI.removeListener(UIEvents.PINNED_ENDPOINT,
|
|
|
164
|
+ this.pinnedEndpointEventHandler);
|
|
|
165
|
+ }
|
|
|
166
|
+
|
|
|
167
|
+ /**
|
|
|
168
|
+ * Enables or disabled the follow me functionality
|
|
|
169
|
+ *
|
|
|
170
|
+ * @param enable {true} to enable the follow me functionality, {false} -
|
|
|
171
|
+ * to disable it
|
|
|
172
|
+ */
|
|
|
173
|
+ enableFollowMe (enable) {
|
|
|
174
|
+ this.isEnabled = enable;
|
|
|
175
|
+ if (this.isEnabled)
|
|
|
176
|
+ this._addFollowMeListeners();
|
|
|
177
|
+ else
|
|
|
178
|
+ this._removeFollowMeListeners();
|
|
|
179
|
+ }
|
|
|
180
|
+
|
|
|
181
|
+ /**
|
|
|
182
|
+ * Notifies this instance that the (visibility of the) film strip was
|
|
|
183
|
+ * toggled (in the user interface of the local participant).
|
|
|
184
|
+ *
|
|
|
185
|
+ * @param filmStripVisible {Boolean} {true} if the film strip was shown (as
|
|
|
186
|
+ * a result of the toggle) or {false} if the film strip was hidden
|
|
|
187
|
+ */
|
|
|
188
|
+ _filmStripToggled (filmStripVisible) {
|
|
|
189
|
+ this._local.filmStripVisible = filmStripVisible;
|
|
|
190
|
+ }
|
|
|
191
|
+
|
|
|
192
|
+ /**
|
|
|
193
|
+ * Notifies this instance that the (visibility of the) shared document was
|
|
|
194
|
+ * toggled (in the user interface of the local participant).
|
|
|
195
|
+ *
|
|
|
196
|
+ * @param sharedDocumentVisible {Boolean} {true} if the shared document was
|
|
|
197
|
+ * shown (as a result of the toggle) or {false} if it was hidden
|
|
|
198
|
+ */
|
|
|
199
|
+ _sharedDocumentToggled (sharedDocumentVisible) {
|
|
|
200
|
+ this._local.sharedDocumentVisible = sharedDocumentVisible;
|
|
|
201
|
+ }
|
|
|
202
|
+
|
|
|
203
|
+ /**
|
|
|
204
|
+ * Changes the nextOnPage property value.
|
|
|
205
|
+ *
|
|
|
206
|
+ * @param smallVideo the {SmallVideo} that was pinned or unpinned
|
|
|
207
|
+ * @param isPinned indicates if the given {SmallVideo} was pinned or
|
|
|
208
|
+ * unpinned
|
|
|
209
|
+ * @private
|
|
|
210
|
+ */
|
|
|
211
|
+ _nextOnStage (smallVideo, isPinned) {
|
|
|
212
|
+ if (!this._conference.isModerator)
|
|
|
213
|
+ return;
|
|
|
214
|
+
|
|
|
215
|
+ var nextOnStage = null;
|
|
|
216
|
+ if(isPinned)
|
|
|
217
|
+ nextOnStage = smallVideo.getId();
|
|
|
218
|
+
|
|
|
219
|
+ this._local.nextOnStage = nextOnStage;
|
|
|
220
|
+ }
|
|
|
221
|
+
|
|
|
222
|
+ /**
|
|
|
223
|
+ * Sends the follow-me command, when a local property change occurs.
|
|
|
224
|
+ *
|
|
|
225
|
+ * @param property the property name
|
|
|
226
|
+ * @param oldValue the old value
|
|
|
227
|
+ * @param newValue the new value
|
|
|
228
|
+ * @private
|
|
|
229
|
+ */
|
|
|
230
|
+ _localPropertyChange (property, oldValue, newValue) {
|
|
|
231
|
+ // Only a moderator is allowed to send commands.
|
|
|
232
|
+ var conference = this._conference;
|
|
|
233
|
+ if (!conference.isModerator)
|
|
|
234
|
+ return;
|
|
|
235
|
+
|
|
|
236
|
+ var commands = conference.commands;
|
|
|
237
|
+ // XXX The "Follow Me" command represents a snapshot of all states
|
|
|
238
|
+ // which are to be followed so don't forget to removeCommand before
|
|
|
239
|
+ // sendCommand!
|
|
|
240
|
+ commands.removeCommand(_COMMAND);
|
|
|
241
|
+ var self = this;
|
|
|
242
|
+ commands.sendCommandOnce(
|
|
|
243
|
+ _COMMAND,
|
|
|
244
|
+ {
|
|
|
245
|
+ attributes: {
|
|
|
246
|
+ filmStripVisible: self._local.filmStripVisible,
|
|
|
247
|
+ nextOnStage: self._local.nextOnStage,
|
|
|
248
|
+ sharedDocumentVisible: self._local.sharedDocumentVisible
|
|
|
249
|
+ }
|
|
|
250
|
+ });
|
|
|
251
|
+ }
|
|
|
252
|
+
|
|
|
253
|
+ /**
|
|
|
254
|
+ * Notifies this instance about a &qout;Follow Me&qout; command (delivered
|
|
|
255
|
+ * by the Command(s) API of {this._conference}).
|
|
|
256
|
+ *
|
|
|
257
|
+ * @param attributes the attributes {Object} carried by the command
|
|
|
258
|
+ * @param id the identifier of the participant who issued the command. A
|
|
|
259
|
+ * notable idiosyncrasy of the Command(s) API to be mindful of here is that
|
|
|
260
|
+ * the command may be issued by the local participant.
|
|
|
261
|
+ */
|
|
|
262
|
+ _onFollowMeCommand ({ attributes }, id) {
|
|
|
263
|
+ // We require to know who issued the command because (1) only a
|
|
|
264
|
+ // moderator is allowed to send commands and (2) a command MUST be
|
|
|
265
|
+ // issued by a defined commander.
|
|
|
266
|
+ if (typeof id === 'undefined')
|
|
|
267
|
+ return;
|
|
|
268
|
+ // The Command(s) API will send us our own commands and we don't want
|
|
|
269
|
+ // to act upon them.
|
|
|
270
|
+ if (this._conference.isLocalId(id))
|
|
|
271
|
+ return;
|
|
|
272
|
+
|
|
|
273
|
+ // TODO Don't obey commands issued by non-moderators.
|
|
|
274
|
+
|
|
|
275
|
+ // Applies the received/remote command to the user experience/interface
|
|
|
276
|
+ // of the local participant.
|
|
|
277
|
+ this._onFilmStripVisible(attributes.filmStripVisible);
|
|
|
278
|
+ this._onNextOnStage(attributes.nextOnStage);
|
|
|
279
|
+ this._onSharedDocumentVisible(attributes.sharedDocumentVisible);
|
|
|
280
|
+ }
|
|
|
281
|
+
|
|
|
282
|
+ _onFilmStripVisible(filmStripVisible) {
|
|
|
283
|
+ if (typeof filmStripVisible !== 'undefined') {
|
|
|
284
|
+ // XXX The Command(s) API doesn't preserve the types (of
|
|
|
285
|
+ // attributes, at least) at the time of this writing so take into
|
|
|
286
|
+ // account that what originated as a Boolean may be a String on
|
|
|
287
|
+ // receipt.
|
|
|
288
|
+ filmStripVisible = (filmStripVisible == 'true');
|
|
|
289
|
+
|
|
|
290
|
+ // FIXME The UI (module) very likely doesn't (want to) expose its
|
|
|
291
|
+ // eventEmitter as a public field. I'm not sure at the time of this
|
|
|
292
|
+ // writing whether calling UI.toggleFilmStrip() is acceptable (from
|
|
|
293
|
+ // a design standpoint) either.
|
|
|
294
|
+ if (filmStripVisible !== FilmStrip.isFilmStripVisible())
|
|
|
295
|
+ this._UI.eventEmitter.emit(
|
|
|
296
|
+ UIEvents.TOGGLE_FILM_STRIP,
|
|
|
297
|
+ filmStripVisible);
|
|
|
298
|
+ }
|
|
|
299
|
+ }
|
|
|
300
|
+
|
|
|
301
|
+ _onNextOnStage(id) {
|
|
|
302
|
+
|
|
|
303
|
+ var clickId = null;
|
|
|
304
|
+ if(typeof id !== 'undefined' && !VideoLayout.isPinned(id))
|
|
|
305
|
+ clickId = id;
|
|
|
306
|
+ else if (typeof id == 'undefined')
|
|
|
307
|
+ clickId = VideoLayout.getPinnedId();
|
|
|
308
|
+
|
|
|
309
|
+ if (clickId !== null)
|
|
|
310
|
+ VideoLayout.handleVideoThumbClicked(clickId);
|
|
|
311
|
+ }
|
|
|
312
|
+
|
|
|
313
|
+ _onSharedDocumentVisible(sharedDocumentVisible) {
|
|
|
314
|
+ if (typeof sharedDocumentVisible !== 'undefined') {
|
|
|
315
|
+ // XXX The Command(s) API doesn't preserve the types (of
|
|
|
316
|
+ // attributes, at least) at the time of this writing so take into
|
|
|
317
|
+ // account that what originated as a Boolean may be a String on
|
|
|
318
|
+ // receipt.
|
|
|
319
|
+ sharedDocumentVisible = (sharedDocumentVisible == 'true');
|
|
|
320
|
+
|
|
|
321
|
+ if (sharedDocumentVisible
|
|
|
322
|
+ !== this._UI.getSharedDocumentManager().isVisible())
|
|
|
323
|
+ this._UI.getSharedDocumentManager().toggleEtherpad();
|
|
|
324
|
+ }
|
|
|
325
|
+ }
|
|
|
326
|
+}
|
|
|
327
|
+
|
|
|
328
|
+export default FollowMe;
|