You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
831 B

  1. /**
  2. * Module dependencies.
  3. */
  4. var global = (function() { return this; })();
  5. /**
  6. * WebSocket constructor.
  7. */
  8. var WebSocket = global.WebSocket || global.MozWebSocket;
  9. /**
  10. * Module exports.
  11. */
  12. module.exports = WebSocket ? ws : null;
  13. /**
  14. * WebSocket constructor.
  15. *
  16. * The third `opts` options object gets ignored in web browsers, since it's
  17. * non-standard, and throws a TypeError if passed to the constructor.
  18. * See: https://github.com/einaros/ws/issues/227
  19. *
  20. * @param {String} uri
  21. * @param {Array} protocols (optional)
  22. * @param {Object) opts (optional)
  23. * @api public
  24. */
  25. function ws(uri, protocols, opts) {
  26. var instance;
  27. if (protocols) {
  28. instance = new WebSocket(uri, protocols);
  29. } else {
  30. instance = new WebSocket(uri);
  31. }
  32. return instance;
  33. }
  34. if (WebSocket) ws.prototype = WebSocket.prototype;