Add nuxt-visitors

This commit is contained in:
2025-04-17 17:45:33 +02:00
parent 3b9c239a75
commit 65221f8f54
9 changed files with 922 additions and 1469 deletions

View File

@@ -1,20 +0,0 @@
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)
},
})