mirror of
https://github.com/ArthurDanjou/artsite.git
synced 2026-01-14 18:59:59 +01:00
Replaced nuxt-visitors module with a custom WebSocket implementation for location tracking. Removed redundant code and comments in `useVisitors` composable and introduced the `location.server` plugin to manage user location. Updated dependencies and configurations to reflect these changes, streamlining the approach.
21 lines
679 B
TypeScript
21 lines
679 B
TypeScript
import type { Peer } from 'crossws'
|
|
import { defineWebSocketHandler } from 'h3'
|
|
import { getQuery } from 'ufo'
|
|
|
|
export default defineWebSocketHandler({
|
|
open(peer: Peer) {
|
|
const locations = Array.from(peer.peers.values()).map(peer => getQuery(peer.websocket.url!))
|
|
peer.subscribe('nuxt-visitors')
|
|
peer.publish('nuxt-visitors', JSON.stringify(locations))
|
|
peer.send(JSON.stringify(locations))
|
|
},
|
|
|
|
close(peer: Peer) {
|
|
peer.unsubscribe('nuxt-visitors')
|
|
setTimeout(() => {
|
|
const locations = Array.from(peer.peers.values()).map(peer => getQuery(peer.websocket.url!))
|
|
peer.publish('nuxt-visitors', JSON.stringify(locations))
|
|
}, 500)
|
|
},
|
|
})
|