@mixd-id/web-scaffold 0.1.230406264 → 0.1.230406265
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.mjs +0 -42
package/package.json
CHANGED
package/src/utils/wss.mjs
CHANGED
|
@@ -45,7 +45,6 @@ class WSS extends EventEmitter2{
|
|
|
45
45
|
_counter = 0
|
|
46
46
|
_callbacks = {}
|
|
47
47
|
_pendingSend = []
|
|
48
|
-
_lastBlurAt
|
|
49
48
|
|
|
50
49
|
constructor(opt) {
|
|
51
50
|
super();
|
|
@@ -58,40 +57,9 @@ class WSS extends EventEmitter2{
|
|
|
58
57
|
url: '',
|
|
59
58
|
}, opt ?? {})
|
|
60
59
|
|
|
61
|
-
/*if(typeof window !== 'undefined'){
|
|
62
|
-
window.addEventListener('online', this._onOnlineChanged)
|
|
63
|
-
window.addEventListener('offline', this._onOnlineChanged)
|
|
64
|
-
window.addEventListener('blur', this._onBlur)
|
|
65
|
-
window.addEventListener('focus', this._onFocus)
|
|
66
|
-
}*/
|
|
67
|
-
|
|
68
60
|
this.connect().then()
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
_onBlur = () => {
|
|
72
|
-
this._lastBlurAt = new Date().getTime()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
_onFocus = () => {
|
|
76
|
-
this.emit('window', 'focus', [])
|
|
77
|
-
|
|
78
|
-
if(this._lastBlurAt){
|
|
79
|
-
this.send('ping', {}, { timeout:1000 })
|
|
80
|
-
.catch(_ => {
|
|
81
|
-
this.reconnect().then()
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_onOnlineChanged = (e) => {
|
|
87
|
-
if(!navigator.onLine){
|
|
88
|
-
this.emit('disconnect', e, [])
|
|
89
|
-
}
|
|
90
|
-
else{
|
|
91
|
-
this.emit('connect', null, [])
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
63
|
async fromBinaryData(binaryData){
|
|
96
64
|
const encryptedString = new TextDecoder().decode(binaryData)
|
|
97
65
|
const decryptedData = this._opt.key ?
|
|
@@ -123,7 +91,6 @@ class WSS extends EventEmitter2{
|
|
|
123
91
|
|
|
124
92
|
reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
|
|
125
93
|
|
|
126
|
-
console.log('pending send', this._pendingSend)
|
|
127
94
|
for(let sendParams of this._pendingSend){
|
|
128
95
|
this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
|
|
129
96
|
}
|
|
@@ -184,8 +151,6 @@ class WSS extends EventEmitter2{
|
|
|
184
151
|
}
|
|
185
152
|
|
|
186
153
|
sendSync(path, params, cb, err, override){
|
|
187
|
-
console.log('sendSync', path, this._instance.readyState)
|
|
188
|
-
|
|
189
154
|
if(this._instance.readyState > 1){
|
|
190
155
|
console.log('unable to send, ready state not 1', this._instance.readyState)
|
|
191
156
|
return
|
|
@@ -211,7 +176,6 @@ class WSS extends EventEmitter2{
|
|
|
211
176
|
.then(async(dataUrlObj) => {
|
|
212
177
|
|
|
213
178
|
const binaryData = await this.toBinaryData(dataUrlObj)
|
|
214
|
-
console.log('sendSync', this._instance.readyState, dataUrlObj)
|
|
215
179
|
this._instance.send(binaryData)
|
|
216
180
|
|
|
217
181
|
this._callbacks[_requestId] = {
|
|
@@ -239,12 +203,6 @@ class WSS extends EventEmitter2{
|
|
|
239
203
|
})
|
|
240
204
|
}
|
|
241
205
|
|
|
242
|
-
async resume(){
|
|
243
|
-
if(this._instance.readyState > 1){
|
|
244
|
-
return this.reconnect()
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
206
|
}
|
|
249
207
|
|
|
250
208
|
export {
|