-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalLogs.js
64 lines (61 loc) · 2.39 KB
/
TerminalLogs.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
import { TerminalLogsStore } from "../store/TerminalLogs";
export const connectWSHandlersFromTerminalLogsStore = AppWSChannel => {
AppWSChannel.addEventListener( "open", () => {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date(),
prefixcontent: "wserver",
name: "connect-success",
linecontent: "Соединение с сервером установлено!"
} );
} );
AppWSChannel.addEventListener( "close", () => {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date(),
prefixcontent: "wserver",
name: "connect-error",
linecontent: "Соединение с сервером разорвано, переподключение..."
} );
} );
AppWSChannel.addMessageListener( data => {
switch ( data.event ) {
case "clientSendedGCommand": {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date( data.time ),
name: "client",
prefixcontent: "command",
linecontent: data.command,
id: data.id
} );
break;
}
case "printerState": {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date( data.time ),
name: data.isPrinterConnected ? "connect-success" : "connect-error",
prefixcontent: "printer",
linecontent: data.isPrinterConnected ? "Принтер подключён" : "Принтер отключён"
} );
break;
}
case "clientSendedGCodeFile": {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date( data.time ),
name: "client",
prefixcontent: "_.gcode",
linecontent: data.preview
} );
break;
}
case "printerSendedLine": {
TerminalLogsStore.addLineIntoTerminalLogs( {
time: new Date( data.time ),
name: "printer",
prefixcontent: "printer",
linecontent: data.line
} );
break;
}
default: break;
}
} );
}