larasopp 1.2.6 → 1.2.7
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/README.md +3 -1
- package/lib/Core.d.ts +1 -2
- package/lib/Core.js +5 -6
- package/package.json +1 -1
- package/src/Core.ts +5 -13
package/README.md
CHANGED
|
@@ -16,11 +16,13 @@ composer require larasopp/larasopp
|
|
|
16
16
|
import Larasopp from "Larasopp";
|
|
17
17
|
|
|
18
18
|
const larasopp = new Larasopp({
|
|
19
|
-
host: '127.0.0.1:
|
|
19
|
+
host: 'ws://127.0.0.1:3001',
|
|
20
20
|
token: 'token'
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
larasopp.connect();
|
|
24
|
+
//or
|
|
25
|
+
larasopp.connect('token');
|
|
24
26
|
|
|
25
27
|
```
|
|
26
28
|
|
package/lib/Core.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export type TConfigDataReviver = {
|
|
|
26
26
|
export interface IConfig {
|
|
27
27
|
host: string;
|
|
28
28
|
token?: string;
|
|
29
|
-
tls?: boolean;
|
|
30
29
|
reviver?: (this: any, key: string, value: any) => any;
|
|
31
30
|
dataReviver?: TConfigDataReviver;
|
|
32
31
|
}
|
|
@@ -45,7 +44,7 @@ declare abstract class Core {
|
|
|
45
44
|
* Connect to websocket
|
|
46
45
|
* @returns {this}
|
|
47
46
|
*/
|
|
48
|
-
connect(): this;
|
|
47
|
+
connect(token?: string): this;
|
|
49
48
|
/**
|
|
50
49
|
* Disconnect
|
|
51
50
|
* @returns {void}
|
package/lib/Core.js
CHANGED
|
@@ -34,14 +34,14 @@ class Core {
|
|
|
34
34
|
value: void 0
|
|
35
35
|
});
|
|
36
36
|
this.events = new easy_event_emitter_1.default;
|
|
37
|
-
this.config =
|
|
37
|
+
this.config = config;
|
|
38
38
|
this.handleOpen = this.handleOpen.bind(this);
|
|
39
39
|
this.handleClose = this.handleClose.bind(this);
|
|
40
40
|
this.handleError = this.handleError.bind(this);
|
|
41
41
|
this.handleMessage = this.handleMessage.bind(this);
|
|
42
42
|
}
|
|
43
43
|
setConfig(config) {
|
|
44
|
-
this.config =
|
|
44
|
+
this.config = config;
|
|
45
45
|
}
|
|
46
46
|
setToken(token) {
|
|
47
47
|
this.config = Object.assign(Object.assign({}, this.config), { token });
|
|
@@ -53,12 +53,11 @@ class Core {
|
|
|
53
53
|
* Connect to websocket
|
|
54
54
|
* @returns {this}
|
|
55
55
|
*/
|
|
56
|
-
connect() {
|
|
56
|
+
connect(token) {
|
|
57
57
|
try {
|
|
58
|
-
const host = [
|
|
59
|
-
host.push(this.config.host);
|
|
58
|
+
const host = [this.config.host];
|
|
60
59
|
if (this.config.token)
|
|
61
|
-
host.push('/token=' + this.config.token);
|
|
60
|
+
host.push('/token=' + (token !== null && token !== void 0 ? token : this.config.token));
|
|
62
61
|
this.ws = new WebSocket(host.join(''));
|
|
63
62
|
this.ws.onopen = this.handleOpen;
|
|
64
63
|
this.ws.onclose = this.handleClose;
|
package/package.json
CHANGED
package/src/Core.ts
CHANGED
|
@@ -34,7 +34,6 @@ export type TConfigDataReviver = {
|
|
|
34
34
|
export interface IConfig {
|
|
35
35
|
host: string;
|
|
36
36
|
token?: string;
|
|
37
|
-
tls?: boolean;
|
|
38
37
|
reviver?: (this: any, key: string, value: any) => any;
|
|
39
38
|
dataReviver?: TConfigDataReviver;
|
|
40
39
|
}
|
|
@@ -52,10 +51,7 @@ abstract class Core {
|
|
|
52
51
|
constructor(config: IConfig) {
|
|
53
52
|
this.events = new EventEmitter;
|
|
54
53
|
|
|
55
|
-
this.config =
|
|
56
|
-
tls: false,
|
|
57
|
-
...config,
|
|
58
|
-
};
|
|
54
|
+
this.config = config;
|
|
59
55
|
|
|
60
56
|
this.handleOpen = this.handleOpen.bind(this);
|
|
61
57
|
this.handleClose = this.handleClose.bind(this);
|
|
@@ -64,10 +60,7 @@ abstract class Core {
|
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
public setConfig(config: IConfig): void {
|
|
67
|
-
this.config =
|
|
68
|
-
tls: false,
|
|
69
|
-
...config,
|
|
70
|
-
};
|
|
63
|
+
this.config = config;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
public setToken(token: string): void {
|
|
@@ -84,11 +77,10 @@ abstract class Core {
|
|
|
84
77
|
* Connect to websocket
|
|
85
78
|
* @returns {this}
|
|
86
79
|
*/
|
|
87
|
-
public connect(): this {
|
|
80
|
+
public connect(token?: string): this {
|
|
88
81
|
try {
|
|
89
|
-
const host = [
|
|
90
|
-
host.push(this.config.
|
|
91
|
-
if (this.config.token) host.push('/token=' + this.config.token);
|
|
82
|
+
const host = [this.config.host];
|
|
83
|
+
if (this.config.token) host.push('/token=' + (token ?? this.config.token));
|
|
92
84
|
|
|
93
85
|
this.ws = new WebSocket(host.join(''));
|
|
94
86
|
this.ws.onopen = this.handleOpen;
|