Procházet zdrojové kódy

Cleanup: fixes to style, typos and documentation.

master
Boris Grozev před 9 roky
rodič
revize
be6d7af377
5 změnil soubory, kde provedl 90 přidání a 92 odebrání
  1. 2
    2
      app.js
  2. 7
    9
      external_api.js
  3. 4
    7
      modules/RTC/LocalStream.js
  4. 59
    45
      modules/xmpp/TraceablePeerConnection.js
  5. 18
    29
      modules/xmpp/xmpp.js

+ 2
- 2
app.js Zobrazit soubor

33
 
33
 
34
 $(document).ready(function () {
34
 $(document).ready(function () {
35
 
35
 
36
-    var URLPRocessor = require("./modules/URLProcessor/URLProcessor");
37
-    URLPRocessor.setConfigParametersFromUrl();
36
+    var URLProcessor = require("./modules/URLProcessor/URLProcessor");
37
+    URLProcessor.setConfigParametersFromUrl();
38
     APP.init();
38
     APP.init();
39
 
39
 
40
     APP.translation.init();
40
     APP.translation.init();

+ 7
- 9
external_api.js Zobrazit soubor

27
      */
27
      */
28
     function JitsiMeetExternalAPI(domain, room_name, width, height, parent_node)
28
     function JitsiMeetExternalAPI(domain, room_name, width, height, parent_node)
29
     {
29
     {
30
+        if(!width || width < MIN_WIDTH)
31
+            width = MIN_WIDTH;
32
+        if(!height || height < MIN_HEIGHT)
33
+            height = MIN_HEIGHT;
34
+
30
         this.parentNode = null;
35
         this.parentNode = null;
31
-        if(parent_node)
32
-        {
36
+        if(parent_node) {
33
             this.parentNode = parent_node;
37
             this.parentNode = parent_node;
34
-        }
35
-        else
36
-        {
38
+        } else {
37
             var scriptTag = document.scripts[document.scripts.length - 1];
39
             var scriptTag = document.scripts[document.scripts.length - 1];
38
             this.parentNode = scriptTag.parentNode;
40
             this.parentNode = scriptTag.parentNode;
39
         }
41
         }
41
         this.iframeHolder =
43
         this.iframeHolder =
42
             this.parentNode.appendChild(document.createElement("div"));
44
             this.parentNode.appendChild(document.createElement("div"));
43
         this.iframeHolder.id = "jitsiConference" + JitsiMeetExternalAPI.id;
45
         this.iframeHolder.id = "jitsiConference" + JitsiMeetExternalAPI.id;
44
-        if(width < MIN_WIDTH)
45
-            width = MIN_WIDTH;
46
-        if(height < MIN_HEIGHT)
47
-            height = MIN_HEIGHT;
48
         this.iframeHolder.style.width = width + "px";
46
         this.iframeHolder.style.width = width + "px";
49
         this.iframeHolder.style.height = height + "px";
47
         this.iframeHolder.style.height = height + "px";
50
         this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id;
48
         this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id;

+ 4
- 7
modules/RTC/LocalStream.js Zobrazit soubor

93
 
93
 
94
 LocalStream.prototype.isMuted = function () {
94
 LocalStream.prototype.isMuted = function () {
95
     var tracks = [];
95
     var tracks = [];
96
-    if(this.type == "audio")
97
-    {
96
+    if (this.isAudioStream()) {
98
         tracks = this.stream.getAudioTracks();
97
         tracks = this.stream.getAudioTracks();
99
-    }
100
-    else
101
-    {
102
-        if(this.stream.ended)
98
+    } else {
99
+        if (this.stream.ended)
103
             return true;
100
             return true;
104
         tracks = this.stream.getVideoTracks();
101
         tracks = this.stream.getVideoTracks();
105
     }
102
     }
108
             return false;
105
             return false;
109
     }
106
     }
110
     return true;
107
     return true;
111
-}
108
+};
112
 
109
 
113
 LocalStream.prototype.getId = function () {
110
 LocalStream.prototype.getId = function () {
114
     return this.stream.getTracks()[0].id;
111
     return this.stream.getTracks()[0].id;

+ 59
- 45
modules/xmpp/TraceablePeerConnection.js Zobrazit soubor

4
 
4
 
5
 function TraceablePeerConnection(ice_config, constraints, session) {
5
 function TraceablePeerConnection(ice_config, constraints, session) {
6
     var self = this;
6
     var self = this;
7
-    var RTCPeerconnectionType = null;
7
+    var RTCPeerConnectionType = null;
8
     if (RTCBrowserType.isFirefox()) {
8
     if (RTCBrowserType.isFirefox()) {
9
-        RTCPeerconnectionType = mozRTCPeerConnection;
9
+        RTCPeerConnectionType = mozRTCPeerConnection;
10
     } else if (RTCBrowserType.isTemasysPluginUsed()) {
10
     } else if (RTCBrowserType.isTemasysPluginUsed()) {
11
-        RTCPeerconnectionType = RTCPeerConnection;
11
+        RTCPeerConnectionType = RTCPeerConnection;
12
     } else {
12
     } else {
13
-        RTCPeerconnectionType = webkitRTCPeerConnection;
13
+        RTCPeerConnectionType = webkitRTCPeerConnection;
14
     }
14
     }
15
-    this.peerconnection = new RTCPeerconnectionType(ice_config, constraints);
15
+    this.peerconnection = new RTCPeerConnectionType(ice_config, constraints);
16
     this.updateLog = [];
16
     this.updateLog = [];
17
     this.stats = {};
17
     this.stats = {};
18
     this.statsinterval = null;
18
     this.statsinterval = null;
95
         this.statsinterval = window.setInterval(function() {
95
         this.statsinterval = window.setInterval(function() {
96
             self.peerconnection.getStats(function(stats) {
96
             self.peerconnection.getStats(function(stats) {
97
                 var results = stats.result();
97
                 var results = stats.result();
98
+                var now = new Date();
98
                 for (var i = 0; i < results.length; ++i) {
99
                 for (var i = 0; i < results.length; ++i) {
99
-                    //console.log(results[i].type, results[i].id, results[i].names())
100
-                    var now = new Date();
101
                     results[i].names().forEach(function (name) {
100
                     results[i].names().forEach(function (name) {
102
                         var id = results[i].id + '-' + name;
101
                         var id = results[i].id + '-' + name;
103
                         if (!self.stats[id]) {
102
                         if (!self.stats[id]) {
121
 
120
 
122
         }, 1000);
121
         }, 1000);
123
     }
122
     }
124
-};
123
+}
125
 
124
 
126
-dumpSDP = function(description) {
125
+/**
126
+ * Returns a string representation of a SessionDescription object.
127
+ */
128
+var dumpSDP = function(description) {
127
     if (typeof description === 'undefined' || description == null) {
129
     if (typeof description === 'undefined' || description == null) {
128
         return '';
130
         return '';
129
     }
131
     }
135
  * Takes a SessionDescription object and returns a "normalized" version.
137
  * Takes a SessionDescription object and returns a "normalized" version.
136
  * Currently it only takes care of ordering the a=ssrc lines.
138
  * Currently it only takes care of ordering the a=ssrc lines.
137
  */
139
  */
138
-normalizePlanB = function(desc) {
140
+var normalizePlanB = function(desc) {
139
     if (typeof desc !== 'object' || desc === null ||
141
     if (typeof desc !== 'object' || desc === null ||
140
         typeof desc.sdp !== 'string') {
142
         typeof desc.sdp !== 'string') {
141
         console.warn('An empty description was passed as an argument.');
143
         console.warn('An empty description was passed as an argument.');
199
 };
201
 };
200
 
202
 
201
 if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
203
 if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
202
-    TraceablePeerConnection.prototype.__defineGetter__('signalingState', function() { return this.peerconnection.signalingState; });
203
-    TraceablePeerConnection.prototype.__defineGetter__('iceConnectionState', function() { return this.peerconnection.iceConnectionState; });
204
-    TraceablePeerConnection.prototype.__defineGetter__('localDescription', function() {
205
-        var desc = this.peerconnection.localDescription;
206
-        this.trace('getLocalDescription::preTransform', dumpSDP(desc));
207
-
208
-        // if we're running on FF, transform to Plan B first.
209
-        if (RTCBrowserType.usesUnifiedPlan()) {
210
-            desc = this.interop.toPlanB(desc);
211
-            this.trace('getLocalDescription::postTransform (Plan B)', dumpSDP(desc));
212
-        }
213
-        return desc;
214
-    });
215
-    TraceablePeerConnection.prototype.__defineGetter__('remoteDescription', function() {
216
-        var desc = this.peerconnection.remoteDescription;
217
-        this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
218
-
219
-        // if we're running on FF, transform to Plan B first.
220
-        if (RTCBrowserType.usesUnifiedPlan()) {
221
-            desc = this.interop.toPlanB(desc);
222
-            this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc));
223
-        }
224
-        return desc;
225
-    });
204
+    TraceablePeerConnection.prototype.__defineGetter__(
205
+        'signalingState',
206
+        function() { return this.peerconnection.signalingState; });
207
+    TraceablePeerConnection.prototype.__defineGetter__(
208
+        'iceConnectionState',
209
+        function() { return this.peerconnection.iceConnectionState; });
210
+    TraceablePeerConnection.prototype.__defineGetter__(
211
+        'localDescription',
212
+        function() {
213
+            var desc = this.peerconnection.localDescription;
214
+            this.trace('getLocalDescription::preTransform', dumpSDP(desc));
215
+
216
+            // if we're running on FF, transform to Plan B first.
217
+            if (RTCBrowserType.usesUnifiedPlan()) {
218
+                desc = this.interop.toPlanB(desc);
219
+                this.trace('getLocalDescription::postTransform (Plan B)', dumpSDP(desc));
220
+            }
221
+            return desc;
222
+        });
223
+    TraceablePeerConnection.prototype.__defineGetter__(
224
+        'remoteDescription',
225
+        function() {
226
+            var desc = this.peerconnection.remoteDescription;
227
+            this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
228
+
229
+            // if we're running on FF, transform to Plan B first.
230
+            if (RTCBrowserType.usesUnifiedPlan()) {
231
+                desc = this.interop.toPlanB(desc);
232
+                this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc));
233
+            }
234
+            return desc;
235
+        });
226
 }
236
 }
227
 
237
 
228
 TraceablePeerConnection.prototype.addStream = function (stream) {
238
 TraceablePeerConnection.prototype.addStream = function (stream) {
234
     catch (e)
244
     catch (e)
235
     {
245
     {
236
         console.error(e);
246
         console.error(e);
237
-        return;
238
     }
247
     }
239
 };
248
 };
240
 
249
 
272
     return this.peerconnection.createDataChannel(label, opts);
281
     return this.peerconnection.createDataChannel(label, opts);
273
 };
282
 };
274
 
283
 
275
-TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) {
284
+TraceablePeerConnection.prototype.setLocalDescription
285
+        = function (description, successCallback, failureCallback) {
276
     this.trace('setLocalDescription::preTransform', dumpSDP(description));
286
     this.trace('setLocalDescription::preTransform', dumpSDP(description));
277
     // if we're running on FF, transform to Plan A first.
287
     // if we're running on FF, transform to Plan A first.
278
     if (RTCBrowserType.usesUnifiedPlan()) {
288
     if (RTCBrowserType.usesUnifiedPlan()) {
298
      */
308
      */
299
 };
309
 };
300
 
310
 
301
-TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) {
311
+TraceablePeerConnection.prototype.setRemoteDescription
312
+        = function (description, successCallback, failureCallback) {
302
     this.trace('setRemoteDescription::preTransform', dumpSDP(description));
313
     this.trace('setRemoteDescription::preTransform', dumpSDP(description));
303
     // TODO the focus should squeze or explode the remote simulcast
314
     // TODO the focus should squeze or explode the remote simulcast
304
     description = this.simulcast.mungeRemoteDescription(description);
315
     description = this.simulcast.mungeRemoteDescription(description);
341
     this.peerconnection.close();
352
     this.peerconnection.close();
342
 };
353
 };
343
 
354
 
344
-TraceablePeerConnection.prototype.createOffer = function (successCallback, failureCallback, constraints) {
355
+TraceablePeerConnection.prototype.createOffer
356
+        = function (successCallback, failureCallback, constraints) {
345
     var self = this;
357
     var self = this;
346
     this.trace('createOffer', JSON.stringify(constraints, null, ' '));
358
     this.trace('createOffer', JSON.stringify(constraints, null, ' '));
347
     this.peerconnection.createOffer(
359
     this.peerconnection.createOffer(
369
     );
381
     );
370
 };
382
 };
371
 
383
 
372
-TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) {
384
+TraceablePeerConnection.prototype.createAnswer
385
+        = function (successCallback, failureCallback, constraints) {
373
     var self = this;
386
     var self = this;
374
     this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
387
     this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
375
     this.peerconnection.createAnswer(
388
     this.peerconnection.createAnswer(
376
         function (answer) {
389
         function (answer) {
377
-            self.trace('createAnswerOnSuccess::preTransfom', dumpSDP(answer));
390
+            self.trace('createAnswerOnSuccess::preTransform', dumpSDP(answer));
378
             // if we're running on FF, transform to Plan A first.
391
             // if we're running on FF, transform to Plan A first.
379
             if (RTCBrowserType.usesUnifiedPlan()) {
392
             if (RTCBrowserType.usesUnifiedPlan()) {
380
                 answer = self.interop.toPlanB(answer);
393
                 answer = self.interop.toPlanB(answer);
381
-                self.trace('createAnswerOnSuccess::postTransfom (Plan B)', dumpSDP(answer));
394
+                self.trace('createAnswerOnSuccess::postTransform (Plan B)', dumpSDP(answer));
382
             }
395
             }
383
             if (config.enableSimulcast && self.simulcast.isSupported()) {
396
             if (config.enableSimulcast && self.simulcast.isSupported()) {
384
                 answer = self.simulcast.mungeLocalDescription(answer);
397
                 answer = self.simulcast.mungeLocalDescription(answer);
385
-                self.trace('createAnswerOnSuccess::postTransfom (simulcast)', dumpSDP(answer));
398
+                self.trace('createAnswerOnSuccess::postTransform (simulcast)', dumpSDP(answer));
386
             }
399
             }
387
             successCallback(answer);
400
             successCallback(answer);
388
         },
401
         },
394
     );
407
     );
395
 };
408
 };
396
 
409
 
397
-TraceablePeerConnection.prototype.addIceCandidate = function (candidate, successCallback, failureCallback) {
398
-    var self = this;
410
+TraceablePeerConnection.prototype.addIceCandidate
411
+        = function (candidate, successCallback, failureCallback) {
412
+    //var self = this;
399
     this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
413
     this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
400
     this.peerconnection.addIceCandidate(candidate);
414
     this.peerconnection.addIceCandidate(candidate);
401
     /* maybe later
415
     /* maybe later
418
         // ignore for now...
432
         // ignore for now...
419
         if(!errback)
433
         if(!errback)
420
             errback = function () {};
434
             errback = function () {};
421
-        this.peerconnection.getStats(null,callback,errback);
435
+        this.peerconnection.getStats(null, callback, errback);
422
     } else {
436
     } else {
423
         this.peerconnection.getStats(callback);
437
         this.peerconnection.getStats(callback);
424
     }
438
     }

+ 18
- 29
modules/xmpp/xmpp.js Zobrazit soubor

26
         connection = XMPP.createConnection();
26
         connection = XMPP.createConnection();
27
         Moderator.setConnection(connection);
27
         Moderator.setConnection(connection);
28
 
28
 
29
-        if (connection.disco) {
30
-            // for chrome, add multistream cap
31
-        }
32
         connection.jingle.pc_constraints = APP.RTC.getPCConstraints();
29
         connection.jingle.pc_constraints = APP.RTC.getPCConstraints();
33
         if (config.useIPv6) {
30
         if (config.useIPv6) {
34
             // https://code.google.com/p/webrtc/issues/detail?id=2828
31
             // https://code.google.com/p/webrtc/issues/detail?id=2828
131
                     // if we get disconnected from the XMPP server permanently.
128
                     // if we get disconnected from the XMPP server permanently.
132
 
129
 
133
                     // If the connection failed, retry.
130
                     // If the connection failed, retry.
134
-                    if (connectionFailed
135
-                        && faultTolerantConnect.retry("connection-failed")) {
131
+                    if (connectionFailed &&
132
+                        faultTolerantConnect.retry("connection-failed")) {
136
                         return;
133
                         return;
137
                     }
134
                     }
138
 
135
 
151
 }
148
 }
152
 
149
 
153
 
150
 
154
-
155
 function maybeDoJoin() {
151
 function maybeDoJoin() {
156
     if (connection && connection.connected &&
152
     if (connection && connection.connected &&
157
-        Strophe.getResourceFromJid(connection.jid)
158
-        && (APP.RTC.localAudio || APP.RTC.localVideo)) {
153
+        Strophe.getResourceFromJid(connection.jid) &&
154
+        (APP.RTC.localAudio || APP.RTC.localVideo)) {
159
         // .connected is true while connecting?
155
         // .connected is true while connecting?
160
         doJoin();
156
         doJoin();
161
     }
157
     }
198
                 async: false,
194
                 async: false,
199
                 cache: false,
195
                 cache: false,
200
                 contentType: 'application/xml',
196
                 contentType: 'application/xml',
201
-                data: "<body rid='" + (connection.rid || connection._proto.rid) +
197
+                data: "<body rid='" +
198
+                    (connection.rid || connection._proto.rid) +
202
                     "' xmlns='http://jabber.org/protocol/httpbind' sid='" +
199
                     "' xmlns='http://jabber.org/protocol/httpbind' sid='" +
203
                     (connection.sid || connection._proto.sid)  +
200
                     (connection.sid || connection._proto.sid)  +
204
                     "' type='terminate'>" +
201
                     "' type='terminate'>" +
224
     // (change URL). If this participant doesn't unload properly, then it
221
     // (change URL). If this participant doesn't unload properly, then it
225
     // becomes a ghost for the rest of the participants that stay in the
222
     // becomes a ghost for the rest of the participants that stay in the
226
     // conference. Thankfully handling the 'unload' event in addition to the
223
     // conference. Thankfully handling the 'unload' event in addition to the
227
-    // 'beforeunload' event seems to garante the execution of the 'unload'
224
+    // 'beforeunload' event seems to guarantee the execution of the 'unload'
228
     // method at least once.
225
     // method at least once.
229
     //
226
     //
230
     // The 'unload' method can safely be run multiple times, it will actually do
227
     // The 'unload' method can safely be run multiple times, it will actually do
274
     promptLogin: function () {
271
     promptLogin: function () {
275
         eventEmitter.emit(XMPPEvents.PROMPT_FOR_LOGIN);
272
         eventEmitter.emit(XMPPEvents.PROMPT_FOR_LOGIN);
276
     },
273
     },
277
-    joinRoom: function(roomName, useNicks, nick)
278
-    {
279
-        var roomjid;
280
-        roomjid = roomName;
274
+    joinRoom: function(roomName, useNicks, nick) {
275
+        var roomjid = roomName;
281
 
276
 
282
         if (useNicks) {
277
         if (useNicks) {
283
             if (nick) {
278
             if (nick) {
286
                 roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
281
                 roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
287
             }
282
             }
288
         } else {
283
         } else {
289
-
290
             var tmpJid = Strophe.getNodeFromJid(connection.jid);
284
             var tmpJid = Strophe.getNodeFromJid(connection.jid);
291
 
285
 
292
             if(!authenticatedUser)
286
             if(!authenticatedUser)
323
         }
317
         }
324
         eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload);
318
         eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload);
325
         connection.jingle.activecall = null;
319
         connection.jingle.activecall = null;
326
-        if(!onUnload)
327
-        {
320
+        if (!onUnload) {
328
             this.sessionTerminated = true;
321
             this.sessionTerminated = true;
329
             connection.emuc.doLeave();
322
             connection.emuc.doLeave();
330
         }
323
         }
331
     },
324
     },
332
-    addListener: function(type, listener)
333
-    {
325
+    addListener: function(type, listener) {
334
         eventEmitter.on(type, listener);
326
         eventEmitter.on(type, listener);
335
     },
327
     },
336
     removeListener: function (type, listener) {
328
     removeListener: function (type, listener) {
398
             return false;
390
             return false;
399
         }
391
         }
400
 
392
 
401
-
402
         if (this.forceMuted && !mute) {
393
         if (this.forceMuted && !mute) {
403
             console.info("Asking focus for unmute");
394
             console.info("Asking focus for unmute");
404
             connection.moderate.setMute(connection.emuc.myroomjid, mute);
395
             connection.moderate.setMute(connection.emuc.myroomjid, mute);
411
             return true;
402
             return true;
412
         }
403
         }
413
 
404
 
414
-        // It is not clear what is the right way to handle multiple tracks.
415
-        // So at least make sure that they are all muted or all unmuted and
416
-        // that we send presence just once.
417
         APP.RTC.localAudio.setMute(mute);
405
         APP.RTC.localAudio.setMute(mute);
418
-        // isMuted is the opposite of audioEnabled
419
         this.sendAudioInfoPresence(mute, callback);
406
         this.sendAudioInfoPresence(mute, callback);
420
         return true;
407
         return true;
421
     },
408
     },
439
                         var sdp = new SDP(answer.sdp);
426
                         var sdp = new SDP(answer.sdp);
440
                         if (sdp.media.length > 1) {
427
                         if (sdp.media.length > 1) {
441
                             if (unmute)
428
                             if (unmute)
442
-                                sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
429
+                                sdp.media[1] = sdp.media[1].replace(
430
+                                    'a=recvonly', 'a=sendrecv');
443
                             else
431
                             else
444
-                                sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
432
+                                sdp.media[1] = sdp.media[1].replace(
433
+                                    'a=sendrecv', 'a=recvonly');
445
                             sdp.raw = sdp.session + sdp.media.join('');
434
                             sdp.raw = sdp.session + sdp.media.join('');
446
                             answer.sdp = sdp.raw;
435
                             answer.sdp = sdp.raw;
447
                         }
436
                         }
451
                             },
440
                             },
452
                             function (error) {
441
                             function (error) {
453
                                 console.log('mute SLD error');
442
                                 console.log('mute SLD error');
454
-                                eventEmitter.emit(XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR);
443
+                                eventEmitter.emit(
444
+                                    XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR);
455
                             }
445
                             }
456
                         );
446
                         );
457
                     },
447
                     },
473
             startingCallback, startedCallback, connection);
463
             startingCallback, startedCallback, connection);
474
     },
464
     },
475
     addToPresence: function (name, value, dontSend) {
465
     addToPresence: function (name, value, dontSend) {
476
-        switch (name)
477
-        {
466
+        switch (name) {
478
             case "displayName":
467
             case "displayName":
479
                 connection.emuc.addDisplayNameToPresence(value);
468
                 connection.emuc.addDisplayNameToPresence(value);
480
                 break;
469
                 break;

Načítá se…
Zrušit
Uložit