Преглед изворни кода

Fixes a possible exception. Clarifies (& potentially optimizes) code.

dev1
Lyubomir Marinov пре 9 година
родитељ
комит
3a179705ea
1 измењених фајлова са 23 додато и 9 уклоњено
  1. 23
    9
      modules/xmpp/JingleSessionPC.js

+ 23
- 9
modules/xmpp/JingleSessionPC.js Прегледај датотеку

@@ -102,17 +102,31 @@ JingleSessionPC.prototype.doInitialize = function () {
102 102
             RTC.getPCConstraints(),
103 103
             this);
104 104
 
105
-    this.peerconnection.onicecandidate = function (event) {
106
-        var protocol;
107
-        if (event && event.candidate) {
108
-            protocol = (typeof event.candidate.protocol === 'string')
109
-                ? event.candidate.protocol.toLowerCase() : '';
110
-            if ((self.webrtcIceTcpDisable && protocol == 'tcp') ||
111
-                (self.webrtcIceUdpDisable && protocol == 'udp')) {
112
-                return;
105
+    this.peerconnection.onicecandidate = function (ev) {
106
+        if (!ev) {
107
+            // There was an incomplete check for ev before which left the last
108
+            // line of the function unprotected from a potential throw of an
109
+            // exception. Consequently, it may be argued that the check is
110
+            // unnecessary. Anyway, I'm leaving it and making the check
111
+            // complete.
112
+            return;
113
+        }
114
+        var candidate = ev.candidate;
115
+        if (candidate) {
116
+            // Discard candidates of disabled protocols.
117
+            var protocol = candidate.protocol;
118
+            if (typeof protocol === 'string') {
119
+                protocol = protocol.toLowerCase();
120
+                if (protocol == 'tcp') {
121
+                    if (self.webrtcIceTcpDisable)
122
+                        return;
123
+                } else if (protocol == 'udp') {
124
+                    if (self.webrtcIceUdpDisable)
125
+                        return;
126
+                }
113 127
             }
114 128
         }
115
-        self.sendIceCandidate(event.candidate);
129
+        self.sendIceCandidate(candidate);
116 130
     };
117 131
     this.peerconnection.onaddstream = function (event) {
118 132
         if (event.stream.id !== 'default') {

Loading…
Откажи
Сачувај