Commit 66a721a5 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Improve typing of sfu.js.

parent 6a554831
...@@ -11,10 +11,24 @@ let group; ...@@ -11,10 +11,24 @@ let group;
/** @type {ServerConnection} */ /** @type {ServerConnection} */
let serverConnection; let serverConnection;
/**
* @typedef {Object} userpass
* @property {string} username
* @property {string} password
*/
/* Some browsers disable session storage when cookies are disabled, /* Some browsers disable session storage when cookies are disabled,
we fall back to a global variable. */ we fall back to a global variable. */
/**
* @type {userpass}
*/
let fallbackUserPass = null; let fallbackUserPass = null;
/**
* @param {string} username
* @param {string} password
*/
function setUserPass(username, password) { function setUserPass(username, password) {
let userpass = {username: username, password: password}; let userpass = {username: username, password: password};
try { try {
...@@ -22,10 +36,13 @@ function setUserPass(username, password) { ...@@ -22,10 +36,13 @@ function setUserPass(username, password) {
fallbackUserPass = null; fallbackUserPass = null;
} catch(e) { } catch(e) {
console.warn("Couldn't store password:", e); console.warn("Couldn't store password:", e);
fallbackUserPass = {username: username, password: password}; fallbackUserPass = userpass;
} }
} }
/**
* @returns {userpass}
*/
function getUserPass() { function getUserPass() {
let userpass; let userpass;
try { try {
...@@ -38,6 +55,9 @@ function getUserPass() { ...@@ -38,6 +55,9 @@ function getUserPass() {
return userpass || null; return userpass || null;
} }
/**
* @returns {string}
*/
function getUsername() { function getUsername() {
let userpass = getUserPass(); let userpass = getUserPass();
if(!userpass) if(!userpass)
...@@ -53,14 +73,13 @@ function showVideo() { ...@@ -53,14 +73,13 @@ function showVideo() {
document.getElementById('collapse-video').style.display = "block"; document.getElementById('collapse-video').style.display = "block";
} }
/**
* @param {boolean} [force]
*/
function hideVideo(force) { function hideVideo(force) {
let mediadiv = document.getElementById('peers'); let mediadiv = document.getElementById('peers');
if (force === undefined) { if(mediadiv.childElementCount > 0 && !force)
force = false;
}
if (mediadiv.childElementCount > 0 && !force) {
return; return;
}
let video_container = document.getElementById('video-container'); let video_container = document.getElementById('video-container');
video_container.classList.add('no-video'); video_container.classList.add('no-video');
} }
...@@ -114,6 +133,10 @@ function gotConnected() { ...@@ -114,6 +133,10 @@ function gotConnected() {
this.request(document.getElementById('requestselect').value); this.request(document.getElementById('requestselect').value);
} }
/**
* @param {number} code
* @param {string} reason
*/
function gotClose(code, reason) { function gotClose(code, reason) {
delUpMediaKind(null); delUpMediaKind(null);
setConnected(false); setConnected(false);
...@@ -149,7 +172,9 @@ function gotDownStream(c) { ...@@ -149,7 +172,9 @@ function gotDownStream(c) {
// Store current browser viewport height in css variable // Store current browser viewport height in css variable
function setViewportHeight() { function setViewportHeight() {
document.documentElement.style.setProperty('--vh', `${window.innerHeight/100}px`); document.documentElement.style.setProperty(
'--vh', `${window.innerHeight/100}px`,
);
}; };
setViewportHeight(); setViewportHeight();
...@@ -208,6 +233,9 @@ function toggleLocalMute() { ...@@ -208,6 +233,9 @@ function toggleLocalMute() {
setLocalMute(!localMute); setLocalMute(!localMute);
} }
/**
* @param {boolean} mute
*/
function setLocalMute(mute) { function setLocalMute(mute) {
localMute = mute; localMute = mute;
muteLocalTracks(localMute); muteLocalTracks(localMute);
...@@ -356,8 +384,10 @@ function gotDownStats(stats) { ...@@ -356,8 +384,10 @@ function gotDownStats(stats) {
} }
} }
/**
* @param {string} value
*/
function mapMediaOption(value) { function mapMediaOption(value) {
console.assert(typeof(value) === 'string');
switch(value) { switch(value) {
case 'default': case 'default':
return true; return true;
...@@ -668,6 +698,9 @@ function setMedia(c, isUp) { ...@@ -668,6 +698,9 @@ function setMedia(c, isUp) {
resizePeers(); resizePeers();
} }
/**
* @param {string} id
*/
function delMedia(id) { function delMedia(id) {
let mediadiv = document.getElementById('peers'); let mediadiv = document.getElementById('peers');
let peer = document.getElementById('peer-' + id); let peer = document.getElementById('peer-' + id);
...@@ -737,9 +770,8 @@ function resizePeers() { ...@@ -737,9 +770,8 @@ function resizePeers() {
let max_video_height = Math.trunc((peers.offsetHeight - 30) / columns); let max_video_height = Math.trunc((peers.offsetHeight - 30) / columns);
let media_list = document.getElementsByClassName("media"); let media_list = document.getElementsByClassName("media");
[].forEach.call(media_list, function (element) { for(let i = 0; i < media_list.length; i++)
element.style['max-height'] = max_video_height + "px"; media_list[i].style['max_height'] = max_video_height + "px";
});
if (count <= 2 && container.offsetHeight > container.offsetWidth) { if (count <= 2 && container.offsetHeight > container.offsetWidth) {
peers.style['grid-template-columns'] = "repeat(1, 1fr)"; peers.style['grid-template-columns'] = "repeat(1, 1fr)";
...@@ -853,6 +885,10 @@ function gotPermissions(perms) { ...@@ -853,6 +885,10 @@ function gotPermissions(perms) {
const urlRegexp = /https?:\/\/[-a-zA-Z0-9@:%/._\\+~#=?]+[-a-zA-Z0-9@:%/_\\+~#=]/g; const urlRegexp = /https?:\/\/[-a-zA-Z0-9@:%/._\\+~#=?]+[-a-zA-Z0-9@:%/_\\+~#=]/g;
/**
* @param {string} line
* @returns {Array.<Text|HTMLElement>}
*/
function formatLine(line) { function formatLine(line) {
let r = new RegExp(urlRegexp); let r = new RegExp(urlRegexp);
let result = []; let result = [];
...@@ -874,6 +910,10 @@ function formatLine(line) { ...@@ -874,6 +910,10 @@ function formatLine(line) {
return result; return result;
} }
/**
* @param {Array.<string>} lines
* @returns {HTMLElement}
*/
function formatLines(lines) { function formatLines(lines) {
let elts = []; let elts = [];
if(lines.length > 0) if(lines.length > 0)
...@@ -1091,8 +1131,8 @@ function chatResizer(e) { ...@@ -1091,8 +1131,8 @@ function chatResizer(e) {
function start_drag(e) { function start_drag(e) {
let left_width = (start_width + e.clientX - start_x) * 100 / full_width; let left_width = (start_width + e.clientX - start_x) * 100 / full_width;
left.style.flex = left_width; left.style.flex = left_width.toString();
right.style.flex = 100 - left_width; right.style.flex = (100 - left_width).toString();
} }
function stop_drag(e) { function stop_drag(e) {
document.documentElement.removeEventListener( document.documentElement.removeEventListener(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment