Michelle Bu 12 anni fa
parent
commit
376465f5cc
6 ha cambiato i file con 18 aggiunte e 11 eliminazioni
  1. 1 1
      demo/static/peer.html
  2. 14 5
      demo/static/peer.js
  3. 1 1
      demo/static/peer1.html
  4. 2 3
      dist/peer.js
  5. 0 0
      dist/peer.min.js
  6. 0 1
      lib/peer.js

+ 1 - 1
demo/static/peer.html

@@ -11,7 +11,7 @@
 <script type="text/javascript" src="/peer.js"></script>
 <script>
 $(document).ready(function() {
-  originator = new Peer({ id: 'michelle', host: 'localhost', port: '9000', debug: true });
+  originator = new Peer({ apikey: 'abc', id: 'michelle', host: 'localhost', port: '9000', debug: true });
   originator.on('ready', function(id) {
     console.log(id);
   });

+ 14 - 5
demo/static/peer.js

@@ -844,15 +844,15 @@ function Peer(options) {
   options = util.extend({
     debug: false,
     host: 'localhost',
-    protocol: 'http',
     config: { 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }] },
     port: 80
   }, options);
   this.options = options;
   util.debug = options.debug;
 
+  // TODO: default should be the cloud server.
   this._server = options.host + ':' + options.port;
-  this._httpUrl = options.protocol + '://' + this._server;
+  this._httpUrl = 'http://' + this._server;
   this._config = options.config;
 
   // Ensure alphanumeric_-
@@ -882,8 +882,12 @@ Peer.prototype._checkIn = function() {
   if (!this._id) {
     try {
       var http = new XMLHttpRequest();
+      var url = this._httpUrl + '/id';
+      if (!!this._apikey)
+        url += '?key=' + this._apikey;
+
       // If there's no ID we need to wait for one before trying to init socket.
-      http.open('get', this._httpUrl + '/id', true);
+      http.open('get', url, true);
       http.onreadystatechange = function() {
         if (!self._id && http.readyState > 2 && !!http.responseText) {
           try {
@@ -922,7 +926,7 @@ Peer.prototype._startXhrStream = function() {
     http.onreadystatechange = function() {
       self._handleStream(http);
     };
-    http.send(JSON.stringify({ id: this._id }));
+    http.send(JSON.stringify({ id: this._id, key: this._apikey }));
   } catch(e) {
     util.log('XMLHttpRequest not available; defaulting to WebSockets');
   }
@@ -960,8 +964,13 @@ Peer.prototype._socketInit = function() {
     return;
 
   var wsurl = 'ws://' + this._server + '/ws';
-  if (!!this._id)
+  if (!!this._id) {
     wsurl += '?id=' + this._id;
+    if (!!this._apikey)
+      wsurl += '&key=' + this._apikey;
+  } else if (!!this._apikey) {
+    wsurl += '?key=' + this._apikey;
+  }
   this._socket = new WebSocket(wsurl);
 
   var self = this;

+ 1 - 1
demo/static/peer1.html

@@ -15,7 +15,7 @@ $(document).ready(function() {
   $('#connect').click(function() {
     var source = $('#source').val();
 
-    sink = new Peer({ host: 'localhost', port: '9000', debug: true });
+    sink = new Peer({ apikey: 'abc', host: 'localhost', port: '9000', debug: true });
       sink.connect(source, { username: 'michelle' }, function(err, connection) {
         x = connection;
         console.log('got connection');

+ 2 - 3
dist/peer.js

@@ -844,15 +844,15 @@ function Peer(options) {
   options = util.extend({
     debug: false,
     host: 'localhost',
-    protocol: 'http',
     config: { 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }] },
     port: 80
   }, options);
   this.options = options;
   util.debug = options.debug;
 
+  // TODO: default should be the cloud server.
   this._server = options.host + ':' + options.port;
-  this._httpUrl = options.protocol + '://' + this._server;
+  this._httpUrl = 'http://' + this._server;
   this._config = options.config;
 
   // Ensure alphanumeric_-
@@ -883,7 +883,6 @@ Peer.prototype._checkIn = function() {
     try {
       var http = new XMLHttpRequest();
       var url = this._httpUrl + '/id';
-      console.log(this._apikey);
       if (!!this._apikey)
         url += '?key=' + this._apikey;
 

File diff suppressed because it is too large
+ 0 - 0
dist/peer.min.js


+ 0 - 1
lib/peer.js

@@ -43,7 +43,6 @@ Peer.prototype._checkIn = function() {
     try {
       var http = new XMLHttpRequest();
       var url = this._httpUrl + '/id';
-      console.log(this._apikey);
       if (!!this._apikey)
         url += '?key=' + this._apikey;
 

Some files were not shown because too many files changed in this diff