@mixd-id/web-scaffold 0.1.230406262 → 0.1.230406264

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.230406262",
4
+ "version": "0.1.230406264",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -480,8 +480,6 @@ export default{
480
480
 
481
481
  .comp{
482
482
  @apply flex flex-col p-2;
483
- @apply backdrop-blur-lg;
484
- padding-bottom: 50px;
485
483
  }
486
484
 
487
485
  </style>
@@ -133,11 +133,12 @@
133
133
  <script>
134
134
 
135
135
  import VirtualTable from "./VirtualTable.vue";
136
+ import VirtualGrid from "./VirtualGrid.vue";
136
137
  import throttle from "lodash/throttle";
137
138
  import PresetSelector from "../widgets/PresetSelector.vue";
138
139
  import groupBy from "lodash/groupBy";
139
- import {capitalize} from "lodash";
140
140
  import {sortsFn} from "../utils/preset-selector.mjs";
141
+ import PresetBar from "../widgets/PresetBar.vue";
141
142
 
142
143
  export default{
143
144
 
@@ -359,7 +360,7 @@ export default{
359
360
 
360
361
  },
361
362
 
362
- components: {PresetSelector, VirtualTable},
363
+ components: {PresetBar, PresetSelector, VirtualGrid, VirtualTable},
363
364
 
364
365
  emits: [ 'after-load', 'open-preset' ],
365
366
 
@@ -311,6 +311,10 @@ export default{
311
311
  @apply panel-400;
312
312
  @apply border-[1px] border-text-50 z-20 flex max-h-[90vh];
313
313
  @apply rounded-xl overflow-hidden transition-all;
314
+ background-color: rgba(255, 255, 255, .6)
315
+ }
316
+ html[data-theme='dark'] .modal{
317
+ background-color: rgba(0, 0, 0, .3)
314
318
  }
315
319
 
316
320
  .modal.v-show{
package/src/utils/wss.js CHANGED
@@ -95,7 +95,7 @@ class WSS extends EventEmitter2{
95
95
  this._opt = opt
96
96
  this._instance = new WebSocket.Server(opt);
97
97
 
98
- this._instance.on('connection', (socket, req) => {
98
+ this._instance.on('connection', async (socket, req) => {
99
99
 
100
100
  socket.leave = (channel) => {
101
101
  if((socket.channels ?? {})[channel]){
@@ -128,6 +128,8 @@ class WSS extends EventEmitter2{
128
128
  }
129
129
 
130
130
  socket.on('message', async (binaryData) => {
131
+ console.log('message#1', socket.isAuth)
132
+ if(!socket.isAuth) return
131
133
 
132
134
  let obj
133
135
  try{
@@ -143,17 +145,6 @@ class WSS extends EventEmitter2{
143
145
  let data
144
146
  switch(path){
145
147
 
146
- case '_auth':
147
- try{
148
- for(let fn of this._authFn){
149
- await fn(params, socket)
150
- }
151
- }
152
- catch(e){
153
- return socket.close(1002, e.message);
154
- }
155
- break
156
-
157
148
  case 'ping':
158
149
  data = { type:'pong' }
159
150
  break
@@ -192,6 +183,16 @@ class WSS extends EventEmitter2{
192
183
  socket.on('close', (e) => {
193
184
  this.emit('close', e, socket)
194
185
  });
186
+
187
+ const token = req.headers['sec-websocket-protocol'];
188
+ try{
189
+ await this._opt.auth(token, socket)
190
+ socket.isAuth = true
191
+ socket.send(await this.toBinaryData({ auth:true }))
192
+ }
193
+ catch(e){
194
+ return socket.close(1002, e.message);
195
+ }
195
196
  })
196
197
  }
197
198
 
package/src/utils/wss.mjs CHANGED
@@ -46,7 +46,6 @@ class WSS extends EventEmitter2{
46
46
  _callbacks = {}
47
47
  _pendingSend = []
48
48
  _lastBlurAt
49
- _readyState = 0
50
49
 
51
50
  constructor(opt) {
52
51
  super();
@@ -55,19 +54,16 @@ class WSS extends EventEmitter2{
55
54
  auth: {},
56
55
  debug: false,
57
56
  key: '',
58
- onConnect: null,
59
- onConnectError: null,
60
- onDisconnect: null,
61
57
  timeout: 30000,
62
58
  url: '',
63
59
  }, opt ?? {})
64
60
 
65
- if(typeof window !== 'undefined'){
61
+ /*if(typeof window !== 'undefined'){
66
62
  window.addEventListener('online', this._onOnlineChanged)
67
63
  window.addEventListener('offline', this._onOnlineChanged)
68
64
  window.addEventListener('blur', this._onBlur)
69
65
  window.addEventListener('focus', this._onFocus)
70
- }
66
+ }*/
71
67
 
72
68
  this.connect().then()
73
69
  }
@@ -113,31 +109,27 @@ class WSS extends EventEmitter2{
113
109
 
114
110
  async connect(reconnect = false){
115
111
 
116
- this._readyState = 0
112
+ this._instance = new WebSocket(this._opt.url, this._opt.token)
117
113
 
118
- this._instance = new WebSocket(this._opt.url)
119
114
  this._instance.binaryType = 'arraybuffer';
120
- this._instance.onopen = () => {
121
- this._readyState = 2
122
- this.send('_auth', this._opt.auth)
123
- .then(() => {
124
- this._readyState = 1
125
-
126
- reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
127
-
128
- for(let sendParams of this._pendingSend){
129
- this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
130
- }
131
- this._pendingSend = []
132
- })
133
- };
134
115
 
135
116
  this._instance.onmessage = async (event) => {
136
117
  const obj = await this.fromBinaryData(event.data);
137
118
 
138
- const { _requestId, status, data } = obj
119
+ const { _requestId, status, data, auth } = obj
120
+
121
+ if(auth){
122
+ this._instance.isAuth = auth
139
123
 
140
- if(_requestId){
124
+ reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
125
+
126
+ console.log('pending send', this._pendingSend)
127
+ for(let sendParams of this._pendingSend){
128
+ this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
129
+ }
130
+ this._pendingSend = []
131
+ }
132
+ else if(_requestId){
141
133
  if(this._callbacks[_requestId]){
142
134
  const { cb, err, path, params, t1 } = this._callbacks[_requestId]
143
135
  status === 200 ? cb(data) : err(data)
@@ -160,10 +152,13 @@ class WSS extends EventEmitter2{
160
152
  };
161
153
 
162
154
  this._instance.onerror = (e) => {
155
+ console.log('onerror', e)
156
+
163
157
  this.emit('error', e, [])
164
158
  }
165
159
 
166
160
  this._instance.onclose = (e) => {
161
+ console.log('onclose', e)
167
162
 
168
163
  switch(e.code){
169
164
 
@@ -189,7 +184,14 @@ class WSS extends EventEmitter2{
189
184
  }
190
185
 
191
186
  sendSync(path, params, cb, err, override){
192
- if(this._instance.readyState !== 1 || (path !== '_auth' && this._readyState !== 1)){
187
+ console.log('sendSync', path, this._instance.readyState)
188
+
189
+ if(this._instance.readyState > 1){
190
+ console.log('unable to send, ready state not 1', this._instance.readyState)
191
+ return
192
+ }
193
+ else if(!this._instance.isAuth){
194
+ console.log('add pending send', { path, params, cb, err })
193
195
  this._pendingSend.push({ path, params, cb, err })
194
196
  return
195
197
  }
@@ -207,7 +209,9 @@ class WSS extends EventEmitter2{
207
209
  params
208
210
  })
209
211
  .then(async(dataUrlObj) => {
212
+
210
213
  const binaryData = await this.toBinaryData(dataUrlObj)
214
+ console.log('sendSync', this._instance.readyState, dataUrlObj)
211
215
  this._instance.send(binaryData)
212
216
 
213
217
  this._callbacks[_requestId] = {
@@ -235,6 +239,12 @@ class WSS extends EventEmitter2{
235
239
  })
236
240
  }
237
241
 
242
+ async resume(){
243
+ if(this._instance.readyState > 1){
244
+ return this.reconnect()
245
+ }
246
+ }
247
+
238
248
  }
239
249
 
240
250
  export {