ssl options, closes #13

This commit is contained in:
Michelle Bu 2013-06-15 19:21:07 -07:00
parent c0130c418b
commit 70ee781154
2 changed files with 35 additions and 13 deletions

View File

@ -10,22 +10,35 @@ PeerServer helps broker connections between PeerJS clients. Data is not proxied
### Run PeerServer
Install the library
Install the library:
npm install peer
npm install peer
Run the server
Run the server:
var PeerServer = require('peer').PeerServer;
var server = new PeerServer({ port: 9000 });
Connecting to the server from PeerJS
Connecting to the server from PeerJS:
<script>
// No API key requried when not using cloud server
// No API key required when not using cloud server
var peer = new Peer('someid', {host: 'localhost', port: 9000});
</script>
Using HTTPS: Simply pass in PEM-encoded certificate and key.
var fs = require('fs');
var PeerServer = require('peer').PeerServer;
var server = new PeerServer({
port: 9000,
ssl: {
key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
certificate: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
}
});
## Problems?
Discuss PeerJS on our Google Group:

View File

@ -9,20 +9,29 @@ function PeerServer(options) {
if (!(this instanceof PeerServer)) return new PeerServer(options);
EventEmitter.call(this);
this._app = restify.createServer();
this._httpServer = this._app;
this._options = util.extend({
port: 80,
debug: false,
timeout: 5000,
key: 'peerjs',
ip_limit: 5000,
concurrent_limit: 5000
concurrent_limit: 5000,
ssl: {}
}, options);
util.debug = this._options.debug;
// Set up HTTPS server if key and certificate are provided.
var secure = this._options.ssl.key && this._options.ssl.certificate;
// Print warning if only one of the two is given.
if (Object.keys(this._options.ssl).length === 1) {
util.prettyError('Warning: PeerServer will not run on an HTTPS server'
+ ' because either the key or the certificate has not been provided.');
}
this._options.ssl['name'] = 'PeerServer';
this._app = restify.createServer(this._options.ssl);
// Connected clients
this._clients = {};
@ -50,7 +59,7 @@ PeerServer.prototype._initializeWSS = function() {
var self = this;
// Create WebSocket server as well.
this._wss = new WebSocketServer({ path: '/peerjs', server: this._httpServer });
this._wss = new WebSocketServer({ path: '/peerjs', server: this._app});
this._wss.on('connection', function(socket) {
var query = url.parse(socket.upgradeReq.url, true).query;
@ -253,7 +262,7 @@ PeerServer.prototype._initializeHTTP = function() {
this._app.post('/:key/:id/:token/leave', handle);
// Listen on user-specified port.
this._httpServer.listen(this._options.port);
this._app.listen(this._options.port);
};
/** Saves a streaming response and takes care of timeouts and headers. */