diff --git a/packages/sdk/src/core/contextInternal.ts b/packages/sdk/src/core/contextInternal.ts index 8e04aead4..fa2bff78d 100644 --- a/packages/sdk/src/core/contextInternal.ts +++ b/packages/sdk/src/core/contextInternal.ts @@ -68,14 +68,12 @@ export class ContextInternal { public onSetAuthoritative = (userId: Guid) => { this._rigidBodyOrphanSet.forEach( - (value) => { - if (value === this._rigidBodyDefaultOwner) { - const actor = this.actorSet.get(value); - actor.owner = userId; - - this._rigidBodyOwnerMap.set(value, userId); - } - }) + (actorId) => { + const actor = this.actorSet.get(actorId); + actor.owner = userId; + this._rigidBodyOwnerMap.set(actorId, userId); + } + ) this._rigidBodyOrphanSet.clear(); this._rigidBodyDefaultOwner = userId; }; @@ -531,22 +529,23 @@ export class ContextInternal { this.context.emitter.emit('user-left', user); if (userId !== this._rigidBodyDefaultOwner) { - this._rigidBodyOwnerMap.forEach( (value, key) => { - if (value === userId) { - const actor = this.actorSet.get(key); - actor.owner = this._rigidBodyDefaultOwner; - this._rigidBodyOwnerMap.set(key, this._rigidBodyDefaultOwner); + this._rigidBodyOwnerMap.forEach( + (ownerId, actorId) => { + if (ownerId === userId) { + const actor = this.actorSet.get(actorId); + actor.owner = this._rigidBodyDefaultOwner; + this._rigidBodyOwnerMap.set(actorId, this._rigidBodyDefaultOwner); + } } - }) + ) } else { this._rigidBodyOwnerMap.forEach( - (value, key) => { - if (value === userId) { - const actor = this.actorSet.get(key); - actor.owner = this._rigidBodyDefaultOwner; - this._rigidBodyOrphanSet.add(key); + (ownerId, actorId) => { + if (ownerId === userId) { + this._rigidBodyOrphanSet.add(actorId); } - }) + } + ) } } }