@mixd-id/web-scaffold 0.1.240411109 → 0.1.240411111
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/package.json +1 -1
- package/src/utils/wss.js +10 -5
- package/src/utils/wss.mjs +6 -1
package/package.json
CHANGED
package/src/utils/wss.js
CHANGED
|
@@ -68,6 +68,8 @@ const revertDataUrlObj = (obj) => {
|
|
|
68
68
|
const isClosedError = (e) =>
|
|
69
69
|
e && (e.message === 'Disconnects client' || e.message === 'The client is closed')
|
|
70
70
|
|
|
71
|
+
const REJECT_CLOSE_CODE = 4001
|
|
72
|
+
|
|
71
73
|
const reportError = (e) => {
|
|
72
74
|
if(isClosedError(e)) return
|
|
73
75
|
'$report' in process ? process.$report(e) : console.error(e)
|
|
@@ -134,7 +136,11 @@ class WSS extends EventEmitter2{
|
|
|
134
136
|
|
|
135
137
|
// Protocol errors (e.g. invalid close codes) emit 'error'; without a
|
|
136
138
|
// listener they crash the process. ws closes the socket afterwards.
|
|
137
|
-
|
|
139
|
+
// WS_ERR_* are malformed frames from the client — not worth reporting.
|
|
140
|
+
socket.on('error', (e) => {
|
|
141
|
+
if(`${e?.code ?? ''}`.startsWith('WS_ERR_')) return
|
|
142
|
+
reportError(e)
|
|
143
|
+
})
|
|
138
144
|
|
|
139
145
|
let closed = false
|
|
140
146
|
|
|
@@ -215,8 +221,6 @@ class WSS extends EventEmitter2{
|
|
|
215
221
|
subscriber = client
|
|
216
222
|
await client.connect()
|
|
217
223
|
|
|
218
|
-
// Socket closed while authenticating/connecting: the close handler may
|
|
219
|
-
// have run before the client was open, so release it here.
|
|
220
224
|
if(closed){
|
|
221
225
|
disconnectQuietly(client)
|
|
222
226
|
return
|
|
@@ -228,7 +232,7 @@ class WSS extends EventEmitter2{
|
|
|
228
232
|
catch(e){
|
|
229
233
|
disconnectQuietly(subscriber)
|
|
230
234
|
if(closed) return
|
|
231
|
-
return socket.close(
|
|
235
|
+
return socket.close(REJECT_CLOSE_CODE, (e.message ?? '').substring(0, 123));
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
if(this._opt.ping !== false && !closed){
|
|
@@ -285,7 +289,7 @@ class WSS extends EventEmitter2{
|
|
|
285
289
|
if(typeof obj !== 'object' || obj === null) throw new Error('Invalid message')
|
|
286
290
|
}
|
|
287
291
|
catch(e){
|
|
288
|
-
return socket.close(
|
|
292
|
+
return socket.close(REJECT_CLOSE_CODE, (e.message ?? '').substring(0, 123));
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
const { _requestId, path, params, ping, pong } = obj
|
|
@@ -439,6 +443,7 @@ class WSS extends EventEmitter2{
|
|
|
439
443
|
|
|
440
444
|
module.exports = {
|
|
441
445
|
WSS,
|
|
446
|
+
REJECT_CLOSE_CODE,
|
|
442
447
|
convertDataUrlObj,
|
|
443
448
|
revertDataUrlObj
|
|
444
449
|
}
|
package/src/utils/wss.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import CryptoJS from "crypto-js";
|
|
2
2
|
import EventEmitter2 from "eventemitter2";
|
|
3
3
|
|
|
4
|
+
// Must match REJECT_CLOSE_CODE in wss.js
|
|
5
|
+
const REJECT_CLOSE_CODE = 4001
|
|
6
|
+
|
|
4
7
|
const fileToDataURL = (file) => {
|
|
5
8
|
return new Promise((resolve, reject) => {
|
|
6
9
|
const reader = new FileReader();
|
|
@@ -157,7 +160,8 @@ class WSS extends EventEmitter2{
|
|
|
157
160
|
this._instance.onclose = (e) => {
|
|
158
161
|
switch(e.code){
|
|
159
162
|
|
|
160
|
-
|
|
163
|
+
// Rejected by server (auth failure etc.), retrying won't help
|
|
164
|
+
case REJECT_CLOSE_CODE:
|
|
161
165
|
this.emit('connect_error', e, [])
|
|
162
166
|
break
|
|
163
167
|
|
|
@@ -280,6 +284,7 @@ class WSS extends EventEmitter2{
|
|
|
280
284
|
|
|
281
285
|
export {
|
|
282
286
|
WSS,
|
|
287
|
+
REJECT_CLOSE_CODE,
|
|
283
288
|
fileToDataURL,
|
|
284
289
|
convertDataUrlObj
|
|
285
290
|
}
|