1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Improve typing of sfu.js.

This commit is contained in:
Juliusz Chroboczek 2020-09-12 16:34:52 +02:00
parent 6a554831a1
commit 66a721a55c

View file

@ -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) {
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() {
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() {
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; return;
}
if (mediadiv.childElementCount > 0 && !force) {
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() {
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) {
// 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() {
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) {
} }
} }
/**
* @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) {
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() {
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) {
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) {
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) {
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(