larasopp 1.2.6 → 1.2.8

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 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:9002',
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 = Object.assign({ tls: false }, 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 = Object.assign({ tls: false }, config);
44
+ this.config = config;
45
45
  }
46
46
  setToken(token) {
47
47
  this.config = Object.assign(Object.assign({}, this.config), { token });
@@ -53,13 +53,10 @@ class Core {
53
53
  * Connect to websocket
54
54
  * @returns {this}
55
55
  */
56
- connect() {
56
+ connect(token) {
57
57
  try {
58
- const host = [(this.config.tls ? 'wss' : 'ws') + '://'];
59
- host.push(this.config.host);
60
- if (this.config.token)
61
- host.push('/token=' + this.config.token);
62
- this.ws = new WebSocket(host.join(''));
58
+ const host = this.config.host + '/token=' + (token !== null && token !== void 0 ? token : this.config.token);
59
+ this.ws = new WebSocket(encodeURI(host));
63
60
  this.ws.onopen = this.handleOpen;
64
61
  this.ws.onclose = this.handleClose;
65
62
  this.ws.onerror = this.handleError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larasopp",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Websocket client for laravel",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
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,13 +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 = [(this.config.tls ? 'wss' : 'ws') + '://'];
90
- host.push(this.config.host);
91
- if (this.config.token) host.push('/token=' + this.config.token);
92
-
93
- this.ws = new WebSocket(host.join(''));
82
+ const host = this.config.host + '/token=' + (token ?? this.config.token);
83
+ this.ws = new WebSocket(encodeURI(host));
94
84
  this.ws.onopen = this.handleOpen;
95
85
  this.ws.onclose = this.handleClose;
96
86
  this.ws.onerror = this.handleError;