Let viewers set a per-streamer display name
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 29s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 29s
Viewers can type a custom name shown to the streamer instead of their Google account name. It's saved per (streamer, viewer) pair in SQLite and pre-filled on future visits to the same send link. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ed2b051c91
commit
fab55cde1d
4 changed files with 76 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ const mainSection = document.getElementById('hidden-until-login');
|
|||
const userPic = document.getElementById('user-pic');
|
||||
const userName = document.getElementById('user-name');
|
||||
const logoutBtn = document.getElementById('logout');
|
||||
const displayNameInput = document.getElementById('display-name');
|
||||
const messageInput = document.getElementById('message');
|
||||
const sendBtn = document.getElementById('send');
|
||||
const statusEl = document.getElementById('status');
|
||||
|
|
@ -22,6 +23,13 @@ function showLoggedOut() {
|
|||
mainSection.style.display = 'none';
|
||||
}
|
||||
|
||||
async function loadDisplayName() {
|
||||
const res = await fetch(`/api/viewer-name?token=${encodeURIComponent(token)}`);
|
||||
if (!res.ok) return;
|
||||
const { name } = await res.json();
|
||||
displayNameInput.value = name || '';
|
||||
}
|
||||
|
||||
async function handleCredentialResponse(response) {
|
||||
const res = await fetch('/auth/google', {
|
||||
method: 'POST',
|
||||
|
|
@ -32,6 +40,7 @@ async function handleCredentialResponse(response) {
|
|||
if (res.ok) {
|
||||
const { user } = await res.json();
|
||||
showLoggedIn(user);
|
||||
loadDisplayName();
|
||||
// The socket connected before login with no session cookie; reconnect so
|
||||
// its handshake picks up the freshly-issued, now-authenticated cookie.
|
||||
socket.disconnect();
|
||||
|
|
@ -55,6 +64,7 @@ async function init() {
|
|||
const { user } = await meRes.json();
|
||||
if (user) {
|
||||
showLoggedIn(user);
|
||||
loadDisplayName();
|
||||
} else {
|
||||
showLoggedOut();
|
||||
}
|
||||
|
|
@ -63,7 +73,8 @@ async function init() {
|
|||
sendBtn.addEventListener('click', () => {
|
||||
const text = messageInput.value.trim();
|
||||
if (!text) return;
|
||||
socket.emit('send_message', { token, text });
|
||||
const name = displayNameInput.value.trim();
|
||||
socket.emit('send_message', { token, text, name });
|
||||
messageInput.value = '';
|
||||
statusEl.textContent = 'Отправлено';
|
||||
setTimeout(() => { statusEl.textContent = ''; }, 1500);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue