larasopp 1.2.15 → 1.2.16
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.
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +10 -4
- package/package.json +1 -1
- package/src/Core.ts +11 -6
package/lib/Core.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ declare abstract class Core {
|
|
|
7
7
|
private config;
|
|
8
8
|
private reconnectCount;
|
|
9
9
|
constructor(config: IConfig);
|
|
10
|
-
setConfig(config: IConfig):
|
|
11
|
-
setToken(token: string):
|
|
10
|
+
setConfig(config: IConfig): this;
|
|
11
|
+
setToken(token: string): this;
|
|
12
12
|
/**
|
|
13
13
|
* Connect to websocket
|
|
14
14
|
* @returns {this}
|
package/lib/Core.js
CHANGED
|
@@ -47,12 +47,16 @@ class Core {
|
|
|
47
47
|
}
|
|
48
48
|
setConfig(config) {
|
|
49
49
|
this.config = config;
|
|
50
|
+
return this;
|
|
50
51
|
}
|
|
51
52
|
setToken(token) {
|
|
52
53
|
this.config = Object.assign(Object.assign({}, this.config), { token });
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (this.status) {
|
|
55
|
+
this.send({
|
|
56
|
+
token
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* Connect to websocket
|
|
@@ -62,7 +66,9 @@ class Core {
|
|
|
62
66
|
if (this.status)
|
|
63
67
|
return this;
|
|
64
68
|
try {
|
|
65
|
-
|
|
69
|
+
if (token)
|
|
70
|
+
this.setToken(token);
|
|
71
|
+
const host = this.config.host + '/token=' + this.config.token;
|
|
66
72
|
this.ws = new WebSocket(encodeURI(host));
|
|
67
73
|
this.ws.onopen = this.handleOpen;
|
|
68
74
|
this.ws.onclose = this.handleClose;
|
package/package.json
CHANGED
package/src/Core.ts
CHANGED
|
@@ -26,18 +26,22 @@ abstract class Core {
|
|
|
26
26
|
this.handleMessage = this.handleMessage.bind(this);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
public setConfig(config: IConfig)
|
|
29
|
+
public setConfig(config: IConfig) {
|
|
30
30
|
this.config = config;
|
|
31
|
+
return this;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
public setToken(token: string)
|
|
34
|
+
public setToken(token: string) {
|
|
34
35
|
this.config = {
|
|
35
36
|
...this.config,
|
|
36
37
|
token
|
|
37
38
|
};
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (this.status) {
|
|
40
|
+
this.send({
|
|
41
|
+
token
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
/**
|
|
@@ -47,7 +51,8 @@ abstract class Core {
|
|
|
47
51
|
public connect(token?: string): this {
|
|
48
52
|
if (this.status) return this;
|
|
49
53
|
try {
|
|
50
|
-
|
|
54
|
+
if (token) this.setToken(token);
|
|
55
|
+
const host = this.config.host + '/token=' + this.config.token;
|
|
51
56
|
this.ws = new WebSocket(encodeURI(host));
|
|
52
57
|
this.ws.onopen = this.handleOpen;
|
|
53
58
|
this.ws.onclose = this.handleClose;
|