mirror of
https://github.com/ArthurDanjou/artsite.git
synced 2026-01-14 15:54:13 +01:00
Add nuxt-visitors
This commit is contained in:
@@ -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)
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user