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.

wswrapper.js 979B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. const events_1 = require("events");
  3. class WSWrapper extends events_1.EventEmitter {
  4. constructor(url, _protocols, _websocketOptions) {
  5. super();
  6. this.setMaxListeners(Infinity);
  7. this._ws = new WebSocket(url);
  8. this._ws.onclose = () => {
  9. this.emit('close');
  10. };
  11. this._ws.onopen = () => {
  12. this.emit('open');
  13. };
  14. this._ws.onerror = (error) => {
  15. this.emit('error', error);
  16. };
  17. this._ws.onmessage = (message) => {
  18. this.emit('message', message.data);
  19. };
  20. }
  21. close() {
  22. if (this.readyState === 1) {
  23. this._ws.close();
  24. }
  25. }
  26. send(message) {
  27. this._ws.send(message);
  28. }
  29. get readyState() {
  30. return this._ws.readyState;
  31. }
  32. }
  33. WSWrapper.CONNECTING = 0;
  34. WSWrapper.OPEN = 1;
  35. WSWrapper.CLOSING = 2;
  36. WSWrapper.CLOSED = 3;
  37. module.exports = WSWrapper;
  38. //# sourceMappingURL=wswrapper.js.map