LegacyWDSSocketEntry.js 768 B

12345678910111213141516171819202122232425262728293031
  1. const SockJS = require('sockjs-client/dist/sockjs');
  2. const safeThis = require('./utils/safeThis');
  3. /**
  4. * A SockJS client adapted for use with webpack-dev-server.
  5. * @constructor
  6. * @param {string} url The socket URL.
  7. */
  8. function SockJSClient(url) {
  9. this.socket = new SockJS(url);
  10. }
  11. /**
  12. * Creates a handler to handle socket close events.
  13. * @param {function(): void} fn
  14. */
  15. SockJSClient.prototype.onClose = function onClose(fn) {
  16. this.socket.onclose = fn;
  17. };
  18. /**
  19. * Creates a handler to handle socket message events.
  20. * @param {function(*): void} fn
  21. */
  22. SockJSClient.prototype.onMessage = function onMessage(fn) {
  23. this.socket.onmessage = function onMessageHandler(event) {
  24. fn(event.data);
  25. };
  26. };
  27. safeThis.__webpack_dev_server_client__ = SockJSClient;