Skip to content

Commit

Permalink
Fix presence state sync
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetenstad committed Jan 30, 2024
1 parent 5804017 commit e3cd31d
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/stores/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,9 @@ export const useOnlineStore = defineStore('online', {
initRoom(userId: string) {
this.room
.on('presence', { event: 'sync' }, () => {
// hmm?
})
.on('presence', { event: 'join' }, ({ newPresences }) => {
newPresences.forEach((p) => {
// @ts-ignore
const presence = p as OnlinePresence
this.presences = this.presences.filter(
(p) => p.userId != presence.userId
)
this.presences.push(presence)
})
})
.on('presence', { event: 'leave' }, ({ leftPresences }) => {
leftPresences.forEach((p) => {
// @ts-ignore
const presence = p as OnlinePresence
this.presences = this.presences.filter(
(p) => p.userId != presence.userId
)
if (presence.userId == this.spectating) {
this.spectating = null
}
})
const state = this.room.presenceState()
// @ts-ignore
this.presences = Object.values(state).flat()
})
.subscribe(async (status) => {
if (status !== 'SUBSCRIBED') {
Expand Down

0 comments on commit e3cd31d

Please sign in to comment.