@electerm/electerm-react 3.15.36 → 3.15.38
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/client/components/bookmark-form/index.jsx +4 -1
- package/client/components/terminal/terminal.jsx +3 -3
- package/client/components/vnc/vnc-session.jsx +3 -4
- package/client/entry/basic.js +62 -0
- package/client/entry/electerm.jsx +9 -0
- package/client/entry/worker.js +146 -0
- package/client/store/tab.js +3 -0
- package/package.json +1 -1
|
@@ -90,6 +90,9 @@ export default class BookmarkIndex2 extends PureComponent {
|
|
|
90
90
|
|
|
91
91
|
renderTypes (bookmarkType, isNew, keys) {
|
|
92
92
|
if (!isNew || this.state.aiMode) return null
|
|
93
|
+
const filtered = window.et && Array.isArray(window.et.supportSessionTypes)
|
|
94
|
+
? keys.filter(k => window.et.supportSessionTypes.includes(k))
|
|
95
|
+
: keys
|
|
93
96
|
return (
|
|
94
97
|
<Radio.Group
|
|
95
98
|
buttonStyle='solid'
|
|
@@ -99,7 +102,7 @@ export default class BookmarkIndex2 extends PureComponent {
|
|
|
99
102
|
disabled={!isNew}
|
|
100
103
|
onChange={this.handleChange}
|
|
101
104
|
>
|
|
102
|
-
{
|
|
105
|
+
{filtered.map(v => {
|
|
103
106
|
const txt = v === 'ssh' ? 'Ssh/Sftp' : e(v)
|
|
104
107
|
return (<Radio.Button key={v} value={v}>{txt}</Radio.Button>)
|
|
105
108
|
})}
|
|
@@ -1356,7 +1356,7 @@ class Term extends Component {
|
|
|
1356
1356
|
id
|
|
1357
1357
|
)
|
|
1358
1358
|
}
|
|
1359
|
-
return `ws://${host}:${port}/terminals/${id}`
|
|
1359
|
+
return `ws://${host}:${port}/terminals/${id}?token=${tokenElecterm}`
|
|
1360
1360
|
}
|
|
1361
1361
|
|
|
1362
1362
|
remoteInit = async (term = this.term) => {
|
|
@@ -1448,7 +1448,7 @@ class Term extends Component {
|
|
|
1448
1448
|
if (this.onClose) {
|
|
1449
1449
|
if (r && r.port) {
|
|
1450
1450
|
try {
|
|
1451
|
-
const tmpSock = new WebSocket(this.buildWsUrl(r.port)
|
|
1451
|
+
const tmpSock = new WebSocket(this.buildWsUrl(r.port))
|
|
1452
1452
|
tmpSock.onopen = () => tmpSock.close()
|
|
1453
1453
|
} catch (_e) {}
|
|
1454
1454
|
}
|
|
@@ -1477,7 +1477,7 @@ class Term extends Component {
|
|
|
1477
1477
|
term.pid = id
|
|
1478
1478
|
this.pid = id
|
|
1479
1479
|
const wsUrl = this.buildWsUrl(r.port)
|
|
1480
|
-
const socket = new WebSocket(wsUrl
|
|
1480
|
+
const socket = new WebSocket(wsUrl)
|
|
1481
1481
|
socket.onclose = this.oncloseSocket
|
|
1482
1482
|
socket.onerror = this.onerrorSocket
|
|
1483
1483
|
this.socket = socket
|
|
@@ -96,7 +96,7 @@ export default class VncSession extends PureComponent {
|
|
|
96
96
|
extra
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
|
-
return `ws://${host}:${port}/${type}/${id}${extra}`
|
|
99
|
+
return `ws://${host}:${port}/${type}/${id}?token=${tokenElecterm}${extra}`
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
getControlProps = (options = {}) => {
|
|
@@ -226,7 +226,7 @@ export default class VncSession extends PureComponent {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
const { width, height } = this.calcCanvasSize()
|
|
229
|
-
const wsUrl = this.buildWsUrl(port, 'vnc',
|
|
229
|
+
const wsUrl = this.buildWsUrl(port, 'vnc', `&width=${width}&height=${height}`)
|
|
230
230
|
// When scaleViewport is false, we don't set fixed dimensions on the canvas
|
|
231
231
|
// so it can render at the actual remote screen size
|
|
232
232
|
const vncOpts = {
|
|
@@ -243,8 +243,7 @@ export default class VncSession extends PureComponent {
|
|
|
243
243
|
overflow: 'hidden'
|
|
244
244
|
}
|
|
245
245
|
: {},
|
|
246
|
-
credentials: {}
|
|
247
|
-
wsProtocols: [this.props.config.tokenElecterm]
|
|
246
|
+
credentials: {}
|
|
248
247
|
}
|
|
249
248
|
if (username) {
|
|
250
249
|
vncOpts.credentials.username = username
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* init app data then write main script to html body
|
|
3
|
+
*/
|
|
4
|
+
import '../css/basic.styl'
|
|
5
|
+
import '../css/mobile.styl'
|
|
6
|
+
import { get as _get } from 'lodash-es'
|
|
7
|
+
import '../common/pre'
|
|
8
|
+
|
|
9
|
+
const { isDev } = window.et
|
|
10
|
+
const { version } = window.pre.packInfo
|
|
11
|
+
|
|
12
|
+
async function loadWorker () {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const url = !isDev ? `js/worker-${version}.js` : 'js/worker.js'
|
|
15
|
+
window.worker = new window.Worker(url)
|
|
16
|
+
function onInit (e) {
|
|
17
|
+
if (!e || !e.data) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
const {
|
|
21
|
+
action
|
|
22
|
+
} = e.data
|
|
23
|
+
if (action === 'worker-init') {
|
|
24
|
+
window.worker.removeEventListener('message', onInit)
|
|
25
|
+
resolve(1)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
window.worker.addEventListener('message', onInit)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function load () {
|
|
33
|
+
window.capitalizeFirstLetter = (string) => {
|
|
34
|
+
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
35
|
+
}
|
|
36
|
+
function loadScript () {
|
|
37
|
+
const rcs = document.createElement('script')
|
|
38
|
+
const url = !isDev ? `js/electerm-${version}.js` : 'js/electerm.js'
|
|
39
|
+
rcs.src = url
|
|
40
|
+
rcs.type = 'module'
|
|
41
|
+
rcs.onload = () => {
|
|
42
|
+
const loadingEl = document.getElementById('content-loading')
|
|
43
|
+
if (loadingEl) {
|
|
44
|
+
document.body.removeChild(loadingEl)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
document.body.appendChild(rcs)
|
|
48
|
+
}
|
|
49
|
+
window.getLang = (lang = window.store?.config.language || 'en_us') => {
|
|
50
|
+
return _get(window.langMap, `[${lang}].lang`)
|
|
51
|
+
}
|
|
52
|
+
window.translate = txt => {
|
|
53
|
+
const lang = window.getLang()
|
|
54
|
+
const str = _get(lang, `[${txt}]`) || txt
|
|
55
|
+
return window.capitalizeFirstLetter(str)
|
|
56
|
+
}
|
|
57
|
+
await loadWorker()
|
|
58
|
+
loadScript()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// window.addEventListener('load', load)
|
|
62
|
+
load()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRoot } from 'react-dom/client'
|
|
2
|
+
import 'antd/dist/reset.css'
|
|
3
|
+
import '@fontsource/maple-mono/index.css'
|
|
4
|
+
import Main from '../components/main/index.jsx'
|
|
5
|
+
|
|
6
|
+
const rootElement = createRoot(document.getElementById('container'))
|
|
7
|
+
rootElement.render(
|
|
8
|
+
<Main />
|
|
9
|
+
)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web worker
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
self.insts = {}
|
|
6
|
+
|
|
7
|
+
function createWs (
|
|
8
|
+
type,
|
|
9
|
+
id,
|
|
10
|
+
sftpId = '',
|
|
11
|
+
config
|
|
12
|
+
) {
|
|
13
|
+
// init gloabl ws
|
|
14
|
+
const { host, port, tokenElecterm } = config
|
|
15
|
+
const wsUrl = `ws://${host}:${port}/${type}/${id}?&sftpId=${sftpId}&token=${tokenElecterm}`
|
|
16
|
+
const ws = new WebSocket(wsUrl)
|
|
17
|
+
ws.s = msg => {
|
|
18
|
+
try {
|
|
19
|
+
ws.send(JSON.stringify(msg))
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error('ws send error', e)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
ws.id = id
|
|
25
|
+
ws.once = (callack, id) => {
|
|
26
|
+
const func = (evt) => {
|
|
27
|
+
const arg = JSON.parse(evt.data)
|
|
28
|
+
if (id === arg.id) {
|
|
29
|
+
callack(arg)
|
|
30
|
+
ws.removeEventListener('message', func)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
ws.addEventListener('message', func)
|
|
34
|
+
}
|
|
35
|
+
ws.onclose = () => {
|
|
36
|
+
if (ws.dup) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
send({
|
|
40
|
+
id: ws.id,
|
|
41
|
+
action: 'close'
|
|
42
|
+
})
|
|
43
|
+
delete self.insts[ws.id]
|
|
44
|
+
}
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
ws.onopen = () => {
|
|
47
|
+
if (self.insts[ws.id]) {
|
|
48
|
+
ws.dup = true
|
|
49
|
+
ws.close()
|
|
50
|
+
resolve(null)
|
|
51
|
+
} else {
|
|
52
|
+
resolve(ws)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function send (data) {
|
|
59
|
+
self.postMessage(data)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function onMsg (e) {
|
|
63
|
+
const {
|
|
64
|
+
id,
|
|
65
|
+
wsId,
|
|
66
|
+
args,
|
|
67
|
+
action,
|
|
68
|
+
type,
|
|
69
|
+
persist
|
|
70
|
+
} = e.data
|
|
71
|
+
if (action === 'create') {
|
|
72
|
+
const inst = self.insts[id]
|
|
73
|
+
if (inst instanceof WebSocket) {
|
|
74
|
+
return send({
|
|
75
|
+
action,
|
|
76
|
+
id,
|
|
77
|
+
persist
|
|
78
|
+
}, '*')
|
|
79
|
+
} else if (inst) {
|
|
80
|
+
return false
|
|
81
|
+
} else {
|
|
82
|
+
const ws = await createWs(...args)
|
|
83
|
+
if (ws) {
|
|
84
|
+
self.insts[id] = ws
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
send({
|
|
88
|
+
action,
|
|
89
|
+
persist,
|
|
90
|
+
id
|
|
91
|
+
}, '*')
|
|
92
|
+
} else if (action === 'once') {
|
|
93
|
+
const ws = self.insts[wsId]
|
|
94
|
+
if (ws) {
|
|
95
|
+
const cb = (data) => {
|
|
96
|
+
send({
|
|
97
|
+
id,
|
|
98
|
+
wsId,
|
|
99
|
+
data
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
ws.once(cb, id)
|
|
103
|
+
}
|
|
104
|
+
} else if (action === 'close') {
|
|
105
|
+
const ws = self.insts[wsId]
|
|
106
|
+
if (ws) {
|
|
107
|
+
ws.close()
|
|
108
|
+
}
|
|
109
|
+
} else if (action === 's') {
|
|
110
|
+
const ws = self.insts[wsId]
|
|
111
|
+
if (ws) {
|
|
112
|
+
ws.s(...args)
|
|
113
|
+
}
|
|
114
|
+
} else if (action === 'addEventListener') {
|
|
115
|
+
const ws = self.insts[wsId]
|
|
116
|
+
if (ws) {
|
|
117
|
+
if (!ws.cbs) {
|
|
118
|
+
ws.cbs = {}
|
|
119
|
+
}
|
|
120
|
+
const cb = (e) => {
|
|
121
|
+
send({
|
|
122
|
+
wsId,
|
|
123
|
+
id,
|
|
124
|
+
data: {
|
|
125
|
+
data: e.data
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
ws.cbs[id] = cb
|
|
130
|
+
ws.addEventListener(type, cb)
|
|
131
|
+
}
|
|
132
|
+
} else if (action === 'removeEventListener') {
|
|
133
|
+
const ws = self.insts[wsId]
|
|
134
|
+
if (ws && ws.cbs && ws.cbs[id]) {
|
|
135
|
+
ws.removeEventListener(type, ws.cbs[id])
|
|
136
|
+
delete ws.cbs[id]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
self.addEventListener('message', onMsg)
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
send({
|
|
144
|
+
action: 'worker-init'
|
|
145
|
+
})
|
|
146
|
+
}, 10)
|
package/client/store/tab.js
CHANGED