Sfoglia il codice sorgente

Coding style

For lack of a better word/phrase, I'm calling all changes coding style.
I'm targeting readability through naming and syntax.
j8
Lyubo Marinov 8 anni fa
parent
commit
e9dc9c47a9

+ 1
- 1
.jshintignore Vedi File

8
 # The following are checked by ESLint with the maximum configuration which
8
 # The following are checked by ESLint with the maximum configuration which
9
 # supersedes JSHint.
9
 # supersedes JSHint.
10
 flow-typed/
10
 flow-typed/
11
-react/
12
 modules/API/
11
 modules/API/
13
 modules/transport/
12
 modules/transport/
13
+react/
14
 
14
 
15
 # The following are checked by ESLint with the minimum configuration which does
15
 # The following are checked by ESLint with the minimum configuration which does
16
 # not supersede JSHint but take advantage of advanced language features such as
16
 # not supersede JSHint but take advantage of advanced language features such as

+ 16
- 17
modules/API/API.js Vedi File

37
         'email': APP.conference.changeLocalEmail,
37
         'email': APP.conference.changeLocalEmail,
38
         'avatar-url': APP.conference.changeLocalAvatarUrl
38
         'avatar-url': APP.conference.changeLocalAvatarUrl
39
     };
39
     };
40
-    transport.on('event', event => {
41
-        const { name, data } = event;
42
-
40
+    transport.on('event', ({ data, name }) => {
43
         if (name && commands[name]) {
41
         if (name && commands[name]) {
44
             commands[name](...data);
42
             commands[name](...data);
45
 
43
 
101
      * module.
99
      * module.
102
      * @returns {void}
100
      * @returns {void}
103
      */
101
      */
104
-    init(options = {}) {
105
-        if (!shouldBeEnabled() && !options.forceEnable) {
102
+    init({ forceEnable } = {}) {
103
+        if (!shouldBeEnabled() && !forceEnable) {
106
             return;
104
             return;
107
         }
105
         }
108
 
106
 
109
         /**
107
         /**
110
          * Current status (enabled/disabled) of API.
108
          * Current status (enabled/disabled) of API.
109
+         *
110
+         * @private
111
+         * @type {boolean}
111
          */
112
          */
112
-        this.enabled = true;
113
+        this._enabled = true;
113
 
114
 
114
         APP.conference.addListener(
115
         APP.conference.addListener(
115
             JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
116
             JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
126
      * @returns {void}
127
      * @returns {void}
127
      */
128
      */
128
     _sendEvent(name, data = {}) {
129
     _sendEvent(name, data = {}) {
129
-        if (this.enabled) {
130
+        if (this._enabled) {
130
             transport.sendEvent({
131
             transport.sendEvent({
131
-                name,
132
-                data
132
+                data,
133
+                name
133
             });
134
             });
134
         }
135
         }
135
     }
136
     }
151
      * @param {Object} options - Object with the message properties.
152
      * @param {Object} options - Object with the message properties.
152
      * @returns {void}
153
      * @returns {void}
153
      */
154
      */
154
-    notifyReceivedChatMessage(options = {}) {
155
-        const { id, nick, body, ts } = options;
156
-
155
+    notifyReceivedChatMessage({ body, id, nick, ts } = {}) {
157
         if (APP.conference.isLocalId(id)) {
156
         if (APP.conference.isLocalId(id)) {
158
             return;
157
             return;
159
         }
158
         }
160
 
159
 
161
         this._sendEvent('incoming-message', {
160
         this._sendEvent('incoming-message', {
162
             from: id,
161
             from: id,
163
-            nick,
164
             message: body,
162
             message: body,
163
+            nick,
165
             stamp: ts
164
             stamp: ts
166
         });
165
         });
167
     }
166
     }
198
      */
197
      */
199
     notifyDisplayNameChanged(id, displayname) {
198
     notifyDisplayNameChanged(id, displayname) {
200
         this._sendEvent('display-name-change', {
199
         this._sendEvent('display-name-change', {
201
-            id,
202
-            displayname
200
+            displayname,
201
+            id
203
         });
202
         });
204
     }
203
     }
205
 
204
 
241
      * @returns {void}
240
      * @returns {void}
242
      */
241
      */
243
     dispose() {
242
     dispose() {
244
-        if (this.enabled) {
245
-            this.enabled = false;
243
+        if (this._enabled) {
244
+            this._enabled = false;
246
             APP.conference.removeListener(
245
             APP.conference.removeListener(
247
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
246
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
248
                 onDesktopSharingEnabledChanged);
247
                 onDesktopSharingEnabledChanged);

+ 1
- 2
modules/API/constants.js Vedi File

3
 /**
3
 /**
4
  * JitsiMeetExternalAPI id - unique for a webpage.
4
  * JitsiMeetExternalAPI id - unique for a webpage.
5
  */
5
  */
6
-export const API_ID
7
-    = getConfigParamsFromUrl().jitsi_meet_external_api_id;
6
+export const API_ID = getConfigParamsFromUrl().jitsi_meet_external_api_id;

+ 6
- 10
modules/API/external/external_api.js Vedi File

81
 
81
 
82
     for (const key in config) { // eslint-disable-line guard-for-in
82
     for (const key in config) { // eslint-disable-line guard-for-in
83
         try {
83
         try {
84
-            params.push(`${key}=${
85
-                encodeURIComponent(JSON.stringify(config[key]))}`);
84
+            params.push(
85
+                `${key}=${encodeURIComponent(JSON.stringify(config[key]))}`);
86
         } catch (e) {
86
         } catch (e) {
87
             console.warn(`Error encoding ${key}: ${e}`);
87
             console.warn(`Error encoding ${key}: ${e}`);
88
         }
88
         }
233
      */
233
      */
234
     _setupListeners() {
234
     _setupListeners() {
235
 
235
 
236
-        this._transport.on('event', event => {
237
-            const { name, data } = event;
238
-
236
+        this._transport.on('event', ({ data, name }) => {
239
             if (name === 'participant-joined') {
237
             if (name === 'participant-joined') {
240
                 changeParticipantNumber(this, 1);
238
                 changeParticipantNumber(this, 1);
241
-            }
242
-
243
-            if (name === 'participant-left') {
239
+            } else if (name === 'participant-left') {
244
                 changeParticipantNumber(this, -1);
240
                 changeParticipantNumber(this, -1);
245
             }
241
             }
246
 
242
 
364
             return;
360
             return;
365
         }
361
         }
366
         this._transport.sendEvent({
362
         this._transport.sendEvent({
367
-            name: commands[name],
368
-            data: args
363
+            data: args,
364
+            name: commands[name]
369
         });
365
         });
370
     }
366
     }
371
 
367
 

+ 13
- 13
modules/remotecontrol/Receiver.js Vedi File

1
-/* global APP, JitsiMeetJS, interfaceConfig, config */
1
+/* global APP, config, interfaceConfig, JitsiMeetJS */
2
+
2
 import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
3
 import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
3
 import {
4
 import {
4
     DISCO_REMOTE_CONTROL_FEATURE,
5
     DISCO_REMOTE_CONTROL_FEATURE,
10
 
11
 
11
 import RemoteControlParticipant from "./RemoteControlParticipant";
12
 import RemoteControlParticipant from "./RemoteControlParticipant";
12
 
13
 
13
-const logger = require("jitsi-meet-logger").getLogger(__filename);
14
 const ConferenceEvents = JitsiMeetJS.events.conference;
14
 const ConferenceEvents = JitsiMeetJS.events.conference;
15
+const logger = require("jitsi-meet-logger").getLogger(__filename);
15
 
16
 
16
 /**
17
 /**
17
  * This class represents the receiver party for a remote controller session.
18
  * This class represents the receiver party for a remote controller session.
33
         this._hangupListener = this._onHangup.bind(this);
34
         this._hangupListener = this._onHangup.bind(this);
34
         // We expect here that even if we receive the supported event earlier
35
         // We expect here that even if we receive the supported event earlier
35
         // it will be cached and we'll receive it.
36
         // it will be cached and we'll receive it.
36
-        transport.on('event', data => {
37
-            if(data.name === REMOTE_CONTROL_EVENT_TYPE) {
38
-                this._onRemoteControlAPIEvent(data.event);
37
+        transport.on('event', ({ event, name }) => {
38
+            if(name === REMOTE_CONTROL_EVENT_TYPE) {
39
+                this._onRemoteControlAPIEvent(event);
39
 
40
 
40
                 return true;
41
                 return true;
41
             }
42
             }
193
         }
194
         }
194
         this._sendRemoteControlEvent(userId, {
195
         this._sendRemoteControlEvent(userId, {
195
             type: EVENT_TYPES.permissions,
196
             type: EVENT_TYPES.permissions,
196
-            action: action
197
+            action
197
         });
198
         });
198
     }
199
     }
199
 
200
 
204
      */
205
      */
205
     _onRemoteControlAPIEvent(event) {
206
     _onRemoteControlAPIEvent(event) {
206
         switch(event.type) {
207
         switch(event.type) {
207
-            case EVENT_TYPES.supported:
208
-                this._onRemoteControlSupported();
209
-                break;
210
-            case EVENT_TYPES.permissions:
211
-                this._onRemoteControlPermissionsEvent(
212
-                    event.userId, event.action);
213
-                break;
208
+        case EVENT_TYPES.supported:
209
+            this._onRemoteControlSupported();
210
+            break;
211
+        case EVENT_TYPES.permissions:
212
+            this._onRemoteControlPermissionsEvent(event.userId, event.action);
213
+            break;
214
         }
214
         }
215
     }
215
     }
216
 
216
 

+ 6
- 4
modules/remotecontrol/RemoteControl.js Vedi File

25
      * enabled or not.
25
      * enabled or not.
26
      */
26
      */
27
     init() {
27
     init() {
28
-        if(config.disableRemoteControl || this.initialized
29
-            || !APP.conference.isDesktopSharingEnabled) {
28
+        if(config.disableRemoteControl
29
+                || this.initialized
30
+                || !APP.conference.isDesktopSharingEnabled) {
30
             return;
31
             return;
31
         }
32
         }
32
         logger.log("Initializing remote control.");
33
         logger.log("Initializing remote control.");
42
      * the user supports remote control and with false if not.
43
      * the user supports remote control and with false if not.
43
      */
44
      */
44
     checkUserRemoteControlSupport(user) {
45
     checkUserRemoteControlSupport(user) {
45
-        return user.getFeatures().then(features =>
46
-            features.has(DISCO_REMOTE_CONTROL_FEATURE), () => false
46
+        return user.getFeatures().then(
47
+            features => features.has(DISCO_REMOTE_CONTROL_FEATURE),
48
+            () => false
47
         );
49
         );
48
     }
50
     }
49
 }
51
 }

+ 57
- 43
modules/transport/PostMessageTransportBackend.js Vedi File

1
 import Postis from 'postis';
1
 import Postis from 'postis';
2
 
2
 
3
+/**
4
+ * The default options for postis.
5
+ *
6
+ * @type {Object}
7
+ */
8
+const DEFAULT_POSTIS_OPTIONS = {
9
+    window: window.opener || window.parent
10
+};
11
+
3
 /**
12
 /**
4
  * The list of methods of incomming postis messages that we have to support for
13
  * The list of methods of incomming postis messages that we have to support for
5
  * backward compatability for the users that are directly sending messages to
14
  * backward compatability for the users that are directly sending messages to
7
  *
16
  *
8
  * @type {string[]}
17
  * @type {string[]}
9
  */
18
  */
10
-const legacyIncomingMethods = [ 'display-name', 'toggle-audio', 'toggle-video',
11
-    'toggle-film-strip', 'toggle-chat', 'toggle-contact-list',
12
-    'toggle-share-screen', 'video-hangup', 'email', 'avatar-url' ];
19
+const LEGACY_INCOMING_METHODS = [
20
+    'avatar-url',
21
+    'display-name',
22
+    'email',
23
+    'toggle-audio',
24
+    'toggle-chat',
25
+    'toggle-contact-list',
26
+    'toggle-film-strip',
27
+    'toggle-share-screen',
28
+    'toggle-video',
29
+    'video-hangup'
30
+];
13
 
31
 
14
 /**
32
 /**
15
  * The list of methods of outgoing postis messages that we have to support for
33
  * The list of methods of outgoing postis messages that we have to support for
18
  *
36
  *
19
  * @type {string[]}
37
  * @type {string[]}
20
  */
38
  */
21
-const legacyOutgoingMethods = [ 'display-name-change', 'incoming-message',
22
-    'outgoing-message', 'participant-joined', 'participant-left',
23
-    'video-ready-to-close', 'video-conference-joined',
24
-    'video-conference-left' ];
39
+const LEGACY_OUTGOING_METHODS = [
40
+    'display-name-change',
41
+    'incoming-message',
42
+    'outgoing-message',
43
+    'participant-joined',
44
+    'participant-left',
45
+    'video-conference-joined',
46
+    'video-conference-left',
47
+    'video-ready-to-close'
48
+];
25
 
49
 
26
 /**
50
 /**
27
  * The postis method used for all messages.
51
  * The postis method used for all messages.
30
  */
54
  */
31
 const POSTIS_METHOD_NAME = 'data';
55
 const POSTIS_METHOD_NAME = 'data';
32
 
56
 
33
-/**
34
- * The default options for postis.
35
- *
36
- * @type {Object}
37
- */
38
-const defaultPostisOptions = {
39
-    window: window.opener || window.parent
40
-};
41
-
42
 /**
57
 /**
43
  * Implements message transport using the postMessage API.
58
  * Implements message transport using the postMessage API.
44
  */
59
  */
49
      * @param {Object} options - Optional parameters for configuration of the
64
      * @param {Object} options - Optional parameters for configuration of the
50
      * transport.
65
      * transport.
51
      */
66
      */
52
-    constructor(options = {}) {
53
-        const postisOptions = Object.assign({}, defaultPostisOptions,
54
-            options.postisOptions);
55
-
56
-        this.postis = Postis(postisOptions);
67
+    constructor({ enableLegacyFormat, postisOptions } = {}) {
68
+        this.postis = Postis({
69
+            ...DEFAULT_POSTIS_OPTIONS,
70
+            ...postisOptions
71
+        });
57
 
72
 
58
-        this._enableLegacyFormat = options.enableLegacyFormat;
73
+        this._enableLegacyFormat = enableLegacyFormat;
59
 
74
 
60
         if (!this._enableLegacyFormat) {
75
         if (!this._enableLegacyFormat) {
61
             // backward compatability
76
             // backward compatability
62
-            legacyIncomingMethods.forEach(method =>
63
-                this.postis.listen(method,
64
-                    params => this._onPostisDataReceived(method, params)));
77
+            LEGACY_INCOMING_METHODS.forEach(method =>
78
+                this.postis.listen(
79
+                    method,
80
+                    params => this._legacyDataReceiveCallback(method, params)));
65
         }
81
         }
66
 
82
 
67
-        this.postis.listen(POSTIS_METHOD_NAME, data =>
68
-            this._dataReceivedCallBack(data));
69
-
70
-        this._dataReceivedCallBack = () => {
71
-            // do nothing until real callback is set;
83
+        this._receiveCallback = () => {
84
+            // Do nothing until a callback is set by the consumer of
85
+            // PostMessageTransportBackend via setReceiveCallback.
72
         };
86
         };
87
+
88
+        this.postis.listen(
89
+            POSTIS_METHOD_NAME,
90
+            data => this._receiveCallback(data));
73
     }
91
     }
74
 
92
 
75
     /**
93
     /**
79
      * @param {Any} params - The params property from postis data object.
97
      * @param {Any} params - The params property from postis data object.
80
      * @returns {void}
98
      * @returns {void}
81
      */
99
      */
82
-    _onPostisDataReceived(method, params = {}) {
83
-        const newData = {
100
+    _legacyDataReceiveCallback(method, params = {}) {
101
+        this._receiveCallback({
84
             data: {
102
             data: {
85
                 name: method,
103
                 name: method,
86
                 data: params
104
                 data: params
87
             }
105
             }
88
-        };
89
-
90
-        this._dataReceivedCallBack(newData);
106
+        });
91
     }
107
     }
92
 
108
 
93
     /**
109
     /**
96
      * @param {Object} data - The data to be sent.
112
      * @param {Object} data - The data to be sent.
97
      * @returns {void}
113
      * @returns {void}
98
      */
114
      */
99
-    _sendLegacyData(data) {
100
-        const method = data.name;
101
-
102
-        if (method && legacyOutgoingMethods.indexOf(method) !== -1) {
115
+    _sendLegacyData({ data, name }) {
116
+        if (name && LEGACY_OUTGOING_METHODS.indexOf(name) !== -1) {
103
             this.postis.send({
117
             this.postis.send({
104
-                method,
105
-                params: data.data
118
+                method: name,
119
+                params: data
106
             });
120
             });
107
         }
121
         }
108
     }
122
     }
143
      * @param {Function} callback - The new callback.
157
      * @param {Function} callback - The new callback.
144
      * @returns {void}
158
      * @returns {void}
145
      */
159
      */
146
-    setDataReceivedCallback(callback) {
147
-        this._dataReceivedCallBack = callback;
160
+    setReceiveCallback(callback) {
161
+        this._receiveCallback = callback;
148
     }
162
     }
149
 }
163
 }

+ 18
- 23
modules/transport/Transport.js Vedi File

14
      * @param {Object} options - Optional parameters for configuration of the
14
      * @param {Object} options - Optional parameters for configuration of the
15
      * transport.
15
      * transport.
16
      */
16
      */
17
-    constructor(options = {}) {
18
-        const { transport } = options;
19
-
17
+    constructor({ transport } = {}) {
20
         this._requestID = 0;
18
         this._requestID = 0;
21
 
19
 
22
         this._responseHandlers = new Map();
20
         this._responseHandlers = new Map();
66
             this.emit('request', data.data, (result, error) => {
64
             this.emit('request', data.data, (result, error) => {
67
                 this._transport.send({
65
                 this._transport.send({
68
                     type: MESSAGE_TYPE_RESPONSE,
66
                     type: MESSAGE_TYPE_RESPONSE,
69
-                    result,
70
                     error,
67
                     error,
71
-                    id: data.id
68
+                    id: data.id,
69
+                    result
72
                 });
70
                 });
73
             });
71
             });
74
         } else {
72
         } else {
97
      */
95
      */
98
     emit(eventName, ...args) {
96
     emit(eventName, ...args) {
99
         const listenersForEvent = this._listeners.get(eventName);
97
         const listenersForEvent = this._listeners.get(eventName);
100
-
101
-        if (!listenersForEvent || listenersForEvent.size === 0) {
102
-            this._unprocessedMessages.add(args);
103
-
104
-            return false;
105
-        }
106
-
107
         let isProcessed = false;
98
         let isProcessed = false;
108
 
99
 
109
-        listenersForEvent.forEach(listener => {
110
-            isProcessed = listener(...args) || isProcessed;
111
-        });
100
+        if (listenersForEvent && listenersForEvent.size) {
101
+            listenersForEvent.forEach(listener => {
102
+                isProcessed = listener(...args) || isProcessed;
103
+            });
104
+        }
112
 
105
 
113
         if (!isProcessed) {
106
         if (!isProcessed) {
114
             this._unprocessedMessages.add(args);
107
             this._unprocessedMessages.add(args);
115
         }
108
         }
109
+
110
+        return isProcessed;
116
     }
111
     }
117
 
112
 
118
     /**
113
     /**
146
     /**
141
     /**
147
      * Removes all listeners, or those of the specified eventName.
142
      * Removes all listeners, or those of the specified eventName.
148
      *
143
      *
149
-     * @param {string} [eventName] -  The name of the event.
144
+     * @param {string} eventName - The name of the event.
150
      * @returns {Transport} References to the instance of Transport class, so
145
      * @returns {Transport} References to the instance of Transport class, so
151
      * that calls can be chained.
146
      * that calls can be chained.
152
      */
147
      */
204
         if (!this._transport) {
199
         if (!this._transport) {
205
             return Promise.reject(new Error('No transport defined!'));
200
             return Promise.reject(new Error('No transport defined!'));
206
         }
201
         }
202
+
207
         this._requestID++;
203
         this._requestID++;
204
+
208
         const id = this._requestID;
205
         const id = this._requestID;
209
 
206
 
210
         return new Promise((resolve, reject) => {
207
         return new Promise((resolve, reject) => {
211
-            this._responseHandlers.set(this._requestID, response => {
212
-                const { result, error } = response;
213
-
208
+            this._responseHandlers.set(this._requestID, ({ error, result }) => {
214
                 if (result) {
209
                 if (result) {
215
                     resolve(result);
210
                     resolve(result);
216
                 } else if (error) {
211
                 } else if (error) {
221
             });
216
             });
222
 
217
 
223
             this._transport.send({
218
             this._transport.send({
224
-                id,
225
                 type: MESSAGE_TYPE_REQUEST,
219
                 type: MESSAGE_TYPE_REQUEST,
226
-                data
220
+                data,
221
+                id
227
             });
222
             });
228
         });
223
         });
229
     }
224
     }
236
      */
231
      */
237
     setTransport(transport) {
232
     setTransport(transport) {
238
         this._disposeTransport();
233
         this._disposeTransport();
234
+
239
         this._transport = transport;
235
         this._transport = transport;
240
-        this._transport.setDataReceivedCallback(
241
-            this._onDataReceived.bind(this));
236
+        this._transport.setReceiveCallback(this._onDataReceived.bind(this));
242
     }
237
     }
243
 }
238
 }

+ 1
- 2
modules/transport/index.js Vedi File

12
 const postisOptions = {};
12
 const postisOptions = {};
13
 
13
 
14
 if (typeof API_ID === 'number') {
14
 if (typeof API_ID === 'number') {
15
-    postisOptions.scope
16
-        = `jitsi_meet_external_api_${API_ID}`;
15
+    postisOptions.scope = `jitsi_meet_external_api_${API_ID}`;
17
 }
16
 }
18
 
17
 
19
 export const transport = new Transport({
18
 export const transport = new Transport({

Loading…
Annulla
Salva