瀏覽代碼

bugs bzzzz

Michelle Bu 12 年之前
父節點
當前提交
241d0991d7
共有 7 個文件被更改,包括 17 次插入20 次删除
  1. 0 6
      demo/server.js
  2. 1 1
      demo/static/peer.html
  3. 7 6
      demo/static/peer.js
  4. 1 1
      demo/static/peer1.html
  5. 7 6
      dist/peer.js
  6. 0 0
      dist/peer.min.js
  7. 1 0
      lib/peer.js

+ 0 - 6
demo/server.js

@@ -7,15 +7,9 @@ app.use(express.bodyParser());
 
 app.use(express.static(__dirname + '/static'));
 
-app.set('view engine', 'ejs');
 app.set('views', __dirname + '/views');
 
 
-app.get('/', function(req, res){
-  res.render('index');
-});
-
-
 app.listen(8000);
 
 

+ 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('michelle', { key: 'r6l1dggn5hebqpvi', host: 'localhost', port: '9000', debug: true });
+  originator = new Peer('michelle', { key: 'x8w1becrbresif6r', host: 'localhost', port: '9000', debug: true });
   originator.on('open', function(id) {
     console.log(id);
   });

+ 7 - 6
demo/static/peer.js

@@ -1384,11 +1384,12 @@ Socket.prototype._checkIn = function() {
   if (!this._id) {
     try {
       var http = new XMLHttpRequest();
-      var url = this._httpUrl + '/id';
+      var url = this._httpUrl;
       // Set API key if necessary.
       if (!!this._key) {
         url += '/' + this._key;
       }
+      url += '/id';
 
       // If there's no ID we need to wait for one before trying to init socket.
       http.open('get', url, true);
@@ -1468,11 +1469,12 @@ Socket.prototype._startXhrStream = function() {
     var self = this;
 
     var http = new XMLHttpRequest();
-    var url = this._httpUrl + '/id';
+    var url = this._httpUrl;
     // Set API key if necessary.
     if (!!this._key) {
       url += '/' + this._key;
     }
+    url += '/id';
     http.open('post', url, true);
     http.setRequestHeader('Content-Type', 'application/json');
     http.onreadystatechange = function() {
@@ -1495,9 +1497,7 @@ Socket.prototype._handleStream = function(http, pad) {
   }
 
   if (this._index === undefined) {
-    // TODO
-    this._index = 2;
-    //this._index = pad ? 2 : 1;
+    this._index = pad ? 2 : 1;
   }
   
   if (http.responseText === null) {
@@ -1555,11 +1555,12 @@ Socket.prototype.send = function(data) {
   } else {
     var self = this;
     var http = new XMLHttpRequest();
-    var url = this._httpUrl + '/' + type.toLowerCase();
+    var url = this._httpUrl;
     // Set API key if necessary.
     if (!!this._key) {
       url += '/' + this._key;
     }
+    url += '/' + type.toLowerCase();
       
     http.open('post', url, true);
     http.setRequestHeader('Content-Type', 'application/json');

+ 1 - 1
demo/static/peer1.html

@@ -14,7 +14,7 @@ $(document).ready(function() {
   $('#connect').click(function() {
     var source = $('#source').val();
 
-    sink = new Peer({ key: 'r6l1dggn5hebqpvi', host: 'localhost', port: '9000', debug: true });
+    sink = new Peer({ key: 'x8w1becrbresif6r', host: 'localhost', port: '9000', debug: true });
     connection = sink.connect(source, { username: 'michelle_spoof' })
     connection.on('data', function(data) {
       console.log(data);

+ 7 - 6
dist/peer.js

@@ -1384,11 +1384,12 @@ Socket.prototype._checkIn = function() {
   if (!this._id) {
     try {
       var http = new XMLHttpRequest();
-      var url = this._httpUrl + '/id';
+      var url = this._httpUrl;
       // Set API key if necessary.
       if (!!this._key) {
         url += '/' + this._key;
       }
+      url += '/id';
 
       // If there's no ID we need to wait for one before trying to init socket.
       http.open('get', url, true);
@@ -1468,11 +1469,12 @@ Socket.prototype._startXhrStream = function() {
     var self = this;
 
     var http = new XMLHttpRequest();
-    var url = this._httpUrl + '/id';
+    var url = this._httpUrl;
     // Set API key if necessary.
     if (!!this._key) {
       url += '/' + this._key;
     }
+    url += '/id';
     http.open('post', url, true);
     http.setRequestHeader('Content-Type', 'application/json');
     http.onreadystatechange = function() {
@@ -1495,9 +1497,7 @@ Socket.prototype._handleStream = function(http, pad) {
   }
 
   if (this._index === undefined) {
-    // TODO
-    this._index = 2;
-    //this._index = pad ? 2 : 1;
+    this._index = pad ? 2 : 1;
   }
   
   if (http.responseText === null) {
@@ -1555,11 +1555,12 @@ Socket.prototype.send = function(data) {
   } else {
     var self = this;
     var http = new XMLHttpRequest();
-    var url = this._httpUrl + '/' + type.toLowerCase();
+    var url = this._httpUrl;
     // Set API key if necessary.
     if (!!this._key) {
       url += '/' + this._key;
     }
+    url += '/' + type.toLowerCase();
       
     http.open('post', url, true);
     http.setRequestHeader('Content-Type', 'application/json');

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


+ 1 - 0
lib/peer.js

@@ -51,6 +51,7 @@ Peer.prototype._startSocket = function() {
   });
   this._socket.on('open', function() {
     if (this.id) {
+      this.emit('open', this.id);
       self._processQueue();
     }
   });

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