open method
Implementation
Future<MeshDocument> open(String path, {bool create = true}) async {
final pending = _connectingDocuments[path];
if (pending != null) {
await pending;
}
if (_connectedDocuments[path] != null) {
final connectedDoc = _connectedDocuments[path];
connectedDoc!.count++;
return connectedDoc.ref;
}
// todo: add support for state vector / partial updates
// todo: initial bytes loading
final c = Completer<_RefCount<MeshDocument>>();
_connectingDocuments[path] = c.future;
try {
final result = (await room.sendRequest("room.connect", {"path": path, "create": create})) as JsonResponse;
MeshSchema schema = MeshSchema.fromJson(result.json["schema"]);
final doc = MeshDocument(
schema: schema,
sendChangesToBackend: (base64) => _changesToSync.sink.add(_QueuedSync(path: path, base64: base64)),
);
final rc = _RefCount(doc);
_connectedDocuments[path] = rc;
notifyListeners();
c.complete(rc);
return doc;
} catch (err) {
c.completeError(err);
rethrow;
} finally {
_connectingDocuments.remove(path);
}
}