@zhin.js/client 1.0.3 → 1.0.5
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/README.md +117 -3
- package/{src → client}/index.ts +0 -1
- package/{src → client}/store/index.ts +22 -1
- package/client/store/reducers/config.ts +135 -0
- package/{src → client}/store/reducers/index.ts +4 -1
- package/client/websocket/hooks.ts +280 -0
- package/client/websocket/index.ts +48 -0
- package/client/websocket/instance.ts +46 -0
- package/client/websocket/manager.ts +412 -0
- package/client/websocket/messageHandler.ts +166 -0
- package/client/websocket/types.ts +208 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -0
- package/dist/router/index.d.ts +25 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +49 -0
- package/dist/router/index.js.map +1 -0
- package/dist/store/index.d.ts +19 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +67 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/reducers/config.d.ts +54 -0
- package/dist/store/reducers/config.d.ts.map +1 -0
- package/dist/store/reducers/config.js +78 -0
- package/dist/store/reducers/config.js.map +1 -0
- package/dist/store/reducers/index.d.ts +13 -0
- package/dist/store/reducers/index.d.ts.map +1 -0
- package/dist/store/reducers/index.js +11 -0
- package/dist/store/reducers/index.js.map +1 -0
- package/dist/store/reducers/route.d.ts +37 -0
- package/dist/store/reducers/route.d.ts.map +1 -0
- package/dist/store/reducers/route.js +85 -0
- package/dist/store/reducers/route.js.map +1 -0
- package/dist/store/reducers/script.d.ts +17 -0
- package/dist/store/reducers/script.d.ts.map +1 -0
- package/dist/store/reducers/script.js +74 -0
- package/dist/store/reducers/script.js.map +1 -0
- package/dist/store/reducers/ui.d.ts +14 -0
- package/dist/store/reducers/ui.d.ts.map +1 -0
- package/dist/store/reducers/ui.js +23 -0
- package/dist/store/reducers/ui.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/websocket/hooks.d.ts +55 -0
- package/dist/websocket/hooks.d.ts.map +1 -0
- package/dist/websocket/hooks.js +225 -0
- package/dist/websocket/hooks.js.map +1 -0
- package/dist/websocket/index.d.ts +13 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +31 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/instance.d.ts +18 -0
- package/dist/websocket/instance.d.ts.map +1 -0
- package/dist/websocket/instance.js +39 -0
- package/dist/websocket/instance.js.map +1 -0
- package/dist/websocket/manager.d.ts +110 -0
- package/dist/websocket/manager.d.ts.map +1 -0
- package/dist/websocket/manager.js +341 -0
- package/dist/websocket/manager.js.map +1 -0
- package/dist/websocket/messageHandler.d.ts +48 -0
- package/dist/websocket/messageHandler.d.ts.map +1 -0
- package/dist/websocket/messageHandler.js +140 -0
- package/dist/websocket/messageHandler.js.map +1 -0
- package/dist/websocket/types.d.ts +125 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/dist/websocket/types.js +43 -0
- package/dist/websocket/types.js.map +1 -0
- package/package.json +8 -18
- package/app/index.html +0 -13
- package/app/postcss.config.js +0 -5
- package/app/src/components/ThemeToggle.tsx +0 -21
- package/app/src/hooks/useTheme.ts +0 -17
- package/app/src/layouts/dashboard.tsx +0 -259
- package/app/src/main.tsx +0 -121
- package/app/src/pages/dashboard-bots.tsx +0 -198
- package/app/src/pages/dashboard-home.tsx +0 -301
- package/app/src/pages/dashboard-logs.tsx +0 -298
- package/app/src/pages/dashboard-plugin-detail.tsx +0 -349
- package/app/src/pages/dashboard-plugins.tsx +0 -166
- package/app/src/style.css +0 -1105
- package/app/src/theme/index.ts +0 -92
- package/app/tailwind.config.js +0 -70
- package/app/tsconfig.json +0 -16
- package/src/websocket/index.ts +0 -193
- package/src/websocket/useWebSocket.ts +0 -42
- /package/{src → client}/router/index.tsx +0 -0
- /package/{src → client}/store/reducers/route.ts +0 -0
- /package/{src → client}/store/reducers/script.ts +0 -0
- /package/{src → client}/store/reducers/ui.ts +0 -0
- /package/{src → client}/types.ts +0 -0
package/app/src/theme/index.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Theme configuration
|
|
2
|
-
export const themes = {
|
|
3
|
-
light: {
|
|
4
|
-
background: '0 0% 100%',
|
|
5
|
-
foreground: '222.2 84% 4.9%',
|
|
6
|
-
card: '0 0% 100%',
|
|
7
|
-
'card-foreground': '222.2 84% 4.9%',
|
|
8
|
-
popover: '0 0% 100%',
|
|
9
|
-
'popover-foreground': '222.2 84% 4.9%',
|
|
10
|
-
primary: '221.2 83.2% 53.3%',
|
|
11
|
-
'primary-foreground': '210 40% 98%',
|
|
12
|
-
secondary: '210 40% 96.1%',
|
|
13
|
-
'secondary-foreground': '222.2 47.4% 11.2%',
|
|
14
|
-
muted: '210 40% 96.1%',
|
|
15
|
-
'muted-foreground': '215.4 16.3% 46.9%',
|
|
16
|
-
accent: '210 40% 96.1%',
|
|
17
|
-
'accent-foreground': '222.2 47.4% 11.2%',
|
|
18
|
-
destructive: '0 84.2% 60.2%',
|
|
19
|
-
'destructive-foreground': '210 40% 98%',
|
|
20
|
-
border: '214.3 31.8% 91.4%',
|
|
21
|
-
input: '214.3 31.8% 91.4%',
|
|
22
|
-
ring: '221.2 83.2% 53.3%',
|
|
23
|
-
radius: '0.5rem',
|
|
24
|
-
},
|
|
25
|
-
dark: {
|
|
26
|
-
background: '222.2 84% 4.9%',
|
|
27
|
-
foreground: '210 40% 98%',
|
|
28
|
-
card: '222.2 84% 4.9%',
|
|
29
|
-
'card-foreground': '210 40% 98%',
|
|
30
|
-
popover: '222.2 84% 4.9%',
|
|
31
|
-
'popover-foreground': '210 40% 98%',
|
|
32
|
-
primary: '217.2 91.2% 59.8%',
|
|
33
|
-
'primary-foreground': '222.2 47.4% 11.2%',
|
|
34
|
-
secondary: '217.2 32.6% 17.5%',
|
|
35
|
-
'secondary-foreground': '210 40% 98%',
|
|
36
|
-
muted: '217.2 32.6% 17.5%',
|
|
37
|
-
'muted-foreground': '215 20.2% 65.1%',
|
|
38
|
-
accent: '217.2 32.6% 17.5%',
|
|
39
|
-
'accent-foreground': '210 40% 98%',
|
|
40
|
-
destructive: '0 62.8% 30.6%',
|
|
41
|
-
'destructive-foreground': '210 40% 98%',
|
|
42
|
-
border: '217.2 32.6% 17.5%',
|
|
43
|
-
input: '217.2 32.6% 17.5%',
|
|
44
|
-
ring: '224.3 76.3% 48%',
|
|
45
|
-
radius: '0.5rem',
|
|
46
|
-
},
|
|
47
|
-
} as const
|
|
48
|
-
|
|
49
|
-
export type Theme = keyof typeof themes
|
|
50
|
-
export type ThemeColors = typeof themes.light
|
|
51
|
-
|
|
52
|
-
// Apply theme to document
|
|
53
|
-
export function applyTheme(theme: Theme) {
|
|
54
|
-
const root = document.documentElement
|
|
55
|
-
const colors = themes[theme]
|
|
56
|
-
|
|
57
|
-
// Remove old theme class
|
|
58
|
-
root.classList.remove('light', 'dark')
|
|
59
|
-
// Add new theme class
|
|
60
|
-
root.classList.add(theme)
|
|
61
|
-
|
|
62
|
-
// Apply CSS variables
|
|
63
|
-
Object.entries(colors).forEach(([key, value]) => {
|
|
64
|
-
root.style.setProperty(`--${key}`, value)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// Save to localStorage
|
|
68
|
-
localStorage.setItem('theme', theme)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Get current theme from localStorage or system preference
|
|
72
|
-
export function getInitialTheme(): Theme {
|
|
73
|
-
const stored = localStorage.getItem('theme') as Theme | null
|
|
74
|
-
if (stored && (stored === 'light' || stored === 'dark')) {
|
|
75
|
-
return stored
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Check system preference
|
|
79
|
-
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
80
|
-
return 'dark'
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return 'light'
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Initialize theme on app load
|
|
87
|
-
export function initializeTheme() {
|
|
88
|
-
const theme = getInitialTheme()
|
|
89
|
-
applyTheme(theme)
|
|
90
|
-
return theme
|
|
91
|
-
}
|
|
92
|
-
|
package/app/tailwind.config.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/** @type {import('tailwindcss').Config} */
|
|
2
|
-
const cwd = process.cwd();
|
|
3
|
-
export default {
|
|
4
|
-
content: [
|
|
5
|
-
"./index.html",
|
|
6
|
-
'./src/**/*.{js,ts,jsx,tsx,mdx}',
|
|
7
|
-
`${cwd}/**/radix-ui/**/*.{js,ts,jsx,tsx}`,
|
|
8
|
-
`${cwd}/**/@radix-ui/themes/**/*.{js,ts,jsx,tsx}`,
|
|
9
|
-
],
|
|
10
|
-
theme: {
|
|
11
|
-
extend: {
|
|
12
|
-
colors: {
|
|
13
|
-
border: 'hsl(var(--border))',
|
|
14
|
-
input: 'hsl(var(--input))',
|
|
15
|
-
ring: 'hsl(var(--ring))',
|
|
16
|
-
background: 'hsl(var(--background))',
|
|
17
|
-
foreground: 'hsl(var(--foreground))',
|
|
18
|
-
primary: {
|
|
19
|
-
DEFAULT: 'hsl(var(--primary))',
|
|
20
|
-
foreground: 'hsl(var(--primary-foreground))',
|
|
21
|
-
},
|
|
22
|
-
secondary: {
|
|
23
|
-
DEFAULT: 'hsl(var(--secondary))',
|
|
24
|
-
foreground: 'hsl(var(--secondary-foreground))',
|
|
25
|
-
},
|
|
26
|
-
destructive: {
|
|
27
|
-
DEFAULT: 'hsl(var(--destructive))',
|
|
28
|
-
foreground: 'hsl(var(--destructive-foreground))',
|
|
29
|
-
},
|
|
30
|
-
muted: {
|
|
31
|
-
DEFAULT: 'hsl(var(--muted))',
|
|
32
|
-
foreground: 'hsl(var(--muted-foreground))',
|
|
33
|
-
},
|
|
34
|
-
accent: {
|
|
35
|
-
DEFAULT: 'hsl(var(--accent))',
|
|
36
|
-
foreground: 'hsl(var(--accent-foreground))',
|
|
37
|
-
},
|
|
38
|
-
popover: {
|
|
39
|
-
DEFAULT: 'hsl(var(--popover))',
|
|
40
|
-
foreground: 'hsl(var(--popover-foreground))',
|
|
41
|
-
},
|
|
42
|
-
card: {
|
|
43
|
-
DEFAULT: 'hsl(var(--card))',
|
|
44
|
-
foreground: 'hsl(var(--card-foreground))',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
borderRadius: {
|
|
48
|
-
lg: 'var(--radius)',
|
|
49
|
-
md: 'calc(var(--radius) - 2px)',
|
|
50
|
-
sm: 'calc(var(--radius) - 4px)',
|
|
51
|
-
},
|
|
52
|
-
keyframes: {
|
|
53
|
-
"accordion-down": {
|
|
54
|
-
from: { height: "0" },
|
|
55
|
-
to: { height: "var(--radix-accordion-content-height)" },
|
|
56
|
-
},
|
|
57
|
-
"accordion-up": {
|
|
58
|
-
from: { height: "var(--radix-accordion-content-height)" },
|
|
59
|
-
to: { height: "0" },
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
animation: {
|
|
63
|
-
"accordion-down": "accordion-down 0.2s ease-out",
|
|
64
|
-
"accordion-up": "accordion-up 0.2s ease-out",
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
darkMode: "class",
|
|
69
|
-
plugins: [],
|
|
70
|
-
}
|
package/app/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"target": "ES2020",
|
|
5
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"paths": {
|
|
10
|
-
"@/*": ["src/*"],
|
|
11
|
-
"@zhin.js/client": [
|
|
12
|
-
"../src"
|
|
13
|
-
]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/websocket/index.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { store, loadScripts, loadScript, unloadScript } from '../store'
|
|
2
|
-
/**
|
|
3
|
-
* WebSocket 客户端管理
|
|
4
|
-
* 用于连接服务器并接收动态入口脚本
|
|
5
|
-
* 脚本加载状态由 Redux store 管理
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface WebSocketMessage {
|
|
9
|
-
type: 'sync' | 'add' | 'delete' | 'init-data' | 'data-update'
|
|
10
|
-
data?: {
|
|
11
|
-
key: string
|
|
12
|
-
value: any
|
|
13
|
-
}
|
|
14
|
-
timestamp?: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface WebSocketManagerOptions {
|
|
18
|
-
url?: string
|
|
19
|
-
reconnectInterval?: number
|
|
20
|
-
maxReconnectAttempts?: number
|
|
21
|
-
onConnect?: () => void
|
|
22
|
-
onDisconnect?: () => void
|
|
23
|
-
onError?: (error: Event) => void
|
|
24
|
-
onMessage?: (message: WebSocketMessage) => void
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class WebSocketManager {
|
|
28
|
-
private ws: WebSocket | null = null
|
|
29
|
-
private url: string
|
|
30
|
-
private reconnectInterval: number
|
|
31
|
-
private maxReconnectAttempts: number
|
|
32
|
-
private reconnectAttempts = 0
|
|
33
|
-
private reconnectTimer: NodeJS.Timeout | null = null
|
|
34
|
-
private options: WebSocketManagerOptions
|
|
35
|
-
|
|
36
|
-
constructor(options: WebSocketManagerOptions = {}) {
|
|
37
|
-
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
38
|
-
const host = window.location.host
|
|
39
|
-
|
|
40
|
-
this.url = options.url || `${protocol}//${host}/server`
|
|
41
|
-
this.reconnectInterval = options.reconnectInterval || 3000
|
|
42
|
-
this.maxReconnectAttempts = options.maxReconnectAttempts || 10
|
|
43
|
-
this.options = options
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 连接 WebSocket
|
|
48
|
-
*/
|
|
49
|
-
connect() {
|
|
50
|
-
if (this.ws?.readyState === WebSocket.OPEN) return
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
this.ws = new WebSocket(this.url)
|
|
54
|
-
|
|
55
|
-
this.ws.onopen = () => {
|
|
56
|
-
this.reconnectAttempts = 0
|
|
57
|
-
this.options.onConnect?.()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.ws.onmessage = (event) => {
|
|
61
|
-
try {
|
|
62
|
-
const message: WebSocketMessage = JSON.parse(event.data)
|
|
63
|
-
this.handleMessage(message)
|
|
64
|
-
this.options.onMessage?.(message)
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error('[WS] Parse error:', error)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.ws.onclose = () => {
|
|
71
|
-
this.options.onDisconnect?.()
|
|
72
|
-
this.attemptReconnect()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.ws.onerror = () => {
|
|
76
|
-
this.options.onError?.(new Event('error'))
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
this.attemptReconnect()
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 处理服务器消息
|
|
85
|
-
*/
|
|
86
|
-
private handleMessage(message: WebSocketMessage) {
|
|
87
|
-
switch (message.type) {
|
|
88
|
-
case 'sync':
|
|
89
|
-
// 同步所有入口 - dispatch 到 Redux
|
|
90
|
-
if (message.data?.key === 'entries') {
|
|
91
|
-
const entries = Array.isArray(message.data.value)
|
|
92
|
-
? message.data.value
|
|
93
|
-
: [message.data.value]
|
|
94
|
-
store.dispatch({ type: 'script/syncEntries', payload: entries })
|
|
95
|
-
// 使用 AsyncThunk 加载脚本
|
|
96
|
-
store.dispatch(loadScripts(entries))
|
|
97
|
-
}
|
|
98
|
-
break
|
|
99
|
-
|
|
100
|
-
case 'add':
|
|
101
|
-
// 添加新入口 - dispatch 到 Redux
|
|
102
|
-
if (message.data?.key === 'entries') {
|
|
103
|
-
store.dispatch({ type: 'script/addEntry', payload: message.data.value })
|
|
104
|
-
// 使用 AsyncThunk 加载脚本
|
|
105
|
-
store.dispatch(loadScript(message.data.value))
|
|
106
|
-
}
|
|
107
|
-
break
|
|
108
|
-
|
|
109
|
-
case 'delete':
|
|
110
|
-
// 删除入口 - dispatch 到 Redux
|
|
111
|
-
if (message.data?.key === 'entries') {
|
|
112
|
-
store.dispatch({ type: 'script/removeEntry', payload: message.data.value })
|
|
113
|
-
// 使用 AsyncThunk 卸载脚本
|
|
114
|
-
store.dispatch(unloadScript(message.data.value))
|
|
115
|
-
}
|
|
116
|
-
break
|
|
117
|
-
|
|
118
|
-
case 'init-data':
|
|
119
|
-
case 'data-update':
|
|
120
|
-
break
|
|
121
|
-
|
|
122
|
-
default:
|
|
123
|
-
console.warn('[WS] Unknown type:', message.type)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 尝试重新连接
|
|
129
|
-
*/
|
|
130
|
-
private attemptReconnect() {
|
|
131
|
-
if (this.reconnectAttempts >= this.maxReconnectAttempts) return
|
|
132
|
-
|
|
133
|
-
this.reconnectAttempts++
|
|
134
|
-
this.reconnectTimer = setTimeout(() => {
|
|
135
|
-
this.connect()
|
|
136
|
-
}, this.reconnectInterval)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 断开连接
|
|
141
|
-
*/
|
|
142
|
-
disconnect() {
|
|
143
|
-
if (this.reconnectTimer) {
|
|
144
|
-
clearTimeout(this.reconnectTimer)
|
|
145
|
-
this.reconnectTimer = null
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (this.ws) {
|
|
149
|
-
this.ws.close()
|
|
150
|
-
this.ws = null
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 发送消息
|
|
156
|
-
*/
|
|
157
|
-
send(message: any) {
|
|
158
|
-
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
159
|
-
this.ws.send(JSON.stringify(message))
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 检查是否已连接
|
|
165
|
-
*/
|
|
166
|
-
isConnected() {
|
|
167
|
-
return this.ws?.readyState === WebSocket.OPEN
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// 创建全局单例并自动连接
|
|
172
|
-
const globalWebSocketManager = new WebSocketManager()
|
|
173
|
-
|
|
174
|
-
// 模块加载时自动连接
|
|
175
|
-
if (typeof window !== 'undefined') {
|
|
176
|
-
globalWebSocketManager.connect()
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* 获取全局 WebSocket 管理器
|
|
181
|
-
*/
|
|
182
|
-
export function getWebSocketManager(): WebSocketManager {
|
|
183
|
-
return globalWebSocketManager
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 销毁全局 WebSocket 管理器
|
|
188
|
-
*/
|
|
189
|
-
export function destroyWebSocketManager() {
|
|
190
|
-
globalWebSocketManager.disconnect()
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export default WebSocketManager
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react'
|
|
2
|
-
import { useSelector } from '../store'
|
|
3
|
-
import { getWebSocketManager } from './index'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* WebSocket Hook
|
|
7
|
-
* 用于在 React 组件中访问 WebSocket 状态和方法
|
|
8
|
-
* WebSocket 在模块加载时已自动连接,无需手动初始化
|
|
9
|
-
* 状态由 Redux store 管理
|
|
10
|
-
*/
|
|
11
|
-
export function useWebSocket() {
|
|
12
|
-
// 从 Redux 读取状态
|
|
13
|
-
const entries = useSelector((state: any) => state.script.entries || [])
|
|
14
|
-
const loadedScripts = useSelector((state: any) => state.script.loadedScripts || [])
|
|
15
|
-
|
|
16
|
-
const connect = useCallback(() => {
|
|
17
|
-
getWebSocketManager().connect()
|
|
18
|
-
}, [])
|
|
19
|
-
|
|
20
|
-
const disconnect = useCallback(() => {
|
|
21
|
-
getWebSocketManager().disconnect()
|
|
22
|
-
}, [])
|
|
23
|
-
|
|
24
|
-
const send = useCallback((message: any) => {
|
|
25
|
-
getWebSocketManager().send(message)
|
|
26
|
-
}, [])
|
|
27
|
-
|
|
28
|
-
const isConnected = useCallback(() => {
|
|
29
|
-
return getWebSocketManager().isConnected()
|
|
30
|
-
}, [])
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
entries,
|
|
34
|
-
loadedScripts,
|
|
35
|
-
connect,
|
|
36
|
-
disconnect,
|
|
37
|
-
send,
|
|
38
|
-
isConnected
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default useWebSocket
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → client}/types.ts
RENAMED
|
File without changes
|