reverb-ws-client 1.0.2 → 1.0.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +31 -7
- package/dist/index.mjs +31 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -96,11 +96,34 @@ var Channel = class {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
// src/logger.ts
|
|
100
|
+
var Logger = class {
|
|
101
|
+
constructor(options = {}) {
|
|
102
|
+
this.options = options;
|
|
103
|
+
}
|
|
104
|
+
options;
|
|
105
|
+
log(...args) {
|
|
106
|
+
if (!this.options.debug) return;
|
|
107
|
+
console.log(...args);
|
|
108
|
+
}
|
|
109
|
+
warn(...args) {
|
|
110
|
+
if (!this.options.debug) return;
|
|
111
|
+
console.warn(...args);
|
|
112
|
+
}
|
|
113
|
+
error(...args) {
|
|
114
|
+
if (!this.options.debug) return;
|
|
115
|
+
console.error(...args);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
99
119
|
// src/ConnectionManager.ts
|
|
100
120
|
var ConnectionManager = class {
|
|
101
121
|
constructor(options, onMessage) {
|
|
102
122
|
this.options = options;
|
|
103
123
|
this.onMessage = onMessage;
|
|
124
|
+
this.logger = new Logger({
|
|
125
|
+
debug: options.debug ?? false
|
|
126
|
+
});
|
|
104
127
|
}
|
|
105
128
|
options;
|
|
106
129
|
onMessage;
|
|
@@ -110,6 +133,7 @@ var ConnectionManager = class {
|
|
|
110
133
|
maxReconnectAttempts = 5;
|
|
111
134
|
reconnectDelay = 2e3;
|
|
112
135
|
manuallyDisconnected = false;
|
|
136
|
+
logger;
|
|
113
137
|
connect() {
|
|
114
138
|
if (this.state === "connecting" || this.state === "connected") return;
|
|
115
139
|
this.manuallyDisconnected = false;
|
|
@@ -119,23 +143,23 @@ var ConnectionManager = class {
|
|
|
119
143
|
this.ws.onopen = () => {
|
|
120
144
|
this.state = "connected";
|
|
121
145
|
this.reconnectAttempts = 0;
|
|
122
|
-
|
|
146
|
+
this.logger.log("[Reverb] Connected");
|
|
123
147
|
};
|
|
124
148
|
this.ws.onmessage = (event) => {
|
|
125
149
|
try {
|
|
126
150
|
const parsed = JSON.parse(event.data);
|
|
127
151
|
this.onMessage(parsed);
|
|
128
152
|
} catch (err) {
|
|
129
|
-
|
|
153
|
+
this.logger.warn("[Reverb] WebSocket error", err);
|
|
130
154
|
}
|
|
131
155
|
};
|
|
132
156
|
this.ws.onerror = (err) => {
|
|
133
|
-
|
|
157
|
+
this.logger.warn("[Reverb] WebSocket error", err);
|
|
134
158
|
};
|
|
135
159
|
this.ws.onclose = () => {
|
|
136
160
|
this.ws = null;
|
|
137
161
|
this.state = "disconnected";
|
|
138
|
-
|
|
162
|
+
this.logger.log("[Reverb] Disconnected");
|
|
139
163
|
if (!this.manuallyDisconnected) {
|
|
140
164
|
this.reconnect();
|
|
141
165
|
}
|
|
@@ -151,7 +175,7 @@ var ConnectionManager = class {
|
|
|
151
175
|
}
|
|
152
176
|
send(data) {
|
|
153
177
|
if (!this.ws || this.state !== "connected") {
|
|
154
|
-
|
|
178
|
+
this.logger.warn("[Reverb] Cannot send, socket not connected");
|
|
155
179
|
return;
|
|
156
180
|
}
|
|
157
181
|
this.ws.send(JSON.stringify(data));
|
|
@@ -166,13 +190,13 @@ var ConnectionManager = class {
|
|
|
166
190
|
}
|
|
167
191
|
reconnect() {
|
|
168
192
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
169
|
-
|
|
193
|
+
this.logger.warn("[Reverb] Max reconnect attempts reached");
|
|
170
194
|
return;
|
|
171
195
|
}
|
|
172
196
|
this.state = "reconnecting";
|
|
173
197
|
this.reconnectAttempts++;
|
|
174
198
|
setTimeout(() => {
|
|
175
|
-
|
|
199
|
+
this.logger.log("[Reverb] Reconnecting...");
|
|
176
200
|
this.connect();
|
|
177
201
|
}, this.reconnectDelay);
|
|
178
202
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -70,11 +70,34 @@ var Channel = class {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
// src/logger.ts
|
|
74
|
+
var Logger = class {
|
|
75
|
+
constructor(options = {}) {
|
|
76
|
+
this.options = options;
|
|
77
|
+
}
|
|
78
|
+
options;
|
|
79
|
+
log(...args) {
|
|
80
|
+
if (!this.options.debug) return;
|
|
81
|
+
console.log(...args);
|
|
82
|
+
}
|
|
83
|
+
warn(...args) {
|
|
84
|
+
if (!this.options.debug) return;
|
|
85
|
+
console.warn(...args);
|
|
86
|
+
}
|
|
87
|
+
error(...args) {
|
|
88
|
+
if (!this.options.debug) return;
|
|
89
|
+
console.error(...args);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
73
93
|
// src/ConnectionManager.ts
|
|
74
94
|
var ConnectionManager = class {
|
|
75
95
|
constructor(options, onMessage) {
|
|
76
96
|
this.options = options;
|
|
77
97
|
this.onMessage = onMessage;
|
|
98
|
+
this.logger = new Logger({
|
|
99
|
+
debug: options.debug ?? false
|
|
100
|
+
});
|
|
78
101
|
}
|
|
79
102
|
options;
|
|
80
103
|
onMessage;
|
|
@@ -84,6 +107,7 @@ var ConnectionManager = class {
|
|
|
84
107
|
maxReconnectAttempts = 5;
|
|
85
108
|
reconnectDelay = 2e3;
|
|
86
109
|
manuallyDisconnected = false;
|
|
110
|
+
logger;
|
|
87
111
|
connect() {
|
|
88
112
|
if (this.state === "connecting" || this.state === "connected") return;
|
|
89
113
|
this.manuallyDisconnected = false;
|
|
@@ -93,23 +117,23 @@ var ConnectionManager = class {
|
|
|
93
117
|
this.ws.onopen = () => {
|
|
94
118
|
this.state = "connected";
|
|
95
119
|
this.reconnectAttempts = 0;
|
|
96
|
-
|
|
120
|
+
this.logger.log("[Reverb] Connected");
|
|
97
121
|
};
|
|
98
122
|
this.ws.onmessage = (event) => {
|
|
99
123
|
try {
|
|
100
124
|
const parsed = JSON.parse(event.data);
|
|
101
125
|
this.onMessage(parsed);
|
|
102
126
|
} catch (err) {
|
|
103
|
-
|
|
127
|
+
this.logger.warn("[Reverb] WebSocket error", err);
|
|
104
128
|
}
|
|
105
129
|
};
|
|
106
130
|
this.ws.onerror = (err) => {
|
|
107
|
-
|
|
131
|
+
this.logger.warn("[Reverb] WebSocket error", err);
|
|
108
132
|
};
|
|
109
133
|
this.ws.onclose = () => {
|
|
110
134
|
this.ws = null;
|
|
111
135
|
this.state = "disconnected";
|
|
112
|
-
|
|
136
|
+
this.logger.log("[Reverb] Disconnected");
|
|
113
137
|
if (!this.manuallyDisconnected) {
|
|
114
138
|
this.reconnect();
|
|
115
139
|
}
|
|
@@ -125,7 +149,7 @@ var ConnectionManager = class {
|
|
|
125
149
|
}
|
|
126
150
|
send(data) {
|
|
127
151
|
if (!this.ws || this.state !== "connected") {
|
|
128
|
-
|
|
152
|
+
this.logger.warn("[Reverb] Cannot send, socket not connected");
|
|
129
153
|
return;
|
|
130
154
|
}
|
|
131
155
|
this.ws.send(JSON.stringify(data));
|
|
@@ -140,13 +164,13 @@ var ConnectionManager = class {
|
|
|
140
164
|
}
|
|
141
165
|
reconnect() {
|
|
142
166
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
143
|
-
|
|
167
|
+
this.logger.warn("[Reverb] Max reconnect attempts reached");
|
|
144
168
|
return;
|
|
145
169
|
}
|
|
146
170
|
this.state = "reconnecting";
|
|
147
171
|
this.reconnectAttempts++;
|
|
148
172
|
setTimeout(() => {
|
|
149
|
-
|
|
173
|
+
this.logger.log("[Reverb] Reconnecting...");
|
|
150
174
|
this.connect();
|
|
151
175
|
}, this.reconnectDelay);
|
|
152
176
|
}
|