Skip to content

Commit

Permalink
fix remote client colors
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Oct 10, 2023
1 parent 8fad7a8 commit 86be977
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/components/LaserTool/LaserPathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ export class LaserPathManager {
state.svg.setAttribute("d", paths);
state.svg.setAttribute(
"fill",
collaborator.pointer?.laserColor || getClientColor(key),
collaborator.pointer?.laserColor ||
getClientColor(collaborator.id || key),
);
}

Expand Down
17 changes: 10 additions & 7 deletions src/components/canvases/InteractiveCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
if (user.userState) {
pointerUserStates[socketId] = user.userState;
}
pointerViewportCoords[socketId] = sceneCoordsToViewportCoords(
{
sceneX: user.pointer.x,
sceneY: user.pointer.y,
},
props.appState,
);
pointerViewportCoords[socketId] = {
...sceneCoordsToViewportCoords(
{
sceneX: user.pointer.x,
sceneY: user.pointer.y,
},
props.appState,
),
id: user.id || socketId,
};
cursorButton[socketId] = user.button;
});

Expand Down
12 changes: 6 additions & 6 deletions src/renderer/renderScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,10 @@ const _renderInteractiveScene = ({
selectionColors.push(
...renderConfig.remoteSelectedElementIds[element.id].map(
(socketId) => {
const picture =
appState.collaborators.get(socketId)?.avatarUrl;
const background = getClientColor(picture || socketId);
const { id } =
renderConfig.remotePointerViewportCoords[socketId];

const background = getClientColor(id);
return background;
},
),
Expand Down Expand Up @@ -731,7 +732,7 @@ const _renderInteractiveScene = ({

// Paint remote pointers
for (const clientId in renderConfig.remotePointerViewportCoords) {
let { x, y } = renderConfig.remotePointerViewportCoords[clientId];
let { x, y, id } = renderConfig.remotePointerViewportCoords[clientId];

x -= appState.offsetLeft;
y -= appState.offsetTop;
Expand All @@ -750,8 +751,7 @@ const _renderInteractiveScene = ({
y = Math.max(y, 0);
y = Math.min(y, normalizedHeight - height);

const picture = appState.collaborators.get(clientId)?.avatarUrl;
const background = getClientColor(picture || clientId);
const background = getClientColor(id);

context.save();
context.strokeStyle = background;
Expand Down
4 changes: 3 additions & 1 deletion src/scene/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export type InteractiveCanvasRenderConfig = {
// collab-related state
// ---------------------------------------------------------------------------
remoteSelectedElementIds: { [elementId: string]: string[] };
remotePointerViewportCoords: { [id: string]: { x: number; y: number } };
remotePointerViewportCoords: {
[id: string]: { x: number; y: number; id: string };
};
remotePointerUserStates: { [id: string]: string };
remotePointerUsernames: { [id: string]: string };
remotePointerButton?: { [id: string]: string | undefined };
Expand Down

0 comments on commit 86be977

Please sign in to comment.