misc_pterodactyl-panel/resources/assets/scripts/store/modules/socket.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-12-16 23:29:44 +00:00
import Status from '../../helpers/statuses';
2018-12-17 02:57:34 +00:00
import {SocketState} from "../types";
export default {
namespaced: true,
state: {
connected: false,
2018-08-07 04:33:43 +00:00
connectionError: false,
status: Status.STATUS_OFF,
outputBuffer: [],
},
mutations: {
2018-12-16 23:29:44 +00:00
SOCKET_CONNECT: (state: SocketState) => {
state.connected = true;
2018-08-07 04:33:43 +00:00
state.connectionError = false;
},
2019-02-10 05:15:45 +00:00
SOCKET_ERROR: (state: SocketState, err: Error) => {
2018-08-07 04:33:43 +00:00
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;
},
},
};