Эх сурвалжийг харах

Merge branch 'master' of github.com:peers/peerjs

ericz 12 жил өмнө
parent
commit
8f5bdcef0f

+ 22 - 0
LICENSE

@@ -0,0 +1,22 @@
+Copyright (c) 2013 Michelle Bu and Eric Zhang, http://peerjs.com
+
+(The MIT License)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 2 - 79
README.md

@@ -1,80 +1,3 @@
-# Peers: a node.js PeerConnection library #
+# PeerJS: a WebRTC PeerConnection/DataChannel library #
 
-
-## Chrome ##
-
-* Run Canary with `--enable-data-channel`
-
-
-## Firefox ##
-
-Currently awaiting next Firefox WebRTC update.
-
-* Firefox flags:
-  `media.navigator.enabled: true`
-  `media.navigator.permission.disabled: true`
-  `media.peerconnection.enabled: true`
-
-## Usage ##
-
-### Server ###
-
-`npm install peer`
-
-```js
-var PeerServer = require('peer').PeerServer({ port: 80, debug: true });
-```
-
-### Client ###
-
-`<script type="text/javascript" src="/client/dist/peer.js"></script>`
-
-
-#### First peer ####
-
-```js
-var connections = {};
-
-p1 = new Peer({ host: 'localhost', port: '8000' });
-p1.on('ready', function(id) {
-  console.log(id); // => 'some_id_1'
-});
-
-p1.on('connection', function(connection) {
-  // Sends a message to the other peer. This can even be a blob or JSON.
-  connection.send('Hi there!');
-  connection.send({ file: new Blob([1, 2, 3])});
-
-  // Probably want to save the connection object.
-  connections[connection.metadata.username] = connection;
-
-  if (connection.metadata.username == 'spy') {
-    connection.close();
-  } else {
-    // Add handler for connection data.
-    connection.on('data', function(data) {
-      console.log(data);
-    }
-  }
-});
-
-```
-
-#### Second Peer ####
-
-```js
-p2 = new Peer({ server: 'localhost' });
-p2.on('ready', function(id) {
-  console.log(id);
-
-  p2.connect('some_id_1', { username: 'friend' }, function(err, connection) {
-    connection.send('Hi, bye.');
-
-    connection.close();
-  });
-});
-```
-
-#### Other events ####
-
-* Connection - `close`: Called when a peer disconnects.
+http://peerjs.com

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

+ 4 - 10
demo/static/peer.js

@@ -888,12 +888,6 @@ Peer.prototype._startSocket = function() {
   this._socket.on('message', function(data) {
     self._handleServerJSONMessage(data);
   });
-  this._socket.on('open', function() {
-    if (self.id) {
-      self.emit('open', self.id);
-      self._processQueue();
-    }
-  });
   this._socket.on('error', function(error) {
     util.log(error);
     self.emit('error', error);
@@ -913,13 +907,13 @@ Peer.prototype._handleServerJSONMessage = function(message) {
   var peer = message.src;
   var connection = this.connections[peer];
   switch (message.type) {
-    case 'ID':
+    case 'OPEN':
       if (!this.id) {
         // If we're just now getting an ID then we may have a queue.
         this.id = message.id;
-        this.emit('open', this.id);
-        this._processQueue();
       }
+      this.emit('open', this.id);
+      this._processQueue();
       break;
     case 'ERROR':
       this.emit('error', message.msg);
@@ -1401,7 +1395,7 @@ Socket.prototype._checkIn = function() {
             if (!!response.id) {
               self._id = response.id;
               self._startWebSocket();
-              self.emit('message', { type: 'ID', id: self._id });
+              self.emit('message', { type: 'OPEN', id: self._id });
             }
           } catch (e) {
             self._startWebSocket();

+ 1 - 1
demo/static/peer1.html

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

+ 4 - 10
dist/peer.js

@@ -888,12 +888,6 @@ Peer.prototype._startSocket = function() {
   this._socket.on('message', function(data) {
     self._handleServerJSONMessage(data);
   });
-  this._socket.on('open', function() {
-    if (self.id) {
-      self.emit('open', self.id);
-      self._processQueue();
-    }
-  });
   this._socket.on('error', function(error) {
     util.log(error);
     self.emit('error', error);
@@ -913,13 +907,13 @@ Peer.prototype._handleServerJSONMessage = function(message) {
   var peer = message.src;
   var connection = this.connections[peer];
   switch (message.type) {
-    case 'ID':
+    case 'OPEN':
       if (!this.id) {
         // If we're just now getting an ID then we may have a queue.
         this.id = message.id;
-        this.emit('open', this.id);
-        this._processQueue();
       }
+      this.emit('open', this.id);
+      this._processQueue();
       break;
     case 'ERROR':
       this.emit('error', message.msg);
@@ -1401,7 +1395,7 @@ Socket.prototype._checkIn = function() {
             if (!!response.id) {
               self._id = response.id;
               self._startWebSocket();
-              self.emit('message', { type: 'ID', id: self._id });
+              self.emit('message', { type: 'OPEN', id: self._id });
             }
           } catch (e) {
             self._startWebSocket();

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
dist/peer.min.js


+ 1 - 1
lib/socket.js

@@ -37,7 +37,7 @@ Socket.prototype._checkIn = function() {
             if (!!response.id) {
               self._id = response.id;
               self._startWebSocket();
-              self.emit('message', { type: 'ID', id: self._id });
+              self.emit('message', { type: 'OPEN', id: self._id });
             }
           } catch (e) {
             self._startWebSocket();

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно