import { io } from 'socket.io-client';
export const useWebsocketStore = defineStore('websocketStore', {
state: () => ({
isConnected: false,
socket: null,
}),
actions: {
init() {
this.socket = io();
this.bindEvents();
},
bindEvents() {
if (this.socket) {
this.socket.on("connect", () => {
this.isConnected = true;
});
this.socket.on("disconnect", () => {
this.isConnected = false;
});
this.socket.on("error", (error) => {
console.log(error);
});
}
},
},
});
import { io } from 'socket.io-client';
export const useWebsocketStore = defineStore('websocketStore', {
state: () => ({
isConnected: false,
socket: null,
}),
actions: {
init() {
this.socket = io();
this.bindEvents();
},
bindEvents() {
if (this.socket) {
this.socket.on("connect", () => {
this.isConnected = true;
});
this.socket.on("disconnect", () => {
this.isConnected = false;
});
this.socket.on("error", (error) => {
console.log(error);
});
}
},
},
});