diff --git a/web/RdfDbChannel.ts b/web/RdfDbChannel.ts --- a/web/RdfDbChannel.ts +++ b/web/RdfDbChannel.ts @@ -48,6 +48,7 @@ export class RdfDbChannel { sendMessage(body: string): boolean { // one try, best effort, true if we think it worked if (!this.ws || this.ws.readyState !== this.ws.OPEN) { + log("dropping message: " + body); return false; } log("send patch to server, " + body.length + " bytes"); diff --git a/web/SyncedGraph.ts b/web/SyncedGraph.ts --- a/web/SyncedGraph.ts +++ b/web/SyncedGraph.ts @@ -151,22 +151,19 @@ export class SyncedGraph { } applyAndSendPatch(patch: Patch) { - console.time("applyAndSendPatch"); if (!this.client) { - log("not connected-- dropping patch"); + throw new Error("no client yet"); + } + if (patch.isEmpty()) { return; } - if (!patch.isEmpty()) { - this._applyPatch(patch); - // // chaos delay - // setTimeout(()=>{ - if (this.client) { - log("sending patch:\n", patch.dump()); - this.client.sendPatch(patch); - } - // },300*Math.random()) - } - console.timeEnd("applyAndSendPatch"); + this._applyPatch(patch); + // // chaos delay + // setTimeout(()=>{ + log("sending patch:\n", patch.dump()); + this.client.sendPatch(patch); + + // },300*Math.random()) } _applyPatch(patch: Patch) { diff --git a/web/rdfdbclient.ts b/web/rdfdbclient.ts --- a/web/rdfdbclient.ts +++ b/web/rdfdbclient.ts @@ -5,7 +5,7 @@ const log = debug("rdfdbclient"); export class RdfDbClient { private channel: RdfDbChannel; - _patchesToSend: Patch[]; + private patchesToSend: Patch[]; // Send and receive patches from rdfdb. Primarily used in SyncedGraph. // // What this should do, and does not yet, is keep the graph @@ -19,10 +19,10 @@ export class RdfDbClient { private applyPatch: (p: Patch) => void, setStatus: (status: string) => void ) { - this._patchesToSend = []; + this.patchesToSend = []; this.channel = new RdfDbChannel(patchSenderUrl); this.channel.statusDisplay.subscribe((st: string) => { - setStatus(st + `; ${this._patchesToSend.length} pending `); + setStatus(st + `; ${this.patchesToSend.length} pending `); }); this.channel.newConnection.subscribe(() => { this.clearGraphOnNewConnection(); @@ -40,7 +40,7 @@ export class RdfDbClient { sendPatch(patch: Patch) { log("queue patch to server ", patch.summary()); - this._patchesToSend.push(patch); + this.patchesToSend.push(patch); this._continueSending(); } @@ -51,11 +51,13 @@ export class RdfDbClient { async _continueSending() { // we could call this less often and coalesce patches together to optimize // the dragging cases. See rdfdb 'compactPatches' and 'processInbox'. - while (this._patchesToSend.length) { - const patch = this._patchesToSend.splice(0, 1)[0]; + while (this.patchesToSend.length) { + const patch = this.patchesToSend.splice(0, 1)[0]; const json = await patch.toJsonPatch(); const ret = this.channel.sendMessage(json); if (!ret) { + log('sendMessage failed- retrying') + this.patchesToSend.unshift(patch); setTimeout(this._continueSending.bind(this), 500); // this.disconnect()