[6a3a178] | 1 | 'use strict';
|
---|
| 2 | /* global WebSocket */
|
---|
| 3 |
|
---|
| 4 | /* eslint-disable
|
---|
| 5 | no-unused-vars
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | 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); }
|
---|
| 9 |
|
---|
| 10 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
| 11 |
|
---|
| 12 | 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); } }
|
---|
| 13 |
|
---|
| 14 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
---|
| 15 |
|
---|
| 16 | 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); }
|
---|
| 17 |
|
---|
| 18 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
| 19 |
|
---|
| 20 | 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); }; }
|
---|
| 21 |
|
---|
| 22 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
---|
| 23 |
|
---|
| 24 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
---|
| 25 |
|
---|
| 26 | 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; } }
|
---|
| 27 |
|
---|
| 28 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
---|
| 29 |
|
---|
| 30 | var BaseClient = require('./BaseClient');
|
---|
| 31 |
|
---|
| 32 | module.exports = /*#__PURE__*/function (_BaseClient) {
|
---|
| 33 | _inherits(WebsocketClient, _BaseClient);
|
---|
| 34 |
|
---|
| 35 | var _super = _createSuper(WebsocketClient);
|
---|
| 36 |
|
---|
| 37 | function WebsocketClient(url) {
|
---|
| 38 | var _this;
|
---|
| 39 |
|
---|
| 40 | _classCallCheck(this, WebsocketClient);
|
---|
| 41 |
|
---|
| 42 | _this = _super.call(this);
|
---|
| 43 | _this.client = new WebSocket(url.replace(/^http/, 'ws'));
|
---|
| 44 |
|
---|
| 45 | _this.client.onerror = function (err) {// TODO: use logger to log the error event once client and client-src
|
---|
| 46 | // are reorganized to have the same directory structure
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | return _this;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | _createClass(WebsocketClient, [{
|
---|
| 53 | key: "onOpen",
|
---|
| 54 | value: function onOpen(f) {
|
---|
| 55 | this.client.onopen = f;
|
---|
| 56 | }
|
---|
| 57 | }, {
|
---|
| 58 | key: "onClose",
|
---|
| 59 | value: function onClose(f) {
|
---|
| 60 | this.client.onclose = f;
|
---|
| 61 | } // call f with the message string as the first argument
|
---|
| 62 |
|
---|
| 63 | }, {
|
---|
| 64 | key: "onMessage",
|
---|
| 65 | value: function onMessage(f) {
|
---|
| 66 | this.client.onmessage = function (e) {
|
---|
| 67 | f(e.data);
|
---|
| 68 | };
|
---|
| 69 | }
|
---|
| 70 | }], [{
|
---|
| 71 | key: "getClientPath",
|
---|
| 72 | value: function getClientPath(options) {
|
---|
| 73 | return require.resolve('./WebsocketClient');
|
---|
| 74 | }
|
---|
| 75 | }]);
|
---|
| 76 |
|
---|
| 77 | return WebsocketClient;
|
---|
| 78 | }(BaseClient); |
---|