Compare commits

..

4 Commits

Author SHA1 Message Date
briquet 629b3fab20 ✨(backend) help find duplicate users in the admin
Add a filter listing the users with duplicate emails and show
the last login of users.

Backported from suitenumerique/docs
2026-11-14 09:02:04 +01:00
briquet 5a1190d4fd ⚡️(backend) index user emails for exact lookups
Emails are now stored normalized and looked up with exact equality.
The UPPER(email) index on email was replaced with a standard btree index.
2026-11-14 09:02:03 +01:00
briquet 51b869b284 ♻️(backend) match emails in a single normalized form
Ensure email are always compared in a normalized form to avoid subtle
unicode case folding issues.
2026-11-14 09:02:02 +01:00
briquet 799100f15f 🗃️(backend) normalize stored emails
Store email in a normalized form in database
2026-11-13 11:53:53 +01:00
98 changed files with 920 additions and 1264 deletions
+6 -10
View File
@@ -12,7 +12,10 @@ and this project adheres to
- 🌐(i18n) add Portuguese language support
- ✨(frontend) add jittered exponential backoff to LiveKit reconnections
- ✨(backend) add OIDC_ALLOW_DUPLICATE_EMAILS to let users share an email
- ✨(frontend) tell participants when a recording is interrupted
- ✨(backend) show the last login of users in the admin
- ✨(backend) filter users sharing an email in the admin
### Changed
@@ -27,13 +30,9 @@ and this project adheres to
- 🔒️(frontend) send the display name in the join request body
- 🔥(backend) drop is_administrable from unregistered room payloads
- 🍱(frontend) add Portuguese glyphs to Marianne subsetted fonts
- 🚸(frontend) bring new speakers to the top of the carousel
- 🚸(frontend) bring raised hands into view in the carousel
- ⚡️(frontend) preload notification sound on the pre-join screen when idle
- ⚡️(frontend) cache mediapipe models served by nginx
- ⚡️(frontend) preload background effects assets on hover
- ⚡️(frontend) lazy load the settings dialog
- ⚡️(frontend) serve preset virtual backgrounds as WebP
- 💥(backend) refuse new users whose email is already used
- ♻️(backend) match emails in a single normalized form
- ⚡️(backend) index user emails for exact lookups
### Fixed
@@ -49,9 +48,6 @@ and this project adheres to
- 🔒️(docker) move frontend to nginx/nginx-unprivileged image
- 🐛(frontend) accept meeting links with query params in join dialog
- 🐛(backend) allow muting when everyone_can_mute is stored as null #1942
- 🐛(frontend) apply the sans font token on every page
- 🐛(frontend) promote the active speaker in the carousel layout
- ⚡️(frontend) serve sounds as content-hashed, long-term cached assets
## [1.37.0] - 2026-11-01
+9
View File
@@ -45,6 +45,15 @@ parse as a UUID, yet to normalize to an existing room's id, matched no registere
unregistered one. The token minted for that unregistered room was valid for the registered room: anyone could join a
trusted or restricted room without being admitted through the lobby.
### User emails matched in a single normalized form
User emails are now stored stripped, with their ASCII letters lowercased, and compared exactly. A migration normalizes
the stored emails and stores blank ones as NULL. Other letters keep their case.
- With `OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION` disabled (the default), a new `sub` whose email is already used by
another user is now refused, by the OIDC login and by external API calls made with a Menshen token, instead of getting
a second account. To keep creating users with a duplicate email, set the new `OIDC_ALLOW_DUPLICATE_EMAILS=True`.
## v1.37.0
### Crisp support chat replaced by the La Suite support form
+1 -1
View File
@@ -33,7 +33,7 @@ server {
}
# Serve static files with caching
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp3)$ {
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
+1 -6
View File
@@ -71,13 +71,8 @@ server {
add_header Cache-Control "public, max-age=2592000";
}
location ^~ /assets/mediapipe/models/ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
# Serve static files with caching
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp3)$ {
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
+1 -1
View File
@@ -272,7 +272,7 @@ is told by `event.outcome`, `lasuite.outcome` and `event.reason`, never by the n
| `event.action` | Emitted when | Notable fields |
|---|---|---|
| `application.token.issue` | An application asks for a delegated token (`POST /external-api/v1.0/application/token/`), whether it gets one or is refused. It can be refused for bad credentials, an inactive application, an invalid or unauthorized email domain, an unknown user, or a provisioning conflict | On success: `user.*` is the delegated user, `entity.target` the application, and `lasuite.details` holds `scopes`, `user_provisioned` and `expires_in`. On refusal: `event.reason`, `http.response.status_code` and `lasuite.details.requested_domain`. Until its credentials are verified, the client id the caller submitted is only recorded as `lasuite.details.claimed_client_id`: it never sets `lasuite.application` or `organization` |
| `user.provision` | An application creates a provisional user from an email address, or fails to. It is a `failure` with reason `conflict` when a concurrent request created the user first. Also emitted when a La Suite application calls the external API, through the resource server or with a Menshen token, for a `sub` no account has and `OIDC_CREATE_USER` lets the backend create one | `user.target` and `entity.target` are the user, the existing one on a conflict. `lasuite.auth.method` is `client_credentials`, `resource_server` or `menshen_token`. A provisional user has no `sub` yet: its id links this event to the winning one and to its later `user.login`. On a conflict over an email, `lasuite.details.requested_sub` is the `sub` no account was created for |
| `user.provision` | An application creates a provisional user from an email address, or fails to. It is a `failure` with reason `conflict` when a concurrent request created the user first. Also emitted when a La Suite application calls the external API, through the resource server or with a Menshen token, for a `sub` no account has and `OIDC_CREATE_USER` lets the backend create one. An OIDC sign-in refused because the email of its unknown `sub` is already used, with `OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION` disabled, or shared by several active users, with it enabled, is recorded as a `failure` with reason `conflict` | `user.target` and `entity.target` are the user, the existing one on a conflict. `lasuite.auth.method` is `client_credentials`, `resource_server`, `menshen_token` or `oidc`. A provisional user has no `sub` yet: its id links this event to the winning one and to its later `user.login`. On a conflict over an email, `lasuite.details.requested_sub` is the `sub` no account was created for |
| `transit_code.issue` | An application mints a single-use transit code for its delegated user | `entity.target` is the code, whose `id` is its SHA-256. `user.target` is the user it is minted for. `lasuite.details.expires_in` |
| `transit_code.exchange` | An embedded frontend exchanges a transit code for a user access token | `event.category` is `authentication`, `lasuite.auth.method` is `transit_code`, and `entity.target` is the code's SHA-256. Once the code verifies, even if the exchange is then refused: `lasuite.actor.type` is `application` (the one that minted it), and `user.target` the user it was minted for. On success, `user.*` is that user too, with `lasuite.details.expires_in`. A code that does not verify is recorded as an `anonymous` failed authentication |
+2 -1
View File
@@ -16,7 +16,8 @@ Authentication relies on [django-lasuite](https://github.com/suitenumerique/djan
| OIDC_VERIFY_SSL | Verify SSL certificates when contacting the OIDC provider | `true` |
| OIDC_USE_NONCE | Use `nonce` to prevent replay attacks | `true` |
| OIDC_STORE_ID_TOKEN | Store the ID token returned by the OIDC provider (useful for backend validation) | `true` |
| OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION | Fallback to identifying users by email if `sub` claim does not match. Enable only if emails are unique. | `false` |
| OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION | Fallback to identifying users by email if `sub` claim does not match. Cannot be enabled together with `OIDC_ALLOW_DUPLICATE_EMAILS`. | `false` |
| OIDC_ALLOW_DUPLICATE_EMAILS | When the email fallback is disabled, create a new user for an unknown `sub` even if its email is already used by another user. Otherwise, the login is refused. Emails are compared once stripped, with their ASCII letters lowercased. | `false` |
| **Endpoints** | | |
| OIDC_OP_JWKS_ENDPOINT | URL to retrieve JSON Web Key Sets (for token verification) | — |
| OIDC_OP_AUTHORIZATION_ENDPOINT | URL for authorization requests | — |
+2 -1
View File
@@ -379,7 +379,8 @@ These are the environmental options available on meet backend.
| DJANGO_CELERY_BROKER_TRANSPORT_OPTIONS | Celery broker options | {} |
| OIDC_CREATE_USER | Create OIDC user if not exists | true |
| OIDC_VERIFY_SSL | Verify SSL for OIDC | true |
| OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION | Fallback to email for identification | false |
| OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION | Fallback to email for identification, cannot be enabled with OIDC_ALLOW_DUPLICATE_EMAILS | false |
| OIDC_ALLOW_DUPLICATE_EMAILS | Without the email fallback, create a user for a new sub whose email is already used | false |
| OIDC_RP_SIGN_ALGO | Token verification algorithm used by OIDC | RS256 |
| OIDC_RP_CLIENT_ID | OIDC client ID | meet |
| OIDC_RP_CLIENT_SECRET | OIDC client secret | |
+40 -2
View File
@@ -4,6 +4,7 @@ from django import forms
from django.contrib import admin, messages
from django.contrib.auth import admin as auth_admin
from django.db import transaction
from django.db.models import Exists, OuterRef
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
@@ -46,6 +47,26 @@ class FileInline(admin.TabularInline):
return super().get_queryset(request).filter(hard_deleted_at__isnull=True)
class DuplicateEmailFilter(admin.SimpleListFilter):
"""Filter the users whose stored email is shared with another user."""
title = _("duplicate email")
parameter_name = "duplicate_email"
def lookups(self, request, model_admin):
"""Return the filter options."""
return [("yes", _("Yes"))]
def queryset(self, request, queryset):
"""Keep the users sharing their email with another user."""
if self.value() != "yes":
return queryset
others = models.User.objects.filter(email=OuterRef("email")).exclude(
pk=OuterRef("pk")
)
return queryset.filter(Exists(others))
@admin.register(models.User)
class UserAdmin(auth_admin.UserAdmin):
"""Admin class for the User model"""
@@ -89,7 +110,10 @@ class UserAdmin(auth_admin.UserAdmin):
),
},
),
(_("Important dates"), {"fields": ("created_at", "updated_at")}),
(
_("Important dates"),
{"fields": ("created_at", "updated_at", "last_login")},
),
)
add_fieldsets = (
(
@@ -112,9 +136,16 @@ class UserAdmin(auth_admin.UserAdmin):
"is_superuser",
"is_device",
"created_at",
"last_login",
"updated_at",
)
list_filter = ("is_staff", "is_superuser", "is_device", "is_active")
list_filter = (
"is_staff",
"is_superuser",
"is_device",
"is_active",
DuplicateEmailFilter,
)
ordering = (
"is_active",
"-is_superuser",
@@ -131,9 +162,16 @@ class UserAdmin(auth_admin.UserAdmin):
"short_name",
"created_at",
"updated_at",
"last_login",
)
search_fields = ("id", "sub", "admin_email", "email", "full_name")
def get_ordering(self, request):
"""Group the users sharing an email when filtering on duplicates."""
if DuplicateEmailFilter.parameter_name in request.GET:
return ("email", "created_at")
return super().get_ordering(request)
@admin.register(models.File)
class FileAdmin(admin.ModelAdmin):
+26 -13
View File
@@ -1,5 +1,7 @@
"""Authentication Backends for the Meet core app."""
import logging
from django.conf import settings
from django.core.exceptions import (
SuspiciousOperation,
@@ -13,9 +15,13 @@ from lasuite.oidc_login.backends import (
)
from rest_framework.authentication import SessionAuthentication
from core.models import User
from core import audit, auditing
from core.models import DuplicateEmailError, User
from core.utils import normalize_email
from core.validators import sub_validator
logger = logging.getLogger(__name__)
class OIDCAuthenticationBackend(LaSuiteOIDCAuthenticationBackend):
"""Custom OpenID Connect (OIDC) Authentication Backend.
@@ -83,18 +89,25 @@ class OIDCAuthenticationBackend(LaSuiteOIDCAuthenticationBackend):
) from err
try:
return User.objects.get(sub=sub)
except User.DoesNotExist:
if email and settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION:
try:
return User.objects.get(email__iexact=email)
except User.DoesNotExist:
pass
except User.MultipleObjectsReturned as e:
raise SuspiciousOperation(
"Multiple user accounts share a common email."
) from e
return None
return User.objects.get_user_by_sub_or_email(sub, email)
except DuplicateEmailError as err:
logger.warning("Email already used, not creating user: %s", sub)
existing_user = (
User.objects.filter(email=normalize_email(email))
.order_by("-is_active", "-created_at")
.first()
)
audit.log(
auditing.USER_PROVISION,
outcome=audit.Outcome.FAILURE,
reason=audit.Reason.CONFLICT,
actor=None,
actor_type=audit.ActorType.ANONYMOUS,
auth_method="oidc",
target=existing_user,
requested_sub=sub,
)
raise SuspiciousOperation(err.message) from err
class SessionAuthenticationWith401(SessionAuthentication):
@@ -20,6 +20,7 @@ from rest_framework import authentication, exceptions
from core import audit, auditing
from core.models import Application, ApplicationScope
from core.services import jwt_token
from core.utils import normalize_email
from core.validators import sub_validator
User = get_user_model()
@@ -63,6 +64,10 @@ def get_or_create_user_by_sub(sub, email=None, *, auth_method, client_id=None):
Shared by the resource server backends, so that tokens introspected with the
OIDC provider or with Menshen resolve users the same way.
Users are never identified by email here, but a user to create is refused
when its normalized email is already stored, unless
OIDC_ALLOW_DUPLICATE_EMAILS is set.
Args:
sub: Subject identifier from the introspected token
email: Email to store on a newly created user
@@ -90,12 +95,10 @@ def get_or_create_user_by_sub(sub, email=None, *, auth_method, client_id=None):
if not settings.OIDC_CREATE_USER:
return None
# Users are never identified by email here. But a second account with the
# same email (e.g. provisionnal account) would break the lookups by email:
# refuse it.
normalized_email = normalize_email(email)
existing_user = (
User.objects.filter(email__iexact=email).first()
if settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION and email
User.objects.filter(email=normalized_email).first()
if normalized_email and not settings.OIDC_ALLOW_DUPLICATE_EMAILS
else None
)
if existing_user is not None:
@@ -6,7 +6,6 @@ from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.db.models import Count
from django.db.models.functions import Lower
from core.models import File, RecordingAccess, ResourceAccess, RoleChoices
@@ -21,14 +20,15 @@ ROLE_PRIORITY = {
class Command(BaseCommand):
"""
Merge duplicate users sharing the same email (case-insensitive) into the
most recently created one.
Merge duplicate users sharing the same email into the most recently
created one.
Emails are compared case-insensitively, so 'John@Example.com' and
'john@example.com' are treated as duplicates. The KEPT user is the most
recently created. All room memberships, recording accesses and files are
transferred to it. When a conflict exists, the higher-privilege role wins.
Stale users are then deleted.
Emails are stored normalized (stripped, ASCII letters lowercased) and are
compared exactly, so 'John@Example.com' and 'john@example.com' are both
stored as 'john@example.com' and treated as duplicates. The KEPT user is
the most recently created. All room memberships, recording accesses and
files are transferred to it. When a conflict exists, the higher-privilege
role wins. Stale users are then deleted.
Each email group is processed inside a single database transaction.
"""
@@ -60,16 +60,13 @@ class Command(BaseCommand):
users_qs = users_qs.filter(email__icontains=email_filter)
self.stdout.write(f"[INFO] Filtering emails containing '{email_filter}'.\n")
# Group emails case-insensitively so 'John@X.com' and 'john@x.com'
# are detected as duplicates of each other.
duplicate_emails = (
users_qs.exclude(email__isnull=True)
.exclude(email="")
.annotate(email_lower=Lower("email"))
.values("email_lower")
.values("email")
.annotate(cnt=Count("id"))
.filter(cnt__gt=1)
.values_list("email_lower", flat=True)
.values_list("email", flat=True)
)
if not duplicate_emails:
@@ -85,12 +82,9 @@ class Command(BaseCommand):
failed_emails = []
for email in duplicate_emails:
# Case-insensitive lookup to fetch every casing variant of the email.
# Secondary sort by id ensures a stable, deterministic order when
# created_at timestamps are equal (common in tests and bulk imports).
users = list(
User.objects.filter(email__iexact=email).order_by("created_at", "id")
)
users = list(User.objects.filter(email=email).order_by("created_at", "id"))
kept_user = users[-1]
stale_users = users[:-1]
@@ -130,10 +124,6 @@ class Command(BaseCommand):
failed_emails.append(email)
self.stderr.write(f"[ERROR] Failed to merge '{email}': {exc}")
if not kept_user.email.islower():
kept_user.email = kept_user.email.lower()
kept_user.save(update_fields=["email"])
if failed_emails:
raise CommandError(
f"Failed to merge {len(failed_emails)} email group(s): {', '.join(failed_emails)}"
@@ -0,0 +1,44 @@
"""Store user emails stripped and ASCII-lowercased, and blank ones as NULL."""
import string
from django.db import migrations
BATCH_SIZE = 500
_ASCII_LOWERCASE_TABLE = str.maketrans(string.ascii_uppercase, string.ascii_lowercase)
def normalize_email(email):
"""Strip an email and lowercase its ASCII letters only."""
return (email or "").strip().translate(_ASCII_LOWERCASE_TABLE)
def forwards(apps, schema_editor):
"""Normalize the user emails, writing the changed rows in batches."""
User = apps.get_model("core", "User")
batch = []
for user_id, email in User.objects.values_list("id", "email").iterator(
chunk_size=BATCH_SIZE
):
normalized = normalize_email(email) or None
if normalized == email:
continue
batch.append(User(id=user_id, email=normalized))
if len(batch) == BATCH_SIZE:
User.objects.bulk_update(batch, ["email"])
batch = []
if batch:
User.objects.bulk_update(batch, ["email"])
class Migration(migrations.Migration):
atomic = False
dependencies = [
("core", "0029_alter_application_client_secret_sha256"),
]
operations = [
migrations.RunPython(forwards, migrations.RunPython.noop, elidable=True),
]
@@ -0,0 +1,20 @@
# Generated by Django 5.2.17 on 2026-11-10 16:28
import core.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0030_normalize_user_emails'),
]
operations = [
migrations.AlterModelManagers(
name='user',
managers=[
('objects', core.models.UserManager()),
],
),
]
@@ -0,0 +1,26 @@
# Generated by Django 5.2.17 on 2026-11-10 17:00
from django.contrib.postgres.operations import (
AddIndexConcurrently,
RemoveIndexConcurrently,
)
from django.db import migrations, models
class Migration(migrations.Migration):
atomic = False
dependencies = [
('core', '0031_alter_user_managers'),
]
operations = [
AddIndexConcurrently(
model_name="user",
index=models.Index(fields=["email"], name="user_email_idx"),
),
RemoveIndexConcurrently(
model_name="user",
name="user_email_upper_idx",
),
]
+51 -2
View File
@@ -115,6 +115,16 @@ class RoomAccessLevel(models.TextChoices):
RESTRICTED = "restricted", _("Restricted Access")
class DuplicateEmailError(Exception):
"""Raised when an email is already associated with a pre-existing user."""
def __init__(self, message=None, email=None):
"""Set message and email to describe the exception."""
self.message = message
self.email = email
super().__init__(self.message)
class BaseModel(models.Model):
"""
Serves as an abstract base model for other models, ensuring that records are validated
@@ -152,6 +162,36 @@ class BaseModel(models.Model):
super().save(*args, **kwargs)
class UserManager(auth_models.UserManager):
"""Custom manager for User model with additional methods."""
def get_user_by_sub_or_email(self, sub, email):
"""Fetch existing user by sub or email."""
try:
return self.get(sub=sub)
except self.model.DoesNotExist as err:
normalized_email = utils.normalize_email(email)
if not normalized_email:
return None
if settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION:
users = self.filter(email=normalized_email).order_by("-is_active")[:2]
if len(users) == 2 and users[1].is_active:
raise DuplicateEmailError(
"Several active users are associated with this email."
) from err
return users[0] if users else None
if (
not settings.OIDC_ALLOW_DUPLICATE_EMAILS
and self.filter(email=normalized_email).exists()
):
raise DuplicateEmailError(
"We couldn't find a user with this sub but the email is already "
"associated with a registered user."
) from err
return None
class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
"""User model to work with OIDC only authentication."""
@@ -229,7 +269,7 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
),
)
objects = auth_models.UserManager()
objects = UserManager()
USERNAME_FIELD = "admin_email"
REQUIRED_FIELDS = []
@@ -247,12 +287,21 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
)
]
indexes = [
models.Index(models.functions.Upper("email"), name="user_email_upper_idx"),
models.Index(fields=["email"], name="user_email_idx"),
]
def __str__(self):
return self.email or self.admin_email or str(self.id)
def save(self, *args, **kwargs):
"""Store the email normalized, and a blank one as NULL, even on a partial save."""
email = utils.normalize_email(self.email) or None
update_fields = kwargs.get("update_fields")
if update_fields is not None and email != self.email:
kwargs["update_fields"] = {*update_fields, "email"}
self.email = email
super().save(*args, **kwargs)
def email_user(self, subject, message, from_email=None, **kwargs):
"""Email this user."""
if not self.email:
@@ -5,6 +5,7 @@ from django.core.exceptions import SuspiciousOperation, ValidationError
from django.db import IntegrityError
from core import audit, auditing, models
from core.utils import normalize_email
class ProvisionalUserError(Exception):
@@ -42,7 +43,7 @@ class ProvisionalUserService:
def _get_by_email(self, email: str) -> models.User | None:
"""Return the user with this email, or None if not found."""
try:
return models.User.objects.get(email__iexact=email)
return models.User.objects.get(email=normalize_email(email))
except models.User.DoesNotExist:
return None
except models.User.MultipleObjectsReturned as e:
@@ -8,6 +8,7 @@ import pytest
from lasuite.marketing.tasks import create_or_update_contact
from core import models
from core.audit.testing import find_events
from core.authentication.backends import OIDCAuthenticationBackend
from core.factories import UserFactory
@@ -296,17 +297,26 @@ def test_finds_user_by_sub(django_assert_num_queries):
def test_finds_user_when_email_fallback_disabled(django_assert_num_queries, settings):
"""Should not return a user when not found by sub, and email fallback is disabled."""
"""Should refuse a sub that is not found when its email is already used, and email
fallback is disabled."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = False
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="foo@mail.com")
with django_assert_num_queries(1):
user = klass.get_existing_user("wrong-sub", db_user.email)
assert user is None
with (
django_assert_num_queries(3),
pytest.raises(
SuspiciousOperation,
match=(
"We couldn't find a user with this sub but the email is already "
"associated with a registered user."
),
),
):
klass.get_existing_user("wrong-sub", db_user.email)
def test_finds_user_when_email_is_none(django_assert_num_queries, settings):
@@ -340,7 +350,7 @@ def test_finds_user_by_email(django_assert_num_queries, settings):
def test_finds_user_case_insensitive_email(django_assert_num_queries, settings):
"""Should match email case-insensitively when falling back to email."""
"""Should match email ignoring ASCII case when falling back to email."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
klass = OIDCAuthenticationBackend()
@@ -353,7 +363,7 @@ def test_finds_user_case_insensitive_email(django_assert_num_queries, settings):
def test_finds_user_multiple_users_same_email(django_assert_num_queries, settings):
"""Should handle multiple users with same email appropriately."""
"""Should refuse to pick one of several active users sharing the email."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
@@ -363,30 +373,278 @@ def test_finds_user_multiple_users_same_email(django_assert_num_queries, setting
UserFactory(email=email) # Second user with same email
with (
django_assert_num_queries(2),
django_assert_num_queries(3),
pytest.raises(
SuspiciousOperation,
match="Multiple user accounts share a common email.",
match="Several active users are associated with this email.",
),
):
klass.get_existing_user("wrong-sub", email)
def test_finds_user_whitespace_email(django_assert_num_queries, settings):
"""Should not match emails with whitespace."""
"""Should match emails with surrounding whitespace once stripped."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
settings.OIDC_CREATE_USER = False
klass = OIDCAuthenticationBackend()
UserFactory(email="foo@mail.com")
db_user = UserFactory(email="foo@mail.com")
with django_assert_num_queries(2):
user = klass.get_existing_user("wrong-sub", " foo@mail.com ")
assert user == db_user
@pytest.mark.parametrize("fallback", [True, False])
def test_finds_user_whitespace_only_email(
django_assert_num_queries, settings, fallback
):
"""Should not look a user up by email when the email is empty once stripped, even
if a legacy user is stored with an empty email."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = fallback
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
legacy_user = UserFactory()
models.User.objects.filter(pk=legacy_user.pk).update(email="")
with django_assert_num_queries(1):
user = klass.get_existing_user("wrong-sub", " ")
assert user is None
def test_authentication_getter_existing_user_via_email_case_insensitive(
monkeypatch, settings
):
"""
If an existing user doesn't match the sub but matches the email with another
ASCII case, the user should be returned and its email should stay normalized.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="john.doe@example.com")
def get_userinfo_mocked(*args):
return {"sub": "123", "email": "JOHN.DOE@EXAMPLE.COM"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
user = klass.get_or_create_user(
access_token="test-token", id_token=None, payload=None
)
assert user == db_user
db_user.refresh_from_db()
assert db_user.email == "john.doe@example.com"
@pytest.mark.parametrize(
"email",
[
"dısk@example.com",
"diſk@example.com",
"disK@example.com",
],
ids=["dotless-i", "long-s", "kelvin-sign"],
)
@pytest.mark.parametrize("fallback", [True, False])
def test_authentication_getter_existing_user_via_email_non_ascii(
monkeypatch, settings, fallback, email
):
"""
If an existing user doesn't match the sub and the email only matches its email
through Unicode case folding, a new user should be created and the existing user
should be left untouched.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = fallback
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="disk@example.com")
db_sub = db_user.sub
def get_userinfo_mocked(*args):
return {"sub": "other-sub", "email": email}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
user = klass.get_or_create_user(
access_token="test-token", id_token=None, payload=None
)
assert user != db_user
assert user.sub == "other-sub"
assert user.email == email
assert models.User.objects.count() == 2
db_user.refresh_from_db()
assert db_user.sub == db_sub
assert db_user.email == "disk@example.com"
def test_authentication_getter_existing_inactive_user_via_email(monkeypatch, settings):
"""
If the only user matching the email is inactive, the login should be refused
instead of creating another user.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
klass = OIDCAuthenticationBackend()
UserFactory(email="john.doe@example.com", is_active=False)
def get_userinfo_mocked(*args):
return {"sub": "123", "email": "John.Doe@example.com"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
with pytest.raises(SuspiciousOperation, match="User account is disabled"):
klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)
assert models.User.objects.count() == 1
def test_authentication_getter_no_fallback_to_email_no_duplicate(monkeypatch, settings):
"""
When the email fallback is disabled, an unknown sub whose email is already used,
in another ASCII case, should be refused instead of creating a second user.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = False
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="john.doe@example.com")
def get_userinfo_mocked(*args):
return {"sub": "123", "email": "JOHN.DOE@EXAMPLE.COM"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
with pytest.raises(
SuspiciousOperation,
match=(
"We couldn't find a user with this sub but the email is already "
"associated with a registered user."
),
):
klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)
assert models.User.objects.count() == 1
db_user.refresh_from_db()
assert db_user.sub != "123"
def test_authentication_getter_no_fallback_to_email_no_duplicate_is_audited(
audit_events, caplog, monkeypatch, settings
):
"""
A login refused because its email is already used should log the refused sub, and
be audited as a conflict with the user holding the email, never naming the email.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = False
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="john.doe@example.com")
def get_userinfo_mocked(*args):
return {"sub": "new-sub", "email": "JOHN.DOE@EXAMPLE.COM"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
with pytest.raises(SuspiciousOperation):
klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)
assert "Email already used, not creating user: new-sub" in caplog.text
assert "john.doe@example.com" not in caplog.text.lower()
[provision] = find_events(audit_events, "user.provision")
assert provision["event"]["outcome"] == "failure"
assert provision["event"]["reason"] == "conflict"
assert provision["lasuite"]["actor"] == {"type": "anonymous"}
assert provision["lasuite"]["auth"] == {"method": "oidc"}
assert provision["user"] == {
"target": {"id": str(db_user.pk), "domain": "example.com"}
}
assert provision["entity"]["target"]["id"] == str(db_user.pk)
assert provision["entity"]["target"]["raw"] == {"sub": db_user.sub}
assert provision["lasuite"]["details"] == {"requested_sub": "new-sub"}
assert provision["log"]["level"] == "warning"
assert "john.doe@example.com" not in str(provision).lower()
@pytest.mark.parametrize("fallback", [True, False])
def test_authentication_getter_email_conflict_audits_active_user(
audit_events, fallback, monkeypatch, settings
):
"""
A login refused because of its email, with or without the email fallback, should
be audited against the newest active user holding the email, not a newer inactive
one.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = fallback
settings.OIDC_ALLOW_DUPLICATE_EMAILS = False
klass = OIDCAuthenticationBackend()
UserFactory(email="john.doe@example.com")
active_user = UserFactory(email="john.doe@example.com")
UserFactory(email="john.doe@example.com", is_active=False)
def get_userinfo_mocked(*args):
return {"sub": "new-sub", "email": "john.doe@example.com"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
with pytest.raises(SuspiciousOperation):
klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)
[provision] = find_events(audit_events, "user.provision")
assert provision["event"]["reason"] == "conflict"
assert provision["user"]["target"]["id"] == str(active_user.pk)
assert provision["lasuite"]["details"] == {"requested_sub": "new-sub"}
assert models.User.objects.count() == 3
def test_authentication_getter_no_fallback_to_email_allow_duplicate(
monkeypatch, settings
):
"""
When the email fallback is disabled and duplicate emails are allowed, an unknown
sub whose email is already used should get a new user.
"""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = False
settings.OIDC_ALLOW_DUPLICATE_EMAILS = True
klass = OIDCAuthenticationBackend()
db_user = UserFactory(email="john.doe@example.com")
def get_userinfo_mocked(*args):
return {"sub": "123", "email": "JOHN.DOE@EXAMPLE.COM"}
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
user = klass.get_or_create_user(
access_token="test-token", id_token=None, payload=None
)
assert user != db_user
assert user.sub == "123"
assert user.email == "john.doe@example.com"
assert models.User.objects.count() == 2
@pytest.mark.parametrize(
"email",
[
@@ -19,6 +19,13 @@ pytestmark = pytest.mark.django_db
# pylint: disable=W0613
def _user_with_stored_email(email):
"""Create a user storing the email as is, like the rows predating the normalization."""
user = UserFactory()
User.objects.filter(pk=user.pk).update(email=email)
return user
def test_merge_no_duplicates_does_nothing():
"""Command should do nothing when no duplicate users exist."""
user = UserFactory(email="unique@example.com")
@@ -36,24 +43,30 @@ def test_merge_keeps_most_recently_created_user():
assert User.objects.filter(id=user2.id).exists()
def test_merge_user_case_insensitive():
"""Emails differing only by case should be treated as duplicates and merged,
keeping the most recently created user."""
user1 = UserFactory(email="Dup@example.com")
user2 = UserFactory(email="dup@example.com")
@pytest.mark.parametrize(
"lookalike_email",
[
"dısk@example.com",
"diſk@example.com",
"disK@example.com",
],
ids=["dotless-i", "long-s", "kelvin-sign"],
)
def test_merge_does_not_merge_lookalike_emails(lookalike_email):
"""A user whose email only matches the duplicates' email through Unicode case
folding should not be merged with them, even when created last."""
user1 = UserFactory(email="disk@example.com")
user2 = UserFactory(email="disk@example.com")
ra = UserResourceAccessFactory(user=user1)
lookalike = UserFactory(email=lookalike_email)
call_command("merge_duplicate_users")
assert not User.objects.filter(id=user1.id).exists()
assert User.objects.filter(id=user2.id).exists()
user3 = UserFactory(email="joe@example.com")
user4 = UserFactory(email="Joe@example.com")
call_command("merge_duplicate_users")
assert not User.objects.filter(id=user3.id).exists()
assert User.objects.filter(id=user4.id).exists()
user4.refresh_from_db()
assert user4.email.islower()
ra.refresh_from_db()
assert ra.user == user2
lookalike.refresh_from_db()
assert lookalike.email == lookalike_email
assert not ResourceAccess.objects.filter(user=lookalike).exists()
def test_merge_deletes_all_stale_users():
@@ -409,10 +422,11 @@ def test_merge_does_not_merge_users_with_null_email():
assert User.objects.filter(id=user2.id).exists()
def test_merge_does_not_merge_users_with_blank_email():
"""Users with empty-string email must never be merged together, even if multiple exist."""
user1 = UserFactory(email="")
user2 = UserFactory(email="")
def test_merge_does_not_merge_users_with_legacy_blank_email():
"""Users with a legacy empty-string email must never be merged together, even if
multiple exist."""
user1 = _user_with_stored_email("")
user2 = _user_with_stored_email("")
call_command("merge_duplicate_users")
assert User.objects.filter(id=user1.id).exists()
assert User.objects.filter(id=user2.id).exists()
@@ -474,7 +488,7 @@ def test_merge_email_filter_no_match_does_nothing():
def test_merge_email_filter_is_case_insensitive():
"""Command should match emails case-insensitively when filtering."""
UserFactory(email="user1@Example.com")
UserFactory(email="user1@Example.com")
call_command("merge_duplicate_users", email_filter="@example.com")
UserFactory(email="user1@example.com")
UserFactory(email="user1@example.com")
call_command("merge_duplicate_users", email_filter="@Example.COM")
assert User.objects.filter(email="user1@example.com").count() == 1
@@ -5,6 +5,7 @@
import json
from unittest import mock
from django.core.exceptions import SuspiciousOperation
from django.db import IntegrityError
import pytest
@@ -38,6 +39,20 @@ def test_get_or_create_existing_user_is_not_audited(audit_events):
assert not find_events(audit_events, "user.provision")
def test_get_or_create_several_users_same_normalized_email(audit_events):
"""Several users sharing the normalized email should be refused, not picked."""
UserFactory(email="john.doe@example.com")
UserFactory(email="John.Doe@example.com")
with pytest.raises(
SuspiciousOperation, match="Multiple user accounts share a common email."
):
ProvisionalUserService().get_or_create(" JOHN.DOE@example.com", "my-client")
assert User.objects.count() == 2
assert not find_events(audit_events, "user.provision")
def test_get_or_create_creation_is_audited(audit_events):
"""A created user is identified by its id, without sub nor email."""
user, created = ProvisionalUserService().get_or_create(
@@ -0,0 +1,62 @@
"""Tests for the user admin class."""
import pytest
from core import factories
pytestmark = pytest.mark.django_db
@pytest.fixture(autouse=True)
def static_storage_without_manifest(settings):
"""Render the admin pages without collecting the static files first."""
settings.STORAGES = {
**settings.STORAGES,
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"
},
}
def _admin_client(client):
"""Log a superuser in the client."""
client.force_login(factories.UserFactory(is_staff=True, is_superuser=True))
return client
def test_admin_users_duplicate_email_filter(client):
"""The filter should keep the users sharing their stored email, grouped by email
and ordered by creation, but not the users whose email only matches through
Unicode case folding."""
first_jim = factories.UserFactory(email="jim@example.com")
first_ann = factories.UserFactory(email="ann@example.com")
second_jim = factories.UserFactory(email="JIM@example.com")
second_ann = factories.UserFactory(email="ann@example.com")
factories.UserFactory(email="jım@example.com")
factories.UserFactory(email="bob@example.com")
factories.UserFactory(email=None)
factories.UserFactory(email=None)
response = _admin_client(client).get("/admin/core/user/?duplicate_email=yes")
assert response.status_code == 200
assert [user.pk for user in response.context["cl"].result_list] == [
first_ann.pk,
second_ann.pk,
first_jim.pk,
second_jim.pk,
]
def test_admin_users_last_login(client):
"""The last login of users should be shown in the list and on the change page."""
user = factories.UserFactory()
admin_client = _admin_client(client)
changelist = admin_client.get("/admin/core/user/")
change = admin_client.get(f"/admin/core/user/{user.pk}/change/")
assert changelist.status_code == 200
assert "column-last_login" in changelist.content.decode()
assert change.status_code == 200
assert "field-last_login" in change.content.decode()
@@ -280,19 +280,22 @@ def test_menshen_unknown_user_not_created(settings):
@responses.activate
@pytest.mark.parametrize("fallback", [True, False])
@pytest.mark.parametrize("existing_sub", [None, "other-sub"])
def test_menshen_unknown_user_email_already_used(settings, existing_sub):
def test_menshen_unknown_user_email_already_used(settings, existing_sub, fallback):
"""An unknown sub should not create a second account with an email already
used, by a provisional user or a user with another sub, when
OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION=True."""
used, by a provisional user or a user with another sub, whether
OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION is set or not."""
settings.OIDC_CREATE_USER = True
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = fallback
existing_user = UserFactory(sub=existing_sub, email="User@Example.com")
existing_user = UserFactory(sub=existing_sub, email="user@example.com")
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
responses.POST,
INTROSPECTION_ENDPOINT,
json=_introspection("new-sub", email=" User@Example.COM "),
)
response = _create_room()
@@ -305,6 +308,43 @@ def test_menshen_unknown_user_email_already_used(settings, existing_sub):
assert not Room.objects.exists()
@responses.activate
@pytest.mark.parametrize("existing_sub", [None, "other-sub"])
def test_menshen_unknown_user_email_already_used_allowed(
audit_events, settings, existing_sub
):
"""An unknown sub should get its own account, even with an email already used,
when OIDC_ALLOW_DUPLICATE_EMAILS=True."""
settings.OIDC_CREATE_USER = True
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = False
settings.OIDC_ALLOW_DUPLICATE_EMAILS = True
existing_user = UserFactory(sub=existing_sub, email="user@example.com")
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
json=_introspection("new-sub", email=" User@Example.COM "),
)
response = _create_room()
assert response.status_code == 201
assert User.objects.count() == 2
user = User.objects.get(sub="new-sub")
assert user != existing_user
assert user.email == "user@example.com"
existing_user.refresh_from_db()
assert existing_user.sub == existing_sub
[provision] = find_events(audit_events, "user.provision")
assert provision["event"]["outcome"] == "success"
assert provision["lasuite"]["outcome"] == "success"
assert provision["entity"]["target"]["id"] == str(user.pk)
@responses.activate
def test_menshen_is_audited_as_application(audit_events):
"""A call with a Menshen token is made by the client Menshen reports, acting for
@@ -382,10 +422,12 @@ def test_menshen_unknown_user_email_already_used_is_audited(audit_events, settin
settings.OIDC_CREATE_USER = True
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
existing_user = UserFactory(sub=None, email="User@Example.com")
existing_user = UserFactory(sub=None, email="user@example.com")
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
responses.POST,
INTROSPECTION_ENDPOINT,
json=_introspection("new-sub", email=" User@Example.COM "),
)
response = _create_room()
+57 -4
View File
@@ -4,11 +4,12 @@ Unit tests for the User model
from unittest import mock
from django.contrib.auth.models import update_last_login
from django.core.exceptions import ValidationError
import pytest
from core import factories
from core import factories, models
pytestmark = pytest.mark.django_db
@@ -117,12 +118,13 @@ def test_models_users_email_unique_when_sub_is_null():
def test_models_users_email_unique_case_insensitive_when_sub_is_null():
"""Email uniqueness should be case-insensitive among users with no sub (pending users)."""
factories.UserFactory(sub=None, email="Test@example.com")
"""Email uniqueness among users with no sub (pending users) should also ignore the
case of non-ASCII letters, which the email normalization keeps."""
factories.UserFactory(sub=None, email="test@éxample.com")
with pytest.raises(
ValidationError, match="Constraint “unique_email_when_sub_is_null” is violated."
):
factories.UserFactory(sub=None, email="test@example.com")
factories.UserFactory(sub=None, email="test@Éxample.com")
def test_models_users_email_not_unique_when_sub_is_set():
@@ -175,3 +177,54 @@ def test_models_users_sub_blank_is_accepted():
"""sub='' passes validation because blank=True; null is preferred but not enforced."""
user = factories.UserFactory.build(sub="")
user.full_clean()
@pytest.mark.parametrize(
"email, expected_email",
[
("John.Doe@Example.COM", "john.doe@example.com"),
(" john.doe@example.com ", "john.doe@example.com"),
],
)
def test_models_users_email_normalized_on_save(email, expected_email):
"""The email of a user should be stripped and have its ASCII letters only lowercased
when saved."""
user = factories.UserFactory(email=email)
user.refresh_from_db()
assert user.email == expected_email
def test_models_users_email_normalized_on_login():
"""The last login update at login should store a legacy email normalized."""
user = factories.UserFactory()
models.User.objects.filter(pk=user.pk).update(email="John.Doe@Example.COM")
user.refresh_from_db()
update_last_login(None, user)
user.refresh_from_db()
assert user.last_login is not None
assert user.email == "john.doe@example.com"
@pytest.mark.parametrize("email", ["", " "])
def test_models_users_email_blank_stored_as_null(email):
"""An empty or whitespace-only email should be stored as NULL."""
user = factories.UserFactory(email=email)
user.refresh_from_db()
assert user.email is None
def test_models_users_get_user_by_sub_or_email_active_preferred(settings):
"""An active user should be preferred over an inactive one sharing its email."""
settings.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION = True
factories.UserFactory(email="john.doe@example.com", is_active=False)
active_user = factories.UserFactory(email="John.Doe@example.com")
factories.UserFactory(email="john.doe@example.com", is_active=False)
assert (
models.User.objects.get_user_by_sub_or_email(
"unknown-sub", "JOHN.DOE@example.com"
)
== active_user
)
@@ -0,0 +1,17 @@
"""Unit tests for the OIDC_ALLOW_DUPLICATE_EMAILS setting."""
from unittest import mock
import pytest
from meet.settings import Test
def test_oidc_allow_duplicate_emails_with_email_fallback_is_refused():
"""Users identified by email cannot share one, so both settings stop the loading."""
with (
mock.patch.object(Test, "OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION", True),
mock.patch.object(Test, "OIDC_ALLOW_DUPLICATE_EMAILS", True),
pytest.raises(ValueError, match="OIDC_ALLOW_DUPLICATE_EMAILS"),
):
Test.post_setup()
+12
View File
@@ -27,6 +27,7 @@ from core.utils import (
NotificationError,
create_livekit_client,
generate_token,
normalize_email,
notify_participants,
)
@@ -420,3 +421,14 @@ def test_notify_participants_success(mock_create_livekit_client):
# Verify aclose was called
mock_api_instance.aclose.assert_called_once()
def test_normalize_email():
"""The "normalize_email" function should strip and lowercase ASCII letters only."""
assert normalize_email(" John.Doe@Example.COM ") == "john.doe@example.com"
assert normalize_email("Dısk@Example.com") == "dısk@example.com"
assert normalize_email("Diſk@Example.com") == "diſk@example.com"
assert normalize_email("DisK@Example.com") == "disK@example.com"
assert normalize_email("Élise@Example.com") == "Élise@example.com"
assert normalize_email("") == ""
assert normalize_email(None) == ""
+11
View File
@@ -345,6 +345,17 @@ def is_uuid(value: str) -> bool:
return True
_ASCII_LOWERCASE_TABLE = str.maketrans(string.ascii_uppercase, string.ascii_lowercase)
def normalize_email(email):
"""Strip an email and lowercase its ASCII letters only.
Emails are stored in this form and compared exactly.
"""
return (email or "").strip().translate(_ASCII_LOWERCASE_TABLE)
def detect_mimetype(file_buffer: bytes, filename: str | None = None) -> str:
"""
Detect MIME type using multiple methods for better accuracy.
+17
View File
@@ -617,6 +617,14 @@ class Base(Configuration):
environ_name="OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION",
environ_prefix=None,
)
# WARNING: Enabling this setting allows multiple user accounts to share the same email
# address. This may cause security issues and is not recommended for production use when
# email is activated as fallback for identification
OIDC_ALLOW_DUPLICATE_EMAILS = values.BooleanValue(
default=False,
environ_name="OIDC_ALLOW_DUPLICATE_EMAILS",
environ_prefix=None,
)
OIDC_USER_SUB_FIELD_IMMUTABLE = values.BooleanValue(
default=True, environ_name="OIDC_USER_SUB_FIELD_IMMUTABLE", environ_prefix=None
)
@@ -1657,6 +1665,15 @@ class Base(Configuration):
if cls.LIVEKIT_API_TIMEOUT_SECONDS < 1:
raise ValueError("LIVEKIT_API_TIMEOUT_SECONDS must be at least 1")
if (
cls.OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION
and cls.OIDC_ALLOW_DUPLICATE_EMAILS
):
raise ValueError(
"Both OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION and "
"OIDC_ALLOW_DUPLICATE_EMAILS cannot be set to True simultaneously."
)
if (
cls.SUMMARY_SERVICE_VERSION == 1
and cls.SUMMARY_SERVICE_ENDPOINT is not None
+1 -6
View File
@@ -10,13 +10,8 @@ server {
add_header Cache-Control "public, max-age=2592000";
}
location ^~ /assets/mediapipe/models/ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
# Serve static files with caching
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp3)$ {
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
+14 -11
View File
@@ -22,7 +22,6 @@
"@tanstack/react-query": "5.101.4",
"@timephy/rnnoise-wasm": "1.0.0",
"hoofd": "1.7.3",
"howler": "2.2.4",
"humanize-duration": "3.34.1",
"i18next": "26.3.6",
"i18next-browser-languagedetector": "8.2.1",
@@ -36,6 +35,7 @@
"react-dom": "18.3.1",
"react-i18next": "17.0.12",
"react-stately": "3.49.0",
"use-sound": "5.0.0",
"valtio": "2.3.2",
"wouter": "3.10.0"
},
@@ -44,7 +44,6 @@
"@pandacss/dev": "1.11.1",
"@tanstack/eslint-plugin-query": "5.100.14",
"@tanstack/react-query-devtools": "5.100.14",
"@types/howler": "2.2.13",
"@types/humanize-duration": "3.27.4",
"@types/node": "24.12.4",
"@types/react": "18.3.12",
@@ -2556,13 +2555,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/howler": {
"version": "2.2.13",
"resolved": "https://registry.npmjs.org/@types/howler/-/howler-2.2.13.tgz",
"integrity": "sha512-40+EBjqIHHrC4VShlz/7i0lBUsE3QkgzZinQQji74Hd8sBkJZUBaT7LWFLK6rcabsDOOQpoMbEJvtaFQwxOu/g==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/humanize-duration": {
"version": "3.27.4",
"resolved": "https://registry.npmjs.org/@types/humanize-duration/-/humanize-duration-3.27.4.tgz",
@@ -6466,8 +6458,7 @@
"node_modules/howler": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/howler/-/howler-2.2.4.tgz",
"integrity": "sha512-iARIBPgcQrwtEr+tALF+rapJ8qSc+Set2GJQl7xT1MQzWaVkFebdJhR3alVlSiUf5U7nAANKuj3aWpwerocD5w==",
"license": "MIT"
"integrity": "sha512-iARIBPgcQrwtEr+tALF+rapJ8qSc+Set2GJQl7xT1MQzWaVkFebdJhR3alVlSiUf5U7nAANKuj3aWpwerocD5w=="
},
"node_modules/html-parse-stringify": {
"version": "4.0.1",
@@ -11186,6 +11177,18 @@
"punycode": "^2.1.0"
}
},
"node_modules/use-sound": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/use-sound/-/use-sound-5.0.0.tgz",
"integrity": "sha512-MNHT3FFC5HxNCrgZtrnpIMJI2cw/0D2xismcrtyht8BTuF5FhFhb57xO/jlQr2xJaFrc/0btzRQvGyHQwB7PVA==",
"license": "MIT",
"dependencies": {
"howler": "^2.2.4"
},
"peerDependencies": {
"react": ">=16.8"
}
},
"node_modules/use-sync-external-store": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
+1 -2
View File
@@ -30,7 +30,6 @@
"@tanstack/react-query": "5.101.4",
"@timephy/rnnoise-wasm": "1.0.0",
"hoofd": "1.7.3",
"howler": "2.2.4",
"humanize-duration": "3.34.1",
"i18next": "26.3.6",
"i18next-browser-languagedetector": "8.2.1",
@@ -44,6 +43,7 @@
"react-dom": "18.3.1",
"react-i18next": "17.0.12",
"react-stately": "3.49.0",
"use-sound": "5.0.0",
"valtio": "2.3.2",
"wouter": "3.10.0"
},
@@ -52,7 +52,6 @@
"@pandacss/dev": "1.11.1",
"@tanstack/eslint-plugin-query": "5.100.14",
"@tanstack/react-query-devtools": "5.100.14",
"@types/howler": "2.2.13",
"@types/humanize-duration": "3.27.4",
"@types/node": "24.12.4",
"@types/react": "18.3.12",
-3
View File
@@ -36,9 +36,6 @@ const config: Config = {
jsxFramework: 'react',
outdir: 'src/styled-system',
globalFontface: {},
globalVars: {
'--global-font-body': 'var(--fonts-sans)',
},
theme: {
...pandaPreset.theme,
// media queries are defined in em so that zooming with text-only mode triggers breakpoints
Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 436 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

+1 -1
View File
@@ -1,7 +1,7 @@
import { fetchApi } from './fetchApi'
import { keys } from './queryKeys'
import { useQuery } from '@tanstack/react-query'
import type { RecordingMode } from '@/features/recording/types'
import { RecordingMode } from '@/features/recording'
import type { ApiAccessLevel } from '@/features/rooms/api/ApiRoom'
import type { Track, VideoCodec } from 'livekit-client'
type Source = Track.Source
+1 -2
View File
@@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next'
import { useMediaDeviceSelect } from '@livekit/components-react'
import { reportError } from '@/features/analytics/telemetry'
import { canTestAudioOutput } from '@/features/rooms/utils/canTestAudioOutput'
import upriseSoundSrc from '@/assets/sounds/uprise.mp3'
export const SoundTester = () => {
const { t } = useTranslation('settings')
@@ -56,7 +55,7 @@ export const SoundTester = () => {
{/* eslint-disable jsx-a11y/media-has-caption */}
<audio
ref={audioRef}
src={upriseSoundSrc}
src="/sounds/uprise.mp3"
onEnded={() => setIsPlaying(false)}
/>
</>
@@ -1,32 +0,0 @@
import { useEffect, useState } from 'react'
import { getPosthog } from '../utils'
import { useIsAnalyticsEnabled } from './useIsAnalyticsEnabled'
/**
* Same contract as `useFeatureFlagEnabled` from 'posthog-js/react', without a
* static import of posthog-js: that import puts the whole SDK on the critical
* path of every screen, defeating the lazy `getPosthog()`.
*/
export const useFeatureFlagEnabled = (flag: string): boolean | undefined => {
const isAnalyticsEnabled = useIsAnalyticsEnabled()
const [enabled, setEnabled] = useState<boolean | undefined>(undefined)
useEffect(() => {
if (!isAnalyticsEnabled) return
let cancelled = false
let unsubscribe: (() => void) | undefined
void getPosthog().then((ph) => {
if (cancelled) return
setEnabled(ph.isFeatureEnabled(flag))
unsubscribe = ph.onFeatureFlags(() =>
setEnabled(ph.isFeatureEnabled(flag))
)
})
return () => {
cancelled = true
unsubscribe?.()
}
}, [flag, isAnalyticsEnabled])
return enabled
}
@@ -7,11 +7,7 @@ import {
} from 'react-aria-components'
import { RiArrowDownSFill } from '@remixicon/react'
import { css, cx } from '@/styled-system/css'
import {
DIAGNOSTIC_OUTPUT_LANG,
getSummaryLang,
type ConnectionTestStepResult,
} from '../types'
import type { ConnectionTestStepResult } from '../types'
import { StepStatusIndicator } from './StepStatusIndicator'
/** Each step is its own bounded card, collapsed or not. */
@@ -69,7 +65,7 @@ const labelClass = css({
const valueClass = css({
fontFamily: 'mono',
textStyle: 'xs',
color: 'greyscale.600',
color: 'greyscale.500',
overflowWrap: 'anywhere',
})
@@ -114,11 +110,7 @@ const StepRowContent = ({ step }: { step: ConnectionTestStepResult }) => {
<>
<span className={identityClass}>
<span className={labelClass}>{t(`steps.${step.id}`)}</span>
{step.summary && (
<span className={valueClass} lang={getSummaryLang(step)}>
{step.summary}
</span>
)}
{step.summary && <span className={valueClass}>{step.summary}</span>}
</span>
<StepStatusIndicator
status={step.status}
@@ -178,7 +170,7 @@ export const ConnectionTestStepRow = ({
{/* Collapsed panels stay in the DOM for aria-controls, but the log
lines themselves are only mounted when actually visible. */}
{isExpanded && (
<ul className={logListClass} lang={DIAGNOSTIC_OUTPUT_LANG}>
<ul className={logListClass}>
{step.logs?.map((log, index) => (
<li key={`${log.level}-${index}`} className={logItemClass}>
{log.message}
@@ -153,7 +153,7 @@ const counterValueClass = css({
})
/** A zero count is context, not a result: it recedes instead of shouting. */
const emptyCounterClass = css({ color: 'greyscale.600' })
const emptyCounterClass = css({ color: 'greyscale.400' })
const emptySquareClass = css({
backgroundColor: 'transparent!',
border: '1px solid {colors.greyscale.250}',
@@ -25,10 +25,10 @@ export const statusSquareClass: Record<ConnectionTestStepStatus, string> = {
* failure and warning.
*/
export const statusTextClass: Record<ConnectionTestStepStatus, string> = {
pending: css({ color: 'greyscale.600' }),
pending: css({ color: 'greyscale.500' }),
running: css({ color: 'greyscale.700' }),
success: css({ color: 'greyscale.1000' }),
warning: css({ color: 'warning', fontWeight: 'medium' }),
failed: css({ color: 'danger.600', fontWeight: 'medium' }),
skipped: css({ color: 'greyscale.600' }),
skipped: css({ color: 'greyscale.500' }),
}
@@ -136,16 +136,14 @@ const ConnectionTest = () => {
<h2 className={sectionTitleClass}>
{t(`groups.${group.id}`)}
</h2>
<ul className={rowsClass}>
<div className={rowsClass}>
{group.steps.map((id) => {
const step = stepsById.get(id)
return step ? (
<li key={id}>
<ConnectionTestStepRow step={step} />
</li>
<ConnectionTestStepRow key={id} step={step} />
) : null
})}
</ul>
</div>
</section>
))}
@@ -32,23 +32,6 @@ export type ConnectionTestStepResult = {
data?: Record<string, unknown>
}
export const DIAGNOSTIC_OUTPUT_LANG = 'en'
const LANGUAGE_NEUTRAL_STEPS: ReadonlySet<ConnectionTestStepId> = new Set([
'browser',
'microphone',
'camera',
'devices',
])
export const getSummaryLang = ({
id,
status,
}: Pick<ConnectionTestStepResult, 'id' | 'status'>) =>
LANGUAGE_NEUTRAL_STEPS.has(id) && status === 'success'
? undefined
: DIAGNOSTIC_OUTPUT_LANG
export type ConnectionTestGroupId = 'local' | 'network'
/** Display order: everything local first, then everything that leaves the machine. */
@@ -41,23 +41,18 @@ const Image = styled('img', {
const Dot = styled('div', {
base: {
borderRadius: '50%',
borderStyle: 'solid',
borderWidth: '1px',
boxSizing: 'border-box',
display: 'inline-block',
height: '.5rem',
height: '.375rem',
margin: '0 .25rem',
width: '.5rem',
width: '.375rem',
},
variants: {
selected: {
true: {
backgroundColor: 'primary.800',
borderColor: 'primary.800',
},
false: {
backgroundColor: 'primary.100',
borderColor: 'primary.500',
backgroundColor: 'primary.300',
},
},
},
@@ -1,10 +1,8 @@
import type { TrackReferenceOrPlaceholder } from '@livekit/components-core'
import { getScrollBarWidth } from '@livekit/components-core'
import * as React from 'react'
import { TrackLoop } from '@livekit/components-react'
import { TrackLoop, useVisualStableUpdate } from '@livekit/components-react'
import { useSize } from '@/features/rooms/livekit/hooks/useResizeObserver'
import { useCarouselTiles } from '../hooks/useCarouselTiles'
import { useSpeakerPromotionTrigger } from '../hooks/useSpeakerPromotionTrigger'
const MIN_HEIGHT = 130
const MIN_WIDTH = 140
@@ -25,9 +23,8 @@ export interface CarouselLayoutProps extends React.HTMLAttributes<HTMLMediaEleme
* The `CarouselLayout` component displays a list of tracks in a scroll container.
* It will display as many tiles as possible and overflow the rest.
* @remarks
* Tiles are ordered by `useCarouselTiles`: screen shares, new speakers and
* raised hands enter at the top, right below the local camera, and the other
* tiles keep their order.
* To ensure visual stability when tiles are reordered due to track updates,
* the component uses the `useVisualStableUpdate` hook.
* @example
* ```tsx
* const tracks = useTracks([Track.Source.Camera]);
@@ -69,11 +66,7 @@ export function CarouselLayout({
setPrevTiles(tilesThatFit)
}
const sortedTiles = useCarouselTiles(tracks, maxVisibleTiles)
// The carousel scrolls, so only the first tiles are guaranteed on screen.
useSpeakerPromotionTrigger(sortedTiles.slice(0, maxVisibleTiles), tracks, {
raisedHands: true,
})
const sortedTiles = useVisualStableUpdate(tracks, maxVisibleTiles)
React.useLayoutEffect(() => {
if (asideEl.current) {
@@ -46,7 +46,7 @@ export function GridLayout({ tracks, ...props }: GridLayoutProps) {
const { layout } = useGridLayout(gridEl, tracks.length)
const pagination = usePagination(layout.maxTiles, tracks)
useSpeakerPromotionTrigger(pagination.tracks, tracks)
useSpeakerPromotionTrigger(pagination.tracks)
useSwipe(gridEl, {
onLeftSwipe: pagination.nextPage,
@@ -1,23 +0,0 @@
import type { TrackReferenceOrPlaceholder } from '@livekit/components-core'
import { useRef } from 'react'
import { orderCarouselTiles } from '../utils/orderCarouselTiles'
/**
* Carousel counterpart of LiveKit's `useVisualStableUpdate`: same sort, same
* stable update, but screen shares and new speakers end up at the top. See
* `orderCarouselTiles`.
*
* Like `useVisualStableUpdate`, it only reorders when its host renders.
*/
export function useCarouselTiles(
tracks: TrackReferenceOrPlaceholder[],
maxVisibleTiles: number
) {
const previous = useRef<TrackReferenceOrPlaceholder[]>([])
previous.current = orderCarouselTiles(
previous.current,
tracks,
maxVisibleTiles
)
return previous.current
}
@@ -8,65 +8,41 @@ import { useEffect, useReducer, useRef } from 'react'
* Tripwire for speaker promotion.
*
* Listens to `RoomEvent.ActiveSpeakersChanged` imperatively and forces ONE
* re-render of the host when a speaker has a tile in `allTiles` but none in
* `visibleTiles`. That render re-runs the host's tile ordering, which reads
* live `participant.isSpeaking` state and performs the actual swap.
* re-render of the host component only when an active speaker has none of
* their tiles are within the visible span (`maxVisibleTiles`). That render
* re-runs `useVisualStableUpdate`, which reads live `participant.isSpeaking`
* state and performs the actual swap.
*
* Speakers already visible cost nothing, nor do speakers the layout doesn't
* show at all (e.g. the pinned participant, rendered by the focus view).
* Speakers already visible are ignored. Everything else costs zero React work.
*
* With `raisedHands`, it also trips when a hand goes up or down while a
* raised hand is hidden: the hand that just went up, or the next one waiting
* for the slot of a hand that went down. Only for hosts whose ordering
* promotes raised hands; others would render for nothing.
*
* Requires the parent to NOT re-render on these events itself, i.e.
* Requires the parent to NOT re-render on speaker events itself, i.e.
* `useTracks(..., { updateOnlyOn: [] })` upstream.
*/
export function useSpeakerPromotionTrigger(
/** Tiles inside the span the layout guarantees to speakers. */
visibleTiles: TrackReferenceOrPlaceholder[],
/** Every tile the layout shows, visible or not. */
allTiles: TrackReferenceOrPlaceholder[],
{ raisedHands = false }: { raisedHands?: boolean } = {}
sortedTiles: TrackReferenceOrPlaceholder[]
) {
const room = useRoomContext()
const [, forceRender] = useReducer((n: number) => n + 1, 0)
// Read by the listeners at event time, so they never re-subscribe.
const tilesRef = useRef({ visibleTiles, allTiles })
tilesRef.current = { visibleTiles, allTiles }
// Refs so the listener reads current values without re-subscribing
// and without itself being a render dependency.
const tilesRef = useRef(sortedTiles)
tilesRef.current = sortedTiles
useEffect(() => {
const renderIfHidden = (participants: Participant[]) => {
const { visibleTiles, allTiles } = tilesRef.current
const visible = new Set(visibleTiles.map((t) => t.participant.identity))
const shown = new Set(allTiles.map((t) => t.participant.identity))
const hidden = participants.some(
({ identity }) => shown.has(identity) && !visible.has(identity)
const onActiveSpeakersChanged = (speakers: Participant[]) => {
const tiles = tilesRef.current
const hiddenSpeakerExists = speakers.some(
(speaker) =>
!tiles.some((t) => t.participant.identity === speaker.identity)
)
if (hidden) {
if (hiddenSpeakerExists) {
forceRender()
}
}
const onAttributesChanged = (changed: Record<string, string>) => {
if ('handRaisedAt' in changed) {
renderIfHidden(
tilesRef.current.allTiles
.map((t) => t.participant)
.filter((p) => !!p.attributes.handRaisedAt)
)
}
}
room.on(RoomEvent.ActiveSpeakersChanged, renderIfHidden)
if (raisedHands) {
room.on(RoomEvent.ParticipantAttributesChanged, onAttributesChanged)
}
room.on(RoomEvent.ActiveSpeakersChanged, onActiveSpeakersChanged)
return () => {
room.off(RoomEvent.ActiveSpeakersChanged, renderIfHidden)
room.off(RoomEvent.ParticipantAttributesChanged, onAttributesChanged)
room.off(RoomEvent.ActiveSpeakersChanged, onActiveSpeakersChanged)
}
}, [room, raisedHands])
}, [room])
}
@@ -1,201 +0,0 @@
import type { TrackReferenceOrPlaceholder } from '@livekit/components-core'
import { Track } from 'livekit-client'
import { describe, expect, it } from 'vitest'
import { orderCarouselTiles } from './orderCarouselTiles'
type Tile = TrackReferenceOrPlaceholder
// Placeholder tiles are enough: the real LiveKit sort and update run on them.
const tile = (
identity: string,
joinedAt: number,
{
source = Track.Source.Camera,
isLocal = false,
isSpeaking = false,
hasSpoken = isSpeaking,
handRaisedAt,
}: {
source?: Track.Source
isLocal?: boolean
isSpeaking?: boolean
hasSpoken?: boolean
handRaisedAt?: string
} = {}
) =>
({
participant: {
identity,
isLocal,
isSpeaking,
audioLevel: isSpeaking ? 1 : 0,
lastSpokeAt: hasSpoken ? new Date(joinedAt) : undefined,
joinedAt: new Date(joinedAt),
isCameraEnabled: false,
attributes: handRaisedAt ? { handRaisedAt } : {},
},
source,
}) as unknown as Tile
const names = (tiles: Tile[]) =>
tiles.map((t) =>
t.source === Track.Source.ScreenShare
? `${t.participant.identity}:screen`
: t.participant.identity
)
const me = tile('me', 0, { isLocal: true })
const [a, b, c, d, e] = ['a', 'b', 'c', 'd', 'e'].map((id, i) =>
tile(id, i + 1)
)
const speaking = (t: Tile) =>
tile(t.participant.identity, t.participant.joinedAt!.getTime(), {
isSpeaking: true,
})
const quietAgain = (t: Tile) =>
tile(t.participant.identity, t.participant.joinedAt!.getTime(), {
hasSpoken: true,
})
const handUp = (t: Tile, minute = 0) =>
tile(t.participant.identity, t.participant.joinedAt!.getTime(), {
isLocal: t.participant.isLocal,
handRaisedAt: new Date(Date.UTC(2026, 0, 1, 10, minute)).toISOString(),
})
const screenOf = (t: Tile) =>
tile(t.participant.identity, t.participant.joinedAt!.getTime(), {
source: Track.Source.ScreenShare,
})
describe('orderCarouselTiles', () => {
it('follows the LiveKit sort on the first render', () => {
expect(names(orderCarouselTiles([], [d, c, b, a, me], 3))).toEqual([
'me',
'a',
'b',
'c',
'd',
])
})
it('puts a new speaker right below the local camera', () => {
const previous = orderCarouselTiles([], [me, a, b, c, d, e], 4)
const next = orderCarouselTiles(previous, [me, a, b, c, d, speaking(e)], 4)
// LiveKit alone would give me, a, b, e: `e` takes the slot of `c`.
expect(names(next).slice(0, 4)).toEqual(['me', 'e', 'a', 'b'])
})
it('keeps the order of the tiles that stay visible', () => {
let tiles = orderCarouselTiles([], [me, a, b, c, d, e], 4)
tiles = orderCarouselTiles(tiles, [me, a, b, c, speaking(d), e], 4)
expect(names(tiles).slice(0, 4)).toEqual(['me', 'd', 'a', 'b'])
// `d` went quiet, `e` speaks: `d` stays ahead of `a`, `b` is evicted.
tiles = orderCarouselTiles(
tiles,
[me, a, b, c, quietAgain(d), speaking(e)],
4
)
expect(names(tiles).slice(0, 4)).toEqual(['me', 'e', 'd', 'a'])
})
it('does not move a visible participant who speaks', () => {
const previous = orderCarouselTiles([], [me, a, b, c, d], 4)
const next = orderCarouselTiles(previous, [me, a, b, speaking(c), d], 4)
expect(names(next)).toEqual(['me', 'a', 'b', 'c', 'd'])
})
it('keeps screen shares above a new speaker', () => {
const previous = orderCarouselTiles([], [me, screenOf(a), a, b, c, d], 4)
expect(names(previous).slice(0, 4)).toEqual(['me', 'a:screen', 'a', 'b'])
const next = orderCarouselTiles(
previous,
[me, screenOf(a), a, b, c, speaking(d)],
4
)
expect(names(next).slice(0, 4)).toEqual(['me', 'a:screen', 'd', 'a'])
})
it('puts a screen share that starts below the local camera', () => {
const previous = orderCarouselTiles([], [me, a, b, c, d], 4)
const next = orderCarouselTiles(previous, [me, a, b, c, d, screenOf(d)], 4)
expect(names(next).slice(0, 4)).toEqual(['me', 'd:screen', 'a', 'b'])
})
it('fills the slot of a participant who left without reordering', () => {
const previous = orderCarouselTiles([], [me, a, b, c, d], 4)
const next = orderCarouselTiles(previous, [me, b, c, d], 4)
expect(names(next)).toEqual(['me', 'd', 'b', 'c'])
})
it('brings a raised hand to the top like a speaker', () => {
const previous = orderCarouselTiles([], [me, a, b, c, d, e], 4)
const next = orderCarouselTiles(previous, [me, a, b, c, d, handUp(e)], 4)
expect(names(next).slice(0, 4)).toEqual(['me', 'e', 'a', 'b'])
})
it('keeps a raised hand visible when others speak', () => {
let tiles = orderCarouselTiles([], [me, a, b, c, d, e], 3)
tiles = orderCarouselTiles(tiles, [me, a, b, c, d, handUp(e)], 3)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'e', 'a'])
// `d` speaks: it evicts `a`, not the raised hand.
tiles = orderCarouselTiles(tiles, [me, a, b, c, speaking(d), handUp(e)], 3)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'd', 'e'])
})
it('lets the current speaker in when hands fill the carousel', () => {
let tiles = orderCarouselTiles([], [me, handUp(a, 1), handUp(b, 2), c], 3)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'a', 'b'])
// The last hand raised gives way to the speaker.
tiles = orderCarouselTiles(
tiles,
[me, handUp(a, 1), handUp(b, 2), speaking(c)],
3
)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'c', 'a'])
})
it('gives the slot of a lowered hand to the next one waiting', () => {
let tiles = orderCarouselTiles(
[],
[me, handUp(a, 1), handUp(b, 2), handUp(c, 3)],
3
)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'a', 'b'])
// `a` lowers their hand: `c` was waiting and takes over.
tiles = orderCarouselTiles(tiles, [me, a, handUp(b, 2), handUp(c, 3)], 3)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'c', 'b'])
})
it('shows the first hands raised when there are too many', () => {
const tiles = orderCarouselTiles(
[],
[me, a, handUp(b, 3), handUp(c, 1), handUp(d, 2)],
3
)
expect(names(tiles).slice(0, 3)).toEqual(['me', 'c', 'd'])
})
it('keeps the local camera first when the local hand is raised', () => {
const tiles = orderCarouselTiles([], [a, screenOf(a), b, handUp(me)], 3)
expect(names(tiles)).toEqual(['me', 'a:screen', 'a', 'b'])
})
it('is stable when run twice on the same input', () => {
const tracks = [me, a, b, c, d, speaking(e)]
const previous = orderCarouselTiles([], [me, a, b, c, d, e], 4)
const once = orderCarouselTiles(previous, tracks, 4)
expect(names(orderCarouselTiles(once, tracks, 4))).toEqual(names(once))
})
})
@@ -1,88 +0,0 @@
import {
log,
sortTrackReferences,
updatePages,
type TrackReferenceOrPlaceholder,
} from '@livekit/components-core'
import { Track } from 'livekit-client'
// LiveKit's track reference id changes when a placeholder gets its track;
// this key doesn't, so turning a camera on is not seen as a new tile.
const keyOf = (tile: TrackReferenceOrPlaceholder) =>
`${tile.participant.identity}_${tile.source}`
/** When the participant raised their hand, if it is still raised. */
const handRaisedAt = (tile: TrackReferenceOrPlaceholder) => {
if (tile.source !== Track.Source.Camera) return undefined
const time = Date.parse(tile.participant.attributes.handRaisedAt ?? '')
return Number.isNaN(time) ? undefined : time
}
/**
* LiveKit's sort knows nothing about raised hands. This moves them right
* after the tiles that must stay ahead (local camera, screen shares, whoever
* is speaking now), first raised first, so they are among the first tiles
* picked as visible for as long as the hand is up.
*/
const sortWithRaisedHands = (tracks: TrackReferenceOrPlaceholder[]) => {
const rank = (tile: TrackReferenceOrPlaceholder) => {
const { isLocal, isSpeaking } = tile.participant
if (isLocal || isSpeaking || tile.source === Track.Source.ScreenShare) {
return 0
}
return handRaisedAt(tile) === undefined ? 2 : 1
}
return sortTrackReferences(tracks).sort((a, b) => {
if (rank(a) !== rank(b)) return rank(a) - rank(b)
// Equal ranks keep LiveKit's order, except raised hands: first come first.
return rank(a) === 1 ? handRaisedAt(a)! - handRaisedAt(b)! : 0
})
}
/**
* Orders the carousel tiles; the first `maxVisibleTiles` are the visible ones.
*
* This is what LiveKit's `useVisualStableUpdate` does, plus one step:
* 1. `sortTrackReferences` decides which tiles deserve to be visible, with
* raised hands added to it, see `sortWithRaisedHands`;
* 2. `updatePages` applies that to the `previous` order with as few moves as
* possible: an incoming tile is swapped with the outgoing one;
* 3. added here: within the visible tiles, the local camera goes first, then
* the screen shares, then the speakers and raised hands that step 2 just
* brought in. The other tiles keep the order step 2 gave them.
*
* Step 2 alone leaves an incoming tile wherever the evicted one happened to
* be, often at the bottom of the column.
*/
export function orderCarouselTiles(
previous: TrackReferenceOrPlaceholder[],
tracks: TrackReferenceOrPlaceholder[],
maxVisibleTiles: number
): TrackReferenceOrPlaceholder[] {
const sorted = sortWithRaisedHands(tracks)
let stable = sorted
try {
stable = updatePages(previous, sorted, maxVisibleTiles)
} catch (error) {
log.error('Error while running updatePages(): ', error)
}
const previouslyVisible = new Set(
previous.slice(0, maxVisibleTiles).map(keyOf)
)
const rank = (tile: TrackReferenceOrPlaceholder) => {
if (tile.source === Track.Source.ScreenShare) return 1
if (tile.participant.isLocal) return 0
const justCameIn = !previouslyVisible.has(keyOf(tile))
const wantsAttention =
tile.participant.isSpeaking || handRaisedAt(tile) !== undefined
return justCameIn && wantsAttention ? 2 : 3
}
return [
// Array.prototype.sort is stable: tiles of equal rank keep their order.
...stable.slice(0, maxVisibleTiles).sort((a, b) => rank(a) - rank(b)),
...stable.slice(maxVisibleTiles),
]
}
@@ -1,25 +0,0 @@
import { useEffect } from 'react'
import { notificationsStore } from '@/stores/notifications'
import { runWhenIdle } from '@/utils/runWhenIdle'
import { loadNotificationSound } from '../notificationSound'
/**
* Fetch and decode the notification sound while the browser is idle, so it
* doesn't compete with the room connection and is ready for the first
* notification. Meant for screens shown before the meeting, e.g. pre-join.
*/
export const usePreloadNotificationSound = () => {
useEffect(() => {
const isAnySoundEnabled = Array.from(
notificationsStore.soundNotifications.values()
).some(Boolean)
const saveData = (navigator as { connection?: { saveData?: boolean } })
.connection?.saveData
if (!isAnySoundEnabled || saveData) return
return runWhenIdle(() => {
// Best effort: the room loads the sound itself if this fails.
loadNotificationSound().catch(() => {})
})
}, [])
}
@@ -1,25 +1,24 @@
import { useEffect } from 'react'
import useSound from 'use-sound'
import { useSnapshot } from 'valtio'
import { notificationsStore } from '@/stores/notifications'
import type { NotificationType } from '@/features/notifications/NotificationType'
import {
loadNotificationSound,
playNotificationSound,
} from '@/features/notifications/notificationSound'
// fixme - handle dynamic audio output changes
export const useNotificationSound = () => {
const notificationsSnap = useSnapshot(notificationsStore)
useEffect(() => {
loadNotificationSound().catch(() => {})
}, [])
const [play] = useSound('/sounds/notifications.mp3', {
sprite: {
participantJoined: [0, 1150],
handRaised: [1400, 180],
messageReceived: [1580, 300],
participantWaiting: [2039, 710],
success: [2740, 1304],
},
volume: notificationsSnap.soundNotificationVolume,
})
const triggerNotificationSound = (type: NotificationType) => {
const isSoundEnabled = notificationsSnap.soundNotifications.get(type)
if (isSoundEnabled) {
playNotificationSound(type, notificationsSnap.soundNotificationVolume)
}
if (isSoundEnabled) play({ id: type })
}
return { triggerNotificationSound }
}
@@ -1,66 +0,0 @@
import type { Howl } from 'howler'
import type { NotificationType } from './NotificationType'
import notificationSoundSrc from '@/assets/sounds/notifications.mp3'
const NOTIFICATION_SOUND_SPRITE: Record<string, [number, number]> = {
participantJoined: [0, 1150],
handRaised: [1400, 180],
messageReceived: [1580, 300],
participantWaiting: [2039, 710],
success: [2740, 1304],
}
let howl: Howl | undefined
let howlPromise: Promise<Howl> | undefined
/**
* Lazily load howler and the notification sound sprite.
*
* The Howl instance is shared by every consumer: whoever calls first triggers
* the (single) download and decoding of the file, later calls reuse it. It can
* thus be called ahead of time, e.g. from the pre-join screen, so the sound is
* ready before the first notification of the meeting.
*/
export const loadNotificationSound = (): Promise<Howl> => {
if (!howlPromise) {
howlPromise = import('howler')
.then(
({ Howl }) =>
new Promise<Howl>((resolve, reject) => {
const instance = new Howl({
src: [notificationSoundSrc],
// The extension is kept by the build, but don't rely on it.
format: ['mp3'],
sprite: NOTIFICATION_SOUND_SPRITE,
onload: () => {
howl = instance
resolve(instance)
},
onloaderror: (_id, error) => {
instance.unload()
reject(new Error(`Notification sound failed to load: ${error}`))
},
})
})
)
.catch((error) => {
// Let a later call retry.
howlPromise = undefined
throw error
})
}
return howlPromise
}
/**
* Play a notification sound, if the sprite is already loaded. A sound which
* isn't ready is skipped rather than played late.
*/
export const playNotificationSound = (
type: NotificationType,
volume: number
) => {
if (!howl) return
howl.volume(volume)
howl.play(type)
}
@@ -1,18 +1,14 @@
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useSidePanel } from '@/features/rooms/livekit/hooks/useSidePanel'
import { useEffectsPreload } from '@/features/rooms/livekit/hooks/useEffectsPreload'
import { Button } from '@/primitives'
import { RiImageCircleAiFill } from '@remixicon/react'
export const EffectsButton = React.memo(() => {
const { t } = useTranslation('rooms', { keyPrefix: 'participantTileFocus' })
const { isEffectsOpen, toggleEffects } = useSidePanel()
const { hoverProps, focusProps } = useEffectsPreload()
return (
<Button
{...hoverProps}
{...focusProps}
size={'sm'}
variant={'primaryTextDark'}
square
@@ -1,4 +1,4 @@
import { Button, Div, Text } from '@/primitives'
import { Button, Div, H, Text } from '@/primitives'
import { css } from '@/styled-system/css'
import { useRoomId } from '@/features/rooms/livekit/hooks/useRoomId'
@@ -189,9 +189,9 @@ export const ScreenRecordingSidePanel = () => {
})}
/>
<VStack gap={0} marginBottom={15}>
<Text as="h2" variant="h1" margin="sm" fullWidth>
<H lvl={1} margin={'sm'} fullWidth>
{t('heading')}
</Text>
</H>
<LimitDescription
keyPrefix={'screenRecording'}
supportArticleLink={data?.support?.help_article_recording}
@@ -1,4 +1,4 @@
import { A, Button, Div, Text } from '@/primitives'
import { A, Button, Div, H, Text } from '@/primitives'
import { css } from '@/styled-system/css'
import { useRoomId } from '@/features/rooms/livekit/hooks/useRoomId'
@@ -203,9 +203,9 @@ export const TranscriptSidePanel = () => {
})}
/>
<VStack gap={0} marginBottom={15}>
<Text as="h2" variant="h1" margin="sm" fullWidth>
<H lvl={1} margin={'sm'}>
{t('heading')}
</Text>
</H>
<LimitDescription
keyPrefix={'transcript'}
supportArticleLink={data?.support?.help_article_transcript}
@@ -240,9 +240,6 @@ export const TranscriptSidePanel = () => {
<Button
variant="text"
size="xs"
aria-label={t('details.languageAriaLabel', {
language: selectedLanguageLabel,
})}
onPress={() =>
openSettingsDialog(SettingsDialogExtendedKey.TRANSCRIPTION)
}
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import type { RecordingMode } from '../types'
import { useIsRecordingModeEnabled } from './useIsRecordingModeEnabled'
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import type { RecordingMode } from '../types'
import { useIsRecordingModeEnabled } from './useIsRecordingModeEnabled'
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { FeatureFlags } from '@/features/analytics/enums'
@@ -15,7 +15,6 @@ import {
import { SelectDevice } from '../livekit/components/controls/Device/SelectDevice'
import { ToggleDevice } from '../livekit/components/controls/Device/ToggleDevice'
import { BackgroundProcessorFactory } from '../livekit/components/blur'
import { useEffectsPreload } from '../livekit/hooks/useEffectsPreload'
import { Lobby } from './Lobby'
import { openPermissionsDialog } from '@/stores/permissions'
import { isSafari } from '@/utils/livekit'
@@ -34,7 +33,6 @@ import { useDeviceMissing } from '../livekit/hooks/useDeviceMissing'
import { useJoinTracks } from '../livekit/hooks/useJoinTracks'
import { SilentMicDetector } from './SilentMicDetector'
import { type PreviewTrack, toggleTrack } from '../utils/toggleTrack'
import { usePreloadNotificationSound } from '@/features/notifications/hooks/usePreloadNotificationSound'
const styles = {
page: css({
@@ -274,7 +272,6 @@ const Effects = ({
}: Pick<EffectsConfigurationProps, 'videoTrack'>) => {
const { t } = useTranslation('rooms', { keyPrefix: 'join.effects' })
const [isDialogOpen, setIsDialogOpen] = useState(false)
const { hoverProps, focusProps } = useEffectsPreload()
if (!BackgroundProcessorFactory.isSupported() || isMobileBrowser()) {
return null
@@ -302,8 +299,6 @@ const Effects = ({
onPress={() => setIsDialogOpen(true)}
tooltip={t('description')}
aria-label={t('description')}
{...hoverProps}
{...focusProps}
>
<RiImageCircleAiFill size={24} />
</Button>
@@ -463,7 +458,6 @@ export const Join = ({
roomId: string
}) => {
const { audioTrack, videoTrack } = useJoinTracks()
usePreloadNotificationSound()
return (
<Screen footer={false}>
@@ -1,147 +0,0 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const MODEL = '/assets/mediapipe/models/selfie_segmenter_landscape.tflite'
const WASM_LOADER = '/wasm/vision_wasm_internal.js'
const WASM_BINARY = '/wasm/vision_wasm_internal.wasm'
const isSupported = vi.fn(() => true)
vi.mock('.', () => ({
BackgroundProcessorFactory: { isSupported: () => isSupported() },
MEDIAPIPE_PATH_WASM: '/wasm',
SELFIE_SEGMENTER_MODEL_PATH: MODEL,
}))
vi.mock('@mediapipe/tasks-vision', () => ({
FilesetResolver: {
forVisionTasks: async () => ({
wasmLoaderPath: WASM_LOADER,
wasmBinaryPath: WASM_BINARY,
}),
},
}))
vi.mock('@/features/files/utils/resolveMediaUrl', () => ({
resolveMediaUrlOrFallback: async (url: string) => `resolved:${url}`,
}))
class FakeImage {
static instances: FakeImage[] = []
src = ''
crossOrigin: string | null = null
onerror: (() => void) | null = null
constructor() {
FakeImage.instances.push(this)
}
}
const fetchMock = vi.fn()
const fetchedUrls = () => fetchMock.mock.calls.map(([url]) => url)
const imageUrls = () => FakeImage.instances.map((image) => image.src)
// Let the fire-and-forget preloads settle.
const flush = () => new Promise((resolve) => setTimeout(resolve))
const load = () => import('./preload')
beforeEach(() => {
vi.resetModules()
isSupported.mockReturnValue(true)
FakeImage.instances = []
fetchMock.mockReset()
fetchMock.mockImplementation(async () => ({ ok: true, body: null }))
vi.stubGlobal('fetch', fetchMock)
vi.stubGlobal('Image', FakeImage)
vi.stubGlobal('navigator', {})
})
describe('preloadEffectsAssets', () => {
it('preloads the thumbnails, the model and the wasm', async () => {
const { preloadEffectsAssets } = await load()
preloadEffectsAssets()
await flush()
expect(imageUrls()).toHaveLength(8)
expect(imageUrls()[0]).toBe('/assets/backgrounds/thumbnails/1.webp')
expect(fetchedUrls().sort()).toEqual([MODEL, WASM_LOADER, WASM_BINARY])
expect(fetchMock).toHaveBeenCalledWith(WASM_BINARY, { priority: 'low' })
})
it('preloads only once', async () => {
const { preloadEffectsAssets } = await load()
preloadEffectsAssets()
await flush()
preloadEffectsAssets()
await flush()
expect(imageUrls()).toHaveLength(8)
expect(fetchMock).toHaveBeenCalledTimes(3)
})
it('skips the wasm when the caller reports a degraded connection', async () => {
const { preloadEffectsAssets } = await load()
preloadEffectsAssets({ isConstrained: true })
await flush()
expect(imageUrls()).toHaveLength(8)
expect(fetchedUrls()).toEqual([MODEL])
})
it.each([{ saveData: true }, { effectiveType: '3g' }])(
'skips the wasm when the browser reports %o',
async (connection) => {
vi.stubGlobal('navigator', { connection })
const { preloadEffectsAssets } = await load()
preloadEffectsAssets()
await flush()
expect(fetchedUrls()).toEqual([MODEL])
}
)
it('retries after a failure', async () => {
vi.spyOn(console, 'warn').mockImplementation(() => {})
fetchMock.mockImplementation(async () => ({ ok: false, status: 503 }))
const { preloadEffectsAssets } = await load()
preloadEffectsAssets({ isConstrained: true })
await flush()
preloadEffectsAssets({ isConstrained: true })
await flush()
expect(fetchedUrls()).toEqual([MODEL, MODEL])
})
it('does nothing when background processors are not supported', async () => {
isSupported.mockReturnValue(false)
const { preloadEffectsAssets } = await load()
preloadEffectsAssets()
await flush()
expect(imageUrls()).toHaveLength(0)
expect(fetchMock).not.toHaveBeenCalled()
})
})
describe('preloadBackgroundImage', () => {
it('loads the resolved image once, in CORS mode', async () => {
const { preloadBackgroundImage } = await load()
await preloadBackgroundImage('/assets/backgrounds/1.webp')
await preloadBackgroundImage('/assets/backgrounds/1.webp')
expect(FakeImage.instances).toHaveLength(1)
expect(FakeImage.instances[0].src).toBe(
'resolved:/assets/backgrounds/1.webp'
)
expect(FakeImage.instances[0].crossOrigin).toBe('anonymous')
})
it('skips local files and degraded connections', async () => {
const { preloadBackgroundImage } = await load()
await preloadBackgroundImage('blob:https://meet.example.com/1234')
await preloadBackgroundImage('/assets/backgrounds/1.webp', {
isConstrained: true,
})
expect(FakeImage.instances).toHaveLength(0)
})
})
@@ -1,148 +0,0 @@
import { FilesetResolver } from '@mediapipe/tasks-vision'
import { resolveMediaUrlOrFallback } from '@/features/files/utils/resolveMediaUrl'
import {
BackgroundProcessorFactory,
MEDIAPIPE_PATH_WASM,
SELFIE_SEGMENTER_MODEL_PATH,
} from '.'
/**
* Warm the browser caches with what a background effect needs, ahead of
* the click that applies it. Nothing is instantiated here: the processors
* issue the very same requests later and find them in the HTTP cache.
*
* A meeting may be running, so what is preloaded is arbitrated by cost:
*
* | Asset | Size | Preloaded |
* | ----------------------- | --------- | --------------------------------- |
* | Preset thumbnails | ~80KB | always |
* | Segmentation model | ~250KB | always |
* | MediaPipe wasm + loader | ~9.6MB | low priority, unless constrained |
* | One background image | ~300KB | on thumbnail hover, unless const. |
* | All background images | ~2.4MB | never |
*/
export const PRESET_BACKGROUNDS_COUNT = 8
export const getPresetBackgroundPaths = (index: number) => ({
imagePath: `/assets/backgrounds/${index + 1}.webp`,
thumbnailPath: `/assets/backgrounds/thumbnails/${index + 1}.webp`,
})
type NetworkInformation = {
saveData?: boolean
effectiveType?: string
}
/**
* Data saver or a slow link, as reported by the browser (Chromium only,
* other browsers are considered unconstrained).
*/
const isNetworkConstrained = () => {
const connection = (navigator as { connection?: NetworkInformation })
.connection
if (!connection) return false
return (
connection.saveData === true ||
['slow-2g', '2g', '3g'].includes(connection.effectiveType ?? '')
)
}
/**
* Download a same-origin asset into the HTTP cache. The body is read to
* completion, as an aborted response is not stored, and discarded chunk
* by chunk to avoid buffering several megabytes.
*/
const warmHttpCache = async (url: string, priority: RequestPriority) => {
const response = await fetch(url, { priority })
if (!response.ok) {
throw new Error(`Failed to preload ${url}: HTTP ${response.status}`)
}
const reader = response.body?.getReader()
if (!reader) return
while (!(await reader.read()).done) {
// discard
}
}
// Held so that in-flight and decoded images are not garbage collected,
// and can be reused from the memory cache. Bounded by the presets and
// the user's custom backgrounds.
const preloadedImages = new Map<string, HTMLImageElement>()
const preloadImage = (src: string, key = src, crossOrigin?: 'anonymous') => {
if (preloadedImages.has(key)) return
const image = new Image()
if (crossOrigin) image.crossOrigin = crossOrigin
image.onerror = () => preloadedImages.delete(key)
image.src = src
preloadedImages.set(key, image)
}
// Run each step once, and allow another attempt after a failure.
const once = (run: () => Promise<unknown>) => {
let pending: Promise<void> | undefined
return () => {
pending ??= run().then(
() => undefined,
(error) => {
console.warn(error)
pending = undefined
}
)
return pending
}
}
const preloadModel = once(() =>
warmHttpCache(SELFIE_SEGMENTER_MODEL_PATH, 'auto')
)
const preloadWasm = once(async () => {
// Resolves to the SIMD or non-SIMD build, as the processors will.
const { wasmLoaderPath, wasmBinaryPath } =
await FilesetResolver.forVisionTasks(MEDIAPIPE_PATH_WASM)
await Promise.all([
warmHttpCache(wasmLoaderPath, 'low'),
warmHttpCache(wasmBinaryPath, 'low'),
])
})
/**
* Preload what any background effect needs. Meant to be called when the
* user shows an intent to open the effects (hover or focus of an entry
* point).
*
* @param isConstrained caller's knowledge of a degraded connection (e.g.
* LiveKit connection quality): only the light assets are then preloaded.
*/
export const preloadEffectsAssets = ({ isConstrained = false } = {}) => {
if (!BackgroundProcessorFactory.isSupported()) return
for (let index = 0; index < PRESET_BACKGROUNDS_COUNT; index++) {
preloadImage(getPresetBackgroundPaths(index).thumbnailPath)
}
void preloadModel()
if (isConstrained || isNetworkConstrained()) return
void preloadWasm()
}
/**
* Preload a single full-size background. Meant to be called when the
* user dwells on its thumbnail.
*/
export const preloadBackgroundImage = async (
imagePath: string,
{ isConstrained = false } = {}
) => {
// Local files (not logged-in users) are already in memory.
if (imagePath.startsWith('blob:')) return
if (isConstrained || isNetworkConstrained()) return
if (preloadedImages.has(imagePath)) return
// Same resolution and CORS mode as the processors' own image load, so
// that the cached response can be reused.
const src = await resolveMediaUrlOrFallback(imagePath)
preloadImage(src, imagePath, 'anonymous')
}
@@ -5,7 +5,6 @@ import { styled } from '@/styled-system/jsx'
import { Button } from '@/primitives'
import { canTestAudioOutput } from '@/features/rooms/utils/canTestAudioOutput'
import { resolveAudioOutputDeviceId } from '@/features/rooms/utils/resolveAudioOutputDeviceId'
import upriseSoundSrc from '@/assets/sounds/uprise.mp3'
// Speaker test in the audiooutput menu footer (Meet-style UX). Outputs have
// no track: the test plays a bundled file through the selected sink, and
@@ -130,7 +129,7 @@ export const OutputSoundTester = ({
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
<audio
ref={audioRef}
src={upriseSoundSrc}
src="/sounds/uprise.mp3"
onEnded={() => setIsPlaying(false)}
/>
</StyledContainer>
@@ -9,7 +9,6 @@ import { css } from '@/styled-system/css'
import { useCanPublishTrack } from '../../../hooks/useCanPublishTrack'
import { useCannotUseDevice } from '../../../hooks/useCannotUseDevice'
import { useSidePanel } from '../../../hooks/useSidePanel'
import { useEffectsPreload } from '../../../hooks/useEffectsPreload'
import { BackgroundProcessorFactory } from '../../blur'
import Source = Track.Source
import * as React from 'react'
@@ -28,13 +27,10 @@ import {
const EffectsButton = ({ onPress }: { onPress: () => void }) => {
const { t } = useTranslation('rooms', { keyPrefix: 'selectDevice' })
const { isEffectsOpen, toggleEffects } = useSidePanel()
const { hoverProps, focusProps } = useEffectsPreload()
return (
<Button
size="sm"
square
{...hoverProps}
{...focusProps}
tooltip={t('effects')}
aria-label={t('effects')}
variant="primaryDark"
@@ -3,17 +3,14 @@ import { MenuItem } from 'react-aria-components'
import { useTranslation } from 'react-i18next'
import { menuRecipe } from '@/primitives/menuRecipe'
import { useSidePanel } from '../../../hooks/useSidePanel'
import { useEffectsPreload } from '../../../hooks/useEffectsPreload'
export const EffectsMenuItem = () => {
const { t } = useTranslation('rooms', { keyPrefix: 'options.items' })
const { toggleEffects } = useSidePanel()
const { hoverProps } = useEffectsPreload()
return (
<MenuItem
onAction={() => toggleEffects()}
{...hoverProps}
className={menuRecipe({ icon: true, variant: 'dark' }).item}
>
<RiImageCircleAiFill size={20} />
@@ -7,11 +7,6 @@ import {
ProcessorConfig,
ProcessorType,
} from '../blur'
import {
getPresetBackgroundPaths,
PRESET_BACKGROUNDS_COUNT,
} from '../blur/preload'
import { useEffectsPreload } from '../../hooks/useEffectsPreload'
import { css } from '@/styled-system/css'
import { useResolvedMediaUrls } from '@/features/files/hooks/useResolvedMediaUrls'
import { Button, Dialog, H, P, Text, ToggleButton } from '@/primitives'
@@ -121,8 +116,6 @@ export const EffectsConfiguration = ({
> | null>(null)
const effectAnnouncementId = useRef(0)
const { preloadBackground, cancel: cancelPreload } = useEffectsPreload()
const { processorConfig } = useSnapshot(userChoicesStore)
const selectedId = useMemo(
@@ -153,7 +146,7 @@ export const EffectsConfiguration = ({
const getVirtualBackgroundName = useCallback(
(imagePath?: string) => {
if (!imagePath) return ''
const match = imagePath.match(/\/backgrounds\/(\d+)\.webp$/)
const match = imagePath.match(/\/backgrounds\/(\d+)\.jpg$/)
if (!match) return ''
const index = Number(match[1]) - 1
if (Number.isNaN(index)) return ''
@@ -412,7 +405,6 @@ export const EffectsConfiguration = ({
tooltip: string
ariaLabel: string
thumbnailPath: string
imagePath: string
index: number
}[]
remoteCustomVirtualBackgrounds: {
@@ -458,33 +450,31 @@ export const EffectsConfiguration = ({
config,
}
}),
virtualBackgrounds: [...Array(PRESET_BACKGROUNDS_COUNT).keys()].map(
(index) => {
const { imagePath, thumbnailPath } = getPresetBackgroundPaths(index)
const config: ProcessorConfig = {
type: ProcessorType.VIRTUAL,
imagePath,
}
const id = deriveIdFromProcessorConfig(config)
const isSelected = selectedId === id
const backgroundName = t(`virtual.presets.descriptions.${index}`)
const ariaLabelPrefix = t(
isSelected ? `virtual.selectedLabel` : `virtual.apply`
)
const ariaLabel = `${ariaLabelPrefix} ${backgroundName}`
return {
tooltip: backgroundName,
id,
config,
isSelected: selectedId === id,
thumbnailPath,
imagePath,
ariaLabel,
index,
}
virtualBackgrounds: [...Array(8).keys()].map((index) => {
const imagePath = `/assets/backgrounds/${index + 1}.jpg`
const thumbnailPath = `/assets/backgrounds/thumbnails/${index + 1}.jpg`
const config: ProcessorConfig = {
type: ProcessorType.VIRTUAL,
imagePath,
}
),
const id = deriveIdFromProcessorConfig(config)
const isSelected = selectedId === id
const backgroundName = t(`virtual.presets.descriptions.${index}`)
const ariaLabelPrefix = t(
isSelected ? `virtual.selectedLabel` : `virtual.apply`
)
const ariaLabel = `${ariaLabelPrefix} ${backgroundName}`
return {
tooltip: backgroundName,
id,
config,
isSelected: selectedId === id,
thumbnailPath,
ariaLabel,
index,
}
}),
remoteCustomVirtualBackgrounds: (filesQ.data?.results ?? [])
.filter((file) => file.url)
.map((file) => {
@@ -771,10 +761,6 @@ export const EffectsConfiguration = ({
onChange={getHandleSelectChangeFile(
option.file
)}
onHoverStart={() =>
preloadBackground(option.file.url!)
}
onHoverEnd={cancelPreload}
isSelected={option.isSelected}
className={css({
bgSize: 'cover',
@@ -935,10 +921,6 @@ export const EffectsConfiguration = ({
aria-label={option.ariaLabel}
isDisabled={processorOptions.isDisabled}
onChange={() => toggleEffect(option.config)}
onHoverStart={() =>
preloadBackground(option.imagePath)
}
onHoverEnd={cancelPreload}
isSelected={option.isSelected}
className={css({
bgSize: 'cover',
@@ -1,63 +0,0 @@
import { useCallback, useEffect, useMemo, useRef } from 'react'
import { useMaybeRoomContext } from '@livekit/components-react'
import { ConnectionQuality } from 'livekit-client'
import {
preloadBackgroundImage,
preloadEffectsAssets,
} from '../components/blur/preload'
// Time the pointer must stay on an element before preloading, so that
// sweeping over a menu or a row of thumbnails does not trigger anything.
const HOVER_INTENT_DELAY_MS = 150
/**
* Preload the background effects assets when the user shows an intent to
* use them, to save the download time once they actually click.
*
* In a meeting, the heavy assets are skipped when the connection quality
* is degraded, to avoid competing with the media streams.
*/
export const useEffectsPreload = () => {
const room = useMaybeRoomContext()
const timeout = useRef<ReturnType<typeof setTimeout>>()
const cancel = useCallback(() => clearTimeout(timeout.current), [])
useEffect(() => cancel, [cancel])
const schedule = useCallback(
(preload: (options: { isConstrained: boolean }) => void) => {
cancel()
timeout.current = setTimeout(() => {
// Read when firing: no need to re-render on quality changes.
const quality = room?.localParticipant.connectionQuality
preload({
isConstrained:
quality === ConnectionQuality.Poor ||
quality === ConnectionQuality.Lost,
})
}, HOVER_INTENT_DELAY_MS)
},
[cancel, room]
)
const preloadEffects = useCallback(
() => schedule(preloadEffectsAssets),
[schedule]
)
const preloadBackground = useCallback(
(imagePath: string) =>
schedule((options) => void preloadBackgroundImage(imagePath, options)),
[schedule]
)
return useMemo(
() => ({
hoverProps: { onHoverStart: preloadEffects, onHoverEnd: cancel },
focusProps: { onFocus: preloadEffects, onBlur: cancel },
preloadBackground,
cancel,
}),
[cancel, preloadBackground, preloadEffects]
)
}
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { FeatureFlags } from '@/features/analytics/enums'
import useKonami from '@/features/rooms/livekit/hooks/useKonami'
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { FeatureFlags } from '@/features/analytics/enums'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { isMobileBrowser } from '@livekit/components-core'
@@ -1,38 +1,22 @@
import { lazy, Suspense, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { DialogTrigger } from 'react-aria-components'
import { RiSettings3Line } from '@remixicon/react'
import { Button } from '@/primitives'
const loadSettingsDialog = () => import('./SettingsDialog')
const SettingsDialog = lazy(() =>
loadSettingsDialog().then((m) => ({ default: m.SettingsDialog }))
)
import { SettingsDialog } from './SettingsDialog'
export const SettingsButton = () => {
const { t } = useTranslation('settings')
const [hasOpened, setHasOpened] = useState(false)
const [isOpen, setIsOpen] = useState(false)
return (
<>
<DialogTrigger>
<Button
square
variant="secondaryText"
aria-label={t('settingsButtonLabel')}
tooltip={t('settingsButtonLabel')}
onHoverStart={() => void loadSettingsDialog()}
onFocus={() => void loadSettingsDialog()}
onPress={() => {
setHasOpened(true)
setIsOpen(true)
}}
>
<RiSettings3Line />
</Button>
{hasOpened && (
<Suspense fallback={null}>
<SettingsDialog isOpen={isOpen} onOpenChange={setIsOpen} />
</Suspense>
)}
</>
<SettingsDialog />
</DialogTrigger>
)
}
@@ -102,93 +102,46 @@ export const SettingsDialogExtended = (props: SettingsDialogExtended) => {
</Heading>
)}
<TabList border={false}>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.ACCOUNT}
aria-label={t(`tabs.${SettingsDialogExtendedKey.ACCOUNT}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.ACCOUNT}>
<RiAccountCircleLine />
{isWideScreen && t(`tabs.${SettingsDialogExtendedKey.ACCOUNT}`)}
</Tab>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.AUDIO}
aria-label={t(`tabs.${SettingsDialogExtendedKey.AUDIO}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.AUDIO}>
<RiSpeakerLine />
{isWideScreen && t(`tabs.${SettingsDialogExtendedKey.AUDIO}`)}
</Tab>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.VIDEO}
aria-label={t(`tabs.${SettingsDialogExtendedKey.VIDEO}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.VIDEO}>
<RiVideoOnLine />
{isWideScreen && t(`tabs.${SettingsDialogExtendedKey.VIDEO}`)}
</Tab>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.GENERAL}
aria-label={t(`tabs.${SettingsDialogExtendedKey.GENERAL}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.GENERAL}>
<RiSettings3Line />
{isWideScreen && t(`tabs.${SettingsDialogExtendedKey.GENERAL}`)}
</Tab>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.NOTIFICATIONS}
aria-label={t(`tabs.${SettingsDialogExtendedKey.NOTIFICATIONS}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.NOTIFICATIONS}>
<RiNotification3Line />
{isWideScreen &&
t(`tabs.${SettingsDialogExtendedKey.NOTIFICATIONS}`)}
</Tab>
<Tab
icon
highlight
id={SettingsDialogExtendedKey.SHORTCUTS}
aria-label={t(`tabs.${SettingsDialogExtendedKey.SHORTCUTS}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.SHORTCUTS}>
<RiKeyboardBoxLine />
{isWideScreen && t(`tabs.${SettingsDialogExtendedKey.SHORTCUTS}`)}
</Tab>
{isAdminOrOwner && (
<Tab
icon
highlight
id={SettingsDialogExtendedKey.TRANSCRIPTION}
aria-label={t(
`tabs.${SettingsDialogExtendedKey.TRANSCRIPTION}`
)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.TRANSCRIPTION}>
<Icon name="speech_to_text" />
{isWideScreen &&
t(`tabs.${SettingsDialogExtendedKey.TRANSCRIPTION}`)}
</Tab>
)}
{showRecordingTab && (
<Tab
icon
highlight
id={SettingsDialogExtendedKey.RECORDING}
aria-label={t(`tabs.${SettingsDialogExtendedKey.RECORDING}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.RECORDING}>
<RiRecordCircleLine />
{isWideScreen &&
t(`tabs.${SettingsDialogExtendedKey.RECORDING}`)}
</Tab>
)}
<Tab
icon
highlight
id={SettingsDialogExtendedKey.ACCESSIBILITY}
aria-label={t(`tabs.${SettingsDialogExtendedKey.ACCESSIBILITY}`)}
>
<Tab icon highlight id={SettingsDialogExtendedKey.ACCESSIBILITY}>
<RiEyeLine />
{isWideScreen &&
t(`tabs.${SettingsDialogExtendedKey.ACCESSIBILITY}`)}
@@ -1,4 +1,5 @@
export { SettingsButton } from './components/SettingsButton'
export { SettingsDialog } from './components/SettingsDialog'
export { useTranscriptionLanguage } from './hook/useTranscriptionLanguage'
@@ -1,4 +1,4 @@
import { useFeatureFlagEnabled } from '@/features/analytics/hooks/useFeatureFlagEnabled'
import { useFeatureFlagEnabled } from 'posthog-js/react'
import { FeatureFlags } from '@/features/analytics/enums'
import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled'
import { useConfig } from '@/api/useConfig'
@@ -19,7 +19,6 @@ export const useLanguageLabels = () => {
key: lang,
value: lang,
label: languageLabels[lang],
lang,
}))
return {
languagesList,
-1
View File
@@ -492,7 +492,6 @@
"destination": "Ein neues Dokument wird erstellt auf",
"destinationUnknown": "Ein neues Dokument wird erstellt",
"language": "Meeting-Sprache:",
"languageAriaLabel": "{{language}}, Meeting-Sprache ändern",
"recording": "Auch eine Videoaufzeichnung starten"
},
"button": {
-1
View File
@@ -492,7 +492,6 @@
"destination": "A new document will be created on",
"destinationUnknown": "A new document will be created",
"language": "Meeting language:",
"languageAriaLabel": "{{language}}, change the meeting language",
"recording": "Also start a video recording"
},
"button": {
-1
View File
@@ -491,7 +491,6 @@
"destination": "Se creará un nuevo documento en",
"destinationUnknown": "Se creará un nuevo documento",
"language": "Idioma de la reunión:",
"languageAriaLabel": "{{language}}, cambiar el idioma de la reunión",
"recording": "Iniciar también una grabación de vídeo"
},
"button": {
-1
View File
@@ -492,7 +492,6 @@
"destination": "Un nouveau document sera créé sur",
"destinationUnknown": "Un nouveau document sera créé",
"language": "Langue de la réunion :",
"languageAriaLabel": "{{language}}, modifier la langue de la réunion",
"recording": "Démarrer aussi un enregistrement vidéo"
},
"button": {
-1
View File
@@ -492,7 +492,6 @@
"destination": "Er wordt een nieuw document aangemaakt op",
"destinationUnknown": "Een nieuw document wordt aangemaakt",
"language": "Vergadertalen:",
"languageAriaLabel": "{{language}}, vergadertaal wijzigen",
"recording": "Start ook een video-opname"
},
"button": {
-1
View File
@@ -492,7 +492,6 @@
"destination": "Um novo documento será criado em",
"destinationUnknown": "Um novo documento será criado",
"language": "Idioma da reunião:",
"languageAriaLabel": "{{language}}, alterar o idioma da reunião",
"recording": "Também iniciar uma gravação"
},
"button": {
+2 -6
View File
@@ -95,7 +95,7 @@ export type SelectProps<T> = Omit<
> & {
iconComponent?: RemixiconComponentType
label: ReactNode
items: Array<{ value: T; label: ReactNode; lang?: string }>
items: Array<{ value: T; label: ReactNode }>
errors?: ReactNode
placement?: Placement
variant?: 'light' | 'dark'
@@ -150,11 +150,7 @@ export const Select = <T extends string | number>({
>
{({ isSelected }) => (
<>
{item.lang ? (
<span lang={item.lang}>{item.label}</span>
) : (
item.label
)}
{item.label}
{isSelected && (
<VisuallyHidden>, {t('selected')}</VisuallyHidden>
)}
-9
View File
@@ -52,17 +52,8 @@ subscribe(userChoicesStore, () => {
saveUserChoices(userChoicesStore as LocalUserChoicesLK, false)
})
// Preset backgrounds used to be JPEG files: point the saved choice to their
// WebP replacement. The JPEG files can be removed once this has shipped.
const LEGACY_PRESET_BACKGROUND = /^(\/assets\/backgrounds\/\d+)\.jpg$/
// we run some logic on store loading to check if the processor config is still valid
if (userChoicesStore.processorConfig?.type === ProcessorType.VIRTUAL) {
userChoicesStore.processorConfig.imagePath =
userChoicesStore.processorConfig.imagePath.replace(
LEGACY_PRESET_BACKGROUND,
'$1.webp'
)
if (userChoicesStore.processorConfig.imagePath.startsWith('blob:')) {
// this happens when a not authenticated user had changed their background image
// we restore clear the processor config to avoid displaying a black screen.
-7
View File
@@ -6,13 +6,6 @@ body,
height: 100%;
}
/* RGAA 10.5: every text color must be paired with a declared background
color, so custom browser or system colors cannot make text unreadable. */
body {
background-color: var(--colors-default-bg);
color: var(--colors-default-text);
}
:root {
--avatar-cap-height: 0.7;
}
-34
View File
@@ -1,34 +0,0 @@
/**
* Run a non-urgent task once the page has finished loading and the main
* thread is idle. Returns a function cancelling the task if it didn't run yet.
*
* @param task
* @param timeout max delay (ms) to wait for an idle period once the page is loaded
*/
export const runWhenIdle = (task: () => void, timeout: number = 5000) => {
let cancelSchedule: (() => void) | undefined
const schedule = () => {
// Safari doesn't support requestIdleCallback
if (typeof window.requestIdleCallback === 'function') {
const handle = window.requestIdleCallback(task, { timeout })
cancelSchedule = () => window.cancelIdleCallback(handle)
} else {
const handle = window.setTimeout(task, 1000)
cancelSchedule = () => window.clearTimeout(handle)
}
}
// Initial resources (scripts, styles, fonts...) are still being fetched
// until the load event.
if (document.readyState === 'complete') {
schedule()
} else {
window.addEventListener('load', schedule, { once: true })
}
return () => {
window.removeEventListener('load', schedule)
cancelSchedule?.()
}
}
@@ -79,13 +79,8 @@ data:
add_header Cache-Control "public, max-age=2592000";
}
location ^~ /assets/mediapipe/models/ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
# Serve static files with caching
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp3)$ {
location ~* ^/assets/.*\.(css|js|json|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}