@mixd-id/web-scaffold 0.1.230406262 → 0.1.230406263
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/components/Chart.vue +0 -2
- package/src/components/List.vue +3 -2
- package/src/components/Modal.vue +4 -0
- package/src/utils/wss.js +12 -12
- package/src/utils/wss.mjs +24 -25
package/package.json
CHANGED
package/src/components/Chart.vue
CHANGED
package/src/components/List.vue
CHANGED
|
@@ -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
|
|
package/src/components/Modal.vue
CHANGED
|
@@ -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,7 @@ class WSS extends EventEmitter2{
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
socket.on('message', async (binaryData) => {
|
|
131
|
+
if(!socket.isAuth) return
|
|
131
132
|
|
|
132
133
|
let obj
|
|
133
134
|
try{
|
|
@@ -143,17 +144,6 @@ class WSS extends EventEmitter2{
|
|
|
143
144
|
let data
|
|
144
145
|
switch(path){
|
|
145
146
|
|
|
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
147
|
case 'ping':
|
|
158
148
|
data = { type:'pong' }
|
|
159
149
|
break
|
|
@@ -192,6 +182,16 @@ class WSS extends EventEmitter2{
|
|
|
192
182
|
socket.on('close', (e) => {
|
|
193
183
|
this.emit('close', e, socket)
|
|
194
184
|
});
|
|
185
|
+
|
|
186
|
+
const token = req.headers['sec-websocket-protocol'];
|
|
187
|
+
try{
|
|
188
|
+
await this._opt.auth(token, socket)
|
|
189
|
+
socket.isAuth = true
|
|
190
|
+
socket.send(await this.toBinaryData({ auth:true }))
|
|
191
|
+
}
|
|
192
|
+
catch(e){
|
|
193
|
+
return socket.close(1002, e.message);
|
|
194
|
+
}
|
|
195
195
|
})
|
|
196
196
|
}
|
|
197
197
|
|
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,24 @@ class WSS extends EventEmitter2{
|
|
|
113
109
|
|
|
114
110
|
async connect(reconnect = false){
|
|
115
111
|
|
|
116
|
-
this.
|
|
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
|
+
reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
|
|
139
123
|
|
|
140
|
-
|
|
124
|
+
for(let sendParams of this._pendingSend){
|
|
125
|
+
this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
|
|
126
|
+
}
|
|
127
|
+
this._pendingSend = []
|
|
128
|
+
}
|
|
129
|
+
else if(_requestId){
|
|
141
130
|
if(this._callbacks[_requestId]){
|
|
142
131
|
const { cb, err, path, params, t1 } = this._callbacks[_requestId]
|
|
143
132
|
status === 200 ? cb(data) : err(data)
|
|
@@ -160,10 +149,13 @@ class WSS extends EventEmitter2{
|
|
|
160
149
|
};
|
|
161
150
|
|
|
162
151
|
this._instance.onerror = (e) => {
|
|
152
|
+
console.log('onerror', e)
|
|
153
|
+
|
|
163
154
|
this.emit('error', e, [])
|
|
164
155
|
}
|
|
165
156
|
|
|
166
157
|
this._instance.onclose = (e) => {
|
|
158
|
+
console.log('onclose', e)
|
|
167
159
|
|
|
168
160
|
switch(e.code){
|
|
169
161
|
|
|
@@ -189,10 +181,15 @@ class WSS extends EventEmitter2{
|
|
|
189
181
|
}
|
|
190
182
|
|
|
191
183
|
sendSync(path, params, cb, err, override){
|
|
192
|
-
|
|
184
|
+
|
|
185
|
+
if(this._instance.readyState === 0){
|
|
193
186
|
this._pendingSend.push({ path, params, cb, err })
|
|
194
187
|
return
|
|
195
188
|
}
|
|
189
|
+
else if(this._instance.readyState !== 1){
|
|
190
|
+
console.log('unable to send, ready state not 1', this._instance.readyState)
|
|
191
|
+
return
|
|
192
|
+
}
|
|
196
193
|
|
|
197
194
|
/*if(!navigator.onLine){
|
|
198
195
|
err({ message: 'Unable to send, network disconnected' })
|
|
@@ -207,7 +204,9 @@ class WSS extends EventEmitter2{
|
|
|
207
204
|
params
|
|
208
205
|
})
|
|
209
206
|
.then(async(dataUrlObj) => {
|
|
207
|
+
|
|
210
208
|
const binaryData = await this.toBinaryData(dataUrlObj)
|
|
209
|
+
console.log('sendSync', this._instance.readyState, dataUrlObj)
|
|
211
210
|
this._instance.send(binaryData)
|
|
212
211
|
|
|
213
212
|
this._callbacks[_requestId] = {
|