server.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var PeerServer = require('../').PeerServer;
  2. var expect = require('expect.js');
  3. var sinon = require('sinon');
  4. describe('PeerServer', function() {
  5. describe('constructor', function() {
  6. before(function() {
  7. PeerServer.prototype._initializeWSS = sinon.stub();
  8. PeerServer.prototype._initializeHTTP = sinon.stub();
  9. });
  10. it('should be able to be created without the `new` keyword', function() {
  11. var p = PeerServer();
  12. expect(p.constructor).to.be(PeerServer);
  13. });
  14. it('should default to port 80, key `peerjs`', function() {
  15. var p = new PeerServer();
  16. expect(p._options.key).to.be('peerjs');
  17. expect(p._options.port).to.be(80);
  18. });
  19. it('should accept a custom port', function() {
  20. var p = new PeerServer({ port: 8000 });
  21. expect(p._options.port).to.be(8000);
  22. });
  23. });
  24. describe('#_initializeWSS', function() {
  25. WebSocketServer = sinon.stub();
  26. });
  27. describe('#_configureWS', function() {
  28. });
  29. describe('#_checkKey', function() {
  30. var p;
  31. before(function() {
  32. PeerServer.prototype._initializeHTTP = sinon.stub();
  33. p = new PeerServer({ port: 8000 });
  34. p._checkKey('peerjs', 'myip', function() {});
  35. });
  36. it('should reject keys that are not the default', function(done) {
  37. p._checkKey('bad key', null, function(response) {
  38. expect(response).to.be('Invalid key provided');
  39. done();
  40. });
  41. });
  42. it('should accept valid key/ip pairs', function(done) {
  43. p._checkKey('peerjs', 'myip', function(response) {
  44. expect(response).to.be(null);
  45. done();
  46. });
  47. });
  48. it('should reject ips that are at their limit', function(done) {
  49. p._options.ip_limit = 0;
  50. p._checkKey('peerjs', 'myip', function(response) {
  51. expect(response).to.be('myip has reached its concurrent user limit');
  52. done();
  53. });
  54. });
  55. it('should reject when the server is at its limit', function(done) {
  56. p._options.concurrent_limit = 0;
  57. p._checkKey('peerjs', 'myip', function(response) {
  58. expect(response).to.be('Server has reached its concurrent user limit');
  59. done();
  60. });
  61. });
  62. });
  63. describe('#_initializeHTTP', function() {
  64. });
  65. describe('#_startStreaming', function() {
  66. });
  67. describe('#_pruneOutstanding', function() {
  68. });
  69. describe('#_processOutstanding', function() {
  70. });
  71. describe('#_removePeer', function() {
  72. });
  73. describe('#_handleTransmission', function() {
  74. // TODO: this is probably the most important method to test.
  75. });
  76. describe('#_generateClientId', function() {
  77. var p;
  78. before(function() {
  79. PeerServer.prototype._initializeHTTP = sinon.stub();
  80. p = new PeerServer({ port: 8000 });
  81. });
  82. it('should generate a 16-character ID', function() {
  83. expect(p._generateClientId('anykey').length).to.be(16);
  84. });
  85. });
  86. });