feat/fix: implement WebSockets for NowPlaying, better data fetching with addl. Last.fm fetch, docker build fix
This commit is contained in:
parent
4cec7406c3
commit
7121ec926f
11 changed files with 514 additions and 175 deletions
28
lib/socket.ts
Normal file
28
lib/socket.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"use client"
|
||||
|
||||
import { io, Socket } from "socket.io-client"
|
||||
|
||||
let socket: Socket | null = null
|
||||
|
||||
export const getSocket = (): Socket => {
|
||||
if (!socket) {
|
||||
socket = io(undefined, {
|
||||
autoConnect: false,
|
||||
})
|
||||
}
|
||||
return socket
|
||||
}
|
||||
|
||||
export const connectSocket = (): Socket => {
|
||||
const s = getSocket()
|
||||
if (!s.connected) {
|
||||
s.connect()
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
export const disconnectSocket = (): void => {
|
||||
if (socket?.connected) {
|
||||
socket.disconnect()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue