websocket.js 822 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*!
  2. * socket.io-node
  3. * Copyright(c) 2011 LearnBoost <[email protected]>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module requirements.
  8. */
  9. var protocolVersions = require('./websocket/');
  10. /**
  11. * Export the constructor.
  12. */
  13. exports = module.exports = WebSocket;
  14. /**
  15. * HTTP interface constructor. Interface compatible with all transports that
  16. * depend on request-response cycles.
  17. *
  18. * @api public
  19. */
  20. function WebSocket (mng, data, req) {
  21. var transport
  22. , version = req.headers['sec-websocket-version'];
  23. if (typeof version !== 'undefined' && typeof protocolVersions[version] !== 'undefined') {
  24. transport = new protocolVersions[version](mng, data, req);
  25. }
  26. else transport = new protocolVersions['default'](mng, data, req);
  27. if (typeof this.name !== 'undefined') transport.name = this.name;
  28. return transport;
  29. };