Skip to content

Commit

Permalink
try this on render
Browse files Browse the repository at this point in the history
  • Loading branch information
sammynave committed Jan 5, 2024
1 parent e574902 commit 670b963
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/lib/server/websockets/features/offline/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export class Sync {

this.redisClient.publish(this.stream, data);
}

if (parsed.type === 'connected') {
console.log('connected', parsed);
this.pull(parsed.clientSiteId);
this.push(parsed.clientSiteId);
}
}

private merge(changes) {
Expand Down
20 changes: 12 additions & 8 deletions src/routes/app/offline-first/sync-db-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ export function db({ databasePromise, wsPromise, serverSiteId, name }) {
databasePromise.then(async (database) => {
const ws = await wsPromise;
globalThis.addEventListener('online', async (event) => {
const result = await database.lastTrackedChangeFor(serverSiteId, 1);
const trackedVersion = result?.[0]?.[0] ?? 0;
await pushChangesSince({
database,
ws,
sinceVersion: trackedVersion,
serverSiteId
});
// Request update
ws.send(JSON.stringify({ type: 'connected', siteId: database.siteId }));

// // Send update
// const result = await database.lastTrackedChangeFor(serverSiteId, 1);
// const trackedVersion = result?.[0]?.[0] ?? 0;
// await pushChangesSince({
// database,
// ws,
// sinceVersion: trackedVersion,
// serverSiteId
// });
});
});

Expand Down

0 comments on commit 670b963

Please sign in to comment.