Skip to content

Commit

Permalink
Bug 1830790 - P15 - Switch about:webrtc to use sdpHistory;r=bwc
Browse files Browse the repository at this point in the history
  • Loading branch information
na-g committed May 31, 2023
1 parent 273dc94 commit 2af5978
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions toolkit/content/aboutwebrtc/aboutWebrtc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ let graphData = [];
let mostRecentReports = {};
let sdpHistories = [];
let historyTsMemoForPcid = {};
let sdpHistoryTsMemoForPcid = {};

function clearStatsHistory() {
graphData = [];
mostRecentReports = {};
sdpHistories = [];
historyTsMemoForPcid = {};
sdpHistoryTsMemoForPcid = {};
}

function appendReportToHistory(report) {
Expand All @@ -93,9 +95,11 @@ function appendReportToHistory(report) {
function appendSdpHistory({ pcid, sdpHistory: newHistory }) {
sdpHistories[pcid] ??= [];
let storedHistory = sdpHistories[pcid];
newHistory.forEach(({ timestamp, sdp }) => {
newHistory.forEach(entry => {
const { timestamp } = entry;
if (!storedHistory.length || storedHistory.at(-1).timestamp < timestamp) {
storedHistory.push({ timestamp, sdp });
storedHistory.push(entry);
sdpHistoryTsMemoForPcid[pcid] = timestamp;
}
});
}
Expand All @@ -114,11 +118,15 @@ function appendStats(allStats) {
allStats.forEach(appendReportToHistory);
}

function getAndUpdateTsMemoForPcid(pcid) {
function getAndUpdateStatsTsMemoForPcid(pcid) {
historyTsMemoForPcid[pcid] = mostRecentReports[pcid]?.timestamp;
return historyTsMemoForPcid[pcid] || null;
}

function getSdpTsMemoForPcid(pcid) {
return sdpHistoryTsMemoForPcid[pcid] || null;
}

const REQUEST_FULL_REFRESH = true;
async function getStats(requestFullRefresh) {
if (
Expand All @@ -133,7 +141,12 @@ async function getStats(requestFullRefresh) {
await Promise.all(
[...pcids].map(pcid =>
new Promise(r =>
WGI.getStatsHistorySince(r, pcid, getAndUpdateTsMemoForPcid(pcid))
WGI.getStatsHistorySince(
r,
pcid,
getAndUpdateStatsTsMemoForPcid(pcid),
getSdpTsMemoForPcid(pcid)
)
).then(r => {
appendStats(r.reports);
r.sdpHistories.forEach(hist => appendSdpHistory(hist));
Expand Down Expand Up @@ -609,10 +622,13 @@ const renderSDPHistoryTab = (rndr, hist, props) => {
]);
};

function renderSDPStats(
rndr,
{ offerer, localSdp, remoteSdp, pcid, timestamp }
) {
function renderSDPStats(rndr, { offerer, pcid, timestamp }) {
// Get the most recent (as of timestamp) local and remote SDPs from the
// history
const sdpEntries = getSdpHistory({ pcid, timestamp });
const localSdp = sdpEntries.findLast(({ isLocal }) => isLocal).sdp;
const remoteSdp = sdpEntries.findLast(({ isLocal }) => !isLocal).sdp;

const sdps = offerer
? { offer: localSdp, answer: remoteSdp }
: { offer: remoteSdp, answer: localSdp };
Expand Down

0 comments on commit 2af5978

Please sign in to comment.