From 472900976ebc2e4b3ab1914be13f3b32be817b7a Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Tue, 30 Aug 2022 23:52:13 +0200 Subject: [PATCH 1/2] [mirotalksfu] - allow name storage per room --- public/js/Room.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/public/js/Room.js b/public/js/Room.js index 5e5714dc..d69b59f5 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -393,6 +393,11 @@ function whoAreYou() { return; } + let default_name = window.localStorage.peer_name ? window.localStorage.peer_name : ''; + if (getCookie(room_id + "_name")) { + default_name = getCookie(room_id + "_name"); + } + Swal.fire({ allowOutsideClick: false, allowEscapeKey: false, @@ -401,7 +406,7 @@ function whoAreYou() { imageUrl: image.username, input: 'text', inputPlaceholder: 'Enter your name', - inputValue: window.localStorage.peer_name ? window.localStorage.peer_name : '', + inputValue: default_name, html: `
@@ -417,12 +422,15 @@ function whoAreYou() { }, inputValidator: (name) => { if (!name) return 'Please enter your name'; + if (!getCookie(room_id + "_name")) { + window.localStorage.peer_name = name; + } + setCookie(room_id + "_name", name, 30); peer_name = name; }, }).then(() => { getPeerInfo(); joinRoom(peer_name, room_id); - window.localStorage.peer_name = peer_name; }); if (!DetectRTC.isMobileDevice) { @@ -1256,6 +1264,24 @@ function openURL(url, blank = false) { blank ? window.open(url, '_blank') : (window.location.href = url); } +function setCookie(name, value, expDays) { + let date = new Date(); + date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 1000)); + const expires = "expires=" + date.toUTCString(); + document.cookie = name + "=" + value + "; " + expires + "; path=/"; +} + +function getCookie(cName) { + const name = cName + "="; + const cDecoded = decodeURIComponent(document.cookie); + const cArr = cDecoded .split('; '); + let res; + cArr.forEach(val => { + if (val.indexOf(name) === 0) res = val.substring(name.length); + }) + return res; +} + // #################################################### // HANDLE WHITEBOARD // #################################################### From b2e9e4c3c4b6f20e7265ce5a54c2f16e2606a61c Mon Sep 17 00:00:00 2001 From: Laurent Goussard Date: Tue, 30 Aug 2022 23:53:13 +0200 Subject: [PATCH 2/2] [mirotalksfu] - allow name storage per room --- public/js/Room.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/public/js/Room.js b/public/js/Room.js index d69b59f5..21df2458 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -394,8 +394,8 @@ function whoAreYou() { } let default_name = window.localStorage.peer_name ? window.localStorage.peer_name : ''; - if (getCookie(room_id + "_name")) { - default_name = getCookie(room_id + "_name"); + if (getCookie(room_id + '_name')) { + default_name = getCookie(room_id + '_name'); } Swal.fire({ @@ -422,10 +422,10 @@ function whoAreYou() { }, inputValidator: (name) => { if (!name) return 'Please enter your name'; - if (!getCookie(room_id + "_name")) { + if (!getCookie(room_id + '_name')) { window.localStorage.peer_name = name; } - setCookie(room_id + "_name", name, 30); + setCookie(room_id + '_name', name, 30); peer_name = name; }, }).then(() => { @@ -1265,21 +1265,21 @@ function openURL(url, blank = false) { } function setCookie(name, value, expDays) { - let date = new Date(); - date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 1000)); - const expires = "expires=" + date.toUTCString(); - document.cookie = name + "=" + value + "; " + expires + "; path=/"; + let date = new Date(); + date.setTime(date.getTime() + expDays * 24 * 60 * 60 * 1000); + const expires = 'expires=' + date.toUTCString(); + document.cookie = name + '=' + value + '; ' + expires + '; path=/'; } function getCookie(cName) { - const name = cName + "="; - const cDecoded = decodeURIComponent(document.cookie); - const cArr = cDecoded .split('; '); - let res; - cArr.forEach(val => { - if (val.indexOf(name) === 0) res = val.substring(name.length); - }) - return res; + const name = cName + '='; + const cDecoded = decodeURIComponent(document.cookie); + const cArr = cDecoded.split('; '); + let res; + cArr.forEach((val) => { + if (val.indexOf(name) === 0) res = val.substring(name.length); + }); + return res; } // ####################################################