Bladeren bron

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

dev1
Lyubomir Marinov 9 jaren geleden
bovenliggende
commit
3a179705ea
1 gewijzigde bestanden met toevoegingen van 23 en 9 verwijderingen
  1. 23
    9
      modules/xmpp/JingleSessionPC.js

+ 23
- 9
modules/xmpp/JingleSessionPC.js Bestand weergeven

102
             RTC.getPCConstraints(),
102
             RTC.getPCConstraints(),
103
             this);
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
     this.peerconnection.onaddstream = function (event) {
131
     this.peerconnection.onaddstream = function (event) {
118
         if (event.stream.id !== 'default') {
132
         if (event.stream.id !== 'default') {

Laden…
Annuleren
Opslaan