From 986b0a3d9b7813308655ccff4c8d660e294514f8 Mon Sep 17 00:00:00 2001 From: Paul Berberian Date: Fri, 28 Jun 2024 15:41:02 +0200 Subject: [PATCH] Inspector: attempt to detect and fix double formatting Once https://github.com/canalplus/rx-player/pull/1469 is merged, we risk to be in a situation where the `timestamp [namespace] log` format as exported by the RxPaired's inspector (and can be imported by it) would be unnecessarily repeating. This is a proposal for fixing it by updating the inspector's code so we can detect and just keep the first timestamp+namespace combo To reduce the possibility of false positives and especially to avoid loss of information, I check that the "namespace" are the same. False positives are still a possibility though. --- inspector/src/pages/live_debugging.ts | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/inspector/src/pages/live_debugging.ts b/inspector/src/pages/live_debugging.ts index e464251..0accbf6 100644 --- a/inspector/src/pages/live_debugging.ts +++ b/inspector/src/pages/live_debugging.ts @@ -21,6 +21,25 @@ import { parseAndGenerateInitLog, } from "./utils"; +/** + * We've added the possibility on the RxPlayer to output logs already compatible + * with RxPaired (as in: can be imported by it) to ease-up later debugging when + * people doing the testing do not rely on RxPaired themselves. + * + * This format-update feature could also be added to other tools relying on + * RxPaired, so it makes sense to detect and work-around that possibility here. + * + * In the case where the log preamble seems to be repeated two times at the + * beginning, we'll remove the second one. + * + * Match 1: first timestamp + first namespace + space + * Match 2: first timestamp + * Match 3: first namespace + * Match 4: second timestamp + * Match 5: second namespace + */ +const DOUBLE_FORMATTING_REGEXP = /^(([0-9]+(?:\.[0-9]+)?) \[([^\]]+)\] )([0-9]+(?:\.[0-9]+)?) \[([^\]]+)\] /; + /** * Some minor features are detected to be only present on chromium-based * browsers for now but are sadly neither polyfillable nor feature-detectable. @@ -254,7 +273,14 @@ export default function generateLiveDebuggingPage( return; } } else { - const newLog = event.data; + let newLog = event.data; + const regMatch = (newLog).match(DOUBLE_FORMATTING_REGEXP); + + // If the beginning repeat with the same namespace, it's very probably + // double formatting + if (regMatch !== null && regMatch[3] === regMatch[5]) { + newLog = newLog.substring(0, regMatch[1].length) + newLog.substring(regMatch[0].length); + } logViewState.updateState(STATE_PROPS.LOGS_HISTORY, UPDATE_TYPE.PUSH, [ [newLog, nextLogId++], ]);