Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bhackett1024 committed Sep 13, 2024
1 parent 89a7164 commit 0d7b0f9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
36 changes: 26 additions & 10 deletions packages/shared/client/ReplayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,24 +1389,40 @@ function waitForOpenConnection(
});
}

// Compute the delta to adjust the timestamps for a supplemental server recording.
// A delta is the time difference between the base recording and the supplemental
// recording: a smaller delta moves the supplemental recording later, and a larger
// delta moves the supplemental recording closer.
//
// We want to find a delta that is small enough that all client-first connections
// happen on the client before they happen on the server, and large enough that
// all client-last connections happen on the server before they happen on the client.
function computeSupplementalTimeDelta(recordingId: string, supplemental: SupplementalSession) {
let minDelta: number | undefined;
let maxDelta: number | undefined;
// Delta which ensures that all clientFirst connections happen
// on the client before they happen on the server.
let clientFirstDelta: number | undefined;

// Delta which ensures that all clientLast connections happen
// on the server before they happen on the client.
let clientLastDelta: number | undefined;

for (const { clientFirst, clientRecordingId, clientPoint, serverPoint } of supplemental.connections) {
assert(recordingId == clientRecordingId);
const delta = serverPoint.time - clientPoint.time;
console.log("FoundDelta", delta, clientFirst);
if (clientFirst) {
if (typeof maxDelta == "undefined" || delta > maxDelta) {
maxDelta = delta;
if (typeof clientFirstDelta == "undefined" || delta < clientFirstDelta) {
clientFirstDelta = delta;
}
} else {
if (typeof minDelta == "undefined" || delta < minDelta) {
minDelta = delta;
if (typeof clientLastDelta == "undefined" || delta > clientLastDelta) {
clientLastDelta = delta;
}
}
}
assert(typeof minDelta != "undefined");
assert(typeof maxDelta != "undefined");
assert(minDelta <= maxDelta);
return (minDelta + maxDelta) / 2;
console.log("Deltas", clientFirstDelta, clientLastDelta);
assert(typeof clientFirstDelta != "undefined");
assert(typeof clientLastDelta != "undefined");
assert(clientFirstDelta >= clientLastDelta);
return (clientFirstDelta + clientLastDelta) / 2;
}
26 changes: 26 additions & 0 deletions src/ui/actions/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ function getSupplementalRecordings(recordingId: string): SupplementalRecording[]
time: 54294.69953306548,
},
},
// Second /public network call is made.
{
clientFirst: true,
clientRecordingId: "d5513383-5986-4de5-ab9d-2a7e1f367e90",
clientPoint: {
point: "56141709792928477884264450686451782",
time: 25301.991150442478,
},
serverPoint: {
point: "20444669041365036140696939482054693",
time: 66999.47944537815,
},
},
// Second /public network call returns.
{
clientFirst: false,
clientRecordingId: "d5513383-5986-4de5-ab9d-2a7e1f367e90",
clientPoint: {
point: "56790746901441151898702525872734210",
time: 25524.865255979654,
},
serverPoint: {
point: "20444669041638352324265057053573869",
time: 68611.1162184874,
},
},
],
}];
}
Expand Down

0 comments on commit 0d7b0f9

Please sign in to comment.