Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Fix for transform subscriptions when actor is an attachment #745

Merged
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions packages/sdk/src/internal/adapters/multipeer/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ export const Rules: { [id in Payloads.PayloadType]: Rule } = {
message: Message<Payloads.ActorCorrection>
) => {
const syncActor = session.actorSet.get(message.payload.actorId);
if (syncActor && ((client.authoritative && !syncActor.grabbedBy)
|| (syncActor.grabbedBy === client.id))) {
const attachment = syncActor.initialization.message.payload.actor.attachment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible for syncActor to be undefined here which will cause this to throw an exception. Getting the attachment will need to be moved into the if block below it where syncActor will already be tested for undefined. Alternatively you can do optional chaining on the syncActor like:

const attachment = syncActor?.initialization.message.payload.actor.attachment;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. See latest commit.

if (syncActor && ((client.authoritative && !syncActor.grabbedBy) ||
(syncActor.grabbedBy === client.id) ||
(attachment && attachment.userId === client.userId))) {
const correctionPayload = message.payload;

// Synthesize an actor update message and add in the transform from the correction payload.
Expand Down Expand Up @@ -402,8 +404,10 @@ export const Rules: { [id in Payloads.PayloadType]: Rule } = {
message: Message<Payloads.ActorUpdate>
) => {
const syncActor = session.actorSet.get(message.payload.actor.id);
const attachment = syncActor.initialization.message.payload.actor.attachment;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See same comment above about syncActyor being undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. See latest commit.

if (syncActor && ((client.authoritative && !syncActor.grabbedBy) ||
(syncActor.grabbedBy === client.id))) {
(syncActor.grabbedBy === client.id) ||
(attachment && attachment.userId === client.userId))) {
// Merge the update into the existing actor.
session.cacheActorUpdateMessage(message);

Expand Down