larasopp 1.2.0 → 1.2.3

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
@@ -61,10 +61,6 @@ class Core {
61
61
  * @returns {this}
62
62
  */
63
63
  connect() {
64
- if (!navigator.onLine) {
65
- setTimeout(this.connect.bind(this), 5000);
66
- return this;
67
- }
68
64
  try {
69
65
  const host = [(this.config.tls ? 'wss' : 'ws') + '://'];
70
66
  host.push(this.config.host);
@@ -93,7 +89,7 @@ class Core {
93
89
  (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
94
90
  this._status = false;
95
91
  }
96
- this.ws = null;
92
+ this.ws = undefined;
97
93
  }
98
94
  isJson(str) {
99
95
  try {
@@ -137,6 +133,8 @@ class Core {
137
133
  return this._socketId;
138
134
  }
139
135
  get status() {
136
+ if (!this._status)
137
+ this.connect();
140
138
  return this._status;
141
139
  }
142
140
  _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.3",
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;
@@ -52,7 +52,7 @@ abstract class Core {
52
52
  ...config,
53
53
  };
54
54
  this._status = false;
55
-
55
+
56
56
  this.handleOpen = this.handleOpen.bind(this);
57
57
  this.handleClose = this.handleClose.bind(this);
58
58
  this.handleError = this.handleError.bind(this);
@@ -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) {