From 382f9b2ebedca905028341825350a0fa69d88673 Mon Sep 17 00:00:00 2001 From: RblSb Date: Wed, 29 Jan 2025 20:37:50 +0300 Subject: Cleanup - PWA support (needs https) - Optimize websocket responses - Support `/ad` for youtube cache - New icon! --- src/server/Main.hx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/server/Main.hx') diff --git a/src/server/Main.hx b/src/server/Main.hx index 4f0fd03..d5c0800 100644 --- a/src/server/Main.hx +++ b/src/server/Main.hx @@ -940,7 +940,7 @@ class Main { }), logs: logger.getLogs() } - final json = Json.stringify(data, logger.filterNulls, "\t"); + final json = jsonStringify(data, "\t"); send(client, { type: Dump, dump: { @@ -984,23 +984,34 @@ class Main { } public function send(client:Client, data:WsEvent):Void { - client.ws.send(Json.stringify(data), null); + client.ws.send(jsonStringify(data), null); } public function broadcast(data:WsEvent):Void { - final json = Json.stringify(data); + final json = jsonStringify(data); for (client in clients) client.ws.send(json, null); } public function broadcastExcept(skipped:Client, data:WsEvent):Void { - final json = Json.stringify(data); + final json = jsonStringify(data); for (client in clients) { if (client == skipped) continue; client.ws.send(json, null); } } + public static function jsonStringify(data:Any, ?space:String):String { + return Json.stringify(data, jsonFilterNulls, space); + } + + static function jsonFilterNulls(key:Any, value:Any):Any { + #if js + if (value == null) return js.Lib.undefined; + #end + return value; + } + function skipVideo(data:WsEvent):Void { if (videoList.length == 0) return; final item = videoList.currentItem; -- cgit v1.2.3