peerjs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env node
  2. var path = require('path')
  3. , pkg = require('../package.json')
  4. , fs = require('fs')
  5. , version = pkg.version
  6. , app = require('express')()
  7. , PeerServer = require('../lib')
  8. , opts = require('optimist')
  9. .usage('Usage: $0')
  10. .options({
  11. debug: {
  12. demand: false,
  13. alias: 'd',
  14. description: 'debug',
  15. default: false
  16. },
  17. timeout: {
  18. demand: false,
  19. alias: 't',
  20. description: 'timeout (milliseconds)',
  21. default: 5000
  22. },
  23. ip_limit: {
  24. demand: false,
  25. alias: 'i',
  26. description: 'IP limit',
  27. default: 5000
  28. },
  29. concurrent_limit: {
  30. demand: false,
  31. alias: 'c',
  32. description: 'concurrent limit',
  33. default: 5000
  34. },
  35. key: {
  36. demand: false,
  37. alias: 'k',
  38. description: 'connection key',
  39. default: 'peerjs'
  40. },
  41. sslkey: {
  42. demand: false,
  43. description: 'path to SSL key'
  44. },
  45. sslcert: {
  46. demand: false,
  47. description: 'path to SSL certificate'
  48. },
  49. port: {
  50. demand: true,
  51. alias: 'p',
  52. description: 'port'
  53. },
  54. path: {
  55. demand: false,
  56. description: 'custom path'
  57. },
  58. allow_discovery: {
  59. demand: false,
  60. description: 'allow discovery of peers'
  61. }
  62. })
  63. .boolean('allow_discovery')
  64. .argv;
  65. opts.version = version;
  66. if (opts.sslkey && opts.sslcert) {
  67. opts['ssl'] = {};
  68. opts.ssl['key'] = fs.readFileSync(path.resolve(opts.sslkey));
  69. opts.ssl['certificate'] = fs.readFileSync(path.resolve(opts.sslcert));
  70. }
  71. process.on('uncaughtException', function(e) {
  72. console.error('Error: ' + e);
  73. });
  74. opts.server = app.listen(opts.port);
  75. app.use(PeerServer(opts));
  76. console.log(
  77. 'Started PeerServer, port: ' + opts.port + ', path: ' + (opts.path || '/') + (" (v. %s)"), version
  78. );