Skip to content

Chore/upgrade partykit #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 19 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function ReactBlockNote(props: { theme: "light" | "dark" }) {
const doc = new Y.Doc();
const provider = new YPartyKitProvider(
"blocknote.yousefed.partykit.dev",
"homepage-1",
// "127.0.0.1:1999", // (dev server)
"homepage-2",
doc
);
return [doc, provider];
Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/docs/real-time-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ When a user edits the document, an incremental change (or "update") is captured
For development purposes, you can use our Partykit server to test collaborative features. Replace the `WebrtcProvider` provider in the example below with a `YPartyKitProvider`:

```typescript
// npm install y-partykit@beta
// npm install y-partykit
import YPartyKitProvider from "y-partykit/provider";

const provider = new YPartyKitProvider(
Expand Down
2 changes: 1 addition & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@vercel/og": "^0.5.6",
"veaury": "^2.3.12",
"vue-github-button": "^3.1.0",
"y-partykit": "^0.0.0-4d484bc",
"y-partykit": "^0.0.10",
"yjs": "^13.6.1"
},
"devDependencies": {
Expand Down
38 changes: 30 additions & 8 deletions packages/website/partykitserver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import type { PartyKitServer } from "partykit/server";
import type * as Party from "partykit/server";
import { onConnect } from "y-partykit";

// deploy with npx partykit@beta deploy partykitserver.ts --name blocknote
// preview with npx partykit@beta dev partykitserver.ts
export default {
onConnect(ws, room) {
return onConnect(ws, room, { persist: false, gc: true });
},
} satisfies PartyKitServer;
const EXPIRY_PERIOD_MILLISECONDS = 60 * 60 * 1000; // 1 hour

// deploy with npx partykit deploy partykitserver.ts --name blocknote
// preview with npx partykit dev partykitserver.ts
export default class Server implements Party.Server {
constructor(readonly party: Party.Party) {}

onConnect(conn: Party.Connection, ctx: Party.ConnectionContext) {
// A websocket just connected!

return onConnect(conn, this.party, { persist: false, gc: true });
}

async onMessage(message: string) {
// const data = JSON.parse(message);
// do something, and save to storage
// await this.party.storage.put(data.id, data);
// console.log("on message");
await this.party.storage.setAlarm(Date.now() + EXPIRY_PERIOD_MILLISECONDS);
}

async onAlarm() {
// clear all storage in this room
console.log("alarm, delete storage");
await this.party.storage.deleteAll();
}
}

Server satisfies Party.Worker;