|
@@ -8,9 +8,10 @@ import {
|
8
|
8
|
} from '../../react/features/remote-control';
|
9
|
9
|
import {
|
10
|
10
|
DISCO_REMOTE_CONTROL_FEATURE,
|
11
|
|
- EVENT_TYPES,
|
|
11
|
+ EVENTS,
|
12
|
12
|
PERMISSIONS_ACTIONS,
|
13
|
|
- REMOTE_CONTROL_EVENT_NAME
|
|
13
|
+ REMOTE_CONTROL_MESSAGE_NAME,
|
|
14
|
+ REQUESTS
|
14
|
15
|
} from '../../service/remotecontrol/Constants';
|
15
|
16
|
import { getJitsiMeetTransport } from '../transport';
|
16
|
17
|
|
|
@@ -51,14 +52,14 @@ export default class Receiver extends RemoteControlParticipant {
|
51
|
52
|
super();
|
52
|
53
|
this._controller = null;
|
53
|
54
|
this._remoteControlEventsListener
|
54
|
|
- = this._onRemoteControlEvent.bind(this);
|
|
55
|
+ = this._onRemoteControlMessage.bind(this);
|
55
|
56
|
this._userLeftListener = this._onUserLeft.bind(this);
|
56
|
57
|
this._hangupListener = this._onHangup.bind(this);
|
57
|
58
|
|
58
|
59
|
// We expect here that even if we receive the supported event earlier
|
59
|
60
|
// it will be cached and we'll receive it.
|
60
|
61
|
transport.on('event', event => {
|
61
|
|
- if (event.name === REMOTE_CONTROL_EVENT_NAME) {
|
|
62
|
+ if (event.name === REMOTE_CONTROL_MESSAGE_NAME) {
|
62
|
63
|
this._onRemoteControlAPIEvent(event);
|
63
|
64
|
|
64
|
65
|
return true;
|
|
@@ -120,12 +121,10 @@ export default class Receiver extends RemoteControlParticipant {
|
120
|
121
|
this._controller = null;
|
121
|
122
|
APP.conference.removeConferenceListener(ConferenceEvents.USER_LEFT,
|
122
|
123
|
this._userLeftListener);
|
123
|
|
- if (this.remoteControlExternalAuth) {
|
124
|
|
- transport.sendEvent({
|
125
|
|
- name: REMOTE_CONTROL_EVENT_NAME,
|
126
|
|
- type: EVENT_TYPES.stop
|
127
|
|
- });
|
128
|
|
- }
|
|
124
|
+ transport.sendEvent({
|
|
125
|
+ name: REMOTE_CONTROL_MESSAGE_NAME,
|
|
126
|
+ type: EVENTS.stop
|
|
127
|
+ });
|
129
|
128
|
if (!dontShowDialog) {
|
130
|
129
|
APP.UI.messageHandler.openMessageDialog(
|
131
|
130
|
'dialog.remoteControlTitle',
|
|
@@ -143,89 +142,46 @@ export default class Receiver extends RemoteControlParticipant {
|
143
|
142
|
if (!this._controller) {
|
144
|
143
|
return;
|
145
|
144
|
}
|
146
|
|
- this.sendRemoteControlEvent(this._controller, {
|
147
|
|
- type: EVENT_TYPES.stop
|
|
145
|
+ this.sendRemoteControlEndpointMessage(this._controller, {
|
|
146
|
+ type: EVENTS.stop
|
148
|
147
|
});
|
149
|
148
|
this._stop();
|
150
|
149
|
}
|
151
|
150
|
|
152
|
151
|
/**
|
153
|
|
- * Listens for data channel EndpointMessage events. Handles only events of
|
154
|
|
- * type remote control. Sends "remote-control-event" events to the API
|
155
|
|
- * module.
|
|
152
|
+ * Listens for data channel EndpointMessage. Handles only remote control
|
|
153
|
+ * messages. Sends the remote control messages to the external app that
|
|
154
|
+ * will execute them.
|
156
|
155
|
*
|
157
|
156
|
* @param {JitsiParticipant} participant - The controller participant.
|
158
|
|
- * @param {Object} event - EndpointMessage event from the data channels.
|
159
|
|
- * @param {string} event.name - The function process only events with
|
160
|
|
- * name REMOTE_CONTROL_EVENT_NAME.
|
|
157
|
+ * @param {Object} message - EndpointMessage from the data channels.
|
|
158
|
+ * @param {string} message.name - The function processes only messages with
|
|
159
|
+ * name REMOTE_CONTROL_MESSAGE_NAME.
|
161
|
160
|
* @returns {void}
|
162
|
161
|
*/
|
163
|
|
- _onRemoteControlEvent(participant: Object, event: Object) {
|
164
|
|
- if (event.name !== REMOTE_CONTROL_EVENT_NAME) {
|
|
162
|
+ _onRemoteControlMessage(participant: Object, message: Object) {
|
|
163
|
+ if (message.name !== REMOTE_CONTROL_MESSAGE_NAME) {
|
165
|
164
|
return;
|
166
|
165
|
}
|
167
|
166
|
|
168
|
|
- const remoteControlEvent = Object.assign({}, event);
|
169
|
|
-
|
170
|
167
|
if (this._enabled) {
|
171
|
168
|
if (this._controller === null
|
172
|
|
- && event.type === EVENT_TYPES.permissions
|
173
|
|
- && event.action === PERMISSIONS_ACTIONS.request) {
|
|
169
|
+ && message.type === EVENTS.permissions
|
|
170
|
+ && message.action === PERMISSIONS_ACTIONS.request) {
|
174
|
171
|
const userId = participant.getId();
|
175
|
172
|
|
176
|
|
- if (!config.remoteControlExternalAuth) {
|
177
|
|
- APP.store.dispatch(
|
178
|
|
- openRemoteControlAuthorizationDialog(userId));
|
179
|
|
-
|
180
|
|
- return;
|
|
173
|
+ APP.store.dispatch(
|
|
174
|
+ openRemoteControlAuthorizationDialog(userId));
|
|
175
|
+ } else if (this._controller === participant.getId()) {
|
|
176
|
+ if (message.type === EVENTS.stop) {
|
|
177
|
+ this._stop();
|
|
178
|
+ } else { // forward the message
|
|
179
|
+ transport.sendEvent(message);
|
181
|
180
|
}
|
182
|
|
-
|
183
|
|
- // FIXME: Maybe use transport.sendRequest in this case???
|
184
|
|
- remoteControlEvent.userId = userId;
|
185
|
|
- remoteControlEvent.userJID = participant.getJid();
|
186
|
|
- remoteControlEvent.displayName = participant.getDisplayName()
|
187
|
|
- || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
|
188
|
|
- remoteControlEvent.screenSharing
|
189
|
|
- = APP.conference.isSharingScreen;
|
190
|
|
- } else if (this._controller !== participant.getId()) {
|
191
|
|
- return;
|
192
|
|
- } else if (event.type === EVENT_TYPES.stop) {
|
193
|
|
- this._stop();
|
194
|
|
-
|
195
|
|
- return;
|
196
|
|
- }
|
197
|
|
- transport.sendEvent(remoteControlEvent);
|
|
181
|
+ } // else ignore
|
198
|
182
|
} else {
|
199
|
|
- logger.log('Remote control event is ignored because remote '
|
200
|
|
- + 'control is disabled', event);
|
201
|
|
- }
|
202
|
|
- }
|
203
|
|
-
|
204
|
|
- /**
|
205
|
|
- * Handles remote control permission events.
|
206
|
|
- *
|
207
|
|
- * @param {string} userId - The user id of the participant related to the
|
208
|
|
- * event.
|
209
|
|
- * @param {PERMISSIONS_ACTIONS} action - The action related to the event.
|
210
|
|
- * @returns {void}
|
211
|
|
- */
|
212
|
|
- _onRemoteControlPermissionsEvent(userId: string, action: string) {
|
213
|
|
- switch (action) {
|
214
|
|
- case PERMISSIONS_ACTIONS.grant:
|
215
|
|
- this.grant(userId);
|
216
|
|
- break;
|
217
|
|
- case PERMISSIONS_ACTIONS.deny:
|
218
|
|
- this.deny(userId);
|
219
|
|
- break;
|
220
|
|
- case PERMISSIONS_ACTIONS.error:
|
221
|
|
- this.sendRemoteControlEvent(userId, {
|
222
|
|
- type: EVENT_TYPES.permissions,
|
223
|
|
- action
|
224
|
|
- });
|
225
|
|
- break;
|
226
|
|
- default:
|
227
|
|
-
|
228
|
|
- // Unknown action. Ignore.
|
|
183
|
+ logger.log('Remote control message is ignored because remote '
|
|
184
|
+ + 'control is disabled', message);
|
229
|
185
|
}
|
230
|
186
|
}
|
231
|
187
|
|
|
@@ -237,8 +193,8 @@ export default class Receiver extends RemoteControlParticipant {
|
237
|
193
|
* @returns {void}
|
238
|
194
|
*/
|
239
|
195
|
deny(userId: string) {
|
240
|
|
- this.sendRemoteControlEvent(userId, {
|
241
|
|
- type: EVENT_TYPES.permissions,
|
|
196
|
+ this.sendRemoteControlEndpointMessage(userId, {
|
|
197
|
+ type: EVENTS.permissions,
|
242
|
198
|
action: PERMISSIONS_ACTIONS.deny
|
243
|
199
|
});
|
244
|
200
|
}
|
|
@@ -255,50 +211,63 @@ export default class Receiver extends RemoteControlParticipant {
|
255
|
211
|
this._userLeftListener);
|
256
|
212
|
this._controller = userId;
|
257
|
213
|
logger.log(`Remote control permissions granted to: ${userId}`);
|
|
214
|
+
|
|
215
|
+ let promise;
|
|
216
|
+
|
258
|
217
|
if (APP.conference.isSharingScreen) {
|
259
|
|
- this.sendRemoteControlEvent(userId, {
|
260
|
|
- type: EVENT_TYPES.permissions,
|
261
|
|
- action: PERMISSIONS_ACTIONS.grant
|
262
|
|
- });
|
|
218
|
+ promise = this._sendStartRequest();
|
263
|
219
|
} else {
|
264
|
|
- APP.conference.toggleScreenSharing()
|
265
|
|
- .then(() => {
|
266
|
|
- if (APP.conference.isSharingScreen) {
|
267
|
|
- this.sendRemoteControlEvent(userId, {
|
268
|
|
- type: EVENT_TYPES.permissions,
|
269
|
|
- action: PERMISSIONS_ACTIONS.grant
|
270
|
|
- });
|
271
|
|
- } else {
|
272
|
|
- this.sendRemoteControlEvent(userId, {
|
273
|
|
- type: EVENT_TYPES.permissions,
|
274
|
|
- action: PERMISSIONS_ACTIONS.error
|
275
|
|
- });
|
276
|
|
- }
|
|
220
|
+ promise = APP.conference.toggleScreenSharing()
|
|
221
|
+ .then(() => this._sendStartRequest());
|
|
222
|
+ }
|
|
223
|
+
|
|
224
|
+ promise
|
|
225
|
+ .then(() =>
|
|
226
|
+ this.sendRemoteControlEndpointMessage(userId, {
|
|
227
|
+ type: EVENTS.permissions,
|
|
228
|
+ action: PERMISSIONS_ACTIONS.grant
|
277
|
229
|
})
|
278
|
|
- .catch(() => {
|
279
|
|
- this.sendRemoteControlEvent(userId, {
|
280
|
|
- type: EVENT_TYPES.permissions,
|
281
|
|
- action: PERMISSIONS_ACTIONS.error
|
282
|
|
- });
|
|
230
|
+ )
|
|
231
|
+ .catch(() => {
|
|
232
|
+ this.sendRemoteControlEndpointMessage(userId, {
|
|
233
|
+ type: EVENTS.permissions,
|
|
234
|
+ action: PERMISSIONS_ACTIONS.error
|
283
|
235
|
});
|
284
|
|
- }
|
|
236
|
+
|
|
237
|
+ // FIXME: show err msg
|
|
238
|
+ this._stop();
|
|
239
|
+ });
|
|
240
|
+ }
|
|
241
|
+
|
|
242
|
+ /**
|
|
243
|
+ * Sends remote control start request.
|
|
244
|
+ *
|
|
245
|
+ * @returns {Promise}
|
|
246
|
+ */
|
|
247
|
+ _sendStartRequest() {
|
|
248
|
+ return transport.sendRequest({
|
|
249
|
+ name: REMOTE_CONTROL_MESSAGE_NAME,
|
|
250
|
+ type: REQUESTS.start,
|
|
251
|
+ sourceId: APP.conference.getDesktopSharingSourceId()
|
|
252
|
+ });
|
285
|
253
|
}
|
286
|
254
|
|
287
|
255
|
/**
|
288
|
256
|
* Handles remote control events from the external app. Currently only
|
289
|
|
- * events with type = EVENT_TYPES.supported or EVENT_TYPES.permissions.
|
|
257
|
+ * events with type EVENTS.supported and EVENTS.stop are
|
|
258
|
+ * supported.
|
290
|
259
|
*
|
291
|
260
|
* @param {RemoteControlEvent} event - The remote control event.
|
292
|
261
|
* @returns {void}
|
293
|
262
|
*/
|
294
|
263
|
_onRemoteControlAPIEvent(event: Object) {
|
295
|
264
|
switch (event.type) {
|
296
|
|
- case EVENT_TYPES.permissions:
|
297
|
|
- this._onRemoteControlPermissionsEvent(event.userId, event.action);
|
298
|
|
- break;
|
299
|
|
- case EVENT_TYPES.supported:
|
|
265
|
+ case EVENTS.supported:
|
300
|
266
|
this._onRemoteControlSupported();
|
301
|
267
|
break;
|
|
268
|
+ case EVENTS.stop:
|
|
269
|
+ this.stop();
|
|
270
|
+ break;
|
302
|
271
|
}
|
303
|
272
|
}
|
304
|
273
|
|