-
Notifications
You must be signed in to change notification settings - Fork 4
/
vm.js
73 lines (57 loc) · 1.38 KB
/
vm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class RemoteFolder extends Folder {
static async fetchFolder(root_url, path) {
const path_q = encodeURIComponent(path)
let req = await fetch(`${root_url}/fs?path=${path_q}`)
req = await req.json()
const contents = req.files
.map(f => ({
img: 'img/desktop/TextFile.png',
title: f,
launch: 'cmd'
}))
const data = {
name: path,
icon: 'img/desktop/Folder',
title: path,
contents
}
const target_folder = new RemoteFolder(data)
for (let child in req.folders) {
}
}
}
class VMTerminal {
constructor(host) {
this.socket = new WebSocket(`ws://${host}/terminal`)
}
_send(type, data) {
this.socket.send(JSON.stringify({type,data}))
}
resize(rows, cols) {
this._send(
'resize',
{rows, cols}
)
}
terminate() {
this._send('terminate')
this.socket.close()
}
send_input(data) {
this._send(
'keys',
data
)
}
}
class VMManager {
constructor() {
this.remote = 'localhost:8080'
}
async createTerminal() {
return new VMTerminal(this.remote)
}
async getRootFolder() {
}
}
window.vm = new VMManager()