瀏覽代碼

allowed room in api for a generic server rather than just ws

Michelle Bu 12 年之前
父節點
當前提交
e8f07be8fc
共有 4 個文件被更改,包括 14 次插入12 次删除
  1. 2 2
      README.md
  2. 2 2
      demo/static/peer.html
  3. 1 1
      demo/static/peer1.html
  4. 9 7
      lib/peer.js

+ 2 - 2
README.md

@@ -35,7 +35,7 @@ var PeerServer = require('peer').PeerServer({ port: 80, debug: true });
 ```js
 var connections = {};
 
-p1 = new Peer({ ws: 'ws://www.host.com' });
+p1 = new Peer({ server: 'localhost' });
 p1.on('ready', function(id) {
   console.log(id); // => 'some_id_1'
 });
@@ -63,7 +63,7 @@ p1.on('connection', function(connection) {
 #### Second Peer ####
 
 ```js
-p2 = new Peer({ ws: 'ws://www.host.com' });
+p2 = new Peer({ server: 'localhost' });
 p2.on('ready', function(id) {
   console.log(id);
 

+ 2 - 2
demo/static/peer.html

@@ -12,8 +12,8 @@
 <script>
 $(document).ready(function() {
   connections = {};
-  var REMOTE = 'ws://localhost:9000';
-  originator = new Peer({ ws: REMOTE, debug: true });
+  var REMOTE = 'localhost:9000';
+  originator = new Peer({ server: REMOTE, debug: true });
   originator.on('ready', function(id) {
     console.log(id);
   });

+ 1 - 1
demo/static/peer1.html

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

+ 9 - 7
lib/peer.js

@@ -4,14 +4,16 @@ function Peer(options) {
 
   options = util.extend({
     debug: false,
-    peer: 'ws://localhost'
+    server: 'localhost'
   }, options);
   this.options = options;
   util.debug = options.debug;
 
-  this._id = null;
+  this._id = options.id;
+  // Not used unless using cloud server.
+  this._api_key = options.api_key;
 
-  this._socket = new WebSocket(options.ws);
+  this._socket = new WebSocket('ws://' + options.server);
   this._socketInit();
 
   // Connections for this peer.
@@ -20,6 +22,9 @@ function Peer(options) {
   // Queued connections to make.
   this._queued = [];
 
+  // If no ID provided, get a unique ID from server.
+  
+
   // Make sure connections are cleaned up.
   window.onbeforeunload = this._cleanup;
 };
@@ -71,10 +76,7 @@ Peer.prototype._socketInit = function() {
     }
   };
   this._socket.onopen = function() {
-    // Announce as a PEER to receive an ID.
-    self._socket.send(JSON.stringify({
-      type: 'PEER'
-    }));
+    self._use_socket = true;
   };
 };