Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgriffintn committed Dec 6, 2024
1 parent 8bbb6c4 commit 08d54c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion apps/multiplayer/src/multiplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export class Multiplayer implements DurableObject {

async webSocketClose(ws: WebSocket, code: number, reason: string) {
try {
ws.close(code, reason || 'Durable Object is closing WebSocket');
if (code !== 1006 && code >= 1000 && code < 5000) {
ws.close(code, reason || 'Durable Object is closing WebSocket');
}
} catch (error) {
console.error('Error closing WebSocket:', error);
}
Expand Down
19 changes: 15 additions & 4 deletions apps/web/components/DrawingCanvas/Components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ export function Canvas({
const scaleY = canvasRef.current.height / rect.height;

const x =
(('touches' in e ? e.touches[0].clientX : e.clientX) - rect.left) *
(('touches' in e && e.touches[0]
? e.touches[0].clientX
: 'clientX' in e
? e.clientX
: 0) -
rect.left) *
scaleX;
const y =
(('touches' in e ? e.touches[0].clientY : e.clientY) - rect.top) * scaleY;
(('touches' in e && e.touches[0]
? e.touches[0].clientY
: 'clientY' in e
? e.clientY
: 0) -
rect.top) *
scaleY;

ctx.beginPath();
ctx.moveTo(lastX.current, lastY.current);
Expand Down Expand Up @@ -89,10 +100,10 @@ export function Canvas({
const scaleX = canvas.width / rect.width;
const scaleY = canvas.height / rect.height;

if ('touches' in e) {
if ('touches' in e && e.touches[0]) {
lastX.current = (e.touches[0].clientX - rect.left) * scaleX;
lastY.current = (e.touches[0].clientY - rect.top) * scaleY;
} else {
} else if ('clientX' in e && 'clientY' in e) {
lastX.current = (e.clientX - rect.left) * scaleX;
lastY.current = (e.clientY - rect.top) * scaleY;
}
Expand Down

0 comments on commit 08d54c3

Please sign in to comment.