WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

Idea: client side timestamp

Open dbuezas opened this issue 2 years ago • 10 comments

Not all my cameras can show timestamps in the video, and even with those that do I mostly look at them to check that the video is still running (mostly on slow mobile connections). What is your opinion on an optional (disabled by default) timestamp that shows the time when the last frame was received? 👍 Or 👎 ?

dbuezas avatar Jul 23 '23 19:07 dbuezas

How you plan to get this info?

AlexxIT avatar Jul 23 '23 20:07 AlexxIT

There's the loadeddata and the timeupdate events of the video tag. The idea would be to update the fake timestamp to the present when triggered

dbuezas avatar Jul 24 '23 04:07 dbuezas

If that works - client timestamp is a good idea.

AlexxIT avatar Jul 24 '23 05:07 AlexxIT

I think it will work, I made something similar to show a red dot when video was running and it was reliable (at least android and chrome). I was thinking it could be like this:

local_timestamp: true 
local_timestamp: DD/MM/YY hh:mm:ss.sss

I'll look if there is any minimal formatter I could use. Then styles can be configured with the existing style yaml key

dbuezas avatar Jul 24 '23 09:07 dbuezas

Wdyt about string replacement? Something like

format
  .replace('YY', date.getYear())
  .replace('MM', date.getMonth())
  .etc...

(I'll have to consider padding too, but you get the point) I'm a bit worried about increasing your code's size a bit

dbuezas avatar Jul 24 '23 09:07 dbuezas

local_timestamp: true - needless. Just local_timestamp: DD/MM/YY hh:mm:ss.sss will be enough.

AlexxIT avatar Jul 24 '23 09:07 AlexxIT

This is the simplest way I could come up with for the formatting.

const pad = (p, n) => String(n).padStart(p, '0');

function getTimestamp(format) {
  const d = new Date();
  const h = d.getHours();
  return format
    .replace('DD', pad(2, d.getDate()))
    .replace('MM', pad(2, d.getMonth() + 1))
    .replace('YY', String(d.getFullYear()).slice(-2)
    .replace('hh', pad(2, format.includes('am') ? (h % 12 || 12) : h))
    .replace('mm', pad(2, d.getMinutes()))
    .replace('ss', pad(2, d.getSeconds()))
    .replace('sss', pad(3, d.getMilliseconds()))
    .replace('am', d.getHours() >= 12 ? 'PM' : 'AM');
}

dbuezas avatar Jul 24 '23 11:07 dbuezas

Maybe https://caniuse.com/mdn-javascript_builtins_intl_datetimeformat_format This locale related format

AlexxIT avatar Jul 24 '23 12:07 AlexxIT

I didn't know that was that well supported, I'll take a look at that. Maybe I can pass the options directly

dbuezas avatar Jul 24 '23 13:07 dbuezas

I'd like to wait for the other PRs to be merged to avoid merge conflicts.

dbuezas avatar Jul 28 '23 21:07 dbuezas