Skip to content

Commit

Permalink
rename timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatim23 committed Dec 8, 2023
1 parent b2e97de commit 55b1810
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions examples/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ let metrics = {

let dataChannelLatencyCalcMessage = {
content: 'Opened data channel by viewer',
t1: '',
t2: '',
t3: '',
t4: '',
t5: ''
timestamp1: '',
timestamp2: '',
timestamp3: '',
timestamp4: '',
timestamp5: ''
}

async function startViewer(localView, remoteView, formValues, onStatsReport, remoteMessage) {
Expand Down Expand Up @@ -509,7 +509,7 @@ async function startViewer(localView, remoteView, formValues, onStatsReport, rem
viewer.dataChannel = dataChannelObj;
dataChannelObj.onopen = () => {
if (formValues.enableDQPmetrics) {
dataChannelLatencyCalcMessage.t1 = Date.now();
dataChannelLatencyCalcMessage.timestamp1 = Date.now();
dataChannelObj.send(JSON.stringify(dataChannelLatencyCalcMessage));
} else {
dataChannelObj.send("Opened data channel by viewer");
Expand All @@ -521,25 +521,23 @@ async function startViewer(localView, remoteView, formValues, onStatsReport, rem
remoteMessage.append(`${message.data}\n\n`);
if (formValues.enableDQPmetrics) {

// The datachannel first sends a message of the following format with t1 attached,
// to which the master responds back with the same message attaching t2.
// In response to this, the viewer sends the same message back with t3 and so on until t5.
// The viewer is responsible for attaching t1, t3, t5. The master is responsible for t2 and t4.
// (Master e2e time: t4 - t2, Viewer e2e time: t3 - t1)

// The datachannel first sends a message of the following format with timestamp1 attached,
// to which the master responds back with the same message attaching timestamp2.
// In response to this, the viewer sends the same message back with timestamp3 and so on until timestamp5.
// The viewer is responsible for attaching timestamp1, timestamp3, timestamp5. The master is responsible for timestamp2 and timestamp4.
// (Master e2e time: timestamp4 - timestamp2, Viewer e2e time: timestamp3 - timestamp1)
try {
let dataChannelMessage = JSON.parse(message.data);
if (dataChannelMessage.hasOwnProperty('t1')) {
test = dataChannelMessage;
if (dataChannelMessage.t3 === '') {
dataChannelMessage.t3 = Date.now();
} else if (dataChannelMessage.t5 === '') {
dataChannelMessage.t5 = Date.now();
metrics.master.dataChannel.startTime = Number(dataChannelMessage.t2);
metrics.master.dataChannel.endTime = Number(dataChannelMessage.t4);
if (dataChannelMessage.hasOwnProperty('timestamp1')) {
if (dataChannelMessage.timestamp3 === '') {
dataChannelMessage.timestamp3 = Date.now();
} else if (dataChannelMessage.timestamp5 === '') {
dataChannelMessage.timestamp5 = Date.now();
metrics.master.dataChannel.startTime = Number(dataChannelMessage.timestamp2);
metrics.master.dataChannel.endTime = Number(dataChannelMessage.timestamp4);

metrics.viewer.dataChannel.startTime = Number(dataChannelMessage.t1);
metrics.viewer.dataChannel.endTime = Number(dataChannelMessage.t3);
metrics.viewer.dataChannel.startTime = Number(dataChannelMessage.timestamp1);
metrics.viewer.dataChannel.endTime = Number(dataChannelMessage.timestamp3);
}
dataChannelMessage.content = 'Message from JS viewer';
dataChannelObj.send(JSON.stringify(dataChannelMessage));
Expand Down

0 comments on commit 55b1810

Please sign in to comment.