This commit is contained in:
parent
24d9a945b3
commit
c2bcc86527
12 changed files with 252 additions and 83 deletions
|
|
@ -83,7 +83,8 @@ export const filteredMessages = derived(
|
|||
const prev = filtered[i - 1];
|
||||
const sameUser = String(prev.userId) === String(msg.userId);
|
||||
const sameRealm = String(prev.realmId) === String(msg.realmId);
|
||||
const showHeader = !sameUser || !sameRealm || msg.usedRoll || msg.usedRtd;
|
||||
const hasSelfDestruct = msg.selfDestructAt && msg.selfDestructAt > 0;
|
||||
const showHeader = !sameUser || !sameRealm || msg.usedRoll || msg.usedRtd || hasSelfDestruct;
|
||||
return { ...msg, showHeader };
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@
|
|||
const sources = [
|
||||
{
|
||||
type: 'hls',
|
||||
file: `${proto}://${host}:${STREAM_PORT}/app/${actualStreamKey}/llhls.m3u8?token=${viewerToken}`,
|
||||
file: `${proto}://${host}:${STREAM_PORT}/app/${actualStreamKey}/llhls.m3u8?token=${encodeURIComponent(viewerToken)}`,
|
||||
label: 'LLHLS'
|
||||
}
|
||||
];
|
||||
|
|
@ -151,7 +151,7 @@
|
|||
// Only add token if not already present (segments don't have it)
|
||||
if (viewerToken && url.includes('/app/') && !url.includes('token=')) {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
xhr.open('GET', url + separator + 'token=' + viewerToken, true);
|
||||
xhr.open('GET', url + separator + 'token=' + encodeURIComponent(viewerToken), true);
|
||||
}
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@
|
|||
const sources = [
|
||||
{
|
||||
type: 'hls',
|
||||
file: `${proto}://${host}:${STREAM_PORT}/app/${stream.streamKey}/llhls.m3u8?token=${token}`,
|
||||
file: `${proto}://${host}:${STREAM_PORT}/app/${stream.streamKey}/llhls.m3u8?token=${encodeURIComponent(token)}`,
|
||||
label: 'LLHLS'
|
||||
}
|
||||
];
|
||||
|
|
@ -163,9 +163,9 @@
|
|||
lowLatencyMode: true,
|
||||
backBufferLength: 30,
|
||||
xhrSetup: function(xhr, url) {
|
||||
if (token && url.includes('/app/')) {
|
||||
if (token && url.includes('/app/') && !url.includes('token=')) {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
xhr.open('GET', url + separator + 'token=' + token, true);
|
||||
xhr.open('GET', url + separator + 'token=' + encodeURIComponent(token), true);
|
||||
}
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
} from '$lib/chat/chatStore';
|
||||
import { chatWebSocket } from '$lib/chat/chatWebSocket';
|
||||
import { chatLayout } from '$lib/stores/chatLayout';
|
||||
import { auth } from '$lib/stores/auth';
|
||||
import { auth, isAuthenticated } from '$lib/stores/auth';
|
||||
import {
|
||||
ttsEnabled,
|
||||
ttsSettings,
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
let honkAudio = null;
|
||||
let honkSoundUrl = null;
|
||||
let mentionedMessageIds = new Set(); // Track which messages have already played honk
|
||||
let wasAuthenticated = false; // Track previous auth state for reconnect detection
|
||||
|
||||
$: isConnected = $connectionStatus === 'connected';
|
||||
|
||||
|
|
@ -63,6 +64,16 @@
|
|||
chatWebSocket.getParticipants();
|
||||
}
|
||||
|
||||
// Reconnect WebSocket when user logs in or registers while already connected as guest
|
||||
$: {
|
||||
const nowAuthenticated = $isAuthenticated;
|
||||
if (nowAuthenticated && !wasAuthenticated && isConnected) {
|
||||
console.log('[ChatPanel] Auth state changed to authenticated, reconnecting...');
|
||||
chatWebSocket.manualReconnect();
|
||||
}
|
||||
wasAuthenticated = nowAuthenticated;
|
||||
}
|
||||
|
||||
function toggleMenu() {
|
||||
showMenu = !showMenu;
|
||||
if (showMenu) {
|
||||
|
|
@ -192,11 +203,17 @@
|
|||
console.log('Chat connecting with realmId:', realmId, token ? '(authenticated)' : '(guest)');
|
||||
chatWebSocket.connect(realmId, token);
|
||||
|
||||
// Function to scroll to bottom
|
||||
// Function to scroll to newest messages (bottom for UP flow, top for DOWN flow)
|
||||
const scrollToBottom = () => {
|
||||
if (autoScroll && messagesContainer) {
|
||||
requestAnimationFrame(() => {
|
||||
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||
if ($chatLayout.messagesFromTop) {
|
||||
// column-reverse: newest at top, scroll to top
|
||||
messagesContainer.scrollTop = 0;
|
||||
} else {
|
||||
// normal: newest at bottom, scroll to bottom
|
||||
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -257,7 +274,13 @@
|
|||
|
||||
function handleScroll() {
|
||||
const { scrollTop, scrollHeight, clientHeight } = messagesContainer;
|
||||
autoScroll = scrollTop + clientHeight >= scrollHeight - 50;
|
||||
if ($chatLayout.messagesFromTop) {
|
||||
// column-reverse: user at "newest" means scrollTop near 0
|
||||
autoScroll = scrollTop <= 50;
|
||||
} else {
|
||||
// normal: user at bottom means scrollTop + clientHeight near scrollHeight
|
||||
autoScroll = scrollTop + clientHeight >= scrollHeight - 50;
|
||||
}
|
||||
}
|
||||
|
||||
function handleDeleteMessage(messageId) {
|
||||
|
|
@ -640,7 +663,6 @@
|
|||
<ChatMessage
|
||||
{message}
|
||||
showHeader={message.showHeader ?? false}
|
||||
headerBelow={$chatLayout.messagesFromTop}
|
||||
currentUserId={$chatUserInfo.userId}
|
||||
currentUsername={$chatUserInfo.username}
|
||||
currentRealmId={realmId}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue