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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
import { store } from './store'
let socket = io.connect('/client')
let got_frame = false
// SOCKET ACTIONS
socket.on('res', (data) => {
console.log(data.cmd)
switch (data.cmd) {
case 'get_last_frame':
if (data.res !== 'working') {
socket.emit('cmd', {
cmd: 'get_last_frame',
})
}
break
case 'get_params':
store.dispatch({
type: 'LOAD_PARAMS',
opt: data.res,
})
break
case 'list_checkpoints':
store.dispatch({
type: 'LIST_CHECKPOINTS',
opt: data.res,
})
break
case 'list_videos':
store.dispatch({
type: 'LIST_VIDEOS',
opt: data.res,
})
break
default:
break
}
console.log(data)
})
socket.on('frame', (data) => {
got_frame = true
const blob = new Blob([data.frame], { type: 'image/jpg' })
const url = URL.createObjectURL(blob)
const img = new Image ()
img.onload = function() {
URL.revokeObjectURL(url)
const player = document.querySelector('.player')
player.innerHTML = ''
player.appendChild(img)
}
img.src = url
})
setTimeout(() => {
if (!got_frame) {
// socket.emit('cmd', {
// cmd: 'get_last_frame',
// })
}
}, 500)
export function list_checkpoints() {
socket.emit('cmd', {
cmd: 'list_checkpoints',
})
}
export function list_videos() {
socket.emit('cmd', {
cmd: 'list_videos',
})
}
export function get_params() {
socket.emit('cmd', {
cmd: 'get_params',
})
}
export function set_param(key, value) {
socket.emit('cmd', {
cmd: 'set_param',
payload: {
'key': key,
'value': value,
}
})
}
export { socket }
|