pubo-web 1.0.5-alpha.0 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { RosConfigure } from '../factory/configure';
1
+ import type { RosConfigure } from '../factory/configure';
2
2
  import { InjectUtil } from './inject';
3
3
  interface InitProps {
4
4
  elem: any;
@@ -0,0 +1,15 @@
1
+ import { Emitter } from 'pubo-utils';
2
+ export default class WebsocketClient {
3
+ private client;
4
+ private _status;
5
+ private readonly url;
6
+ emitter: Emitter;
7
+ constructor({ url }: {
8
+ url: any;
9
+ });
10
+ private reconnect;
11
+ private onClose;
12
+ private onMessage;
13
+ connect(): void;
14
+ close(): void;
15
+ }
@@ -0,0 +1,60 @@
1
+ import { Emitter } from 'pubo-utils';
2
+
3
+ var WebsocketClient =
4
+ /** @class */
5
+ function () {
6
+ function WebsocketClient(_a) {
7
+ var url = _a.url;
8
+ this._status = 0;
9
+ this.url = '';
10
+ this.emitter = new Emitter();
11
+ this.url = url;
12
+ this.connect();
13
+ }
14
+
15
+ WebsocketClient.prototype.reconnect = function () {
16
+ var _this = this;
17
+
18
+ if (this._status === 3) {
19
+ setTimeout(function () {
20
+ _this.connect();
21
+ }, 1000);
22
+ }
23
+ };
24
+
25
+ WebsocketClient.prototype.onClose = function () {
26
+ if (this._status !== 2) {
27
+ this._status = 3;
28
+ }
29
+
30
+ this.reconnect();
31
+ };
32
+
33
+ WebsocketClient.prototype.onMessage = function (e) {
34
+ this.emitter.emit('message', e.data);
35
+ };
36
+
37
+ WebsocketClient.prototype.connect = function () {
38
+ var _this = this;
39
+
40
+ this.client = new WebSocket(this.url);
41
+ this.client.onclose = this.onClose.bind(this);
42
+ this.client.onmessage = this.onMessage.bind(this);
43
+
44
+ this.client.onopen = function () {
45
+ _this._status = 1;
46
+ };
47
+ };
48
+
49
+ WebsocketClient.prototype.close = function () {
50
+ if (this.client) {
51
+ this.client.close();
52
+ this.client = null;
53
+ this._status = 2;
54
+ }
55
+ };
56
+
57
+ return WebsocketClient;
58
+ }();
59
+
60
+ export default WebsocketClient;
@@ -1,4 +1,4 @@
1
- import { RosConfigure } from '../factory/configure';
1
+ import type { RosConfigure } from '../factory/configure';
2
2
  import { InjectUtil } from './inject';
3
3
  interface InitProps {
4
4
  elem: any;
@@ -0,0 +1,15 @@
1
+ import { Emitter } from 'pubo-utils';
2
+ export default class WebsocketClient {
3
+ private client;
4
+ private _status;
5
+ private readonly url;
6
+ emitter: Emitter;
7
+ constructor({ url }: {
8
+ url: any;
9
+ });
10
+ private reconnect;
11
+ private onClose;
12
+ private onMessage;
13
+ connect(): void;
14
+ close(): void;
15
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var pubo_utils_1 = require("pubo-utils");
8
+
9
+ var WebsocketClient =
10
+ /** @class */
11
+ function () {
12
+ function WebsocketClient(_a) {
13
+ var url = _a.url;
14
+ this._status = 0;
15
+ this.url = '';
16
+ this.emitter = new pubo_utils_1.Emitter();
17
+ this.url = url;
18
+ this.connect();
19
+ }
20
+
21
+ WebsocketClient.prototype.reconnect = function () {
22
+ var _this = this;
23
+
24
+ if (this._status === 3) {
25
+ setTimeout(function () {
26
+ _this.connect();
27
+ }, 1000);
28
+ }
29
+ };
30
+
31
+ WebsocketClient.prototype.onClose = function () {
32
+ if (this._status !== 2) {
33
+ this._status = 3;
34
+ }
35
+
36
+ this.reconnect();
37
+ };
38
+
39
+ WebsocketClient.prototype.onMessage = function (e) {
40
+ this.emitter.emit('message', e.data);
41
+ };
42
+
43
+ WebsocketClient.prototype.connect = function () {
44
+ var _this = this;
45
+
46
+ this.client = new WebSocket(this.url);
47
+ this.client.onclose = this.onClose.bind(this);
48
+ this.client.onmessage = this.onMessage.bind(this);
49
+
50
+ this.client.onopen = function () {
51
+ _this._status = 1;
52
+ };
53
+ };
54
+
55
+ WebsocketClient.prototype.close = function () {
56
+ if (this.client) {
57
+ this.client.close();
58
+ this.client = null;
59
+ this._status = 2;
60
+ }
61
+ };
62
+
63
+ return WebsocketClient;
64
+ }();
65
+
66
+ exports["default"] = WebsocketClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.5-alpha.0",
3
+ "version": "1.0.10",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.5-alpha.0",
22
+ "pubo-utils": "^1.0.10",
23
23
  "roslib": "^1.2.0"
24
24
  },
25
- "gitHead": "0adede4ec5ab594ec9df7b5415e29690d138052b"
25
+ "gitHead": "64ad9dbebbf1770915c08294f09ec0e37d824adf"
26
26
  }