From 2b4372ad871dba475f6ac1300cf576a85a529f84 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 8 Oct 2020 15:11:52 +0200 Subject: [PATCH] Sort usernames case-insensitively in user interface. --- static/sfu.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index dabbb25..b352cc3 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -1067,6 +1067,25 @@ function resizePeers() { /** @type{Object} */ let users = {}; +/** + * Lexicographic order, with case differences secondary. + * @param{string} a + * @param{string} b + */ +function stringCompare(a, b) { + let la = a.toLowerCase() + let lb = b.toLowerCase() + if(la < lb) + return -1; + else if(la > lb) + return +1; + else if(a < b) + return -1; + else if(a > b) + return +1; + return 0 +} + /** * @param {string} id * @param {string} name @@ -1088,8 +1107,8 @@ function addUser(id, name) { let us = div.children; for(let i = 0; i < us.length; i++) { let child = us[i]; - let childname = users[child.id.slice('user-'.length)]; - if(!childname || childname > name) { + let childname = users[child.id.slice('user-'.length)] || null; + if(!childname || stringCompare(childname, name) > 0) { div.insertBefore(user, child); return; }