فهرست منبع

Fixes #232 by handling errors explicitly rather than trying to parse status codes and ready states.

Michelle Bu 11 سال پیش
والد
کامیت
141db74484
4فایلهای تغییر یافته به همراه16 افزوده شده و 10 حذف شده
  1. 6 5
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 4 0
      examples/chat.html
  4. 6 5
      lib/socket.js

+ 6 - 5
dist/peer.js

@@ -2582,17 +2582,18 @@ Socket.prototype._startXhrStream = function(n) {
     this._http._index = 1;
     this._http._streamIndex = n || 0;
     this._http.open('post', this._httpUrl + '/id?i=' + this._http._streamIndex, true);
+    this._http.onerror = function() {
+      // If we get an error, likely something went wrong.
+      // Stop streaming.
+      clearTimeout(self._timeout);
+      self.emit('disconnected');
+    }
     this._http.onreadystatechange = function() {
       if (this.readyState == 2 && this.old) {
         this.old.abort();
         delete this.old;
       } else if (this.readyState > 2 && this.status === 200 && this.responseText) {
         self._handleStream(this);
-      } else if (this.status !== 200) {
-        // If we get a different status code, likely something went wrong.
-        // Stop streaming.
-        clearTimeout(self._timeout);
-        self.emit('disconnected');
       }
     };
     this._http.send(null);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/peer.min.js


+ 4 - 0
examples/chat.html

@@ -36,6 +36,10 @@ peer.on('open', function(id){
 // Await connections from others
 peer.on('connection', connect);
 
+peer.on('error', function(err) {
+  console.log(err);
+})
+
 // Handle a connection object.
 function connect(c) {
   // Handle a chat connection.

+ 6 - 5
lib/socket.js

@@ -81,17 +81,18 @@ Socket.prototype._startXhrStream = function(n) {
     this._http._index = 1;
     this._http._streamIndex = n || 0;
     this._http.open('post', this._httpUrl + '/id?i=' + this._http._streamIndex, true);
+    this._http.onerror = function() {
+      // If we get an error, likely something went wrong.
+      // Stop streaming.
+      clearTimeout(self._timeout);
+      self.emit('disconnected');
+    }
     this._http.onreadystatechange = function() {
       if (this.readyState == 2 && this.old) {
         this.old.abort();
         delete this.old;
       } else if (this.readyState > 2 && this.status === 200 && this.responseText) {
         self._handleStream(this);
-      } else if (this.status !== 200) {
-        // If we get a different status code, likely something went wrong.
-        // Stop streaming.
-        clearTimeout(self._timeout);
-        self.emit('disconnected');
       }
     };
     this._http.send(null);

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است