larasopp 1.2.0 → 1.2.2

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.js CHANGED
@@ -93,7 +93,7 @@ class Core {
93
93
  (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
94
94
  this._status = false;
95
95
  }
96
- this.ws = null;
96
+ this.ws = undefined;
97
97
  }
98
98
  isJson(str) {
99
99
  try {
@@ -137,6 +137,8 @@ class Core {
137
137
  return this._socketId;
138
138
  }
139
139
  get status() {
140
+ if (!this._status)
141
+ this.connect();
140
142
  return this._status;
141
143
  }
142
144
  _send(message) {
package/lib/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import Listener from "./Listener";
4
4
  declare class Larasopp extends Core {
5
5
  private readonly channels;
6
6
  constructor(config: IConfig);
7
+ private listenResumeSubscribes;
7
8
  subscribe(channel: string): Listener;
8
9
  unsubscribe(channel: string): void;
9
10
  trigger<T>(channel: string, event: string, message: T, permission?: TPermissions, waitSubscribe?: boolean): void;
package/lib/index.js CHANGED
@@ -38,6 +38,14 @@ class Larasopp extends Core_1.default {
38
38
  value: void 0
39
39
  });
40
40
  this.channels = {};
41
+ this.listenResumeSubscribes();
42
+ }
43
+ listenResumeSubscribes() {
44
+ this.addListener('open', () => {
45
+ Object.keys(this.channels).forEach((channel) => this.send({
46
+ subscribe: channel
47
+ }));
48
+ });
41
49
  }
42
50
  subscribe(channel) {
43
51
  const listener = new Listener_1.default(channel, this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larasopp",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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
@@ -39,7 +39,7 @@ export type TChannels = {
39
39
 
40
40
  abstract class Core {
41
41
  public readonly events: Events;
42
- private ws?: WebSocket | null;
42
+ private ws?: WebSocket;
43
43
  protected _status: boolean;
44
44
  private _socketId?: string;
45
45
  private config: IConfig;
@@ -81,12 +81,6 @@ abstract class Core {
81
81
  * @returns {this}
82
82
  */
83
83
  public connect(): this {
84
-
85
- if (!navigator.onLine) {
86
- setTimeout(this.connect.bind(this), 5000);
87
- return this;
88
- }
89
-
90
84
  try {
91
85
  const host = [(this.config.tls ? 'wss' : 'ws') + '://'];
92
86
  host.push(this.config.host);
@@ -115,7 +109,7 @@ abstract class Core {
115
109
  this.ws?.close();
116
110
  this._status = false;
117
111
  }
118
- this.ws = null;
112
+ this.ws = undefined;
119
113
  }
120
114
 
121
115
  protected isJson(str: string) {
@@ -166,6 +160,7 @@ abstract class Core {
166
160
  }
167
161
 
168
162
  public get status(): boolean {
163
+ if (!this._status) this.connect();
169
164
  return this._status;
170
165
  }
171
166
 
package/src/index.ts CHANGED
@@ -19,6 +19,16 @@ class Larasopp extends Core {
19
19
  super(config);
20
20
 
21
21
  this.channels = {};
22
+
23
+ this.listenResumeSubscribes();
24
+ }
25
+
26
+ private listenResumeSubscribes() {
27
+ this.addListener('open', () => {
28
+ Object.keys(this.channels).forEach((channel) => this.send({
29
+ subscribe: channel
30
+ }));
31
+ });
22
32
  }
23
33
 
24
34
  public subscribe(channel: string) {