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";
|
2018-08-02 06:37:14 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
connected: false,
|
2018-08-07 04:33:43 +00:00
|
|
|
connectionError: false,
|
2018-08-02 06:37:14 +00:00
|
|
|
status: Status.STATUS_OFF,
|
2019-05-28 01:26:34 +00:00
|
|
|
outputBuffer: [],
|
2018-08-02 06:37:14 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
2018-12-16 23:29:44 +00:00
|
|
|
SOCKET_CONNECT: (state: SocketState) => {
|
2018-08-02 06:37:14 +00:00
|
|
|
state.connected = true;
|
2018-08-07 04:33:43 +00:00
|
|
|
state.connectionError = false;
|
2018-08-02 06:37:14 +00:00
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2019-05-02 03:12:20 +00:00
|
|
|
'SOCKET_INITIAL STATUS': (state: SocketState, data: string) => {
|
|
|
|
state.status = data;
|
2018-08-02 06:37:14 +00:00
|
|
|
},
|
|
|
|
|
2019-05-02 03:12:20 +00:00
|
|
|
SOCKET_STATUS: (state: SocketState, data: string) => {
|
|
|
|
state.status = data;
|
2019-05-28 01:26:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'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;
|
|
|
|
},
|
2018-08-02 06:37:14 +00:00
|
|
|
},
|
|
|
|
};
|