Compare commits

..

5 Commits

Author SHA1 Message Date
Yeicor
6944f69110 Automatically update version to 0.6.18 2024-03-16 15:23:23 +00:00
Yeicor
1d01c75448 more fixes 2024-03-16 16:22:08 +01:00
Yeicor
cb0a7bdf0c Automatically update version to 0.6.17 2024-03-16 09:57:27 +00:00
Yeicor
a7dba6fd1b Merge remote-tracking branch 'origin/master' 2024-03-16 10:56:54 +01:00
Yeicor
981d923e5e fix 2024-03-16 10:56:46 +01:00
6 changed files with 35 additions and 44 deletions

View File

@@ -57,7 +57,7 @@ async function onModelUpdateRequest(event: NetworkUpdateEvent) {
} }
if (shutdownRequest !== null) { if (shutdownRequest !== null) {
console.log("Shutting down the connection as requested by the server"); console.log("Shutting down the connection as requested by the server");
event.disconnectForALittleBit(); event.disconnect();
} }
sceneDocument.value = doc sceneDocument.value = doc
triggerRef(sceneDocument); // Why not triggered automatically? triggerRef(sceneDocument); // Why not triggered automatically?

View File

@@ -19,12 +19,12 @@ class NetworkUpdateEventModel {
export class NetworkUpdateEvent extends Event { export class NetworkUpdateEvent extends Event {
models: NetworkUpdateEventModel[]; models: NetworkUpdateEventModel[];
disconnectForALittleBit: () => void; disconnect: () => void;
constructor(models: NetworkUpdateEventModel[], disconnectForALittleBit: () => void) { constructor(models: NetworkUpdateEventModel[], disconnect: () => void) {
super("update"); super("update");
this.models = models; this.models = models;
this.disconnectForALittleBit = disconnectForALittleBit; this.disconnect = disconnect;
} }
} }
@@ -59,7 +59,8 @@ export class NetworkManager extends EventTarget {
} }
} }
private async monitorDevServer(url: URL, pendingTimeout: { id: number } = {id: -1}) { private async monitorDevServer(url: URL, stop: () => boolean = () => false) {
while (!stop()) {
try { try {
// WARNING: This will spam the console logs with failed requests when the server is down // WARNING: This will spam the console logs with failed requests when the server is down
const controller = new AbortController(); const controller = new AbortController();
@@ -68,6 +69,7 @@ export class NetworkManager extends EventTarget {
if (response.status === 200) { if (response.status === 200) {
let lines = readLinesStreamings(response.body!.getReader()); let lines = readLinesStreamings(response.body!.getReader());
for await (let line of lines) { for await (let line of lines) {
if (stop()) break;
if (!line || !line.startsWith("data:")) continue; if (!line || !line.startsWith("data:")) continue;
let data: { name: string, hash: string, is_remove: boolean | null } = JSON.parse(line.slice(5)); let data: { name: string, hash: string, is_remove: boolean | null } = JSON.parse(line.slice(5));
// console.debug("WebSocket message", data); // console.debug("WebSocket message", data);
@@ -75,29 +77,18 @@ export class NetworkManager extends EventTarget {
urlObj.searchParams.delete("api_updates"); urlObj.searchParams.delete("api_updates");
urlObj.searchParams.set("api_object", data.name); urlObj.searchParams.set("api_object", data.name);
this.foundModel(data.name, data.hash, urlObj.toString(), data.is_remove, async () => { this.foundModel(data.name, data.hash, urlObj.toString(), data.is_remove, async () => {
console.log("Disconnecting for a little bit"); controller.abort(); // Notify the server that we are done
controller.abort();
clearTimeout(pendingTimeout.id!);
pendingTimeout.id = -2;
setTimeout(() => {
console.log("Reconnecting after a little bit");
this.monitorDevServer(url, pendingTimeout)
}, settings.monitorEveryMs * 50);
}); });
} }
} }
controller.abort();
} catch (e) { // Ignore errors (retry very soon) } catch (e) { // Ignore errors (retry very soon)
} }
if (pendingTimeout.id >= -1) { await new Promise(resolve => setTimeout(resolve, settings.monitorEveryMs));
pendingTimeout.id = setTimeout(() => {
console.log("Reconnecting fast");
this.monitorDevServer(url, pendingTimeout)
}, settings.monitorEveryMs);
} }
return;
} }
private foundModel(name: string, hash: string | null, url: string, isRemove: boolean | null, disconnectForALittleBit: () => void = () => { private foundModel(name: string, hash: string | null, url: string, isRemove: boolean | null, disconnect: () => void = () => {
}) { }) {
let prevHash = this.knownObjectHashes[name]; let prevHash = this.knownObjectHashes[name];
// console.debug("Found model", name, "with hash", hash, "and previous hash", prevHash); // console.debug("Found model", name, "with hash", hash, "and previous hash", prevHash);
@@ -109,7 +100,7 @@ export class NetworkManager extends EventTarget {
if (!(name in this.knownObjectHashes)) return; // Nothing to remove... if (!(name in this.knownObjectHashes)) return; // Nothing to remove...
delete this.knownObjectHashes[name]; delete this.knownObjectHashes[name];
// Also update buffered updates if the model is removed // Also update buffered updates if the model is removed
//this.bufferedUpdates = this.bufferedUpdates.filter(m => m.name !== name); this.bufferedUpdates = this.bufferedUpdates.filter(m => m.name !== name);
} }
let newModel = new NetworkUpdateEventModel(name, url, hash, isRemove); let newModel = new NetworkUpdateEventModel(name, url, hash, isRemove);
this.bufferedUpdates.push(newModel); this.bufferedUpdates.push(newModel);
@@ -117,7 +108,7 @@ export class NetworkManager extends EventTarget {
// Optimization: try to batch updates automatically for faster rendering // Optimization: try to batch updates automatically for faster rendering
if (this.batchTimeout !== null) clearTimeout(this.batchTimeout); if (this.batchTimeout !== null) clearTimeout(this.batchTimeout);
this.batchTimeout = setTimeout(() => { this.batchTimeout = setTimeout(() => {
this.dispatchEvent(new NetworkUpdateEvent(this.bufferedUpdates, disconnectForALittleBit)); this.dispatchEvent(new NetworkUpdateEvent(this.bufferedUpdates, disconnect));
this.bufferedUpdates = []; this.bufferedUpdates = [];
}, batchTimeout); }, batchTimeout);
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "yet-another-cad-viewer", "name": "yet-another-cad-viewer",
"version": "0.6.16", "version": "0.6.18",
"description": "", "description": "",
"license": "MIT", "license": "MIT",
"private": true, "private": true,

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "yacv-server" name = "yacv-server"
version = "0.6.16" version = "0.6.18"
description = "Yet Another CAD Viewer (server)" description = "Yet Another CAD Viewer (server)"
authors = ["Yeicor <4929005+Yeicor@users.noreply.github.com>"] authors = ["Yeicor <4929005+Yeicor@users.noreply.github.com>"]
license = "MIT" license = "MIT"

View File

@@ -75,7 +75,7 @@ class HTTPHandler(SimpleHTTPRequestHandler):
with self.yacv.frontend_lock.r_locked(): with self.yacv.frontend_lock.r_locked():
# Avoid accepting new connections while shutting down # Avoid accepting new connections while shutting down
if self.yacv.shutting_down.is_set() and not self.yacv.at_least_one_client.is_set(): if self.yacv.shutting_down.is_set() and self.yacv.at_least_one_client.is_set():
self.send_error(HTTPStatus.SERVICE_UNAVAILABLE, 'Server is shutting down') self.send_error(HTTPStatus.SERVICE_UNAVAILABLE, 'Server is shutting down')
return return
self.yacv.at_least_one_client.set() self.yacv.at_least_one_client.set()

View File

@@ -18,7 +18,7 @@ from OCP.TopoDS import TopoDS_Shape
from build123d import Shape, Axis, Location, Vector from build123d import Shape, Axis, Location, Vector
from dataclasses_json import dataclass_json from dataclasses_json import dataclass_json
from rwlock import RWLock from yacv_server.rwlock import RWLock
from yacv_server.cad import get_shape, grab_all_cad, CADCoreLike, CADLike from yacv_server.cad import get_shape, grab_all_cad, CADCoreLike, CADLike
from yacv_server.myhttp import HTTPHandler from yacv_server.myhttp import HTTPHandler
from yacv_server.mylogger import logger from yacv_server.mylogger import logger