Michelle Bu %!s(int64=11) %!d(string=hai) anos
pai
achega
3d4ec9bc66
Modificáronse 5 ficheiros con 236 adicións e 231 borrados
  1. 1 1
      bin/build.js
  2. 227 217
      dist/peer.js
  3. 0 0
      dist/peer.min.js
  4. 0 8
      lib/adapter.js
  5. 8 5
      lib/util.js

+ 1 - 1
bin/build.js

@@ -41,9 +41,9 @@ var base = [
     '../deps/js-binarypack/lib/bufferbuilder.js'
   , '../deps/js-binarypack/lib/binarypack.js'
   , '../deps/EventEmitter/EventEmitter.js'
-  , 'util.js'
   , '../deps/reliable/lib/reliable.js'
   , 'adapter.js' 
+  , 'util.js'
   , 'peer.js'
   , 'dataconnection.js'
   , 'mediaconnection.js'

+ 227 - 217
dist/peer.js

@@ -718,214 +718,6 @@ EventEmitter.prototype.emit = function(type) {
 
 
 
-var util = {
-  noop: function() {},
-
-  CLOUD_HOST: '0.peerjs.com',
-  CLOUD_PORT: 9000,
-  
-  // Logging logic
-  logLevel: 0,
-  setLogLevel: function(level) {
-    var debugLevel = parseInt(level, 10);
-    if (!isNaN(parseInt(level, 10))) {
-      util.logLevel = debugLevel;
-    } else {
-      // If they are using truthy/falsy values for debug
-      util.logLevel = (!!level) ? 3 : 0;
-    }
-    util.log = util.warn = util.error = util.noop;
-    if (util.logLevel > 0) {
-      util.error = util._printWith('ERROR');
-    }
-    if (util.logLevel > 1) {
-      util.warn = util._printWith('WARNING');
-    }
-    if (util.logLevel > 2) {
-      util.log = util._print;
-    }
-  },
-  setLogFunction: function(fn) {
-    if (fn.constructor !== Function) {
-      util.warn('The log function you passed in is not a function. Defaulting to regular logs.');
-    } else {
-      util._print = fn;
-    }
-  },
-
-  _printWith: function(prefix) {
-    return function() {
-      var copy = Array.prototype.slice.call(arguments);
-      copy.unshift(prefix);
-      util._print.apply(util, copy);
-    };
-  },
-  _print: function () {
-    var err = false;
-    var copy = Array.prototype.slice.call(arguments);
-    copy.unshift('PeerJS: ');
-    for (var i = 0, l = copy.length; i < l; i++){
-      if (copy[i] instanceof Error) {
-        copy[i] = '(' + copy[i].name + ') ' + copy[i].message;
-        err = true;
-      }
-    }
-    err ? console.error.apply(console, copy) : console.log.apply(console, copy);  
-  },
-  //
-
-  // Lists which features are supported
-  // Temporarily set everything to true
-  supports: (function(){
-    return {
-      audioVideo: true,
-      data: true,
-      binary: false,
-      reliable: false,
-      onnegotiationneeded: true
-    };
-  }()),
-  //
-
-  // Ensure alphanumeric ids
-  validateId: function(id) {
-    // Allow empty ids
-    return !id || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id);
-  },
-
-  validateKey: function(key) {
-    // Allow empty keys
-    return !key || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(key);
-  },
-
-
-  // OLD
-  chromeCompatible: true,
-  firefoxCompatible: true,
-  chromeVersion: 26,
-  firefoxVersion: 22,
-
-  debug: false,
-  browserisms: '',
-
-  inherits: function(ctor, superCtor) {
-    ctor.super_ = superCtor;
-    ctor.prototype = Object.create(superCtor.prototype, {
-      constructor: {
-        value: ctor,
-        enumerable: false,
-        writable: true,
-        configurable: true
-      }
-    });
-  },
-  extend: function(dest, source) {
-    for(var key in source) {
-      if(source.hasOwnProperty(key)) {
-        dest[key] = source[key];
-      }
-    }
-    return dest;
-  },
-  pack: BinaryPack.pack,
-  unpack: BinaryPack.unpack,
-
-  log: function () {
-    if (util.debug) {
-      var err = false;
-      var copy = Array.prototype.slice.call(arguments);
-      copy.unshift('PeerJS: ');
-      for (var i = 0, l = copy.length; i < l; i++){
-        if (copy[i] instanceof Error) {
-          copy[i] = '(' + copy[i].name + ') ' + copy[i].message;
-          err = true;
-        }
-      }
-      err ? console.error.apply(console, copy) : console.log.apply(console, copy);
-    }
-  },
-
-  setZeroTimeout: (function(global) {
-    var timeouts = [];
-    var messageName = 'zero-timeout-message';
-
-    // Like setTimeout, but only takes a function argument.	 There's
-    // no time argument (always zero) and no arguments (you have to
-    // use a closure).
-    function setZeroTimeoutPostMessage(fn) {
-      timeouts.push(fn);
-      global.postMessage(messageName, '*');
-    }
-
-    function handleMessage(event) {
-      if (event.source == global && event.data == messageName) {
-        if (event.stopPropagation) {
-          event.stopPropagation();
-        }
-        if (timeouts.length) {
-          timeouts.shift()();
-        }
-      }
-    }
-    if (global.addEventListener) {
-      global.addEventListener('message', handleMessage, true);
-    } else if (global.attachEvent) {
-      global.attachEvent('onmessage', handleMessage);
-    }
-    return setZeroTimeoutPostMessage;
-  }(this)),
-
-  // Binary stuff
-  blobToArrayBuffer: function(blob, cb){
-    var fr = new FileReader();
-    fr.onload = function(evt) {
-      cb(evt.target.result);
-    };
-    fr.readAsArrayBuffer(blob);
-  },
-  blobToBinaryString: function(blob, cb){
-    var fr = new FileReader();
-    fr.onload = function(evt) {
-      cb(evt.target.result);
-    };
-    fr.readAsBinaryString(blob);
-  },
-  binaryStringToArrayBuffer: function(binary) {
-    var byteArray = new Uint8Array(binary.length);
-    for (var i = 0; i < binary.length; i++) {
-      byteArray[i] = binary.charCodeAt(i) & 0xff;
-    }
-    return byteArray.buffer;
-  },
-  randomToken: function () {
-    return Math.random().toString(36).substr(2);
-  },
-  //
-
-  // When we have proper version/feature mappings we can remove this
-  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;
-  },
-
-  isSecure: function() {
-    return location.protocol === 'https:';
-  }
-};
 /**
  * Reliable transfer for Chrome Canary DataChannel impl.
  * Author: @michellebu
@@ -1229,16 +1021,234 @@ Reliable.higherBandwidthSDP = function(sdp) {
 Reliable.prototype.onmessage = function(msg) {};
 
 exports.Reliable = Reliable;
-if (window.mozRTCPeerConnection) {
-  util.browserisms = 'Firefox';
-} else if (window.webkitRTCPeerConnection) {
-  util.browserisms = 'Webkit';
-} else {
-  util.browserisms = 'Unknown';
-}
-
 exports.RTCSessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
 exports.RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection;
+var defaultConfig = {'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]};
+var util = {
+  noop: function() {},
+
+  CLOUD_HOST: '0.peerjs.com',
+  CLOUD_PORT: 9000,
+  
+  // Logging logic
+  logLevel: 0,
+  setLogLevel: function(level) {
+    var debugLevel = parseInt(level, 10);
+    if (!isNaN(parseInt(level, 10))) {
+      util.logLevel = debugLevel;
+    } else {
+      // If they are using truthy/falsy values for debug
+      util.logLevel = (!!level) ? 3 : 0;
+    }
+    util.log = util.warn = util.error = util.noop;
+    if (util.logLevel > 0) {
+      util.error = util._printWith('ERROR');
+    }
+    if (util.logLevel > 1) {
+      util.warn = util._printWith('WARNING');
+    }
+    if (util.logLevel > 2) {
+      util.log = util._print;
+    }
+  },
+  setLogFunction: function(fn) {
+    if (fn.constructor !== Function) {
+      util.warn('The log function you passed in is not a function. Defaulting to regular logs.');
+    } else {
+      util._print = fn;
+    }
+  },
+
+  _printWith: function(prefix) {
+    return function() {
+      var copy = Array.prototype.slice.call(arguments);
+      copy.unshift(prefix);
+      util._print.apply(util, copy);
+    };
+  },
+  _print: function () {
+    var err = false;
+    var copy = Array.prototype.slice.call(arguments);
+    copy.unshift('PeerJS: ');
+    for (var i = 0, l = copy.length; i < l; i++){
+      if (copy[i] instanceof Error) {
+        copy[i] = '(' + copy[i].name + ') ' + copy[i].message;
+        err = true;
+      }
+    }
+    err ? console.error.apply(console, copy) : console.log.apply(console, copy);  
+  },
+  //
+
+  // Returns browser-agnostic default config
+  defaultConfig: defaultConfig,
+  //
+
+  // Lists which features are supported
+  // Temporarily set everything to true
+  supports: (function(){
+    return {
+      audioVideo: true,
+      data: true,
+      binary: false,
+      reliable: (function() {
+        // Reliable (not RTP).
+        var pc = new RTCPeerConnection(defaultConfig, {});
+        try {
+          pc.createDataChannel('PEERJSRELIABLETEST');
+        } catch (e) {
+          if (e.name === 'NotSupportedError') {
+            return false
+          }
+        }
+      })(),
+      onnegotiationneeded: true,
+      interop: false
+    };
+  }()),
+  //
+
+  // Ensure alphanumeric ids
+  validateId: function(id) {
+    // Allow empty ids
+    return !id || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id);
+  },
+
+  validateKey: function(key) {
+    // Allow empty keys
+    return !key || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(key);
+  },
+
+
+  // OLD
+  chromeCompatible: true,
+  firefoxCompatible: true,
+  chromeVersion: 26,
+  firefoxVersion: 22,
+
+  debug: false,
+  browserisms: '',
+
+  inherits: function(ctor, superCtor) {
+    ctor.super_ = superCtor;
+    ctor.prototype = Object.create(superCtor.prototype, {
+      constructor: {
+        value: ctor,
+        enumerable: false,
+        writable: true,
+        configurable: true
+      }
+    });
+  },
+  extend: function(dest, source) {
+    for(var key in source) {
+      if(source.hasOwnProperty(key)) {
+        dest[key] = source[key];
+      }
+    }
+    return dest;
+  },
+  pack: BinaryPack.pack,
+  unpack: BinaryPack.unpack,
+
+  log: function () {
+    if (util.debug) {
+      var err = false;
+      var copy = Array.prototype.slice.call(arguments);
+      copy.unshift('PeerJS: ');
+      for (var i = 0, l = copy.length; i < l; i++){
+        if (copy[i] instanceof Error) {
+          copy[i] = '(' + copy[i].name + ') ' + copy[i].message;
+          err = true;
+        }
+      }
+      err ? console.error.apply(console, copy) : console.log.apply(console, copy);
+    }
+  },
+
+  setZeroTimeout: (function(global) {
+    var timeouts = [];
+    var messageName = 'zero-timeout-message';
+
+    // Like setTimeout, but only takes a function argument.	 There's
+    // no time argument (always zero) and no arguments (you have to
+    // use a closure).
+    function setZeroTimeoutPostMessage(fn) {
+      timeouts.push(fn);
+      global.postMessage(messageName, '*');
+    }
+
+    function handleMessage(event) {
+      if (event.source == global && event.data == messageName) {
+        if (event.stopPropagation) {
+          event.stopPropagation();
+        }
+        if (timeouts.length) {
+          timeouts.shift()();
+        }
+      }
+    }
+    if (global.addEventListener) {
+      global.addEventListener('message', handleMessage, true);
+    } else if (global.attachEvent) {
+      global.attachEvent('onmessage', handleMessage);
+    }
+    return setZeroTimeoutPostMessage;
+  }(this)),
+
+  // Binary stuff
+  blobToArrayBuffer: function(blob, cb){
+    var fr = new FileReader();
+    fr.onload = function(evt) {
+      cb(evt.target.result);
+    };
+    fr.readAsArrayBuffer(blob);
+  },
+  blobToBinaryString: function(blob, cb){
+    var fr = new FileReader();
+    fr.onload = function(evt) {
+      cb(evt.target.result);
+    };
+    fr.readAsBinaryString(blob);
+  },
+  binaryStringToArrayBuffer: function(binary) {
+    var byteArray = new Uint8Array(binary.length);
+    for (var i = 0; i < binary.length; i++) {
+      byteArray[i] = binary.charCodeAt(i) & 0xff;
+    }
+    return byteArray.buffer;
+  },
+  randomToken: function () {
+    return Math.random().toString(36).substr(2);
+  },
+  //
+
+  // When we have proper version/feature mappings we can remove this
+  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;
+  },
+
+  isSecure: function() {
+    return location.protocol === 'https:';
+  }
+};
+
+exports.util = util;
 /**
  * A peer who can initiate connections with other peers.
  */
