diff --git a/src/app.js b/src/app.js index 42e06c087227c425e6138a283a4d8466c3299b3d..329e7a02b27de923b09bb8ac41be36f27cbcca69 100644 --- a/src/app.js +++ b/src/app.js @@ -576,10 +576,17 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => { switch (currentTool) { case toolSelection.Tools.PEN: { const pathID = pathIDsByPointerID.get(e.pointerId) - room.extendPath( - pathID, - selectedColorAndRadiusPoint(...mousePos, pressure), - ) + if (pathID) { + room.extendPath( + pathID, + selectedColorAndRadiusPoint(...mousePos, pressure), + ) + } else { + pathIDsByPointerID.set( + e.pointerId, + room.addPath(selectedColorAndRadiusPoint(...mousePos, pressure)), + ) + } if (toolSelection.isRecognitionModeSet()) { drawRecognizedUpcoming(room.getPathPoints(pathID), pressure) } diff --git a/src/wasm-crdt.js b/src/wasm-crdt.js index 4709f546452ab6f8167280e8cb536ad06bef221d..eb873ce3c13df7a1b60e95adce12fbd442491f81 100644 --- a/src/wasm-crdt.js +++ b/src/wasm-crdt.js @@ -14,9 +14,10 @@ Array.prototype.remove = function(elem) { } export default class WasmCRDTWrapper { - constructor(WasmCRDT, room, interval) { + constructor(WasmCRDT, room, interval, resolve) { this.room = room this.mesh = null + this.resolve = resolve this.users = { synced: [], @@ -84,12 +85,16 @@ export default class WasmCRDTWrapper { static async initialise(room, options) { const { WasmCRDT } = await WasmCRDTAsync - room.crdt = new WasmCRDTWrapper( - WasmCRDT, - room, - (options.wasm && options.wasm.interval) || 0, - ) - room.crdt.mesh = new P2PMesh(room.crdt, options) + await new Promise((resolve) => { + room.crdt = new WasmCRDTWrapper( + WasmCRDT, + room, + (options.wasm && options.wasm.interval) || 0, + resolve, + ) + + room.crdt.mesh = new P2PMesh(room.crdt, options) + }) } getUserID() { @@ -100,6 +105,7 @@ export default class WasmCRDTWrapper { const success = this.crdt.set_user(uid) if (success) { + this.resolve() this.room.dispatchEvent(new CustomEvent("allocateOwnID", { detail: uid })) }