@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406263",
4
+ "version": "0.1.230406265",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
package/src/utils/wss.js CHANGED
@@ -128,6 +128,7 @@ class WSS extends EventEmitter2{
128
128
  }
129
129
 
130
130
  socket.on('message', async (binaryData) => {
131
+ console.log('message#1', socket.isAuth)
131
132
  if(!socket.isAuth) return
132
133
 
133
134
  let obj
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
- if(this._instance.readyState === 0){
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.readyState !== 1){
190
- console.log('unable to send, ready state not 1', this._instance.readyState)
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] = {