@@ -1262,7 +1272,7 @@ function Peer(id, options) {
     host: util.CLOUD_HOST,
     port: util.CLOUD_PORT,
     key: 'peerjs',
-    config: util.defaultConfig()
+    config: util.defaultConfig
   }, options);
   this.options = options;
   // Detect relative URL host.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/peer.min.js


+ 0 - 8
lib/adapter.js

@@ -1,10 +1,2 @@
-if (window.mozRTCPeerConnection) {
-  util.browserisms = 'Firefox';
-} else if (window.webkitRTCPeerConnection) {
-  util.browserisms = 'Webkit';
-} else {
-  util.browserisms = 'Unknown';
-}
-
 exports.RTCSessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
 exports.RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection;

+ 8 - 5
lib/util.js

@@ -1,3 +1,4 @@
+var defaultConfig = {'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]};
 var util = {
   noop: function() {},
 
@@ -54,6 +55,10 @@ var util = {
   },
   //
 
+  // Returns browser-agnostic default config
+  defaultConfig: defaultConfig,
+  //
+
   // Lists which features are supported
   // Temporarily set everything to true
   supports: (function(){
@@ -63,7 +68,7 @@ var util = {
       binary: false,
       reliable: (function() {
         // Reliable (not RTP).
-        var pc = new RTCPeerConnection(util.defaultConfig, {});
+        var pc = new RTCPeerConnection(defaultConfig, {});
         try {
           pc.createDataChannel('PEERJSRELIABLETEST');
         } catch (e) {
@@ -78,10 +83,6 @@ var util = {
   }()),
   //
 
-  // Returns browser-agnostic default config
-  defaultConfig: {'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }]},
-  //
-
   // Ensure alphanumeric ids
   validateId: function(id) {
     // Allow empty ids
@@ -221,3 +222,5 @@ var util = {
     return location.protocol === 'https:';
   }
 };
+
+exports.util = util;

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio