persistir

fixes #5
This commit is contained in:
Cat /dev/Nulo 2023-03-05 22:15:59 +00:00
parent 03f01903bd
commit aeedc27b00
3 changed files with 14 additions and 0 deletions

View file

@ -35,6 +35,7 @@
"nanoid": "^4.0.1", "nanoid": "^4.0.1",
"navaid": "^1.2.0", "navaid": "^1.2.0",
"regexparam": "^2.0.1", "regexparam": "^2.0.1",
"y-indexeddb": "^9.0.9",
"y-prosemirror": "^1.2.0", "y-prosemirror": "^1.2.0",
"y-protocols": "^1.0.5", "y-protocols": "^1.0.5",
"y-webrtc": "^10.2.4", "y-webrtc": "^10.2.4",

View file

@ -24,6 +24,7 @@ specifiers:
tslib: ^2.5.0 tslib: ^2.5.0
typescript: ^4.9.3 typescript: ^4.9.3
vite: ^4.1.0 vite: ^4.1.0
y-indexeddb: ^9.0.9
y-prosemirror: ^1.2.0 y-prosemirror: ^1.2.0
y-protocols: ^1.0.5 y-protocols: ^1.0.5
y-webrtc: ^10.2.4 y-webrtc: ^10.2.4
@ -34,6 +35,7 @@ dependencies:
nanoid: 4.0.1 nanoid: 4.0.1
navaid: 1.2.0 navaid: 1.2.0
regexparam: 2.0.1 regexparam: 2.0.1
y-indexeddb: 9.0.9_yjs@13.5.48
y-prosemirror: 1.2.0_vhy2hiocjqydif5dwvxgfnpihi y-prosemirror: 1.2.0_vhy2hiocjqydif5dwvxgfnpihi
y-protocols: 1.0.5 y-protocols: 1.0.5
y-webrtc: 10.2.4 y-webrtc: 10.2.4
@ -1195,6 +1197,15 @@ packages:
dev: false dev: false
optional: true optional: true
/y-indexeddb/9.0.9_yjs@13.5.48:
resolution: {integrity: sha512-GcJbiJa2eD5hankj46Hea9z4hbDnDjvh1fT62E5SpZRsv8GcEemw34l1hwI2eknGcv5Ih9JfusT37JLx9q3LFg==}
peerDependencies:
yjs: ^13.0.0
dependencies:
lib0: 0.2.63
yjs: 13.5.48
dev: false
/y-prosemirror/1.2.0_vhy2hiocjqydif5dwvxgfnpihi: /y-prosemirror/1.2.0_vhy2hiocjqydif5dwvxgfnpihi:
resolution: {integrity: sha512-t3uxuX4HIkb1GNt8jV+dplRbNH2OmQD/BNeCCbjLD3Mq0o6JEXxHedv58ZIPFDE6ma24jljlL+u8pGvN6B37XQ==} resolution: {integrity: sha512-t3uxuX4HIkb1GNt8jV+dplRbNH2OmQD/BNeCCbjLD3Mq0o6JEXxHedv58ZIPFDE6ma24jljlL+u8pGvN6B37XQ==}
peerDependencies: peerDependencies:

View file

@ -1,5 +1,6 @@
import * as Y from "yjs"; import * as Y from "yjs";
import { WebrtcProvider } from "y-webrtc"; import { WebrtcProvider } from "y-webrtc";
import { IndexeddbPersistence } from "y-indexeddb";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
export type WorldIdentifier = { export type WorldIdentifier = {
@ -34,6 +35,7 @@ export function getWorldY(world: WorldIdentifier): WorldY {
"wss://y-webrtc-signaling-us.herokuapp.com", "wss://y-webrtc-signaling-us.herokuapp.com",
], ],
}); });
const idbProvider = new IndexeddbPersistence(world.room, ydoc);
const worldY = { ydoc, webrtcProvider: provider }; const worldY = { ydoc, webrtcProvider: provider };
worldYCache[world.room] = worldY; worldYCache[world.room] = worldY;
return worldY; return worldY;