Browse Source

add 'peerjs' bin script for simple(r) bootstrap

Ilya Grigorik 12 years ago
parent
commit
0cb729dcaa
2 changed files with 73 additions and 1 deletions
  1. 71 0
      bin/peerjs
  2. 2 1
      package.json

+ 71 - 0
bin/peerjs

@@ -0,0 +1,71 @@
+#!/usr/bin/env node
+
+var path = require('path')
+  , pkg = require('../package.json')
+  , fs = require('fs')
+  , version = pkg.version
+  , PeerServer = require('../lib/server').PeerServer
+  , opts = require('optimist')
+    .usage('Usage: $0')
+    .options({
+      debug: {
+        demand: false,
+        alias: 'd',
+        description: 'debug',
+        default: false
+      },
+      timeout: {
+        demand: false,
+        alias: 't',
+        description: 'timeout (milliseconds)',
+        default: 5000
+      },
+      ip_limit: {
+        demand: false,
+        alias: 'i',
+        description: 'IP limit',
+        default: 5000
+      },
+      concurrent_limit: {
+        demand: false,
+        alias: 'c',
+        description: 'concurrent limit',
+        default: 5000
+      },
+      key: {
+        demand: false,
+        alias: 'k',
+        description: 'connection key',
+        default: 'peerjs'
+      },
+      sslkey: {
+        demand: false,
+        description: 'path to SSL key'
+      },
+      sslcert: {
+        demand: false,
+        description: 'path to SSL certificate'
+      },
+      port: {
+        demand: true,
+        alias: 'p',
+        description: 'port',
+      }
+    }).argv;
+
+opts.version = version;
+
+if (opts.sslkey && opts.sslcert) {
+  opts['ssl'] = {};
+  opts.ssl['key'] = fs.readFileSync(path.resolve(opts.sslkey));
+  opts.ssl['certificate'] = fs.readFileSync(path.resolve(opts.sslcert));
+}
+
+process.on('uncaughtException', function(e) {
+  console.error('Error: ' + e);
+});
+
+var server = new PeerServer(opts);
+console.log(
+  "Started PeerServer, port: " + opts.port + (" (v. %s)"), version
+);

+ 2 - 1
package.json

@@ -11,6 +11,7 @@
   "license": "MIT",
   "dependencies": {
     "restify": "~2.3.5",
-    "ws": "~0.4.25"
+    "ws": "~0.4.25",
+    "optimist": "*"
   }
 }