@mixd-id/web-scaffold 0.1.230406263 → 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.js +1 -0
- package/src/utils/wss.mjs +7 -38
package/package.json
CHANGED
package/src/utils/wss.js
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 ?
|
|
@@ -119,6 +87,8 @@ class WSS extends EventEmitter2{
|
|
|
119
87
|
const { _requestId, status, data, auth } = obj
|
|
120
88
|
|
|
121
89
|
if(auth){
|
|
90
|
+
this._instance.isAuth = auth
|
|
91
|
+
|
|
122
92
|
reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
|
|
123
93
|
|
|
124
94
|
for(let sendParams of this._pendingSend){
|
|
@@ -181,13 +151,13 @@ class WSS extends EventEmitter2{
|
|
|
181
151
|
}
|
|
182
152
|
|
|
183
153
|
sendSync(path, params, cb, err, override){
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this._pendingSend.push({ path, params, cb, err })
|
|
154
|
+
if(this._instance.readyState > 1){
|
|
155
|
+
console.log('unable to send, ready state not 1', this._instance.readyState)
|
|
187
156
|
return
|
|
188
157
|
}
|
|
189
|
-
else if(this._instance.
|
|
190
|
-
console.log('
|
|
158
|
+
else if(!this._instance.isAuth){
|
|
159
|
+
console.log('add pending send', { path, params, cb, err })
|
|
160
|
+
this._pendingSend.push({ path, params, cb, err })
|
|
191
161
|
return
|
|
192
162
|
}
|
|
193
163
|
|
|
@@ -206,7 +176,6 @@ class WSS extends EventEmitter2{
|
|
|
206
176
|
.then(async(dataUrlObj) => {
|
|
207
177
|
|
|
208
178
|
const binaryData = await this.toBinaryData(dataUrlObj)
|
|
209
|
-
console.log('sendSync', this._instance.readyState, dataUrlObj)
|
|
210
179
|
this._instance.send(binaryData)
|
|
211
180
|
|
|
212
181
|
this._callbacks[_requestId] = {
|