Ver Fonte

fixes #27, at last. api updates as well.

Michelle Bu há 12 anos atrás
pai
commit
a52201beb4
5 ficheiros alterados com 63 adições e 0 exclusões
  1. 31 0
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 1 0
      docs/api.md
  4. 8 0
      lib/peer.js
  5. 23 0
      lib/util.js

+ 31 - 0
dist/peer.js

@@ -720,6 +720,11 @@ EventEmitter.prototype.emit = function(type) {
 
 var util = {
   
+  chromeCompatible: true,
+  firefoxCompatibile: false,
+  chromeVersion: 26,
+  firefoxVersion: 22,
+
   debug: false,
   browserisms: '',
   
@@ -816,6 +821,24 @@ var util = {
   },
   randomToken: function () {
     return Math.random().toString(36).substr(2);
+  },
+  isBrowserCompatible: function() {
+    var c, f;
+    if (this.chromeCompatible) {
+      if ((c = navigator.userAgent.split('Chrome/')) && c.length > 1) {
+        // Get version #.
+        var v = c[1].split('.')[0];
+        return parseInt(v) >= this.chromeVersion;
+      }
+    }
+    if (this.firefoxCompatible) {
+      if ((f = navigator.userAgent.split('Firefox/')) && f.length > 1) {
+        // Get version #.
+        var v = f[1].split('.')[0];
+        return parseInt(v) >= this.firefoxVersion;
+      }
+    }
+    return false;
   }
 };
 /**
@@ -1158,6 +1181,14 @@ function Peer(id, options) {
   if (!(this instanceof Peer)) return new Peer(id, options);
   EventEmitter.call(this);
 
+  // First check if browser can use PeerConnection/DataChannels.
+  // TODO: when media is supported, lower browser version limit and move DC
+  // check to where`connect` is called.
+  if (!util.isBrowserCompatible()) {
+    this._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
+    return;
+  }
+
   // Detect relative URL host.
   if (options.host === '/') {
     options.host = window.location.hostname;

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/peer.min.js


+ 1 - 0
docs/api.md

@@ -82,6 +82,7 @@ Emitted when an unexpected event occurs. Errors on the Peer are **always
 fatal**. Errors from the underlying socket and PeerConnections are forwarded here.
 
 The `error` object also has a `type` parameter that may be helpful in responding to client errors properly:
+* `browser-incompatible`: The client's browser does not support some or all WebRTC features that you are trying to use.
 * `invalid-id`: The ID passed into the Peer constructor contains illegal characters.
 * `invalid-key`: The API key passed into the Peer constructor contains illegal characters or is not in the system (cloud server only).
 * `unavailable-id`: The ID passed into the Peer constructor is already taken.

+ 8 - 0
lib/peer.js

@@ -9,6 +9,14 @@ function Peer(id, options) {
   if (!(this instanceof Peer)) return new Peer(id, options);
   EventEmitter.call(this);
 
+  // First check if browser can use PeerConnection/DataChannels.
+  // TODO: when media is supported, lower browser version limit and move DC
+  // check to where`connect` is called.
+  if (!util.isBrowserCompatible()) {
+    this._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
+    return;
+  }
+
   // Detect relative URL host.
   if (options.host === '/') {
     options.host = window.location.hostname;

+ 23 - 0
lib/util.js

@@ -1,5 +1,10 @@
 var util = {
   
+  chromeCompatible: true,
+  firefoxCompatibile: false,
+  chromeVersion: 26,
+  firefoxVersion: 22,
+
   debug: false,
   browserisms: '',
   
@@ -96,5 +101,23 @@ var util = {
   },
   randomToken: function () {
     return Math.random().toString(36).substr(2);
+  },
+  isBrowserCompatible: function() {
+    var c, f;
+    if (this.chromeCompatible) {
+      if ((c = navigator.userAgent.split('Chrome/')) && c.length > 1) {
+        // Get version #.
+        var v = c[1].split('.')[0];
+        return parseInt(v) >= this.chromeVersion;
+      }
+    }
+    if (this.firefoxCompatible) {
+      if ((f = navigator.userAgent.split('Firefox/')) && f.length > 1) {
+        // Get version #.
+        var v = f[1].split('.')[0];
+        return parseInt(v) >= this.firefoxVersion;
+      }
+    }
+    return false;
   }
 };

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff