Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Fix peer create and destroy actions causing logging bugs #8000

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/client-core/src/systems/LoadingUISystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
import { removeEntity } from '@etherealengine/engine/src/ecs/functions/EntityFunctions'
import { defineSystem } from '@etherealengine/engine/src/ecs/functions/SystemFunctions'
import { WorldState } from '@etherealengine/engine/src/networking/interfaces/WorldState'
import { NameComponent } from '@etherealengine/engine/src/scene/components/NameComponent'
import { setVisibleComponent } from '@etherealengine/engine/src/scene/components/VisibleComponent'
import { ObjectLayers } from '@etherealengine/engine/src/scene/constants/ObjectLayers'
Expand Down Expand Up @@ -119,16 +120,25 @@ const execute = () => {
transition.setState('OUT')
}

const mediaNetwork = Engine.instance.mediaNetwork
const worldState = getState(WorldState)

for (const action of peerCreatedQueue()) {
const selfUser = getState(AuthState).user
if (action.peer.peerID !== 'server' && action.peer.userId !== selfUser.id)
NotificationService.dispatchNotify(`${action.name} ${t('common:toast.joined')}`, { variant: 'default' })
const peerUser = mediaNetwork.peers.get(action.peerID)
if (action.peerID !== 'server' && peerUser && peerUser.userId !== selfUser.id) {
const name = worldState.userNames[peerUser.userId]
NotificationService.dispatchNotify(`${name} ${t('common:toast.joined')}`, { variant: 'default' })
}
}

for (const action of peerDestroyedQueue()) {
const selfUser = getState(AuthState).user
if (action.peer.peerID !== 'server' && action.peer.userId !== selfUser.id)
NotificationService.dispatchNotify(`${action.name} ${t('common:toast.left')}`, { variant: 'default' })
const peerUser = mediaNetwork.peers.get(action.peerID)
if (action.peerID !== 'server' && peerUser && peerUser.userId !== selfUser.id) {
const name = worldState.userNames[peerUser.userId]
NotificationService.dispatchNotify(`${name} ${t('common:toast.left')}`, { variant: 'default' })
}
}

if (transition.state === 'OUT' && transition.alpha === 0) {
Expand Down
8 changes: 3 additions & 5 deletions packages/engine/src/ecs/classes/EngineState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineAction, defineState, getMutableState, useState } from '@etherealengine/hyperflux'

import { matches, matchesEntity, Validator } from '../../common/functions/MatchesUtils'
import { matches, matchesEntity, matchesPeerID, Validator } from '../../common/functions/MatchesUtils'
import { NetworkPeer } from '../../networking/interfaces/NetworkPeer'
import { Entity } from './Entity'

Expand Down Expand Up @@ -154,13 +154,11 @@ export class EngineActions {

static peerCreated = defineAction({
type: 'ee.engine.Engine.PEER_CREATED' as const,
peer: matches.any as Validator<unknown, NetworkPeer>,
name: matches.string
peerID: matchesPeerID
})

static peerDestroyed = defineAction({
type: 'ee.engine.Engine.PEER_DESTROYED' as const,
peer: matches.any as Validator<unknown, NetworkPeer>,
name: matches.string
peerID: matchesPeerID
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function createPeer(
worldState.userNames[userID].set(name)

if (network.topic === 'world') {
dispatchAction(EngineActions.peerCreated({ peer: network.peers.get(peerID)!, name: name ?? '' }))
dispatchAction(EngineActions.peerCreated({ peerID }))
}
}

Expand All @@ -58,9 +58,7 @@ function destroyPeer(network: Network, peerID: PeerID) {
if (userID === Engine.instance.userId) return console.warn(`[NetworkPeerFunctions]: tried to remove local client`)

if (network.topic === 'world') {
const worldState = getState(WorldState)
const name = worldState.userNames[userID]
dispatchAction(EngineActions.peerDestroyed({ peer: network.peers.get(peerID)!, name: name ?? '' }))
dispatchAction(EngineActions.peerDestroyed({ peerID }))
}

network.peers.delete(peerID)
Expand Down