Сделал store для коннекта в webSocket:
export const useSocketStore = defineStore('socket', () => {
const state = reactive<ISocketStoreState>({
socket: null
});
const initWebsocket = () => {
if (state.socket) {
state.socket.disconnect();
}
const manager = socketService.setupSocketConnection();
state.socket = manager.socket('');
state.socket?.on('connect', () => {
console.log('connection sdasd');
});
state.socket?.on('error', (data) => {
console.error(data);
});
};
return {
...toRefs(state),
initWebsocket
};
});
При вызове в другом сторе не видит переменную socket:
export const useChatStore = defineStore('chat', () => {
const state = reactive<IChatState>({
rooms: [],
openedRoom: null,
messages: [],
timeTyping: null
});
const socketStore = useSocketStore();
const setRooms = (rooms: any[]) => {
state.rooms = rooms;
for (const room of rooms) {
socketStore.socket?.emit('joinRoom', {
roomId: room?.id
});
}
};
}