Browse Source

api key support added

Michelle Bu 12 years ago
parent
commit
8d319a83f0
3 changed files with 26 additions and 6 deletions
  1. 13 3
      dist/peer.js
  2. 0 0
      dist/peer.min.js
  3. 13 3
      lib/peer.js

+ 13 - 3
dist/peer.js

@@ -882,8 +882,13 @@ Peer.prototype._checkIn = function() {
   if (!this._id) {
   if (!this._id) {
     try {
     try {
       var http = new XMLHttpRequest();
       var http = new XMLHttpRequest();
+      var url = this._httpUrl + '/id';
+      console.log(this._apikey);
+      if (!!this._apikey)
+        url += '?key=' + this._apikey;
+
       // If there's no ID we need to wait for one before trying to init socket.
       // 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() {
       http.onreadystatechange = function() {
         if (!self._id && http.readyState > 2 && !!http.responseText) {
         if (!self._id && http.readyState > 2 && !!http.responseText) {
           try {
           try {
@@ -922,7 +927,7 @@ Peer.prototype._startXhrStream = function() {
     http.onreadystatechange = function() {
     http.onreadystatechange = function() {
       self._handleStream(http);
       self._handleStream(http);
     };
     };
-    http.send(JSON.stringify({ id: this._id }));
+    http.send(JSON.stringify({ id: this._id, key: this._apikey }));
   } catch(e) {
   } catch(e) {
     util.log('XMLHttpRequest not available; defaulting to WebSockets');
     util.log('XMLHttpRequest not available; defaulting to WebSockets');
   }
   }
@@ -960,8 +965,13 @@ Peer.prototype._socketInit = function() {
     return;
     return;
 
 
   var wsurl = 'ws://' + this._server + '/ws';
   var wsurl = 'ws://' + this._server + '/ws';
-  if (!!this._id)
+  if (!!this._id) {
     wsurl += '?id=' + 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);
   this._socket = new WebSocket(wsurl);
 
 
   var self = this;
   var self = this;

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


+ 13 - 3
lib/peer.js

@@ -43,8 +43,13 @@ Peer.prototype._checkIn = function() {
   if (!this._id) {
   if (!this._id) {
     try {
     try {
       var http = new XMLHttpRequest();
       var http = new XMLHttpRequest();
+      var url = this._httpUrl + '/id';
+      console.log(this._apikey);
+      if (!!this._apikey)
+        url += '?key=' + this._apikey;
+
       // If there's no ID we need to wait for one before trying to init socket.
       // 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() {
       http.onreadystatechange = function() {
         if (!self._id && http.readyState > 2 && !!http.responseText) {
         if (!self._id && http.readyState > 2 && !!http.responseText) {
           try {
           try {
@@ -83,7 +88,7 @@ Peer.prototype._startXhrStream = function() {
     http.onreadystatechange = function() {
     http.onreadystatechange = function() {
       self._handleStream(http);
       self._handleStream(http);
     };
     };
-    http.send(JSON.stringify({ id: this._id }));
+    http.send(JSON.stringify({ id: this._id, key: this._apikey }));
   } catch(e) {
   } catch(e) {
     util.log('XMLHttpRequest not available; defaulting to WebSockets');
     util.log('XMLHttpRequest not available; defaulting to WebSockets');
   }
   }
@@ -121,8 +126,13 @@ Peer.prototype._socketInit = function() {
     return;
     return;
 
 
   var wsurl = 'ws://' + this._server + '/ws';
   var wsurl = 'ws://' + this._server + '/ws';
-  if (!!this._id)
+  if (!!this._id) {
     wsurl += '?id=' + 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);
   this._socket = new WebSocket(wsurl);
 
 
   var self = this;
   var self = this;

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