Permalink
Browse files

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

  • Loading branch information...
1 parent ed8f854 commit a52201beb4f90258b74c0be4f13d0012cc3d357a @michelle michelle committed Mar 28, 2013
Showing with 64 additions and 1 deletion.
  1. +31 −0 dist/peer.js
  2. +1 −1 dist/peer.min.js
  3. +1 −0 docs/api.md
  4. +8 −0 lib/peer.js
  5. +23 −0 lib/util.js
View
@@ -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;
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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.
View
@@ -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;
View
@@ -1,5 +1,10 @@
var util = {
+ chromeCompatible: true,
+ firefoxCompatibile: false,
@MrRio

MrRio Mar 28, 2013

This a typo? firefoxCompatible

@michelle

michelle Mar 29, 2013

Owner

Thanks :)

+ 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;
}
};

0 comments on commit a52201b

Please sign in to comment.