This commit is contained in:
Michelle Bu 2013-12-23 23:28:24 -05:00
parent 5d358ce71f
commit a17fe6380a
2 changed files with 19 additions and 0 deletions

View File

@ -55,6 +55,21 @@ var server = new PeerServer({
});
```
### Events
The `'connection'` event is emitted when a peer connects to the server.
```javascript
PeerServer#on('connection', function(id) { ... })
```
The `'disconnect'` event is emitted when a peer disconnects from the server or
when the peer can no longer be reached.
```javascript
PeerServer#on('disconnect', function(id) { ... })
```
## Problems?
Discuss PeerJS on our Google Group:

View File

@ -79,6 +79,9 @@ PeerServer.prototype._initializeWSS = function() {
self._clients[key][id] = { token: token, ip: ip };
self._ips[ip]++;
socket.send(JSON.stringify({ type: 'OPEN' }));
// We're going to emit here, because for XHR we don't *know* when someone
// disconnects.
self.emit('connection', id);
}
self._configureWS(socket, key, id, token);
} else {
@ -345,6 +348,7 @@ PeerServer.prototype._removePeer = function(key, id) {
if (this._clients[key] && this._clients[key][id]) {
this._ips[this._clients[key][id].ip]--;
delete this._clients[key][id];
this.emit('disconnect', id);
}
};