forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.ts
More file actions
47 lines (40 loc) · 1.34 KB
/
socket.ts
File metadata and controls
47 lines (40 loc) · 1.34 KB
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
import Status from '../../helpers/statuses';
import {SocketState} from "../types";
export default {
namespaced: true,
state: {
connected: false,
connectionError: false,
status: Status.STATUS_OFF,
outputBuffer: [],
},
mutations: {
SOCKET_CONNECT: (state: SocketState) => {
state.connected = true;
state.connectionError = false;
},
SOCKET_ERROR: (state: SocketState, err: Error) => {
state.connected = false;
state.connectionError = err;
},
'SOCKET_INITIAL STATUS': (state: SocketState, data: string) => {
state.status = data;
},
SOCKET_STATUS: (state: SocketState, data: string) => {
state.status = data;
},
'SOCKET_CONSOLE OUTPUT': (state: SocketState, data: string) => {
const { outputBuffer } = state;
if (outputBuffer.length >= 500) {
// Pop all of the output buffer items off the front until we only have 499
// items in the array.
for (let i = 0; i <= (outputBuffer.length - 500); i++) {
outputBuffer.shift();
i++;
}
}
outputBuffer.push(data);
state.outputBuffer = outputBuffer;
},
},
};