SockJSClient.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. /* eslint-disable
  3. no-unused-vars
  4. */
  5. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  12. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  15. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16. var SockJS = require('sockjs-client/dist/sockjs');
  17. var BaseClient = require('./BaseClient');
  18. module.exports = /*#__PURE__*/function (_BaseClient) {
  19. _inherits(SockJSClient, _BaseClient);
  20. var _super = _createSuper(SockJSClient);
  21. function SockJSClient(url) {
  22. var _this;
  23. _classCallCheck(this, SockJSClient);
  24. _this = _super.call(this);
  25. _this.sock = new SockJS(url);
  26. _this.sock.onerror = function (err) {// TODO: use logger to log the error event once client and client-src
  27. // are reorganized to have the same directory structure
  28. };
  29. return _this;
  30. }
  31. _createClass(SockJSClient, [{
  32. key: "onOpen",
  33. value: function onOpen(f) {
  34. this.sock.onopen = f;
  35. }
  36. }, {
  37. key: "onClose",
  38. value: function onClose(f) {
  39. this.sock.onclose = f;
  40. } // call f with the message string as the first argument
  41. }, {
  42. key: "onMessage",
  43. value: function onMessage(f) {
  44. this.sock.onmessage = function (e) {
  45. f(e.data);
  46. };
  47. }
  48. }], [{
  49. key: "getClientPath",
  50. value: function getClientPath(options) {
  51. return require.resolve('./SockJSClient');
  52. }
  53. }]);
  54. return SockJSClient;
  55. }(BaseClient);