Tweek join guard

This commit is contained in:
blankhex committed 2026-10-25 15:12:43 +03:00
1 parent e01393c550
commit 13f2ac95b5
1 file changed
+51 -21
+51 -21
View File
@@ -17,20 +17,36 @@ function sanitizeRoomName(value) {
.replace(/^-+|-+$/g, '') .replace(/^-+|-+$/g, '')
} }
// Heuristic for a machine-generated room name: four PascalCase words in a row,
// each being an uppercase letter followed by one or more lowercase letters
// (e.g. "ObstinateEngineerDifferLargely"). Names people type by hand rarely
// look like this, and Jitsi bounces users to freshly generated rooms, so this
// is the main case worth guarding against.
const AUTO_GENERATED_ROOM = /(?:[A-Z][a-z]+){4}/
function looksAutoGenerated(roomName) {
return AUTO_GENERATED_ROOM.test(roomName)
}
// `room` and `noguard` come from the URL (e.g. /rooms/daily-standup?noguard=1); // `room` and `noguard` come from the URL (e.g. /rooms/daily-standup?noguard=1);
// `onNavigate(room, noguard)` pushes a new route. Selecting a room asks the API // `onNavigate(room, noguard)` pushes a new route. Selecting a room asks the API
// for a JWT and then redirects the browser to the Jitsi server for that room. // for a JWT and then redirects the browser to the Jitsi server for that room.
// //
// Guard: a room arriving through the URL is joined only when the user has // Guard: a room arriving through the URL is prompted about only when it looks
// visited it before. Otherwise we offer to rejoin the most recent room - the // machine-generated - four PascalCase words in a row - AND it is not referenced
// common case when Jitsi bounces the user back to a freshly generated room. A // by any meeting AND the user has not joined it before. Anything else is joined
// room flagged with `?noguard=1` is a deliberate join and skips the guard. // directly, so normal, hand-typed or known rooms are never interrupted; only
// likely Jitsi-generated rooms can be. A room flagged with `?noguard=1` (a
// deliberate join) always skips the guard, as does the "always join rooms
// without asking" device preference.
export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) { export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
const [room, setRoom] = useState('') const [room, setRoom] = useState('')
const [history, setHistory] = useState([]) const [history, setHistory] = useState([])
const [historyLoaded, setHistoryLoaded] = useState(false) const [historyLoaded, setHistoryLoaded] = useState(false)
// Meetings the current user voted to join, shown below the rooms grid. // All meetings, used both for the "Your meetings" list and for the join guard
// (a room referenced by a meeting is a known room).
const [meetings, setMeetings] = useState([]) const [meetings, setMeetings] = useState([])
const [meetingsLoaded, setMeetingsLoaded] = useState(false)
const [error, setError] = useState('') const [error, setError] = useState('')
const [joining, setJoining] = useState(false) const [joining, setJoining] = useState(false)
const [copied, setCopied] = useState('') const [copied, setCopied] = useState('')
@@ -67,6 +83,8 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
setMeetings(data || []) setMeetings(data || [])
} catch (err) { } catch (err) {
console.error(err) console.error(err)
} finally {
setMeetingsLoaded(true)
} }
}, []) }, [])
@@ -113,9 +131,11 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
enter(target) enter(target)
} }
// Join a room that arrived through the URL. `?noguard=1` joins directly; // Join a room that arrived through the URL. `?noguard=1` or the "always join"
// otherwise the room is joined when it is in recent rooms, and unknown rooms // preference joins directly; a room that is not machine-generated, or that is
// are shown in the confirmation notice. // referenced by a meeting, or already in the recent rooms list, is joined too.
// Only a likely generated room that is otherwise unknown is shown in the
// confirmation notice.
useEffect(() => { useEffect(() => {
if (!routeRoom) { if (!routeRoom) {
entered.current = null entered.current = null
@@ -125,22 +145,30 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
const target = sanitizeRoomName(routeRoom) const target = sanitizeRoomName(routeRoom)
if (!target || target === entered.current) return if (!target || target === entered.current) return
// A deliberate join (?noguard=1) or the stored "always join" preference // A deliberate join (?noguard=1) or the stored "always join" preference
// skips the guard entirely, so the recent rooms list is not needed. // skips the guard entirely, so neither list is needed.
const skip = noguard || alwaysJoin const skip = noguard || alwaysJoin
if (!skip && !historyLoaded) return // Both lists feed the guard, so wait until they have loaded before deciding.
if (!skip && (!historyLoaded || !meetingsLoaded)) return
entered.current = target entered.current = target
if (skip || history.some((item) => item.roomName === target)) { const knownRoom =
history.some((item) => item.roomName === target) ||
meetings.some((meeting) => meeting.room === target)
// Prompt only for a machine-generated room that is neither in a meeting nor
// in the recent rooms list.
if (skip || !looksAutoGenerated(target) || knownRoom) {
setPending(null) setPending(null)
enter(target) enter(target)
return return
} }
// Unknown room: suggest the most recent one when there is one. An empty // Likely generated, unknown room: suggest the most recent one when there is
// history means there is nothing to suggest, so lastRoom stays null and the // one. An empty history means there is nothing to suggest, so lastRoom stays
// notice only informs the user about the (possibly generated) room name. // null and the notice only informs the user about the (possibly generated)
// room name.
setPending({ room: target, lastRoom: history[0]?.roomName ?? null }) setPending({ room: target, lastRoom: history[0]?.roomName ?? null })
}, [routeRoom, noguard, alwaysJoin, enter, history, historyLoaded]) }, [routeRoom, noguard, alwaysJoin, enter, history, historyLoaded, meetings, meetingsLoaded])
const submit = (event) => { const submit = (event) => {
event.preventDefault() event.preventDefault()
@@ -207,10 +235,11 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
<section className="card notice"> <section className="card notice">
{pending.lastRoom ? ( {pending.lastRoom ? (
<> <>
<h2>Room not in your recent list</h2> <h2>Room looks automatically generated</h2>
<p> <p>
You are about to join <strong>{pending.room}</strong>, which is You are about to join <strong>{pending.room}</strong>, which
not in your recent rooms. Would you like to rejoin your most looks automatically generated and is not linked to any meeting
or in your recent rooms. Would you like to rejoin your most
recent room instead? recent room instead?
</p> </p>
<div className="row"> <div className="row">
@@ -236,9 +265,10 @@ export default function RoomsPage({ room: routeRoom, noguard, onNavigate }) {
<> <>
<h2>New room</h2> <h2>New room</h2>
<p> <p>
This is your first join to <strong>{pending.room}</strong>. If you The name <strong>{pending.room}</strong> looks automatically
did not type this name yourself it may be a randomly generated generated and is not linked to any meeting or in your recent
room. rooms. If you did not type this name yourself it may be a
randomly generated room.
</p> </p>
<div className="row"> <div className="row">
{/* Same secondary style as the "Join anyway" fallback in the {/* Same secondary style as the "Join anyway" fallback in the