25 lines
547 B
JavaScript
25 lines
547 B
JavaScript
import { defineStore } from 'pinia'
|
|
import { inject } from 'vue'
|
|
|
|
export const useSocketStore = defineStore('socket', () => {
|
|
const socket = inject('socket')
|
|
|
|
const handleConnection = () => {
|
|
try {
|
|
socket.on('connect', () => {
|
|
console.log(`[Socket] Connected -- ${socket.id}`)
|
|
})
|
|
socket.on('disconnect', () => {
|
|
console.log(`[Socket] Disconnected -- ${socket.id}`)
|
|
})
|
|
} catch (error) {
|
|
console.error('[Socket] Connection error:', error)
|
|
}
|
|
}
|
|
|
|
return {
|
|
handleConnection,
|
|
}
|
|
|
|
})
|