瀏覽代碼

Cleanup: fixes to style, typos and documentation.

master
Boris Grozev 9 年之前
父節點
當前提交
be6d7af377
共有 5 個檔案被更改,包括 90 行新增92 行删除
  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 查看文件

@@ -33,8 +33,8 @@ function init() {
33 33
 
34 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 38
     APP.init();
39 39
 
40 40
     APP.translation.init();

+ 7
- 9
external_api.js 查看文件

@@ -27,13 +27,15 @@ var JitsiMeetExternalAPI = (function()
27 27
      */
28 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 35
         this.parentNode = null;
31
-        if(parent_node)
32
-        {
36
+        if(parent_node) {
33 37
             this.parentNode = parent_node;
34
-        }
35
-        else
36
-        {
38
+        } else {
37 39
             var scriptTag = document.scripts[document.scripts.length - 1];
38 40
             this.parentNode = scriptTag.parentNode;
39 41
         }
@@ -41,10 +43,6 @@ var JitsiMeetExternalAPI = (function()
41 43
         this.iframeHolder =
42 44
             this.parentNode.appendChild(document.createElement("div"));
43 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 46
         this.iframeHolder.style.width = width + "px";
49 47
         this.iframeHolder.style.height = height + "px";
50 48
         this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id;

+ 4
- 7
modules/RTC/LocalStream.js 查看文件

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

+ 59
- 45
modules/xmpp/TraceablePeerConnection.js 查看文件

@@ -4,15 +4,15 @@ var XMPPEvents = require("../../service/xmpp/XMPPEvents");
4 4
 
5 5
 function TraceablePeerConnection(ice_config, constraints, session) {
6 6
     var self = this;
7
-    var RTCPeerconnectionType = null;
7
+    var RTCPeerConnectionType = null;
8 8
     if (RTCBrowserType.isFirefox()) {
9
-        RTCPeerconnectionType = mozRTCPeerConnection;
9
+        RTCPeerConnectionType = mozRTCPeerConnection;
10 10
     } else if (RTCBrowserType.isTemasysPluginUsed()) {
11
-        RTCPeerconnectionType = RTCPeerConnection;
11
+        RTCPeerConnectionType = RTCPeerConnection;
12 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 16
     this.updateLog = [];
17 17
     this.stats = {};
18 18
     this.statsinterval = null;
@@ -95,9 +95,8 @@ function TraceablePeerConnection(ice_config, constraints, session) {
95 95
         this.statsinterval = window.setInterval(function() {
96 96
             self.peerconnection.getStats(function(stats) {
97 97
                 var results = stats.result();
98
+                var now = new Date();
98 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 100
                     results[i].names().forEach(function (name) {
102 101
                         var id = results[i].id + '-' + name;
103 102
                         if (!self.stats[id]) {
@@ -121,9 +120,12 @@ function TraceablePeerConnection(ice_config, constraints, session) {
121 120
 
122 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 129
     if (typeof description === 'undefined' || description == null) {
128 130
         return '';
129 131
     }
@@ -135,7 +137,7 @@ dumpSDP = function(description) {
135 137
  * Takes a SessionDescription object and returns a "normalized" version.
136 138
  * Currently it only takes care of ordering the a=ssrc lines.
137 139
  */
138
-normalizePlanB = function(desc) {
140
+var normalizePlanB = function(desc) {
139 141
     if (typeof desc !== 'object' || desc === null ||
140 142
         typeof desc.sdp !== 'string') {
141 143
         console.warn('An empty description was passed as an argument.');
@@ -199,30 +201,38 @@ normalizePlanB = function(desc) {
199 201
 };
200 202
 
201 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 238
 TraceablePeerConnection.prototype.addStream = function (stream) {
@@ -234,7 +244,6 @@ TraceablePeerConnection.prototype.addStream = function (stream) {
234 244
     catch (e)
235 245
     {
236 246
         console.error(e);
237
-        return;
238 247
     }
239 248
 };
240 249
 
@@ -272,7 +281,8 @@ TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
272 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 286
     this.trace('setLocalDescription::preTransform', dumpSDP(description));
277 287
     // if we're running on FF, transform to Plan A first.
278 288
     if (RTCBrowserType.usesUnifiedPlan()) {
@@ -298,7 +308,8 @@ TraceablePeerConnection.prototype.setLocalDescription = function (description, s
298 308
      */
299 309
 };
300 310
 
301
-TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) {
311
+TraceablePeerConnection.prototype.setRemoteDescription
312
+        = function (description, successCallback, failureCallback) {
302 313
     this.trace('setRemoteDescription::preTransform', dumpSDP(description));
303 314
     // TODO the focus should squeze or explode the remote simulcast
304 315
     description = this.simulcast.mungeRemoteDescription(description);
@@ -341,7 +352,8 @@ TraceablePeerConnection.prototype.close = function () {
341 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 357
     var self = this;
346 358
     this.trace('createOffer', JSON.stringify(constraints, null, ' '));
347 359
     this.peerconnection.createOffer(
@@ -369,20 +381,21 @@ TraceablePeerConnection.prototype.createOffer = function (successCallback, failu
369 381
     );
370 382
 };
371 383
 
372
-TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) {
384
+TraceablePeerConnection.prototype.createAnswer
385
+        = function (successCallback, failureCallback, constraints) {
373 386
     var self = this;
374 387
     this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
375 388
     this.peerconnection.createAnswer(
376 389
         function (answer) {
377
-            self.trace('createAnswerOnSuccess::preTransfom', dumpSDP(answer));
390
+            self.trace('createAnswerOnSuccess::preTransform', dumpSDP(answer));
378 391
             // if we're running on FF, transform to Plan A first.
379 392
             if (RTCBrowserType.usesUnifiedPlan()) {
380 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 396
             if (config.enableSimulcast && self.simulcast.isSupported()) {
384 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 400
             successCallback(answer);
388 401
         },
@@ -394,8 +407,9 @@ TraceablePeerConnection.prototype.createAnswer = function (successCallback, fail
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 413
     this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
400 414
     this.peerconnection.addIceCandidate(candidate);
401 415
     /* maybe later
@@ -418,7 +432,7 @@ TraceablePeerConnection.prototype.getStats = function(callback, errback) {
418 432
         // ignore for now...
419 433
         if(!errback)
420 434
             errback = function () {};
421
-        this.peerconnection.getStats(null,callback,errback);
435
+        this.peerconnection.getStats(null, callback, errback);
422 436
     } else {
423 437
         this.peerconnection.getStats(callback);
424 438
     }

+ 18
- 29
modules/xmpp/xmpp.js 查看文件

@@ -26,9 +26,6 @@ function connect(jid, password) {
26 26
         connection = XMPP.createConnection();
27 27
         Moderator.setConnection(connection);
28 28
 
29
-        if (connection.disco) {
30
-            // for chrome, add multistream cap
31
-        }
32 29
         connection.jingle.pc_constraints = APP.RTC.getPCConstraints();
33 30
         if (config.useIPv6) {
34 31
             // https://code.google.com/p/webrtc/issues/detail?id=2828
@@ -131,8 +128,8 @@ function connect(jid, password) {
131 128
                     // if we get disconnected from the XMPP server permanently.
132 129
 
133 130
                     // If the connection failed, retry.
134
-                    if (connectionFailed
135
-                        && faultTolerantConnect.retry("connection-failed")) {
131
+                    if (connectionFailed &&
132
+                        faultTolerantConnect.retry("connection-failed")) {
136 133
                         return;
137 134
                     }
138 135
 
@@ -151,11 +148,10 @@ function connect(jid, password) {
151 148
 }
152 149
 
153 150
 
154
-
155 151
 function maybeDoJoin() {
156 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 155
         // .connected is true while connecting?
160 156
         doJoin();
161 157
     }
@@ -198,7 +194,8 @@ var unload = (function () {
198 194
                 async: false,
199 195
                 cache: false,
200 196
                 contentType: 'application/xml',
201
-                data: "<body rid='" + (connection.rid || connection._proto.rid) +
197
+                data: "<body rid='" +
198
+                    (connection.rid || connection._proto.rid) +
202 199
                     "' xmlns='http://jabber.org/protocol/httpbind' sid='" +
203 200
                     (connection.sid || connection._proto.sid)  +
204 201
                     "' type='terminate'>" +
@@ -224,7 +221,7 @@ function setupEvents() {
224 221
     // (change URL). If this participant doesn't unload properly, then it
225 222
     // becomes a ghost for the rest of the participants that stay in the
226 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 225
     // method at least once.
229 226
     //
230 227
     // The 'unload' method can safely be run multiple times, it will actually do
@@ -274,10 +271,8 @@ var XMPP = {
274 271
     promptLogin: function () {
275 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 277
         if (useNicks) {
283 278
             if (nick) {
@@ -286,7 +281,6 @@ var XMPP = {
286 281
                 roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
287 282
             }
288 283
         } else {
289
-
290 284
             var tmpJid = Strophe.getNodeFromJid(connection.jid);
291 285
 
292 286
             if(!authenticatedUser)
@@ -323,14 +317,12 @@ var XMPP = {
323 317
         }
324 318
         eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload);
325 319
         connection.jingle.activecall = null;
326
-        if(!onUnload)
327
-        {
320
+        if (!onUnload) {
328 321
             this.sessionTerminated = true;
329 322
             connection.emuc.doLeave();
330 323
         }
331 324
     },
332
-    addListener: function(type, listener)
333
-    {
325
+    addListener: function(type, listener) {
334 326
         eventEmitter.on(type, listener);
335 327
     },
336 328
     removeListener: function (type, listener) {
@@ -398,7 +390,6 @@ var XMPP = {
398 390
             return false;
399 391
         }
400 392
 
401
-
402 393
         if (this.forceMuted && !mute) {
403 394
             console.info("Asking focus for unmute");
404 395
             connection.moderate.setMute(connection.emuc.myroomjid, mute);
@@ -411,11 +402,7 @@ var XMPP = {
411 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 405
         APP.RTC.localAudio.setMute(mute);
418
-        // isMuted is the opposite of audioEnabled
419 406
         this.sendAudioInfoPresence(mute, callback);
420 407
         return true;
421 408
     },
@@ -439,9 +426,11 @@ var XMPP = {
439 426
                         var sdp = new SDP(answer.sdp);
440 427
                         if (sdp.media.length > 1) {
441 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 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 434
                             sdp.raw = sdp.session + sdp.media.join('');
446 435
                             answer.sdp = sdp.raw;
447 436
                         }
@@ -451,7 +440,8 @@ var XMPP = {
451 440
                             },
452 441
                             function (error) {
453 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,8 +463,7 @@ var XMPP = {
473 463
             startingCallback, startedCallback, connection);
474 464
     },
475 465
     addToPresence: function (name, value, dontSend) {
476
-        switch (name)
477
-        {
466
+        switch (name) {
478 467
             case "displayName":
479 468
                 connection.emuc.addDisplayNameToPresence(value);
480 469
                 break;

Loading…
取消
儲存