newlnes for bobis

This commit is contained in:
legop3
2025-11-30 03:42:53 -05:00
parent d7b42acced
commit 9be4a4e180
4 changed files with 19 additions and 9 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -11,7 +11,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" /> <meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
<title>Multi Roomba Rover</title> <title>Multi Roomba Rover</title>
<script type="module" crossorigin src="/assets/index-B9l76ume.js"></script> <script type="module" crossorigin src="/assets/index-Cy2FzgJN.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css"> <link rel="stylesheet" crossorigin href="/assets/index-B1UrCI1T.css">
</head> </head>
<body> <body>
+9 -2
View File
@@ -56,6 +56,11 @@ function resolveRoverId(socketId) {
return assignment?.roverId || null; return assignment?.roverId || null;
} }
function normalizeUserText(raw) {
if (typeof raw !== 'string') return '';
return raw.replace(/\\n/g, '\n');
}
function buildMessage(socket, text, meta = {}) { function buildMessage(socket, text, meta = {}) {
const roverId = meta.roverId || resolveRoverId(socket?.id); const roverId = meta.roverId || resolveRoverId(socket?.id);
return { return {
@@ -94,7 +99,8 @@ function handleIncoming({ text, tts } = {}, socket, cb = () => {}) {
// cb({ error: 'Spectators cannot chat' }); // cb({ error: 'Spectators cannot chat' });
// return; // return;
// } // }
const clean = typeof text === 'string' ? text.trim() : ''; const normalized = normalizeUserText(text);
const clean = normalized.trim();
if (!clean) { if (!clean) {
cb({ error: 'Message required' }); cb({ error: 'Message required' });
return; return;
@@ -153,7 +159,8 @@ function maybeSpeak(socket, message, ttsOptions) {
} }
function sendExternalMessage({ text, nickname = 'Discord', role = 'admin', roverId = null }) { function sendExternalMessage({ text, nickname = 'Discord', role = 'admin', roverId = null }) {
const clean = typeof text === 'string' ? text.trim() : ''; const normalized = normalizeUserText(text);
const clean = normalized.trim();
if (!clean || clean.length > 256) { if (!clean || clean.length > 256) {
throw new Error('Message invalid'); throw new Error('Message invalid');
} }
+4 -2
View File
@@ -73,7 +73,9 @@ export default function ChatPanel({ hideInput = false, hideSpectatorNotice = fal
async function handleSend(event) { async function handleSend(event) {
event.preventDefault(); event.preventDefault();
if (!canChat || hideInput) return; if (!canChat || hideInput) return;
const clean = draft.trim(); // Allow users to type "\n" to represent a newline in messages
const normalizedDraft = draft.replace(/\\n/g, '\n');
const clean = normalizedDraft.trim();
if (!clean) return; if (!clean) return;
setSending(true); setSending(true);
try { try {
@@ -121,7 +123,7 @@ export default function ChatPanel({ hideInput = false, hideSpectatorNotice = fal
{msg.roverId && ( {msg.roverId && (
<span className="rounded bg-slate-800 px-1 text-[0.7rem]">rover {msg.roverId}</span> <span className="rounded bg-slate-800 px-1 text-[0.7rem]">rover {msg.roverId}</span>
)} )}
<span className="text-slate-100 break-words leading-tight">{msg.text}</span> <span className="text-slate-100 break-words leading-tight whitespace-pre-wrap">{msg.text}</span>
</div> </div>
); );
}) })