first commit
CI / Type-check & Build (push) Failing after 5m50s
CI / Build & Push image (push) Skipped

This commit is contained in:
ysj7705 committed 2026-08-12 15:01:43 +09:00
commit 69b647145f
58 files changed
+15796

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import { io, type Socket } from 'socket.io-client'
import type { ClientToServerEvents, ServerToClientEvents } from '~/types/signaling'
export type AppSocket = Socket<ServerToClientEvents, ClientToServerEvents>
let socketSingleton: AppSocket | null = null
export function useSocket() {
const socket = useState<AppSocket | null>('app-socket', () => null)
function connect() {
if (!import.meta.client) return null
if (socketSingleton?.connected) {
socket.value = socketSingleton
return socketSingleton
}
socketSingleton = io({
path: '/socket.io/',
transports: ['websocket', 'polling'],
autoConnect: true,
})
socket.value = socketSingleton
return socketSingleton
}
function disconnect() {
socketSingleton?.disconnect()
socketSingleton = null
socket.value = null
}
return { socket, connect, disconnect }
}