Compare commits
3 commits
05629a00a0
...
100cd67823
| Author | SHA1 | Date | |
|---|---|---|---|
| 100cd67823 | |||
| 5b9931c585 | |||
| 77ee36d0ab |
3 changed files with 4 additions and 31 deletions
|
|
@ -8,10 +8,7 @@ start:
|
||||||
bun run start
|
bun run start
|
||||||
|
|
||||||
check:
|
check:
|
||||||
bun run check
|
bun run lint && bun run typecheck && bun run test
|
||||||
|
|
||||||
fix:
|
|
||||||
bun run fix
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker build -t collabd .
|
docker build -t collabd .
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"lint": "bunx biome check --write .",
|
||||||
"dev": "bun run --watch src/index.ts",
|
"dev": "bun run --watch src/index.ts",
|
||||||
"start": "bun run src/index.ts",
|
"start": "bun run src/index.ts",
|
||||||
"test": "bun test",
|
"test": "bun test",
|
||||||
"check": "biome check .",
|
"typecheck": "bunx tsc"
|
||||||
"fix": "biome check --write ."
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lib0": "^0.2.117",
|
"lib0": "^0.2.117",
|
||||||
|
|
|
||||||
|
|
@ -25,33 +25,9 @@ export function encode(msg: ServerMessage): string {
|
||||||
return JSON.stringify(msg);
|
return JSON.stringify(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isClientMessage(obj: unknown): obj is ClientMessage {
|
|
||||||
if (typeof obj !== "object" || obj === null) return false;
|
|
||||||
const msg = obj as Record<string, unknown>;
|
|
||||||
|
|
||||||
switch (msg.type) {
|
|
||||||
case "join":
|
|
||||||
return typeof msg.room === "string";
|
|
||||||
case "leave":
|
|
||||||
return true;
|
|
||||||
case "update":
|
|
||||||
return (
|
|
||||||
Array.isArray(msg.data) && msg.data.every((n) => typeof n === "number")
|
|
||||||
);
|
|
||||||
case "awareness":
|
|
||||||
return (
|
|
||||||
Array.isArray(msg.data) && msg.data.every((n) => typeof n === "number")
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function decode(raw: string): ClientMessage | null {
|
export function decode(raw: string): ClientMessage | null {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(raw);
|
return JSON.parse(raw) as ClientMessage;
|
||||||
if (!isClientMessage(parsed)) return null;
|
|
||||||
return parsed;
|
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue