Add call counter

This commit is contained in:
Pierre HUBERT 2020-04-14 18:20:37 +02:00
parent fe4e659b08
commit 6fa34d8896
3 changed files with 41 additions and 0 deletions

View File

@ -64,6 +64,10 @@
color: inherit; color: inherit;
} }
.call-window .head .time {
font-size: 80%;
}
.call-window .record-label { .call-window .record-label {
color: red; color: red;
margin-left: 10px; margin-left: 10px;

View File

@ -818,4 +818,19 @@ function requestUserScreen() {
}); });
}) })
}
/**
* Rpad function
*
* @param {String} str The string
* @param {number} len Expected length
* @param {string} fill Fill character
*/
function rpad(str, len, fill) {
str = String(str)
fill = String(fill)
while(str.length < len)
str = fill + str
return str
} }

View File

@ -66,6 +66,14 @@ class CallWindow extends CustomEvents {
" <span class='pull-right'></span>" " <span class='pull-right'></span>"
}) })
// Add counter
this.timeEl = createElem2({
insertBefore: this.windowHead.querySelector(".pull-right"),
type: "span",
class: "time",
innerHTML: "00:00:00"
})
// Close button // Close button
this.closeButton = createElem2({ this.closeButton = createElem2({
appendTo: this.windowHead.querySelector(".pull-right"), appendTo: this.windowHead.querySelector(".pull-right"),
@ -74,6 +82,20 @@ class CallWindow extends CustomEvents {
onclick: () => this.Close() onclick: () => this.Close()
}) })
// Make counter lives
this.callDuration = 0;
const interval = setInterval(() => {
if(!this.timeEl.isConnected)
clearInterval(interval)
this.callDuration++;
this.timeEl.innerHTML = rpad(Math.floor(this.callDuration/3600), 2, 0) + ":"
+ rpad(Math.floor((this.callDuration/60)%60), 2, 0) + ":"
+ rpad(this.callDuration%60, 2, 0)
}, 1000);
this.makeWindowDraggable(); this.makeWindowDraggable();