WebRTC
WebRTC copied to clipboard
Idea: client side timestamp
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 👎 ?
How you plan to get this info?
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
If that works - client timestamp is a good idea.
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
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
local_timestamp: true - needless. Just local_timestamp: DD/MM/YY hh:mm:ss.sss will be enough.
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');
}
Maybe https://caniuse.com/mdn-javascript_builtins_intl_datetimeformat_format This locale related format
I didn't know that was that well supported, I'll take a look at that. Maybe I can pass the options directly
I'd like to wait for the other PRs to be merged to avoid merge conflicts.