diff --git a/public/js/Room.js b/public/js/Room.js index 5e5714dc..21df2458 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 // ####################################################