Parcourir la source

ref(remotecontrol): Changing the format of the messages

j8
hristoterezov il y a 8 ans
Parent
révision
b297aa3f3a

+ 1
- 0
.jshintignore Voir le fichier

@@ -9,6 +9,7 @@ node_modules/
9 9
 # supersedes JSHint.
10 10
 flow-typed/
11 11
 modules/API/
12
+modules/remotecontrol/RemoteControlParticipant.js
12 13
 modules/transport/
13 14
 react/
14 15
 

+ 8
- 9
modules/remotecontrol/Controller.js Voir le fichier

@@ -132,15 +132,14 @@ export default class Controller extends RemoteControlParticipant {
132 132
      * @param {RemoteControlEvent} event the remote control event.
133 133
      */
134 134
     _handleReply(participant, event) {
135
-        const remoteControlEvent = event.event;
136 135
         const userId = participant.getId();
137
-        if(this.enabled && event.type === REMOTE_CONTROL_EVENT_TYPE
138
-            && remoteControlEvent.type === EVENT_TYPES.permissions
136
+        if(this.enabled && event.name === REMOTE_CONTROL_EVENT_TYPE
137
+            && event.type === EVENT_TYPES.permissions
139 138
             && userId === this.requestedParticipant) {
140
-            if(remoteControlEvent.action !== PERMISSIONS_ACTIONS.grant) {
139
+            if(event.action !== PERMISSIONS_ACTIONS.grant) {
141 140
                 this.area = null;
142 141
             }
143
-            switch(remoteControlEvent.action) {
142
+            switch(event.action) {
144 143
                 case PERMISSIONS_ACTIONS.grant: {
145 144
                     this.controlledParticipant = userId;
146 145
                     logger.log("Remote control permissions granted to: "
@@ -166,13 +165,13 @@ export default class Controller extends RemoteControlParticipant {
166 165
      * @param {JitsiParticipant} participant the participant that has sent the
167 166
      * event
168 167
      * @param {Object} event EndpointMessage event from the data channels.
169
-     * @property {string} type property. The function process only events of
170
-     * type REMOTE_CONTROL_EVENT_TYPE
168
+     * @property {string} type property. The function process only events with
169
+     * name REMOTE_CONTROL_EVENT_TYPE
171 170
      * @property {RemoteControlEvent} event - the remote control event.
172 171
      */
173 172
     _handleRemoteControlStoppedEvent(participant, event) {
174
-        if(this.enabled && event.type === REMOTE_CONTROL_EVENT_TYPE
175
-            && event.event.type === EVENT_TYPES.stop
173
+        if(this.enabled && event.name === REMOTE_CONTROL_EVENT_TYPE
174
+            && event.type === EVENT_TYPES.stop
176 175
             && participant.getId() === this.controlledParticipant) {
177 176
             this._stop();
178 177
         }

+ 23
- 23
modules/remotecontrol/Receiver.js Voir le fichier

@@ -6,10 +6,10 @@ import {
6 6
     EVENT_TYPES,
7 7
     PERMISSIONS_ACTIONS,
8 8
     REMOTE_CONTROL_EVENT_TYPE
9
-} from "../../service/remotecontrol/Constants";
9
+} from '../../service/remotecontrol/Constants';
10 10
 import { getJitsiMeetTransport } from '../transport';
11 11
 
12
-import RemoteControlParticipant from "./RemoteControlParticipant";
12
+import RemoteControlParticipant from './RemoteControlParticipant';
13 13
 
14 14
 const ConferenceEvents = JitsiMeetJS.events.conference;
15 15
 const logger = require("jitsi-meet-logger").getLogger(__filename);
@@ -41,8 +41,8 @@ export default class Receiver extends RemoteControlParticipant {
41 41
         this._hangupListener = this._onHangup.bind(this);
42 42
         // We expect here that even if we receive the supported event earlier
43 43
         // it will be cached and we'll receive it.
44
-        transport.on('event', ({ event, name }) => {
45
-            if(name === REMOTE_CONTROL_EVENT_TYPE) {
44
+        transport.on('event', event => {
45
+            if (event.name === REMOTE_CONTROL_EVENT_TYPE) {
46 46
                 this._onRemoteControlAPIEvent(event);
47 47
 
48 48
                 return true;
@@ -100,9 +100,7 @@ export default class Receiver extends RemoteControlParticipant {
100 100
             this._userLeftListener);
101 101
         transport.sendEvent({
102 102
             name: REMOTE_CONTROL_EVENT_TYPE,
103
-            event: {
104
-                type: EVENT_TYPES.stop
105
-            }
103
+            type: EVENT_TYPES.stop
106 104
         });
107 105
         if(!dontShowDialog) {
108 106
             APP.UI.messageHandler.openMessageDialog(
@@ -131,16 +129,21 @@ export default class Receiver extends RemoteControlParticipant {
131 129
      * module.
132 130
      * @param {JitsiParticipant} participant the controller participant
133 131
      * @param {Object} event EndpointMessage event from the data channels.
134
-     * @property {string} type property. The function process only events of
135
-     * type REMOTE_CONTROL_EVENT_TYPE
132
+     * @property {string} type property. The function process only events with
133
+     * name REMOTE_CONTROL_EVENT_TYPE
136 134
      * @property {RemoteControlEvent} event - the remote control event.
137 135
      */
138 136
     _onRemoteControlEvent(participant, event) {
139
-        if(this.enabled && event.type === REMOTE_CONTROL_EVENT_TYPE) {
140
-            const remoteControlEvent = event.event;
141
-            if(this.controller === null
142
-                && remoteControlEvent.type === EVENT_TYPES.permissions
143
-                && remoteControlEvent.action === PERMISSIONS_ACTIONS.request) {
137
+        if (event.name !== REMOTE_CONTROL_EVENT_TYPE) {
138
+            return;
139
+        }
140
+
141
+        const remoteControlEvent = Object.assign({}, event);
142
+
143
+        if (this.enabled) {
144
+            if (this.controller === null
145
+                && event.type === EVENT_TYPES.permissions
146
+                && event.action === PERMISSIONS_ACTIONS.request) {
144 147
                 // FIXME: Maybe use transport.sendRequest in this case???
145 148
                 remoteControlEvent.userId = participant.getId();
146 149
                 remoteControlEvent.userJID = participant.getJid();
@@ -148,17 +151,14 @@ export default class Receiver extends RemoteControlParticipant {
148 151
                     || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
149 152
                 remoteControlEvent.screenSharing
150 153
                     = APP.conference.isSharingScreen;
151
-            } else if(this.controller !== participant.getId()) {
154
+            } else if (this.controller !== participant.getId()) {
152 155
                 return;
153
-            } else if(remoteControlEvent.type === EVENT_TYPES.stop) {
156
+            } else if (event.type === EVENT_TYPES.stop) {
154 157
                 this._stop();
155 158
                 return;
156 159
             }
157
-            transport.sendEvent({
158
-                name: REMOTE_CONTROL_EVENT_TYPE,
159
-                event: remoteControlEvent
160
-            });
161
-        } else if(event.type === REMOTE_CONTROL_EVENT_TYPE) {
160
+            transport.sendEvent(remoteControlEvent);
161
+        } else {
162 162
             logger.log("Remote control event is ignored because remote "
163 163
                 + "control is disabled", event);
164 164
         }
@@ -171,7 +171,7 @@ export default class Receiver extends RemoteControlParticipant {
171 171
      * @param {PERMISSIONS_ACTIONS} action the action related to the event.
172 172
      */
173 173
     _onRemoteControlPermissionsEvent(userId, action) {
174
-        if(action === PERMISSIONS_ACTIONS.grant) {
174
+        if (action === PERMISSIONS_ACTIONS.grant) {
175 175
             APP.conference.addConferenceListener(ConferenceEvents.USER_LEFT,
176 176
                 this._userLeftListener);
177 177
             this.controller = userId;
@@ -227,7 +227,7 @@ export default class Receiver extends RemoteControlParticipant {
227 227
      */
228 228
     _onRemoteControlSupported() {
229 229
         logger.log("Remote Control supported.");
230
-        if(!config.disableRemoteControl) {
230
+        if (!config.disableRemoteControl) {
231 231
             this._enable(true);
232 232
         } else {
233 233
             logger.log("Remote Control disabled.");

+ 4
- 2
modules/remotecontrol/RemoteControlParticipant.js Voir le fichier

@@ -31,8 +31,10 @@ export default class RemoteControlParticipant {
31 31
             return;
32 32
         }
33 33
         try{
34
-            APP.conference.sendEndpointMessage(to,
35
-                {type: REMOTE_CONTROL_EVENT_TYPE, event});
34
+            APP.conference.sendEndpointMessage(to, {
35
+                name: REMOTE_CONTROL_EVENT_TYPE,
36
+                ...event
37
+            });
36 38
         } catch (e) {
37 39
             logger.error("Failed to send EndpointMessage via the datachannels",
38 40
                 e);

+ 1
- 1
modules/transport/Transport.js Voir le fichier

@@ -232,7 +232,7 @@ export default class Transport {
232 232
         const id = this._requestID;
233 233
 
234 234
         return new Promise((resolve, reject) => {
235
-            this._responseHandlers.set(this._requestID, ({ error, result }) => {
235
+            this._responseHandlers.set(id, ({ error, result }) => {
236 236
                 if (result) {
237 237
                     resolve(result);
238 238
                 } else if (error) {

Chargement…
Annuler
Enregistrer