PteroTheme/resources/assets/scripts/store/modules/socket.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-12-16 23:29:44 +00:00
import Status from '../../helpers/statuses';
export type SocketState = {
connected: boolean,
connectionError: boolean | Error,
status: number,
}
export default {
namespaced: true,
state: {
connected: false,
2018-08-07 05:33:43 +01:00
connectionError: false,
status: Status.STATUS_OFF,
},
mutations: {
2018-12-16 23:29:44 +00:00
SOCKET_CONNECT: (state: SocketState) => {
state.connected = true;
2018-08-07 05:33:43 +01:00
state.connectionError = false;
},
2018-12-16 23:29:44 +00:00
SOCKET_ERROR: (state: SocketState, err : Error) => {
2018-08-07 05:33:43 +01:00
state.connected = false;
state.connectionError = err;
},
2018-12-16 23:29:44 +00:00
SOCKET_CONNECT_ERROR: (state: SocketState, err : Error) => {
2018-08-07 05:33:43 +01:00
state.connected = false;
state.connectionError = err;
},
2018-12-16 23:29:44 +00:00
'SOCKET_INITIAL STATUS': (state: SocketState, data: { status: number }) => {
state.status = data.status;
},
2018-12-16 23:29:44 +00:00
SOCKET_STATUS: (state: SocketState, data: { status: number }) => {
state.status = data.status;
}
},
};