Skip to content

Commit

Permalink
Inspector: attempt to detect and fix double formatting
Browse files Browse the repository at this point in the history
Once canalplus/rx-player#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.
  • Loading branch information
peaBerberian committed Jun 28, 2024
1 parent 1eeffea commit 986b0a3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion inspector/src/pages/live_debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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++],
]);
Expand Down

0 comments on commit 986b0a3

Please sign in to comment.