mirror of
https://github.com/suitenumerique/meet.git
synced 2026-07-27 12:19:10 +00:00
Compare commits
218 Commits
v0.1.4
...
v-hackathon
| Author | SHA1 | Date | |
|---|---|---|---|
| 808fc7a00f | |||
| c8b4592d88 | |||
| db071f0dcc | |||
| b1b28fe330 | |||
| 98950f43af | |||
| b43f9922b6 | |||
| d49dc72849 | |||
| 82f0251101 | |||
| 2f675c2a3f | |||
| 7105c7cbae | |||
| 376ff8982c | |||
| a4820ae867 | |||
| 2a56cda55c | |||
| 817cf25b37 | |||
| fdaf567f5d | |||
| 0cf5ab1825 | |||
| c9c5d3b452 | |||
| f0b250739c | |||
| 41c9693d10 | |||
| 83cfcacc0e | |||
| e8618099ac | |||
| ac183c9eb9 | |||
| 3dcc93b630 | |||
| 3614b1e803 | |||
| 5e57647b34 | |||
| e271c87a20 | |||
| 40d1f01277 | |||
| 8477296471 | |||
| d200eeb6bd | |||
| 7a51b09664 | |||
| ec22abf82b | |||
| cde4b10794 | |||
| a47f1f92c4 | |||
| 0db36c788b | |||
| a84b76170d | |||
| 998382020d | |||
| 2a12715673 | |||
| 54d4330a97 | |||
| 5dcbe56e56 | |||
| 1a52221ef2 | |||
| 2f3e64b389 | |||
| 2dcaf814e1 | |||
| 583f5b8e70 | |||
| fe8fd36467 | |||
| 0370d9cad0 | |||
| 0da8aa846a | |||
| 70ed99b6c9 | |||
| 1875a394c6 | |||
| 211ba332dc | |||
| 7333c21632 | |||
| 78ebd1a8fd | |||
| 682b69fc11 | |||
| 7a73bf8fc2 | |||
| 1e934957f5 | |||
| 5a7584a3ad | |||
| fb9bf6b08e | |||
| 11b8541005 | |||
| 64607ae8d0 | |||
| c403bbc347 | |||
| 62855fe12c | |||
| f27d451eb6 | |||
| 68792d8019 | |||
| ebb8c14eeb | |||
| 15d43b8d5e | |||
| 1faae96ccd | |||
| 651cc0e5bd | |||
| 0dadd472ff | |||
| be35ee0258 | |||
| bece79f47b | |||
| a499331960 | |||
| d50d167d0a | |||
| e4c7bc0826 | |||
| b5244a5ec0 | |||
| 8cc2cc83c6 | |||
| e591d09b00 | |||
| eeb4dae12d | |||
| 271389d459 | |||
| fe6eefa1f0 | |||
| a276517278 | |||
| 9e9b9015f4 | |||
| 3f0378aada | |||
| 90c88a8bd3 | |||
| 1103902c12 | |||
| 812016d09c | |||
| cadc5c0034 | |||
| b083d837f8 | |||
| db8445f4ab | |||
| 0e5c2be445 | |||
| 0131a65509 | |||
| fb3727e73e | |||
| 3391165e4b | |||
| 0be94aa572 | |||
| b309f91095 | |||
| c50a749293 | |||
| cd9e7c8a1f | |||
| 9d0767ccfe | |||
| 021e52d9eb | |||
| 607a5fc99d | |||
| 756be17cc7 | |||
| 00fa7beebd | |||
| b9d13de591 | |||
| 7896890ffc | |||
| a2043abb51 | |||
| 64bb1b3bb5 | |||
| a1a56402d1 | |||
| 582d3774a4 | |||
| fab08cfaf8 | |||
| 550c48f29e | |||
| 0c64580abf | |||
| 0ad9b7e233 | |||
| b9bcc45cce | |||
| bcd285e368 | |||
| c0ad98eb34 | |||
| 178278235e | |||
| 11664956c7 | |||
| f020979188 | |||
| da5c8d6773 | |||
| 31051cd6c4 | |||
| c51058e6ac | |||
| 3ba913bb21 | |||
| 95116f70e8 | |||
| 5b282b62e7 | |||
| 5e74fce6e2 | |||
| 96b279b350 | |||
| fc4ad562ae | |||
| 480a8df31a | |||
| f76e7f0e51 | |||
| b9ffbd179c | |||
| a3ef1d4a26 | |||
| d11bcc5de9 | |||
| 412914cf01 | |||
| d511aedd39 | |||
| 7edf7d194b | |||
| 6324608a4a | |||
| a402c2f46f | |||
| e21858febe | |||
| 3d615fa582 | |||
| 4293444d3e | |||
| a55a4d5b5d | |||
| dd9a87a33b | |||
| 24242ef01a | |||
| b537cdfd93 | |||
| 80cc7c723f | |||
| e9210213b1 | |||
| 634f1924be | |||
| 4e175a8361 | |||
| c5ce32ef79 | |||
| aaf6b03a25 | |||
| 66bc739411 | |||
| 1b48fa256e | |||
| 053c4a40e9 | |||
| 53d732d802 | |||
| 26ca81db40 | |||
| e6e6a3bde7 | |||
| 26fdaac589 | |||
| 1fd1cb71ba | |||
| c8023573c6 | |||
| 584be7e65b | |||
| 59ec88e84a | |||
| 1b2e0ad431 | |||
| 20464a2845 | |||
| ece6284de2 | |||
| 82e994e5b1 | |||
| 85aa7a7251 | |||
| c4ececd03a | |||
| 57bba04cf3 | |||
| 11e162dbd4 | |||
| e06e9d1496 | |||
| c8cc9909ba | |||
| c218a1f7a2 | |||
| 490aaba30a | |||
| 790d37569c | |||
| 1e140a01b5 | |||
| 4ecb7202ec | |||
| 4b7419fe4a | |||
| 44d3c738d7 | |||
| 888c66a218 | |||
| 86641bd160 | |||
| 3d91af23cc | |||
| 2d0d30ce01 | |||
| 98ae9af84a | |||
| 3dda12ada6 | |||
| 8b2750c413 | |||
| c16c27fa50 | |||
| b3ef57e1b6 | |||
| b554a6a542 | |||
| 574fd6dc89 | |||
| 8d77332a0a | |||
| 0e2c805b41 | |||
| 9782eb8c7c | |||
| f6bc57ba91 | |||
| 4d5aec9a49 | |||
| 74b296aa37 | |||
| 88fadd1d61 | |||
| cac58f49d3 | |||
| 12c27eedac | |||
| 6a7ec95493 | |||
| e41656a760 | |||
| eb90c0f28c | |||
| f3c4b0ac40 | |||
| 038e6368e4 | |||
| 028f20375f | |||
| ccc23ff46a | |||
| e3b7a1f77b | |||
| 69a8eea1ce | |||
| 20493edd07 | |||
| 79f7fcab6e | |||
| ce3a6dab12 | |||
| 1b57dd0ecf | |||
| c6318910c2 | |||
| 03b3630611 | |||
| 5b8c8d493a | |||
| b12fb6bf48 | |||
| a8f64f5a36 | |||
| 6ab5b3300a | |||
| 6189e6454d | |||
| a8b2c56f4b | |||
| b472220151 |
@@ -1,4 +1,5 @@
|
|||||||
name: Docker Hub Workflow
|
name: Docker Hub Workflow
|
||||||
|
run-name: Docker Hub Workflow
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -48,9 +49,15 @@ jobs:
|
|||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
run: echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin
|
run: echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin
|
||||||
|
-
|
||||||
|
name: Run trivy scan
|
||||||
|
uses: numerique-gouv/action-trivy-cache@main
|
||||||
|
with:
|
||||||
|
docker-build-args: '--target backend-production -f Dockerfile'
|
||||||
|
docker-image-name: 'docker.io/lasuite/meet-backend:${{ github.sha }}'
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
target: backend-production
|
target: backend-production
|
||||||
@@ -92,9 +99,15 @@ jobs:
|
|||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
run: echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin
|
run: echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin
|
||||||
|
-
|
||||||
|
name: Run trivy scan
|
||||||
|
uses: numerique-gouv/action-trivy-cache@main
|
||||||
|
with:
|
||||||
|
docker-build-args: '-f src/frontend/Dockerfile --target frontend-production'
|
||||||
|
docker-image-name: 'docker.io/lasuite/meet-frontend:${{ github.sha }}'
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./src/frontend/Dockerfile
|
file: ./src/frontend/Dockerfile
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Helmfile lint
|
||||||
|
run-name: Helmfile lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
helmfile-lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ghcr.io/helmfile/helmfile:latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
uses: numerique-gouv/action-helmfile-lint@main
|
||||||
|
with:
|
||||||
|
app-id: ${{ secrets.APP_ID }}
|
||||||
|
age-key: ${{ secrets.SOPS_PRIVATE }}
|
||||||
|
private-key: ${{ secrets.PRIVATE_KEY }}
|
||||||
|
helmfile-src: "src/helm"
|
||||||
|
repositories: "meet,secrets"
|
||||||
@@ -8,3 +8,5 @@ creation_rules:
|
|||||||
- age1tl80n23wq6zxegupwn70ew0yp225ua5v4dk800x7g2w6pvlxz46qk592pa #marie
|
- age1tl80n23wq6zxegupwn70ew0yp225ua5v4dk800x7g2w6pvlxz46qk592pa #marie
|
||||||
- age1qy04neuzwpasmvljqrcvhwnf0kz5cpyteze38c8avp0czewskasszv9pyw #argocd
|
- age1qy04neuzwpasmvljqrcvhwnf0kz5cpyteze38c8avp0czewskasszv9pyw #argocd
|
||||||
- age18fgn6j2vwwswqcpv9xpcehq8mrf9zs2sglwkamp3tzwx8d9jq9jsrskrk9 #manuuu
|
- age18fgn6j2vwwswqcpv9xpcehq8mrf9zs2sglwkamp3tzwx8d9jq9jsrskrk9 #manuuu
|
||||||
|
- age1hm2hsfgjezpsc3k0y5w5feq9t8vl3seq04qjhgt6ztd6403wfvpsgxu09m # github-repo
|
||||||
|
- age1hnhuzj96ktkhpyygvmz0x9h8mfvssz7ss6emmukags644mdhf4msajk93r # Samuel Paccoud
|
||||||
|
|||||||
+16
-25
@@ -1,15 +1,14 @@
|
|||||||
# Django Meet
|
# Django Meet
|
||||||
|
|
||||||
# ---- base image to inherit from ----
|
# ---- base image to inherit from ----
|
||||||
FROM python:3.10-slim-bullseye as base
|
FROM python:3.12.6-alpine3.20 as base
|
||||||
|
|
||||||
# Upgrade pip to its latest release to speed up dependencies installation
|
# Upgrade pip to its latest release to speed up dependencies installation
|
||||||
RUN python -m pip install --upgrade pip
|
RUN python -m pip install --upgrade pip setuptools
|
||||||
|
|
||||||
# Upgrade system packages to install security updates
|
# Upgrade system packages to install security updates
|
||||||
RUN apt-get update && \
|
RUN apk update && \
|
||||||
apt-get -y upgrade && \
|
apk upgrade
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# ---- Back-end builder image ----
|
# ---- Back-end builder image ----
|
||||||
FROM base as back-builder
|
FROM base as back-builder
|
||||||
@@ -38,12 +37,9 @@ RUN yarn install --frozen-lockfile && \
|
|||||||
FROM base as link-collector
|
FROM base as link-collector
|
||||||
ARG MEET_STATIC_ROOT=/data/static
|
ARG MEET_STATIC_ROOT=/data/static
|
||||||
|
|
||||||
# Install libpangocairo & rdfind
|
RUN apk add \
|
||||||
RUN apt-get update && \
|
pango \
|
||||||
apt-get install -y \
|
rdfind
|
||||||
libpangocairo-1.0-0 \
|
|
||||||
rdfind && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy installed python dependencies
|
# Copy installed python dependencies
|
||||||
COPY --from=back-builder /install /usr/local
|
COPY --from=back-builder /install /usr/local
|
||||||
@@ -66,17 +62,14 @@ FROM base as core
|
|||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Install required system libs
|
RUN apk add \
|
||||||
RUN apt-get update && \
|
gettext \
|
||||||
apt-get install -y \
|
cairo \
|
||||||
gettext \
|
libffi-dev \
|
||||||
libcairo2 \
|
gdk-pixbuf \
|
||||||
libffi-dev \
|
pango \
|
||||||
libgdk-pixbuf2.0-0 \
|
shared-mime-info
|
||||||
libpango-1.0-0 \
|
|
||||||
libpangocairo-1.0-0 \
|
|
||||||
shared-mime-info && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy entrypoint
|
# Copy entrypoint
|
||||||
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
|
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
|
||||||
@@ -106,9 +99,7 @@ FROM core as backend-development
|
|||||||
USER root:root
|
USER root:root
|
||||||
|
|
||||||
# Install psql
|
# Install psql
|
||||||
RUN apt-get update && \
|
RUN apk add postgresql-client
|
||||||
apt-get install -y postgresql-client && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Uninstall Meet and re-install it in editable mode along with development
|
# Uninstall Meet and re-install it in editable mode along with development
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
HELMFILE=src/helm/helmfile.yaml
|
||||||
|
|
||||||
|
environments=$(awk '/environments:/ {flag=1; next} flag && NF {print} !NF {flag=0}' "$HELMFILE" | grep -E '^[[:space:]]{2}[a-zA-Z]+' | sed 's/^[[:space:]]*//;s/:.*//')
|
||||||
|
|
||||||
|
for env in $environments; do
|
||||||
|
echo "################### $env lint ###################"
|
||||||
|
helmfile -e $env -f src/helm/helmfile.yaml lint || exit 1
|
||||||
|
echo -e "\n"
|
||||||
|
done
|
||||||
+3
-1
@@ -13,7 +13,9 @@
|
|||||||
"enabled": false,
|
"enabled": false,
|
||||||
"groupName": "ignored js dependencies",
|
"groupName": "ignored js dependencies",
|
||||||
"matchManagers": ["npm"],
|
"matchManagers": ["npm"],
|
||||||
"matchPackageNames": []
|
"matchPackageNames": [
|
||||||
|
"eslint"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule secrets updated: 9da011f5c2...2ef2610071
@@ -0,0 +1,316 @@
|
|||||||
|
|
||||||
|
from rest_framework.decorators import api_view
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from minio import Minio
|
||||||
|
from django.conf import settings
|
||||||
|
import openai
|
||||||
|
import logging
|
||||||
|
from ..models import Room, RoleChoices
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
import smtplib
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_prompt(transcript, date):
|
||||||
|
return f"""
|
||||||
|
|
||||||
|
Audience: Coworkers.
|
||||||
|
|
||||||
|
**Do:**
|
||||||
|
- Detect the language of the transcript and provide your entire response in the same language.
|
||||||
|
- If any part of the transcript is unclear or lacks detail, politely inform the user, specifying which areas need further clarification.
|
||||||
|
- Ensure the accuracy of all information and refrain from adding unverified details.
|
||||||
|
- Format the response using proper markdown and structured sections.
|
||||||
|
- Be concise and avoid repeating yourself between the sections.
|
||||||
|
- Be super precise on nickname
|
||||||
|
- Be a nit-picker
|
||||||
|
- Auto-evaluate your response
|
||||||
|
|
||||||
|
**Don't:**
|
||||||
|
- Write something your are not sure.
|
||||||
|
- Write something that is not mention in the transcript.
|
||||||
|
- Don't make mistake while mentioning someone
|
||||||
|
|
||||||
|
**Task:**
|
||||||
|
Summarize the provided meeting transcript into clear and well-organized meeting minutes. The summary should be structured into the following sections, excluding irrelevant or inapplicable details:
|
||||||
|
|
||||||
|
1. **Summary**: Write a TL;DR of the meeting.
|
||||||
|
2. **Subjects Discussed**: List the key points or issues in bullet points.
|
||||||
|
4. **Next Steps**: Provide action items as bullet points, assigning each task to a responsible individual and including deadlines (if mentioned). Format action items as tickable checkboxes. Ensure every action is assigned and, if a deadline is provided, that it is clearly stated.
|
||||||
|
|
||||||
|
**Transcript**:
|
||||||
|
{transcript}
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
|
||||||
|
### Summary [Translate this title based on the transcript’s language]
|
||||||
|
[Provide a brief overview of the key points discussed]
|
||||||
|
|
||||||
|
### Subjects Discussed [Translate this title based on the transcript’s language]
|
||||||
|
- [Summarize each topic concisely]
|
||||||
|
|
||||||
|
### Next Steps [Translate this title based on the transcript’s language]
|
||||||
|
- [ ] Action item [Assign to the responsible individual(s) and include a deadline if applicable, follow this strict format: Action - List of owner(s), deadline.]
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_room_and_owners(slug):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
room = Room.objects.get(slug=slug)
|
||||||
|
owner_accesses = room.accesses.filter(role=RoleChoices.OWNER)
|
||||||
|
owners = [access.user for access in owner_accesses]
|
||||||
|
|
||||||
|
logger.info("Room %s has owners: %s", slug, owners)
|
||||||
|
|
||||||
|
except Room.DoesNotExist:
|
||||||
|
logger.error("Room with slug %s does not exist", slug)
|
||||||
|
|
||||||
|
owners = None
|
||||||
|
room = None
|
||||||
|
|
||||||
|
return room, owners
|
||||||
|
|
||||||
|
|
||||||
|
def remove_temporary_file(path):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
if not path or not os.path.exists(path):
|
||||||
|
return
|
||||||
|
|
||||||
|
os.remove(path)
|
||||||
|
logger.info("Temporary file %s has been deleted.", path)
|
||||||
|
|
||||||
|
def get_blocknote_content(summary):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
if not settings.BLOCKNOTE_CONVERTER_URL:
|
||||||
|
logger.error("BLOCKNOTE_CONVERTER_URL is not configured")
|
||||||
|
return None
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"markdown": summary
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Converting summary in BlockNote.js…")
|
||||||
|
response = requests.post(settings.BLOCKNOTE_CONVERTER_URL, headers=headers, json=data)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
logger.error(f"Failed to convert summary. Status code: {response.status_code}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
response_data = response.json()
|
||||||
|
if not 'content' in response_data:
|
||||||
|
logger.error(f"Content is missing: %s", response_data)
|
||||||
|
return None
|
||||||
|
|
||||||
|
content = response_data['content']
|
||||||
|
logger.info("Base64 content: %s", content)
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_document_link(content, email):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
logger.info("Create a document for %s", email)
|
||||||
|
|
||||||
|
if not settings.DOCS_BASE_URL:
|
||||||
|
logger.error("DOCS_BASE_URL is not configured")
|
||||||
|
return None
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"content": content,
|
||||||
|
"owner": email
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Querying docs…")
|
||||||
|
response = requests.post(f"{settings.DOCS_BASE_URL}/api/v1.0/summary/", headers=headers, json=data)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
logger.error(f"Failed to get document's id. Status code: {response.status_code}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
response_data = response.json()
|
||||||
|
if not 'id' in response_data:
|
||||||
|
logger.error(f"ID is missing: %s", response_data)
|
||||||
|
return None
|
||||||
|
|
||||||
|
id = response_data['id']
|
||||||
|
logger.info("Document's id: %s", id)
|
||||||
|
|
||||||
|
return f"{settings.DOCS_BASE_URL}/docs/{id}/"
|
||||||
|
|
||||||
|
|
||||||
|
def email_owner_with_summary(room, link, owner):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
logger.info("Emailing owner: %s", owner)
|
||||||
|
|
||||||
|
try:
|
||||||
|
room.email_summary(owners=[owner], link=link)
|
||||||
|
except smtplib.SMTPException:
|
||||||
|
logger.error("Error while emailing owner")
|
||||||
|
|
||||||
|
def strip_room_slug(filename):
|
||||||
|
"""Wip."""
|
||||||
|
return filename.split("_")[2].split(".")[0]
|
||||||
|
|
||||||
|
def strip_room_date(filename):
|
||||||
|
"""Wip."""
|
||||||
|
return filename.split("_")[1].split(".")[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_minio_client():
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
return Minio(
|
||||||
|
settings.MINIO_URL,
|
||||||
|
access_key=settings.MINIO_ACCESS_KEY,
|
||||||
|
secret_key=settings.MINIO_SECRET_KEY,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("An error occurred while creating the Minio client %s: %s", settings.MINIO_URL, str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def download_temporary_file(minio_client, filename):
|
||||||
|
"""Wip."""
|
||||||
|
|
||||||
|
temp_file_path = None
|
||||||
|
|
||||||
|
logger.info('downloading file %s', filename)
|
||||||
|
|
||||||
|
try:
|
||||||
|
audio_file_stream = minio_client.get_object(settings.MINIO_BUCKET, object_name=filename)
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False, suffix='.ogg') as temp_audio_file:
|
||||||
|
|
||||||
|
for data in audio_file_stream.stream(32 * 1024):
|
||||||
|
temp_audio_file.write(data)
|
||||||
|
|
||||||
|
temp_file_path = temp_audio_file.name
|
||||||
|
logger.info('Temporary file created at %s', temp_file_path)
|
||||||
|
|
||||||
|
audio_file_stream.close()
|
||||||
|
audio_file_stream.release_conn()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("An error occurred while accessing the object: %s", str(e))
|
||||||
|
|
||||||
|
return temp_file_path
|
||||||
|
|
||||||
|
|
||||||
|
# todo - discuss retry policy if the webhook fail
|
||||||
|
@api_view(["POST"])
|
||||||
|
def minio_webhook(request):
|
||||||
|
|
||||||
|
data = request.data
|
||||||
|
|
||||||
|
logger.info('Minio webhook sent %s', data)
|
||||||
|
|
||||||
|
record = data["Records"][0]
|
||||||
|
s3 = record['s3']
|
||||||
|
bucket = s3['bucket']
|
||||||
|
bucket_name = bucket['name']
|
||||||
|
object = s3['object']
|
||||||
|
filename = object['key']
|
||||||
|
|
||||||
|
if bucket_name != settings.MINIO_BUCKET:
|
||||||
|
logger.info('Not interested in this bucket: %s', bucket_name)
|
||||||
|
return Response("Not interested in this bucket")
|
||||||
|
|
||||||
|
if object['contentType'] != 'audio/ogg':
|
||||||
|
logger.info('Not interested in this file type: %s', object['contentType'])
|
||||||
|
return Response("Not interested in this file type")
|
||||||
|
|
||||||
|
room_slug = strip_room_slug(filename)
|
||||||
|
room_date = strip_room_date(filename)
|
||||||
|
logger.info('file received %s for room %s', filename, room_slug)
|
||||||
|
|
||||||
|
minio_client = get_minio_client()
|
||||||
|
|
||||||
|
temp_file_path = None
|
||||||
|
summary = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
temp_file_path = download_temporary_file(minio_client, filename)
|
||||||
|
|
||||||
|
if settings.OPENAI_ENABLE and temp_file_path:
|
||||||
|
logger.info('Initiating OpenAI client …')
|
||||||
|
openai_client = openai.OpenAI(
|
||||||
|
api_key=settings.OPENAI_API_KEY,
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(temp_file_path, "rb") as audio_file:
|
||||||
|
logger.info('Querying transcription …')
|
||||||
|
transcript = openai_client.audio.transcriptions.create(
|
||||||
|
model="whisper-1",
|
||||||
|
file=audio_file
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info('Transcript: \n %s', transcript)
|
||||||
|
prompt = get_prompt(transcript.text, room_date)
|
||||||
|
|
||||||
|
logger.info('Prompt: \n %s', prompt)
|
||||||
|
|
||||||
|
summary_response = openai_client.chat.completions.create(
|
||||||
|
model="gpt-4o",
|
||||||
|
messages=[
|
||||||
|
{"role": "system", "content": "You are a concise and structured assistant, that summarizes meeting transcripts."},
|
||||||
|
{"role": "user", "content": prompt}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
summary = summary_response.choices[0].message.content
|
||||||
|
logger.info('Summary: \n %s', summary)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("An error occurred: %s", str(e))
|
||||||
|
raise
|
||||||
|
|
||||||
|
finally:
|
||||||
|
remove_temporary_file(temp_file_path)
|
||||||
|
|
||||||
|
if not summary:
|
||||||
|
logger.error("Empty summary.")
|
||||||
|
return Response("")
|
||||||
|
|
||||||
|
room, owners = get_room_and_owners(room_slug)
|
||||||
|
|
||||||
|
if not owners or not room:
|
||||||
|
logger.error("No owners in room %s", room_slug)
|
||||||
|
return Response("")
|
||||||
|
|
||||||
|
content = get_blocknote_content(summary)
|
||||||
|
|
||||||
|
if not content:
|
||||||
|
logger.error("Empty content.")
|
||||||
|
return Response("")
|
||||||
|
|
||||||
|
owner = owners[0]
|
||||||
|
|
||||||
|
link = get_document_link(content, owner.email)
|
||||||
|
|
||||||
|
if not link:
|
||||||
|
logger.error("Empty link.")
|
||||||
|
return Response("")
|
||||||
|
|
||||||
|
email_owner_with_summary(room, link, owner)
|
||||||
|
|
||||||
|
return Response("")
|
||||||
@@ -15,6 +15,8 @@ from django.utils.functional import lazy
|
|||||||
from django.utils.text import capfirst, slugify
|
from django.utils.text import capfirst, slugify
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
from timezone_field import TimeZoneField
|
from timezone_field import TimeZoneField
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
@@ -325,3 +327,24 @@ class Room(Resource):
|
|||||||
else:
|
else:
|
||||||
raise ValidationError({"name": f'Room name "{self.name:s}" is reserved.'})
|
raise ValidationError({"name": f'Room name "{self.name:s}" is reserved.'})
|
||||||
super().clean_fields(exclude=exclude)
|
super().clean_fields(exclude=exclude)
|
||||||
|
|
||||||
|
|
||||||
|
def email_summary(self, owners, link):
|
||||||
|
"""Wip"""
|
||||||
|
|
||||||
|
template_vars = {
|
||||||
|
"title": "Votre résumé est prêt",
|
||||||
|
"link": link,
|
||||||
|
"room": self.slug,
|
||||||
|
}
|
||||||
|
msg_html = render_to_string("mail/html/summary.html", template_vars)
|
||||||
|
msg_plain = render_to_string("mail/text/invitation.txt", template_vars)
|
||||||
|
|
||||||
|
for owner in owners:
|
||||||
|
owner.email_user(
|
||||||
|
subject="Votre résumé est prêt",
|
||||||
|
from_email=settings.EMAIL_FROM,
|
||||||
|
message=msg_plain,
|
||||||
|
html_message=msg_html,
|
||||||
|
fail_silently=False,
|
||||||
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from django.urls import include, path
|
|||||||
|
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from core.api import viewsets
|
from core.api import get_frontend_configuration, viewsets, demo
|
||||||
from core.authentication.urls import urlpatterns as oidc_urls
|
from core.authentication.urls import urlpatterns as oidc_urls
|
||||||
|
|
||||||
# - Main endpoints
|
# - Main endpoints
|
||||||
@@ -23,6 +23,8 @@ urlpatterns = [
|
|||||||
[
|
[
|
||||||
*router.urls,
|
*router.urls,
|
||||||
*oidc_urls,
|
*oidc_urls,
|
||||||
|
path("config/", get_frontend_configuration, name="config"),
|
||||||
|
path("minio-webhook/", demo.minio_webhook, name="demo"),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
Utils functions used in the core app
|
Utils functions used in the core app
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# ruff: noqa:S311
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import random
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
@@ -10,6 +15,28 @@ from django.conf import settings
|
|||||||
from livekit.api import AccessToken, VideoGrants
|
from livekit.api import AccessToken, VideoGrants
|
||||||
|
|
||||||
|
|
||||||
|
def generate_color(identity: str) -> str:
|
||||||
|
"""Generates a consistent HSL color based on a given identity string.
|
||||||
|
|
||||||
|
The function seeds the random generator with the identity's hash,
|
||||||
|
ensuring consistent color output. The HSL format allows fine-tuned control
|
||||||
|
over saturation and lightness, empirically adjusted to produce visually
|
||||||
|
appealing and distinct colors. HSL is preferred over hex to constrain the color
|
||||||
|
range and ensure predictability.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# ruff: noqa:S324
|
||||||
|
identity_hash = hashlib.sha1(identity.encode("utf-8"))
|
||||||
|
# Keep only hash's last 16 bits, collisions are not a concern
|
||||||
|
seed = int(identity_hash.hexdigest(), 16) & 0xFFFF
|
||||||
|
random.seed(seed)
|
||||||
|
hue = random.randint(0, 360)
|
||||||
|
saturation = random.randint(50, 75)
|
||||||
|
lightness = random.randint(25, 60)
|
||||||
|
|
||||||
|
return f"hsl({hue}, {saturation}%, {lightness}%)"
|
||||||
|
|
||||||
|
|
||||||
def generate_token(room: str, user, username: Optional[str] = None) -> str:
|
def generate_token(room: str, user, username: Optional[str] = None) -> str:
|
||||||
"""Generate a LiveKit access token for a user in a specific room.
|
"""Generate a LiveKit access token for a user in a specific room.
|
||||||
|
|
||||||
@@ -25,6 +52,8 @@ def generate_token(room: str, user, username: Optional[str] = None) -> str:
|
|||||||
video_grants = VideoGrants(
|
video_grants = VideoGrants(
|
||||||
room=room,
|
room=room,
|
||||||
room_join=True,
|
room_join=True,
|
||||||
|
room_admin=True,
|
||||||
|
room_record=True,
|
||||||
can_update_own_metadata=True,
|
can_update_own_metadata=True,
|
||||||
can_publish_sources=[
|
can_publish_sources=[
|
||||||
"camera",
|
"camera",
|
||||||
@@ -49,6 +78,7 @@ def generate_token(room: str, user, username: Optional[str] = None) -> str:
|
|||||||
.with_grants(video_grants)
|
.with_grants(video_grants)
|
||||||
.with_identity(identity)
|
.with_identity(identity)
|
||||||
.with_name(username or default_username)
|
.with_name(username or default_username)
|
||||||
|
.with_metadata(json.dumps({"color": generate_color(identity)}))
|
||||||
)
|
)
|
||||||
|
|
||||||
return token.to_jwt()
|
return token.to_jwt()
|
||||||
|
|||||||
@@ -251,6 +251,19 @@ class Base(Configuration):
|
|||||||
"REDOC_DIST": "SIDECAR",
|
"REDOC_DIST": "SIDECAR",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Frontend
|
||||||
|
FRONTEND_CONFIGURATION = {
|
||||||
|
"analytics": values.DictValue(
|
||||||
|
{}, environ_name="FRONTEND_ANALYTICS", environ_prefix=None
|
||||||
|
),
|
||||||
|
"support": values.DictValue(
|
||||||
|
{}, environ_name="FRONTEND_SUPPORT", environ_prefix=None
|
||||||
|
),
|
||||||
|
"silence_livekit_debug_logs": values.BooleanValue(
|
||||||
|
False, environ_name="FRONTEND_SILENCE_LIVEKIT_DEBUG", environ_prefix=None
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
# Mail
|
# Mail
|
||||||
EMAIL_BACKEND = values.Value("django.core.mail.backends.smtp.EmailBackend")
|
EMAIL_BACKEND = values.Value("django.core.mail.backends.smtp.EmailBackend")
|
||||||
EMAIL_HOST = values.Value(None)
|
EMAIL_HOST = values.Value(None)
|
||||||
@@ -258,6 +271,7 @@ class Base(Configuration):
|
|||||||
EMAIL_HOST_PASSWORD = values.Value(None)
|
EMAIL_HOST_PASSWORD = values.Value(None)
|
||||||
EMAIL_PORT = values.PositiveIntegerValue(None)
|
EMAIL_PORT = values.PositiveIntegerValue(None)
|
||||||
EMAIL_USE_TLS = values.BooleanValue(False)
|
EMAIL_USE_TLS = values.BooleanValue(False)
|
||||||
|
EMAIL_USE_SSL = values.BooleanValue(False)
|
||||||
EMAIL_FROM = values.Value("from@example.com")
|
EMAIL_FROM = values.Value("from@example.com")
|
||||||
|
|
||||||
AUTH_USER_MODEL = "core.User"
|
AUTH_USER_MODEL = "core.User"
|
||||||
@@ -275,6 +289,7 @@ class Base(Configuration):
|
|||||||
# Easy thumbnails
|
# Easy thumbnails
|
||||||
THUMBNAIL_EXTENSION = "webp"
|
THUMBNAIL_EXTENSION = "webp"
|
||||||
THUMBNAIL_TRANSPARENCY_EXTENSION = "webp"
|
THUMBNAIL_TRANSPARENCY_EXTENSION = "webp"
|
||||||
|
THUMBNAIL_DEFAULT_STORAGE_ALIAS = "default"
|
||||||
THUMBNAIL_ALIASES = {}
|
THUMBNAIL_ALIASES = {}
|
||||||
|
|
||||||
# Celery
|
# Celery
|
||||||
@@ -371,6 +386,53 @@ class Base(Configuration):
|
|||||||
None, environ_name="ANALYTICS_KEY", environ_prefix=None
|
None, environ_name="ANALYTICS_KEY", environ_prefix=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# todo - totally wip
|
||||||
|
AWS_S3_ENDPOINT_URL = values.Value(
|
||||||
|
environ_name="AWS_S3_ENDPOINT_URL", environ_prefix=None
|
||||||
|
)
|
||||||
|
AWS_S3_ACCESS_KEY_ID = values.Value(
|
||||||
|
environ_name="AWS_S3_ACCESS_KEY_ID", environ_prefix=None
|
||||||
|
)
|
||||||
|
AWS_S3_SECRET_ACCESS_KEY = values.Value(
|
||||||
|
environ_name="AWS_S3_SECRET_ACCESS_KEY", environ_prefix=None
|
||||||
|
)
|
||||||
|
AWS_S3_REGION_NAME = values.Value(
|
||||||
|
environ_name="AWS_S3_REGION_NAME", environ_prefix=None
|
||||||
|
)
|
||||||
|
AWS_STORAGE_BUCKET_NAME = values.Value(
|
||||||
|
"meet-media-storage",
|
||||||
|
environ_name="AWS_STORAGE_BUCKET_NAME",
|
||||||
|
environ_prefix=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
OPENAI_API_KEY = values.Value(
|
||||||
|
None, environ_name="OPENAI_API_KEY", environ_prefix=None
|
||||||
|
)
|
||||||
|
OPENAI_ENABLE = values.BooleanValue(
|
||||||
|
True, environ_name="OPENAI_ENABLE", environ_prefix=None
|
||||||
|
)
|
||||||
|
|
||||||
|
# todo - totally wip
|
||||||
|
MINIO_ACCESS_KEY = values.Value(
|
||||||
|
None, environ_name="MINIO_ACCESS_KEY", environ_prefix=None
|
||||||
|
)
|
||||||
|
MINIO_SECRET_KEY = values.Value(
|
||||||
|
None, environ_name="MINIO_SECRET_KEY", environ_prefix=None
|
||||||
|
)
|
||||||
|
MINIO_URL = values.Value(
|
||||||
|
None, environ_name="MINIO_URL", environ_prefix=None
|
||||||
|
)
|
||||||
|
MINIO_BUCKET = values.Value(
|
||||||
|
'livekit-staging-livekit-egress', environ_name="MINIO_BUCKET", environ_prefix=None
|
||||||
|
)
|
||||||
|
|
||||||
|
BLOCKNOTE_CONVERTER_URL = values.Value(
|
||||||
|
'https://converter-blocknote.osc-fr1.scalingo.io/', environ_name="", environ_prefix=None
|
||||||
|
)
|
||||||
|
DOCS_BASE_URL = values.Value(
|
||||||
|
'https://docs-ia.beta.numerique.gouv.fr', environ_name="", environ_prefix=None
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@property
|
@property
|
||||||
def ENVIRONMENT(self):
|
def ENVIRONMENT(self):
|
||||||
@@ -514,6 +576,20 @@ class Production(Base):
|
|||||||
ALLOWED_HOSTS=["foo.com", "foo.fr"]
|
ALLOWED_HOSTS=["foo.com", "foo.fr"]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
"version": 1,
|
||||||
|
"disable_existing_loggers": False,
|
||||||
|
"handlers": {
|
||||||
|
"console": {
|
||||||
|
"class": "logging.StreamHandler",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"handlers": ["console"],
|
||||||
|
"level": "INFO",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
*values.ListValue([], environ_name="ALLOWED_HOSTS"),
|
*values.ListValue([], environ_name="ALLOWED_HOSTS"),
|
||||||
@@ -534,6 +610,14 @@ class Production(Base):
|
|||||||
#
|
#
|
||||||
# In other cases, you should comment the following line to avoid security issues.
|
# In other cases, you should comment the following line to avoid security issues.
|
||||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
SECURE_HSTS_SECONDS = 60
|
||||||
|
SECURE_HSTS_PRELOAD = True
|
||||||
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
||||||
|
SECURE_SSL_REDIRECT = True
|
||||||
|
SECURE_REDIRECT_EXEMPT = [
|
||||||
|
"^__lbheartbeat__",
|
||||||
|
"^__heartbeat__",
|
||||||
|
]
|
||||||
|
|
||||||
# Modern browsers require to have the `secure` attribute on cookies with `Samesite=none`
|
# Modern browsers require to have the `secure` attribute on cookies with `Samesite=none`
|
||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
|
|||||||
+18
-16
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "meet"
|
name = "meet"
|
||||||
version = "0.1.4"
|
version = "0.1.7"
|
||||||
authors = [{ "name" = "DINUM", "email" = "dev@mail.numerique.gouv.fr" }]
|
authors = [{ "name" = "DINUM", "email" = "dev@mail.numerique.gouv.fr" }]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
@@ -25,7 +25,7 @@ license = { file = "LICENSE" }
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"boto3==1.34.154",
|
"boto3==1.35.19",
|
||||||
"Brotli==1.1.0",
|
"Brotli==1.1.0",
|
||||||
"celery[redis]==5.4.0",
|
"celery[redis]==5.4.0",
|
||||||
"django-configurations==2.5.1",
|
"django-configurations==2.5.1",
|
||||||
@@ -36,28 +36,30 @@ dependencies = [
|
|||||||
"django-redis==5.4.0",
|
"django-redis==5.4.0",
|
||||||
"django-storages[s3]==1.14.4",
|
"django-storages[s3]==1.14.4",
|
||||||
"django-timezone-field>=5.1",
|
"django-timezone-field>=5.1",
|
||||||
"django==5.0.7",
|
"django==5.1.1",
|
||||||
"djangorestframework==3.15.2",
|
"djangorestframework==3.15.2",
|
||||||
"drf_spectacular==0.27.2",
|
"drf_spectacular==0.27.2",
|
||||||
"dockerflow==2024.4.2",
|
"dockerflow==2024.4.2",
|
||||||
"easy_thumbnails==2.9",
|
"easy_thumbnails==2.10",
|
||||||
"factory_boy==3.3.0",
|
"factory_boy==3.3.1",
|
||||||
"freezegun==1.5.1",
|
"freezegun==1.5.1",
|
||||||
"gunicorn==22.0.0",
|
"gunicorn==23.0.0",
|
||||||
"jsonschema==4.23.0",
|
"jsonschema==4.23.0",
|
||||||
"june-analytics-python==2.3.0",
|
"june-analytics-python==2.3.0",
|
||||||
"markdown==3.6",
|
"markdown==3.7",
|
||||||
"nested-multipart-parser==1.5.0",
|
"nested-multipart-parser==1.5.0",
|
||||||
"psycopg[binary]==3.2.1",
|
"psycopg[binary]==3.2.2",
|
||||||
"PyJWT==2.9.0",
|
"PyJWT==2.9.0",
|
||||||
"python-frontmatter==1.1.0",
|
"python-frontmatter==1.1.0",
|
||||||
"requests==2.32.3",
|
"requests==2.32.3",
|
||||||
"sentry-sdk==2.12.0",
|
"sentry-sdk==2.14.0",
|
||||||
"url-normalize==1.4.3",
|
"url-normalize==1.4.3",
|
||||||
"WeasyPrint>=60.2",
|
"WeasyPrint>=60.2",
|
||||||
"whitenoise==6.7.0",
|
"whitenoise==6.7.0",
|
||||||
"mozilla-django-oidc==4.0.1",
|
"mozilla-django-oidc==4.0.1",
|
||||||
"livekit-api==0.6.0",
|
"livekit-api==0.7.0",
|
||||||
|
"minio==7.2.9",
|
||||||
|
"openai==1.51.2"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
@@ -71,18 +73,18 @@ dev = [
|
|||||||
"django-extensions==3.2.3",
|
"django-extensions==3.2.3",
|
||||||
"drf-spectacular-sidecar==2024.7.1",
|
"drf-spectacular-sidecar==2024.7.1",
|
||||||
"ipdb==0.13.13",
|
"ipdb==0.13.13",
|
||||||
"ipython==8.26.0",
|
"ipython==8.27.0",
|
||||||
"pyfakefs==5.6.0",
|
"pyfakefs==5.6.0",
|
||||||
"pylint-django==2.5.5",
|
"pylint-django==2.5.5",
|
||||||
"pylint==3.2.6",
|
"pylint==3.2.7",
|
||||||
"pytest-cov==5.0.0",
|
"pytest-cov==5.0.0",
|
||||||
"pytest-django==4.8.0",
|
"pytest-django==4.9.0",
|
||||||
"pytest==8.3.2",
|
"pytest==8.3.3",
|
||||||
"pytest-icdiff==0.9",
|
"pytest-icdiff==0.9",
|
||||||
"pytest-xdist==3.6.1",
|
"pytest-xdist==3.6.1",
|
||||||
"responses==0.25.3",
|
"responses==0.25.3",
|
||||||
"ruff==0.5.6",
|
"ruff==0.6.5",
|
||||||
"types-requests==2.32.0.20240712",
|
"types-requests==2.32.0.20240914",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools]
|
[tool.setuptools]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ WORKDIR /home/frontend
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# ---- Front-end image ----
|
# ---- Front-end image ----
|
||||||
FROM nginxinc/nginx-unprivileged:1.25 as frontend-production
|
FROM nginxinc/nginx-unprivileged:1.26-alpine as frontend-production
|
||||||
|
|
||||||
# Un-privileged user running the application
|
# Un-privileged user running the application
|
||||||
ARG DOCKER_USER
|
ARG DOCKER_USER
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/play-icon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/play-icon.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Meet</title>
|
<title>Visio</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
Generated
+2608
-2834
File diff suppressed because it is too large
Load Diff
+33
-28
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "meet",
|
"name": "meet",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.4",
|
"version": "0.1.7",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "panda codegen && vite",
|
"dev": "panda codegen && vite",
|
||||||
@@ -13,43 +13,48 @@
|
|||||||
"check": "prettier --check ./src"
|
"check": "prettier --check ./src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@livekit/components-react": "2.3.3",
|
"@livekit/components-react": "2.6.5",
|
||||||
"@livekit/components-styles": "1.0.12",
|
"@livekit/components-styles": "1.1.3",
|
||||||
"@pandacss/preset-panda": "0.41.0",
|
"@livekit/track-processors": "0.3.2",
|
||||||
|
"@pandacss/preset-panda": "0.46.1",
|
||||||
|
"@react-aria/toast": "3.0.0-beta.16",
|
||||||
"@remixicon/react": "4.2.0",
|
"@remixicon/react": "4.2.0",
|
||||||
"@tanstack/react-query": "5.49.2",
|
"@tanstack/react-query": "5.59.4",
|
||||||
|
"crisp-sdk-web": "1.0.25",
|
||||||
"hoofd": "1.7.1",
|
"hoofd": "1.7.1",
|
||||||
"i18next": "23.12.1",
|
"i18next": "23.15.2",
|
||||||
"i18next-browser-languagedetector": "8.0.0",
|
"i18next-browser-languagedetector": "8.0.0",
|
||||||
"i18next-parser": "9.0.0",
|
"i18next-parser": "9.0.2",
|
||||||
"i18next-resources-to-backend": "1.2.1",
|
"i18next-resources-to-backend": "1.2.1",
|
||||||
"livekit-client": "2.3.1",
|
"livekit-client": "2.5.7",
|
||||||
"react": "18.2.0",
|
"posthog-js": "1.167.0",
|
||||||
"react-aria-components": "1.2.1",
|
"react": "18.3.1",
|
||||||
"react-dom": "18.2.0",
|
"react-aria-components": "1.4.0",
|
||||||
"react-i18next": "14.1.3",
|
"react-dom": "18.3.1",
|
||||||
"valtio": "1.13.2",
|
"react-i18next": "15.0.2",
|
||||||
"wouter": "3.3.0"
|
"use-sound": "4.0.3",
|
||||||
|
"valtio": "2.0.0",
|
||||||
|
"wouter": "3.3.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@pandacss/dev": "0.41.0",
|
"@pandacss/dev": "0.46.1",
|
||||||
"@tanstack/eslint-plugin-query": "5.49.1",
|
"@tanstack/eslint-plugin-query": "5.59.2",
|
||||||
"@tanstack/react-query-devtools": "5.49.2",
|
"@tanstack/react-query-devtools": "5.59.4",
|
||||||
"@types/node": "20.14.9",
|
"@types/node": "20.16.11",
|
||||||
"@types/react": "18.3.3",
|
"@types/react": "18.3.11",
|
||||||
"@types/react-dom": "18.3.0",
|
"@types/react-dom": "18.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "7.13.1",
|
"@typescript-eslint/eslint-plugin": "8.8.1",
|
||||||
"@typescript-eslint/parser": "7.13.1",
|
"@typescript-eslint/parser": "8.8.1",
|
||||||
"@vitejs/plugin-react": "4.3.1",
|
"@vitejs/plugin-react": "4.3.2",
|
||||||
"eslint": "8.57.0",
|
"eslint": "8.57.0",
|
||||||
"eslint-config-prettier": "9.1.0",
|
"eslint-config-prettier": "9.1.0",
|
||||||
"eslint-plugin-jsx-a11y": "6.9.0",
|
"eslint-plugin-jsx-a11y": "6.10.0",
|
||||||
"eslint-plugin-react-hooks": "4.6.2",
|
"eslint-plugin-react-hooks": "4.6.2",
|
||||||
"eslint-plugin-react-refresh": "0.4.7",
|
"eslint-plugin-react-refresh": "0.4.12",
|
||||||
"postcss": "8.4.39",
|
"postcss": "8.4.47",
|
||||||
"prettier": "3.3.3",
|
"prettier": "3.3.3",
|
||||||
"typescript": "5.5.2",
|
"typescript": "5.6.3",
|
||||||
"vite": "5.3.1",
|
"vite": "5.4.8",
|
||||||
"vite-tsconfig-paths": "4.3.2"
|
"vite-tsconfig-paths": "5.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,34 @@ const config: Config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
fade: { from: { opacity: 0 }, to: { opacity: 1 } },
|
fade: { from: { opacity: 0 }, to: { opacity: 1 } },
|
||||||
|
pulse: {
|
||||||
|
'0%': { boxShadow: '0 0 0 0 rgba(255, 255, 255, 0.7)' },
|
||||||
|
'75%': { boxShadow: '0 0 0 30px rgba(255, 255, 255, 0)' },
|
||||||
|
'100%': { boxShadow: '0 0 0 0 rgba(255, 255, 255, 0)' },
|
||||||
|
},
|
||||||
|
active_speaker: {
|
||||||
|
'0%': { height: '25%' },
|
||||||
|
'25%': { height: '45%' },
|
||||||
|
'50%': { height: '20%' },
|
||||||
|
'100%': { height: '55%' },
|
||||||
|
},
|
||||||
|
active_speaker_small: {
|
||||||
|
'0%': { height: '20%' },
|
||||||
|
'25%': { height: '25%' },
|
||||||
|
'50%': { height: '18%' },
|
||||||
|
'100%': { height: '25%' },
|
||||||
|
},
|
||||||
|
wave_hand: {
|
||||||
|
'0%': { transform: 'rotate(0deg)' },
|
||||||
|
'20%': { transform: 'rotate(-20deg)' },
|
||||||
|
'80%': { transform: 'rotate(20deg)' },
|
||||||
|
'100%': { transform: 'rotate(0)' },
|
||||||
|
},
|
||||||
|
pulse_mic: {
|
||||||
|
'0%': { color: 'primary', opacity: '1' },
|
||||||
|
'50%': { color: 'primary', opacity: '0.8' },
|
||||||
|
'100%': { color: 'primary', opacity: '1' },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
tokens: defineTokens({
|
tokens: defineTokens({
|
||||||
/* we take a few things from the panda preset but for now we clear out some stuff.
|
/* we take a few things from the panda preset but for now we clear out some stuff.
|
||||||
@@ -199,6 +227,7 @@ const config: Config = {
|
|||||||
text: { value: '{colors.white}' },
|
text: { value: '{colors.white}' },
|
||||||
subtle: { value: '{colors.red.100}' },
|
subtle: { value: '{colors.red.100}' },
|
||||||
'subtle-text': { value: '{colors.red.700}' },
|
'subtle-text': { value: '{colors.red.700}' },
|
||||||
|
...pandaPreset.theme.tokens.colors.red,
|
||||||
},
|
},
|
||||||
success: {
|
success: {
|
||||||
DEFAULT: { value: '{colors.green.700}' },
|
DEFAULT: { value: '{colors.green.700}' },
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+14
-14
@@ -6,32 +6,32 @@ import { QueryClientProvider } from '@tanstack/react-query'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useLang } from 'hoofd'
|
import { useLang } from 'hoofd'
|
||||||
import { Switch, Route } from 'wouter'
|
import { Switch, Route } from 'wouter'
|
||||||
|
import { I18nProvider } from 'react-aria-components'
|
||||||
import { Layout } from './layout/Layout'
|
import { Layout } from './layout/Layout'
|
||||||
import { NotFoundScreen } from './components/NotFoundScreen'
|
import { NotFoundScreen } from './components/NotFoundScreen'
|
||||||
import { routes } from './routes'
|
import { routes } from './routes'
|
||||||
import './i18n/init'
|
import './i18n/init'
|
||||||
import { silenceLiveKitLogs } from '@/utils/livekit.ts'
|
|
||||||
import { queryClient } from '@/api/queryClient'
|
import { queryClient } from '@/api/queryClient'
|
||||||
|
import { AppInitialization } from '@/components/AppInitialization'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
useLang(i18n.language)
|
useLang(i18n.language)
|
||||||
|
|
||||||
const isProduction = import.meta.env.PROD
|
|
||||||
silenceLiveKitLogs(isProduction)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<AppInitialization />
|
||||||
<Suspense fallback={null}>
|
<Suspense fallback={null}>
|
||||||
<Layout>
|
<I18nProvider locale={i18n.language}>
|
||||||
<Switch>
|
<Layout>
|
||||||
{Object.entries(routes).map(([, route], i) => (
|
<Switch>
|
||||||
<Route key={i} path={route.path} component={route.Component} />
|
{Object.entries(routes).map(([, route], i) => (
|
||||||
))}
|
<Route key={i} path={route.path} component={route.Component} />
|
||||||
<Route component={NotFoundScreen} />
|
))}
|
||||||
</Switch>
|
<Route component={NotFoundScreen} />
|
||||||
</Layout>
|
</Switch>
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
</Layout>
|
||||||
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
|
</I18nProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export const keys = {
|
export const keys = {
|
||||||
user: 'user',
|
user: 'user',
|
||||||
room: 'room',
|
room: 'room',
|
||||||
|
config: 'config',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { fetchApi } from './fetchApi'
|
||||||
|
import { keys } from './queryKeys'
|
||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
|
||||||
|
export interface ApiConfig {
|
||||||
|
analytics?: {
|
||||||
|
id: string
|
||||||
|
host: string
|
||||||
|
}
|
||||||
|
support?: {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
silence_livekit_debug_logs?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchConfig = (): Promise<ApiConfig> => {
|
||||||
|
return fetchApi<ApiConfig>(`config/`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useConfig = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: [keys.config],
|
||||||
|
queryFn: fetchConfig,
|
||||||
|
staleTime: Infinity,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { silenceLiveKitLogs } from '@/utils/livekit'
|
||||||
|
import { useConfig } from '@/api/useConfig'
|
||||||
|
import { useAnalytics } from '@/features/analytics/hooks/useAnalytics'
|
||||||
|
import { useSupport } from '@/features/support/hooks/useSupport'
|
||||||
|
|
||||||
|
export const AppInitialization = () => {
|
||||||
|
const { data } = useConfig()
|
||||||
|
|
||||||
|
const {
|
||||||
|
analytics = {},
|
||||||
|
support = {},
|
||||||
|
silence_livekit_debug_logs = false,
|
||||||
|
} = data || {}
|
||||||
|
|
||||||
|
useAnalytics(analytics)
|
||||||
|
useSupport(support)
|
||||||
|
silenceLiveKitLogs(silence_livekit_debug_logs)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { cva, RecipeVariantProps } from '@/styled-system/css'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const avatar = cva({
|
||||||
|
base: {
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
color: 'white',
|
||||||
|
display: 'flex',
|
||||||
|
borderRadius: '50%',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
userSelect: 'none',
|
||||||
|
cursor: 'default',
|
||||||
|
flexGrow: 0,
|
||||||
|
flexShrink: 0,
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
context: {
|
||||||
|
list: {
|
||||||
|
width: '32px',
|
||||||
|
height: '32px',
|
||||||
|
fontSize: '1.25rem',
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
context: 'list',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export type AvatarProps = React.HTMLAttributes<HTMLDivElement> & {
|
||||||
|
name?: string
|
||||||
|
bgColor?: string
|
||||||
|
} & RecipeVariantProps<typeof avatar>
|
||||||
|
|
||||||
|
export const Avatar = ({ name, bgColor, context, ...props }: AvatarProps) => {
|
||||||
|
const initial = name?.trim()?.charAt(0) || ''
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: bgColor,
|
||||||
|
}}
|
||||||
|
className={avatar({ context })}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{initial}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Button } from '@/primitives'
|
|
||||||
import { css } from '@/styled-system/css'
|
import { css } from '@/styled-system/css'
|
||||||
import { RiExternalLinkLine } from '@remixicon/react'
|
import { RiExternalLinkLine } from '@remixicon/react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { LinkButton } from '@/primitives'
|
||||||
|
|
||||||
export const Feedback = () => {
|
export const Feedback = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
return (
|
return (
|
||||||
<Button
|
<LinkButton
|
||||||
href="https://grist.incubateur.net/o/docs/forms/1YrfNP1QSSy8p2gCxMFnSf/4"
|
href="https://grist.incubateur.net/o/docs/forms/1YrfNP1QSSy8p2gCxMFnSf/4"
|
||||||
variant="success"
|
variant="success"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -20,6 +20,6 @@ export const Feedback = () => {
|
|||||||
className={css({ marginLeft: 0.5 })}
|
className={css({ marginLeft: 0.5 })}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
</Button>
|
</LinkButton>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,52 @@
|
|||||||
|
import { Button } from '@/primitives'
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useMediaDeviceSelect } from '@livekit/components-react'
|
||||||
|
|
||||||
|
export const SoundTester = () => {
|
||||||
|
const { t } = useTranslation('settings')
|
||||||
|
const [isPlaying, setIsPlaying] = useState(false)
|
||||||
|
const audioRef = useRef<HTMLAudioElement>(null)
|
||||||
|
|
||||||
|
const { activeDeviceId } = useMediaDeviceSelect({ kind: 'audiooutput' })
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateActiveId = async (deviceId: string) => {
|
||||||
|
try {
|
||||||
|
await audioRef?.current?.setSinkId(deviceId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error setting sinkId: ${error}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateActiveId(activeDeviceId)
|
||||||
|
}, [activeDeviceId])
|
||||||
|
|
||||||
|
// prevent pausing the sound
|
||||||
|
navigator.mediaSession.setActionHandler('pause', function () {})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
invisible
|
||||||
|
onPress={() => {
|
||||||
|
audioRef?.current?.play()
|
||||||
|
setIsPlaying(true)
|
||||||
|
}}
|
||||||
|
size="sm"
|
||||||
|
isDisabled={isPlaying}
|
||||||
|
fullWidth
|
||||||
|
style={{
|
||||||
|
color: isPlaying ? 'var(--colors-primary)' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isPlaying ? t('audio.speakers.ongoingTest') : t('audio.speakers.test')}
|
||||||
|
</Button>
|
||||||
|
{/* eslint-disable jsx-a11y/media-has-caption */}
|
||||||
|
<audio
|
||||||
|
ref={audioRef}
|
||||||
|
src="sounds/uprise.mp3"
|
||||||
|
onEnded={() => setIsPlaying(false)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useLocation } from 'wouter'
|
||||||
|
import posthog from 'posthog-js'
|
||||||
|
import { ApiUser } from '@/features/auth/api/ApiUser'
|
||||||
|
|
||||||
|
export const startAnalyticsSession = (data: ApiUser) => {
|
||||||
|
if (posthog._isIdentified()) return
|
||||||
|
const { id, email } = data
|
||||||
|
posthog.identify(id, { email })
|
||||||
|
}
|
||||||
|
|
||||||
|
export const terminateAnalyticsSession = () => {
|
||||||
|
if (!posthog._isIdentified()) return
|
||||||
|
posthog.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
export type useAnalyticsProps = {
|
||||||
|
id?: string
|
||||||
|
host?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAnalytics = ({ id, host }: useAnalyticsProps) => {
|
||||||
|
const [location] = useLocation()
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id || !host) return
|
||||||
|
if (posthog.__loaded) return
|
||||||
|
posthog.init(id, {
|
||||||
|
api_host: host,
|
||||||
|
person_profiles: 'always',
|
||||||
|
})
|
||||||
|
}, [id, host])
|
||||||
|
|
||||||
|
// From PostHog tutorial on PageView tracking in a Single Page Application (SPA) context.
|
||||||
|
useEffect(() => {
|
||||||
|
posthog.capture('$pageview')
|
||||||
|
}, [location])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ export const fetchUser = (): Promise<ApiUser | false> => {
|
|||||||
// make sure to not resolve the promise while trying to silent login
|
// make sure to not resolve the promise while trying to silent login
|
||||||
// so that consumers of fetchUser don't think the work already ended
|
// so that consumers of fetchUser don't think the work already ended
|
||||||
if (canAttemptSilentLogin()) {
|
if (canAttemptSilentLogin()) {
|
||||||
attemptSilentLogin(3600)
|
attemptSilentLogin(300)
|
||||||
} else {
|
} else {
|
||||||
resolve(false)
|
resolve(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ import { useQuery } from '@tanstack/react-query'
|
|||||||
import { keys } from '@/api/queryKeys'
|
import { keys } from '@/api/queryKeys'
|
||||||
import { fetchUser } from './fetchUser'
|
import { fetchUser } from './fetchUser'
|
||||||
import { type ApiUser } from './ApiUser'
|
import { type ApiUser } from './ApiUser'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { startAnalyticsSession } from '@/features/analytics/hooks/useAnalytics'
|
||||||
|
import { initializeSupportSession } from '@/features/support/hooks/useSupport'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns info about currently logged in user
|
* returns info about currently logged-in user
|
||||||
*
|
*
|
||||||
* `isLoggedIn` is undefined while query is loading and true/false when it's done
|
* `isLoggedIn` is undefined while query is loading and true/false when it's done
|
||||||
*/
|
*/
|
||||||
@@ -12,9 +15,16 @@ export const useUser = () => {
|
|||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: [keys.user],
|
queryKey: [keys.user],
|
||||||
queryFn: fetchUser,
|
queryFn: fetchUser,
|
||||||
staleTime: 1000 * 60 * 60, // 1 hour
|
staleTime: Infinity,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (query?.data) {
|
||||||
|
startAnalyticsSession(query.data)
|
||||||
|
initializeSupportSession(query.data)
|
||||||
|
}
|
||||||
|
}, [query.data])
|
||||||
|
|
||||||
const isLoggedIn =
|
const isLoggedIn =
|
||||||
query.status === 'success' ? query.data !== false : undefined
|
query.status === 'success' ? query.data !== false : undefined
|
||||||
const isLoggedOut = isLoggedIn === false
|
const isLoggedOut = isLoggedIn === false
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const JoinMeetingDialog = () => {
|
|||||||
name="roomId"
|
name="roomId"
|
||||||
label={t('joinInputLabel')}
|
label={t('joinInputLabel')}
|
||||||
description={t('joinInputExample', {
|
description={t('joinInputExample', {
|
||||||
example: 'https://meet.numerique.gouv.fr/azer-tyu-qsdf',
|
example: 'https://visio.numerique.gouv.fr/azer-tyu-qsdf',
|
||||||
})}
|
})}
|
||||||
validate={(value) => {
|
validate={(value) => {
|
||||||
return !isRoomValid(value.trim()) ? (
|
return !isRoomValid(value.trim()) ? (
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { getRouteUrl } from '@/navigation/getRouteUrl'
|
||||||
|
import { Button, Dialog, type DialogProps, P, Text } from '@/primitives'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { RiCheckLine, RiFileCopyLine, RiSpam2Fill } from '@remixicon/react'
|
||||||
|
|
||||||
|
// fixme - duplication with the InviteDialog
|
||||||
|
export const LaterMeetingDialog = ({
|
||||||
|
roomId,
|
||||||
|
...dialogProps
|
||||||
|
}: { roomId: string } & Omit<DialogProps, 'title'>) => {
|
||||||
|
const { t } = useTranslation('home')
|
||||||
|
const roomUrl = getRouteUrl('room', roomId)
|
||||||
|
|
||||||
|
const [isCopied, setIsCopied] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isCopied) {
|
||||||
|
const timeout = setTimeout(() => setIsCopied(false), 3000)
|
||||||
|
return () => clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
}, [isCopied])
|
||||||
|
|
||||||
|
const [isHovered, setIsHovered] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
isOpen={!!roomId}
|
||||||
|
{...dialogProps}
|
||||||
|
title={t('laterMeetingDialog.heading')}
|
||||||
|
>
|
||||||
|
<P>{t('laterMeetingDialog.description')}</P>
|
||||||
|
<Button
|
||||||
|
variant={isCopied ? 'success' : 'primary'}
|
||||||
|
size="sm"
|
||||||
|
fullWidth
|
||||||
|
aria-label={t('laterMeetingDialog.copy')}
|
||||||
|
style={{
|
||||||
|
justifyContent: 'start',
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
navigator.clipboard.writeText(roomUrl)
|
||||||
|
setIsCopied(true)
|
||||||
|
}}
|
||||||
|
onHoverChange={setIsHovered}
|
||||||
|
data-attr="later-dialog-copy"
|
||||||
|
>
|
||||||
|
{isCopied ? (
|
||||||
|
<>
|
||||||
|
<RiCheckLine size={18} style={{ marginRight: '8px' }} />
|
||||||
|
{t('laterMeetingDialog.copied')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<RiFileCopyLine
|
||||||
|
size={18}
|
||||||
|
style={{ marginRight: '8px', minWidth: '18px' }}
|
||||||
|
/>
|
||||||
|
{isHovered ? (
|
||||||
|
t('laterMeetingDialog.copy')
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
overflow: 'hidden',
|
||||||
|
userSelect: 'none',
|
||||||
|
textWrap: 'nowrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{roomUrl.replace(/^https?:\/\//, '')}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<HStack>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: '#d9e5ff',
|
||||||
|
borderRadius: '50%',
|
||||||
|
padding: '4px',
|
||||||
|
marginTop: '1rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RiSpam2Fill size={22} style={{ fill: '#4c84fc' }} />
|
||||||
|
</div>
|
||||||
|
<Text variant="sm" style={{ marginTop: '1rem' }}>
|
||||||
|
{t('laterMeetingDialog.permissions')}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { DialogTrigger } from 'react-aria-components'
|
import { DialogTrigger, MenuItem, Menu as RACMenu } from 'react-aria-components'
|
||||||
import { Button, Text } from '@/primitives'
|
import { Button, Menu, Text } from '@/primitives'
|
||||||
import { HStack } from '@/styled-system/jsx'
|
import { HStack } from '@/styled-system/jsx'
|
||||||
import { navigateTo } from '@/navigation/navigateTo'
|
import { navigateTo } from '@/navigation/navigateTo'
|
||||||
import { Screen } from '@/layout/Screen'
|
import { Screen } from '@/layout/Screen'
|
||||||
import { Centered } from '@/layout/Centered'
|
import { Centered } from '@/layout/Centered'
|
||||||
import { generateRoomId } from '@/features/rooms'
|
import { generateRoomId } from '@/features/rooms'
|
||||||
import { authUrl, useUser, UserAware } from '@/features/auth'
|
import { useUser, UserAware } from '@/features/auth'
|
||||||
import { JoinMeetingDialog } from '../components/JoinMeetingDialog'
|
import { JoinMeetingDialog } from '../components/JoinMeetingDialog'
|
||||||
|
import { ProConnectButton } from '@/components/ProConnectButton'
|
||||||
import { useCreateRoom } from '@/features/rooms'
|
import { useCreateRoom } from '@/features/rooms'
|
||||||
import { usePersistentUserChoices } from '@livekit/components-react'
|
import { usePersistentUserChoices } from '@livekit/components-react'
|
||||||
|
import { menuItemRecipe } from '@/primitives/menuItemRecipe'
|
||||||
|
import { RiAddLine, RiLink } from '@remixicon/react'
|
||||||
|
import { LaterMeetingDialog } from '@/features/home/components/LaterMeetingDialog'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
export const Home = () => {
|
export const Home = () => {
|
||||||
const { t } = useTranslation('home')
|
const { t } = useTranslation('home')
|
||||||
@@ -19,13 +24,8 @@ export const Home = () => {
|
|||||||
userChoices: { username },
|
userChoices: { username },
|
||||||
} = usePersistentUserChoices()
|
} = usePersistentUserChoices()
|
||||||
|
|
||||||
const { mutateAsync: createRoom } = useCreateRoom({
|
const { mutateAsync: createRoom } = useCreateRoom()
|
||||||
onSuccess: (data) => {
|
const [laterRoomId, setLaterRoomId] = useState<null | string>(null)
|
||||||
navigateTo('room', data.slug, {
|
|
||||||
state: { create: true, initialRoomData: data },
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserAware>
|
<UserAware>
|
||||||
@@ -42,30 +42,64 @@ export const Home = () => {
|
|||||||
{t('loginToCreateMeeting')}
|
{t('loginToCreateMeeting')}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<HStack gap="gutter">
|
<HStack gap="gutter" alignItems="start">
|
||||||
<Button
|
{isLoggedIn ? (
|
||||||
variant="primary"
|
<Menu>
|
||||||
onPress={
|
<Button variant="primary" data-attr="create-meeting">
|
||||||
isLoggedIn
|
{t('createMeeting')}
|
||||||
? async () => {
|
</Button>
|
||||||
|
<RACMenu>
|
||||||
|
<MenuItem
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
onAction={async () => {
|
||||||
const slug = generateRoomId()
|
const slug = generateRoomId()
|
||||||
await createRoom({ slug, username })
|
createRoom({ slug, username }).then((data) =>
|
||||||
}
|
navigateTo('room', data.slug, {
|
||||||
: undefined
|
state: { create: true, initialRoomData: data },
|
||||||
}
|
})
|
||||||
href={isLoggedIn ? undefined : authUrl()}
|
)
|
||||||
>
|
}}
|
||||||
{isLoggedIn ? t('createMeeting') : t('login', { ns: 'global' })}
|
data-attr="create-option-instant"
|
||||||
</Button>
|
>
|
||||||
|
<RiAddLine size={18} />
|
||||||
|
{t('createMenu.instantOption')}
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
onAction={() => {
|
||||||
|
const slug = generateRoomId()
|
||||||
|
createRoom({ slug, username }).then((data) =>
|
||||||
|
setLaterRoomId(data.slug)
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
data-attr="create-option-later"
|
||||||
|
>
|
||||||
|
<RiLink size={18} />
|
||||||
|
{t('createMenu.laterOption')}
|
||||||
|
</MenuItem>
|
||||||
|
</RACMenu>
|
||||||
|
</Menu>
|
||||||
|
) : (
|
||||||
|
<ProConnectButton />
|
||||||
|
)}
|
||||||
<DialogTrigger>
|
<DialogTrigger>
|
||||||
<Button variant="primary" outline>
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
outline
|
||||||
|
style={{
|
||||||
|
height: !isLoggedIn ? '56px' : undefined, // Temporary, Align with ProConnect Button fixed height
|
||||||
|
}}
|
||||||
|
>
|
||||||
{t('joinMeeting')}
|
{t('joinMeeting')}
|
||||||
</Button>
|
</Button>
|
||||||
<JoinMeetingDialog />
|
<JoinMeetingDialog />
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
</HStack>
|
</HStack>
|
||||||
</Centered>
|
</Centered>
|
||||||
|
<LaterMeetingDialog
|
||||||
|
roomId={laterRoomId || ''}
|
||||||
|
onOpenChange={() => setLaterRoomId(null)}
|
||||||
|
/>
|
||||||
</Screen>
|
</Screen>
|
||||||
</UserAware>
|
</UserAware>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useRoomContext } from '@livekit/components-react'
|
||||||
|
import { Participant, RoomEvent } from 'livekit-client'
|
||||||
|
import { ToastProvider, toastQueue } from './components/ToastProvider'
|
||||||
|
import { NotificationType } from './NotificationType'
|
||||||
|
import { Div } from '@/primitives'
|
||||||
|
import { isMobileBrowser } from '@livekit/components-core'
|
||||||
|
import { useNotificationSound } from '@/features/notifications/hooks/useSoundNotification'
|
||||||
|
|
||||||
|
export const MainNotificationToast = () => {
|
||||||
|
const room = useRoomContext()
|
||||||
|
const { triggerNotificationSound } = useNotificationSound()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const showJoinNotification = (participant: Participant) => {
|
||||||
|
if (isMobileBrowser()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
triggerNotificationSound(NotificationType.Joined)
|
||||||
|
toastQueue.add(
|
||||||
|
{
|
||||||
|
participant,
|
||||||
|
type: NotificationType.Joined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 5000,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
room.on(RoomEvent.ParticipantConnected, showJoinNotification)
|
||||||
|
return () => {
|
||||||
|
room.off(RoomEvent.ParticipantConnected, showJoinNotification)
|
||||||
|
}
|
||||||
|
}, [room, triggerNotificationSound])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const removeParticipantNotifications = (participant: Participant) => {
|
||||||
|
toastQueue.visibleToasts.forEach((toast) => {
|
||||||
|
if (toast.content.participant === participant) {
|
||||||
|
toastQueue.close(toast.key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
room.on(RoomEvent.ParticipantDisconnected, removeParticipantNotifications)
|
||||||
|
return () => {
|
||||||
|
room.off(
|
||||||
|
RoomEvent.ParticipantDisconnected,
|
||||||
|
removeParticipantNotifications
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [room])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleNotificationReceived = (
|
||||||
|
prevMetadataStr: string | undefined,
|
||||||
|
participant: Participant
|
||||||
|
) => {
|
||||||
|
if (!participant) return
|
||||||
|
if (isMobileBrowser()) return
|
||||||
|
if (participant.isLocal) return
|
||||||
|
|
||||||
|
const prevMetadata = JSON.parse(prevMetadataStr || '{}')
|
||||||
|
const metadata = JSON.parse(participant.metadata || '{}')
|
||||||
|
|
||||||
|
if (prevMetadata.raised == metadata.raised) return
|
||||||
|
|
||||||
|
const existingToast = toastQueue.visibleToasts.find(
|
||||||
|
(toast) =>
|
||||||
|
toast.content.participant === participant &&
|
||||||
|
toast.content.type === NotificationType.Raised
|
||||||
|
)
|
||||||
|
|
||||||
|
if (existingToast && prevMetadata.raised && !metadata.raised) {
|
||||||
|
toastQueue.close(existingToast.key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existingToast && !prevMetadata.raised && metadata.raised) {
|
||||||
|
triggerNotificationSound(NotificationType.Raised)
|
||||||
|
toastQueue.add(
|
||||||
|
{
|
||||||
|
participant,
|
||||||
|
type: NotificationType.Raised,
|
||||||
|
},
|
||||||
|
{ timeout: 5000 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
room.on(RoomEvent.ParticipantMetadataChanged, handleNotificationReceived)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
room.off(RoomEvent.ParticipantMetadataChanged, handleNotificationReceived)
|
||||||
|
}
|
||||||
|
}, [room, triggerNotificationSound])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const closeAllToasts = () => {
|
||||||
|
toastQueue.visibleToasts.forEach(({ key }) => toastQueue.close(key))
|
||||||
|
}
|
||||||
|
room.on(RoomEvent.Disconnected, closeAllToasts)
|
||||||
|
return () => {
|
||||||
|
room.off(RoomEvent.Disconnected, closeAllToasts)
|
||||||
|
}
|
||||||
|
}, [room])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Div position="absolute" bottom={0} right={5} zIndex={1000}>
|
||||||
|
<ToastProvider />
|
||||||
|
</Div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export enum NotificationType {
|
||||||
|
Joined = 'joined',
|
||||||
|
Default = 'default',
|
||||||
|
Raised = 'raised',
|
||||||
|
Lowered = 'lowered',
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { useToast } from '@react-aria/toast'
|
||||||
|
import { Button } from '@/primitives'
|
||||||
|
import { RiCloseLine } from '@remixicon/react'
|
||||||
|
import { ToastState } from '@react-stately/toast'
|
||||||
|
import { styled } from '@/styled-system/jsx'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
import { ToastData } from './ToastProvider'
|
||||||
|
import type { QueuedToast } from '@react-stately/toast'
|
||||||
|
|
||||||
|
export const StyledToastContainer = styled('div', {
|
||||||
|
base: {
|
||||||
|
margin: 0.5,
|
||||||
|
boxShadow:
|
||||||
|
'rgba(0, 0, 0, 0.5) 0px 4px 8px 0px, rgba(0, 0, 0, 0.3) 0px 6px 20px 4px',
|
||||||
|
backgroundColor: '#494c4f',
|
||||||
|
color: 'white',
|
||||||
|
borderRadius: '8px',
|
||||||
|
'&[data-entering]': { animation: 'fade 200ms' },
|
||||||
|
'&[data-exiting]': { animation: 'fade 150ms reverse ease-in' },
|
||||||
|
width: 'fit-content',
|
||||||
|
marginLeft: 'auto',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const StyledToast = styled('div', {
|
||||||
|
base: {
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '1rem',
|
||||||
|
padding: '10px',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export interface ToastProps {
|
||||||
|
key: string
|
||||||
|
toast: QueuedToast<ToastData>
|
||||||
|
state: ToastState<ToastData>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Toast({ state, ...props }: ToastProps) {
|
||||||
|
const ref = useRef(null)
|
||||||
|
const { toastProps, contentProps, closeButtonProps } = useToast(
|
||||||
|
props,
|
||||||
|
state,
|
||||||
|
ref
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
<StyledToastContainer {...toastProps} ref={ref}>
|
||||||
|
<StyledToast>
|
||||||
|
<div {...contentProps}>{props.toast.content?.message} machine a</div>
|
||||||
|
<Button square size="sm" invisible {...closeButtonProps}>
|
||||||
|
<RiCloseLine color="white" />
|
||||||
|
</Button>
|
||||||
|
</StyledToast>
|
||||||
|
</StyledToastContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { useToast } from '@react-aria/toast'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
import { Button as RACButton } from 'react-aria-components'
|
||||||
|
import { Track } from 'livekit-client'
|
||||||
|
import Source = Track.Source
|
||||||
|
|
||||||
|
import { useMaybeLayoutContext } from '@livekit/components-react'
|
||||||
|
import { ParticipantTile } from '@/features/rooms/livekit/components/ParticipantTile'
|
||||||
|
import { StyledToastContainer, ToastProps } from './Toast'
|
||||||
|
import { HStack, styled } from '@/styled-system/jsx'
|
||||||
|
import { Div } from '@/primitives'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
|
const ClickableToast = styled(RACButton, {
|
||||||
|
base: {
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
borderRadius: 'inherit',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export function ToastJoined({ state, ...props }: ToastProps) {
|
||||||
|
const { t } = useTranslation('notifications')
|
||||||
|
const ref = useRef(null)
|
||||||
|
const { toastProps, contentProps, titleProps, closeButtonProps } = useToast(
|
||||||
|
props,
|
||||||
|
state,
|
||||||
|
ref
|
||||||
|
)
|
||||||
|
const layoutContext = useMaybeLayoutContext()
|
||||||
|
const participant = props.toast.content.participant
|
||||||
|
const trackReference = {
|
||||||
|
participant,
|
||||||
|
publication: participant.getTrackPublication(Source.Camera),
|
||||||
|
source: Source.Camera,
|
||||||
|
}
|
||||||
|
const pinParticipant = () => {
|
||||||
|
layoutContext?.pin.dispatch?.({
|
||||||
|
msg: 'set_pin',
|
||||||
|
trackReference,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<StyledToastContainer {...toastProps} ref={ref}>
|
||||||
|
<ClickableToast
|
||||||
|
ref={ref}
|
||||||
|
onPress={(e) => {
|
||||||
|
pinParticipant()
|
||||||
|
closeButtonProps.onPress?.(e)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<HStack justify="center" alignItems="center" {...contentProps}>
|
||||||
|
<Div display="flex" overflow="hidden" width="128" height="72">
|
||||||
|
<ParticipantTile
|
||||||
|
trackRef={trackReference}
|
||||||
|
disableSpeakingIndicator={true}
|
||||||
|
disableMetadata={true}
|
||||||
|
style={{
|
||||||
|
borderRadius: '7px 0 0 7px',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Div>
|
||||||
|
<Div padding={20} {...titleProps}>
|
||||||
|
{t('joined.description', {
|
||||||
|
name: participant.name || t('defaultName'),
|
||||||
|
})}
|
||||||
|
</Div>
|
||||||
|
</HStack>
|
||||||
|
</ClickableToast>
|
||||||
|
</StyledToastContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* eslint-disable react-refresh/only-export-components */
|
||||||
|
import { ToastQueue, useToastQueue } from '@react-stately/toast'
|
||||||
|
import { ToastRegion } from './ToastRegion'
|
||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { NotificationType } from '../NotificationType'
|
||||||
|
|
||||||
|
export interface ToastData {
|
||||||
|
participant: Participant
|
||||||
|
type: NotificationType
|
||||||
|
message?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using a global queue for toasts allows for centralized management and queuing of notifications
|
||||||
|
// from anywhere in the app, providing greater flexibility in complex scenarios.
|
||||||
|
export const toastQueue = new ToastQueue<ToastData>({
|
||||||
|
maxVisibleToasts: 5,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const ToastProvider = ({ ...props }) => {
|
||||||
|
const state = useToastQueue<ToastData>(toastQueue)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{state.visibleToasts.length > 0 && (
|
||||||
|
<ToastRegion {...props} state={state} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { useToast } from '@react-aria/toast'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
|
||||||
|
import { StyledToastContainer, ToastProps } from './Toast'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { Button, Div } from '@/primitives'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { RiCloseLine, RiHand } from '@remixicon/react'
|
||||||
|
import { useSidePanel } from '@/features/rooms/livekit/hooks/useSidePanel'
|
||||||
|
|
||||||
|
export function ToastRaised({ state, ...props }: ToastProps) {
|
||||||
|
const { t } = useTranslation('notifications')
|
||||||
|
const ref = useRef(null)
|
||||||
|
const { toastProps, contentProps, titleProps, closeButtonProps } = useToast(
|
||||||
|
props,
|
||||||
|
state,
|
||||||
|
ref
|
||||||
|
)
|
||||||
|
const participant = props.toast.content.participant
|
||||||
|
const { isParticipantsOpen, toggleParticipants } = useSidePanel()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledToastContainer {...toastProps} ref={ref}>
|
||||||
|
<HStack
|
||||||
|
justify="center"
|
||||||
|
alignItems="center"
|
||||||
|
{...contentProps}
|
||||||
|
padding={14}
|
||||||
|
gap={0}
|
||||||
|
>
|
||||||
|
<RiHand
|
||||||
|
color="white"
|
||||||
|
style={{
|
||||||
|
marginRight: '1rem',
|
||||||
|
animationDuration: '300ms',
|
||||||
|
animationName: 'wave_hand',
|
||||||
|
animationIterationCount: '2',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Div {...titleProps} marginRight={0.5}>
|
||||||
|
{t('raised.description', {
|
||||||
|
name: participant.name || t('defaultName'),
|
||||||
|
})}
|
||||||
|
</Div>
|
||||||
|
{!isParticipantsOpen && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="text"
|
||||||
|
style={{
|
||||||
|
color: '#60a5fa',
|
||||||
|
}}
|
||||||
|
onPress={(e) => {
|
||||||
|
toggleParticipants()
|
||||||
|
closeButtonProps.onPress?.(e)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('raised.cta')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button square size="sm" invisible {...closeButtonProps}>
|
||||||
|
<RiCloseLine size={18} color="white" />
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</StyledToastContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { AriaToastRegionProps, useToastRegion } from '@react-aria/toast'
|
||||||
|
import type { ToastState } from '@react-stately/toast'
|
||||||
|
import { Toast } from './Toast'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
import { NotificationType } from '../NotificationType'
|
||||||
|
import { ToastJoined } from './ToastJoined'
|
||||||
|
import { ToastData } from './ToastProvider'
|
||||||
|
import { ToastRaised } from '@/features/notifications/components/ToastRaised.tsx'
|
||||||
|
|
||||||
|
interface ToastRegionProps extends AriaToastRegionProps {
|
||||||
|
state: ToastState<ToastData>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ToastRegion({ state, ...props }: ToastRegionProps) {
|
||||||
|
const ref = useRef(null)
|
||||||
|
const { regionProps } = useToastRegion(props, state, ref)
|
||||||
|
return (
|
||||||
|
<div {...regionProps} ref={ref} className="toast-region">
|
||||||
|
{state.visibleToasts.map((toast) => {
|
||||||
|
if (toast.content?.type === NotificationType.Joined) {
|
||||||
|
return <ToastJoined key={toast.key} toast={toast} state={state} />
|
||||||
|
}
|
||||||
|
if (toast.content?.type === NotificationType.Raised) {
|
||||||
|
return <ToastRaised key={toast.key} toast={toast} state={state} />
|
||||||
|
}
|
||||||
|
return <Toast key={toast.key} toast={toast} state={state} />
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import useSound from 'use-sound'
|
||||||
|
|
||||||
|
// fixme - handle dynamic audio output changes
|
||||||
|
export const useNotificationSound = () => {
|
||||||
|
const [play] = useSound('./sounds/notifications.mp3', {
|
||||||
|
sprite: {
|
||||||
|
joined: [0, 1150],
|
||||||
|
raised: [1400, 180],
|
||||||
|
message: [1580, 300],
|
||||||
|
waiting: [2039, 710],
|
||||||
|
success: [2740, 1304],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const triggerNotificationSound = (type: string) => {
|
||||||
|
play({ id: type })
|
||||||
|
}
|
||||||
|
return { triggerNotificationSound }
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { styled } from '@/styled-system/jsx'
|
||||||
|
|
||||||
|
const StyledContainer = styled('div', {
|
||||||
|
base: {
|
||||||
|
width: '24px',
|
||||||
|
height: '24px',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
backgroundColor: 'primary',
|
||||||
|
borderRadius: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: '2px',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
pushToTalk: {
|
||||||
|
true: {
|
||||||
|
height: '46px',
|
||||||
|
width: '58px',
|
||||||
|
borderLeftRadius: 8,
|
||||||
|
borderRightRadius: 0,
|
||||||
|
backgroundColor: '#dbeafe',
|
||||||
|
border: '1px solid #3b82f6',
|
||||||
|
gap: '3px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const StyledChild = styled('div', {
|
||||||
|
base: {
|
||||||
|
backgroundColor: 'white',
|
||||||
|
width: '4px',
|
||||||
|
height: '4px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
animationDuration: '400ms',
|
||||||
|
animationName: 'active_speaker',
|
||||||
|
animationIterationCount: 'infinite',
|
||||||
|
animationDirection: 'alternate',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
active: {
|
||||||
|
true: {
|
||||||
|
animationIterationCount: 'infinite',
|
||||||
|
},
|
||||||
|
false: {
|
||||||
|
animationIterationCount: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
small: {
|
||||||
|
animationName: 'active_speaker_small',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pushToTalk: {
|
||||||
|
true: {
|
||||||
|
backgroundColor: 'primary',
|
||||||
|
width: '6px',
|
||||||
|
height: '6px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export type ActiveSpeakerProps = {
|
||||||
|
isSpeaking: boolean
|
||||||
|
pushToTalk?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActiveSpeaker = ({
|
||||||
|
isSpeaking,
|
||||||
|
pushToTalk,
|
||||||
|
}: ActiveSpeakerProps) => {
|
||||||
|
return (
|
||||||
|
<StyledContainer pushToTalk={pushToTalk}>
|
||||||
|
<StyledChild
|
||||||
|
pushToTalk={pushToTalk}
|
||||||
|
active={isSpeaking}
|
||||||
|
size="small"
|
||||||
|
style={{
|
||||||
|
animationDelay: '300ms',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<StyledChild
|
||||||
|
pushToTalk={pushToTalk}
|
||||||
|
active={isSpeaking}
|
||||||
|
style={{
|
||||||
|
animationDelay: '100ms',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<StyledChild
|
||||||
|
pushToTalk={pushToTalk}
|
||||||
|
active={isSpeaking}
|
||||||
|
size="small"
|
||||||
|
style={{
|
||||||
|
animationDelay: '500ms',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</StyledContainer>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import {
|
import { LiveKitRoom, type LocalUserChoices } from '@livekit/components-react'
|
||||||
formatChatMessageLinks,
|
|
||||||
LiveKitRoom,
|
|
||||||
type LocalUserChoices,
|
|
||||||
} from '@livekit/components-react'
|
|
||||||
import { Room, RoomOptions } from 'livekit-client'
|
import { Room, RoomOptions } from 'livekit-client'
|
||||||
import { keys } from '@/api/queryKeys'
|
import { keys } from '@/api/queryKeys'
|
||||||
import { queryClient } from '@/api/queryClient'
|
import { queryClient } from '@/api/queryClient'
|
||||||
import { navigateTo } from '@/navigation/navigateTo'
|
|
||||||
import { Screen } from '@/layout/Screen'
|
import { Screen } from '@/layout/Screen'
|
||||||
import { QueryAware } from '@/components/QueryAware'
|
import { QueryAware } from '@/components/QueryAware'
|
||||||
import { ErrorScreen } from '@/components/ErrorScreen'
|
import { ErrorScreen } from '@/components/ErrorScreen'
|
||||||
@@ -19,6 +14,7 @@ import { useCreateRoom } from '../api/createRoom'
|
|||||||
import { InviteDialog } from './InviteDialog'
|
import { InviteDialog } from './InviteDialog'
|
||||||
|
|
||||||
import { VideoConference } from '../livekit/prefabs/VideoConference'
|
import { VideoConference } from '../livekit/prefabs/VideoConference'
|
||||||
|
import posthog from 'posthog-js'
|
||||||
|
|
||||||
export const Conference = ({
|
export const Conference = ({
|
||||||
roomId,
|
roomId,
|
||||||
@@ -31,6 +27,9 @@ export const Conference = ({
|
|||||||
mode?: 'join' | 'create'
|
mode?: 'join' | 'create'
|
||||||
initialRoomData?: ApiRoom
|
initialRoomData?: ApiRoom
|
||||||
}) => {
|
}) => {
|
||||||
|
useEffect(() => {
|
||||||
|
posthog.capture('visit-room', { slug: roomId })
|
||||||
|
}, [roomId])
|
||||||
const fetchKey = [keys.room, roomId, userConfig.username]
|
const fetchKey = [keys.room, roomId, userConfig.username]
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -50,7 +49,6 @@ export const Conference = ({
|
|||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: fetchKey,
|
queryKey: fetchKey,
|
||||||
staleTime: 6 * 60 * 60 * 1000, // By default, LiveKit access tokens expire 6 hours after generation
|
staleTime: 6 * 60 * 60 * 1000, // By default, LiveKit access tokens expire 6 hours after generation
|
||||||
enabled: !initialRoomData,
|
|
||||||
initialData: initialRoomData,
|
initialData: initialRoomData,
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
fetchRoom({
|
fetchRoom({
|
||||||
@@ -80,25 +78,6 @@ export const Conference = ({
|
|||||||
|
|
||||||
const [showInviteDialog, setShowInviteDialog] = useState(mode === 'create')
|
const [showInviteDialog, setShowInviteDialog] = useState(mode === 'create')
|
||||||
|
|
||||||
/**
|
|
||||||
* checks for actual click on the leave button instead of
|
|
||||||
* relying on LiveKitRoom onDisconnected because onDisconnected
|
|
||||||
* triggers even on page reload, it's not a user "onLeave" event really.
|
|
||||||
* Here we want to react to the user actually deciding to leave.
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
const checkOnLeaveClick = (event: MouseEvent) => {
|
|
||||||
const target = event.target as HTMLElement
|
|
||||||
if (target.classList.contains('lk-disconnect-button')) {
|
|
||||||
navigateTo('feedback')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.body.addEventListener('click', checkOnLeaveClick)
|
|
||||||
return () => {
|
|
||||||
document.body.removeEventListener('click', checkOnLeaveClick)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms')
|
||||||
if (isCreateError) {
|
if (isCreateError) {
|
||||||
// this error screen should be replaced by a proper waiting room for anonymous user.
|
// this error screen should be replaced by a proper waiting room for anonymous user.
|
||||||
@@ -121,7 +100,7 @@ export const Conference = ({
|
|||||||
audio={userConfig.audioEnabled}
|
audio={userConfig.audioEnabled}
|
||||||
video={userConfig.videoEnabled}
|
video={userConfig.videoEnabled}
|
||||||
>
|
>
|
||||||
<VideoConference chatMessageFormatter={formatChatMessageLinks} />
|
<VideoConference />
|
||||||
{showInviteDialog && (
|
{showInviteDialog && (
|
||||||
<InviteDialog
|
<InviteDialog
|
||||||
isOpen={showInviteDialog}
|
isOpen={showInviteDialog}
|
||||||
|
|||||||
@@ -1,8 +1,37 @@
|
|||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { getRouteUrl } from '@/navigation/getRouteUrl'
|
import { getRouteUrl } from '@/navigation/getRouteUrl'
|
||||||
import { Div, Button, Dialog, Input, type DialogProps } from '@/primitives'
|
import { Div, Button, type DialogProps, P } from '@/primitives'
|
||||||
import { HStack } from '@/styled-system/jsx'
|
import { HStack, styled, VStack } from '@/styled-system/jsx'
|
||||||
|
import { Heading, Dialog } from 'react-aria-components'
|
||||||
|
import { Text, text } from '@/primitives/Text'
|
||||||
|
import {
|
||||||
|
RiCheckLine,
|
||||||
|
RiCloseLine,
|
||||||
|
RiFileCopyLine,
|
||||||
|
RiSpam2Fill,
|
||||||
|
} from '@remixicon/react'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
// fixme - extract in a proper primitive this dialog without overlay
|
||||||
|
const StyledRACDialog = styled(Dialog, {
|
||||||
|
base: {
|
||||||
|
position: 'fixed',
|
||||||
|
left: '0.75rem',
|
||||||
|
bottom: 80,
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
zIndex: 1000,
|
||||||
|
width: '24.5rem',
|
||||||
|
borderRadius: '8px',
|
||||||
|
padding: '1.5rem',
|
||||||
|
boxShadow:
|
||||||
|
'0 1px 2px 0 rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15)',
|
||||||
|
backgroundColor: 'white',
|
||||||
|
'&[data-entering]': { animation: 'fade 200ms' },
|
||||||
|
'&[data-exiting]': { animation: 'fade 150ms reverse ease-in' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export const InviteDialog = ({
|
export const InviteDialog = ({
|
||||||
roomId,
|
roomId,
|
||||||
@@ -11,48 +40,103 @@ export const InviteDialog = ({
|
|||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms')
|
||||||
const roomUrl = getRouteUrl('room', roomId)
|
const roomUrl = getRouteUrl('room', roomId)
|
||||||
|
|
||||||
const copyLabel = t('shareDialog.copy')
|
const [isCopied, setIsCopied] = useState(false)
|
||||||
const copiedLabel = t('shareDialog.copied')
|
|
||||||
const [copyLinkLabel, setCopyLinkLabel] = useState(copyLabel)
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (copyLinkLabel == copiedLabel) {
|
if (isCopied) {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => setIsCopied(false), 3000)
|
||||||
setCopyLinkLabel(copyLabel)
|
return () => clearTimeout(timeout)
|
||||||
}, 5000)
|
|
||||||
return () => {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [copyLinkLabel, copyLabel, copiedLabel])
|
}, [isCopied])
|
||||||
|
|
||||||
|
const [isHovered, setIsHovered] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog {...dialogProps} title={t('shareDialog.heading')}>
|
<StyledRACDialog {...dialogProps}>
|
||||||
<HStack alignItems="stretch" gap="gutter">
|
{({ close }) => (
|
||||||
<Div flex="1">
|
<VStack
|
||||||
<Input
|
alignItems="left"
|
||||||
type="text"
|
justify="start"
|
||||||
aria-label={t('shareDialog.inputLabel')}
|
gap={0}
|
||||||
value={roomUrl}
|
style={{ maxWidth: '100%', overflow: 'hidden' }}
|
||||||
readOnly
|
>
|
||||||
onClick={(e) => {
|
<Heading slot="title" level={3} className={text({ variant: 'h2' })}>
|
||||||
e.currentTarget.select()
|
{t('shareDialog.heading')}
|
||||||
}}
|
</Heading>
|
||||||
/>
|
<Div position="absolute" top="5" right="5">
|
||||||
</Div>
|
<Button
|
||||||
<Div minWidth="8rem">
|
invisible
|
||||||
|
size="xs"
|
||||||
|
onPress={() => {
|
||||||
|
dialogProps.onClose?.()
|
||||||
|
close()
|
||||||
|
}}
|
||||||
|
aria-label={t('closeDialog')}
|
||||||
|
>
|
||||||
|
<RiCloseLine />
|
||||||
|
</Button>
|
||||||
|
</Div>
|
||||||
|
<P>{t('shareDialog.description')}</P>
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant={isCopied ? 'success' : 'primary'}
|
||||||
size="sm"
|
size="sm"
|
||||||
fullWidth
|
fullWidth
|
||||||
|
aria-label={t('shareDialog.copy')}
|
||||||
|
style={{
|
||||||
|
justifyContent: 'start',
|
||||||
|
}}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
navigator.clipboard.writeText(roomUrl)
|
navigator.clipboard.writeText(roomUrl)
|
||||||
setCopyLinkLabel(copiedLabel)
|
setIsCopied(true)
|
||||||
}}
|
}}
|
||||||
|
onHoverChange={setIsHovered}
|
||||||
|
data-attr="share-dialog-copy"
|
||||||
>
|
>
|
||||||
{copyLinkLabel}
|
{isCopied ? (
|
||||||
|
<>
|
||||||
|
<RiCheckLine size={18} style={{ marginRight: '8px' }} />
|
||||||
|
{t('shareDialog.copied')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<RiFileCopyLine
|
||||||
|
size={18}
|
||||||
|
style={{ marginRight: '8px', minWidth: '18px' }}
|
||||||
|
/>
|
||||||
|
{isHovered ? (
|
||||||
|
t('shareDialog.copy')
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
overflow: 'hidden',
|
||||||
|
userSelect: 'none',
|
||||||
|
textWrap: 'nowrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{roomUrl.replace(/^https?:\/\//, '')}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</Div>
|
<HStack>
|
||||||
</HStack>
|
<div
|
||||||
</Dialog>
|
style={{
|
||||||
|
backgroundColor: '#d9e5ff',
|
||||||
|
borderRadius: '50%',
|
||||||
|
padding: '4px',
|
||||||
|
marginTop: '1rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RiSpam2Fill size={22} style={{ fill: '#4c84fc' }} />
|
||||||
|
</div>
|
||||||
|
<Text variant="sm" style={{ marginTop: '1rem' }}>
|
||||||
|
{t('shareDialog.permissions')}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
)}
|
||||||
|
</StyledRACDialog>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export const Join = ({
|
|||||||
<PreJoin
|
<PreJoin
|
||||||
persistUserChoices
|
persistUserChoices
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
micLabel={t('join.micLabel')}
|
micLabel={t('join.audioinput.label')}
|
||||||
camLabel={t('join.camlabel')}
|
camLabel={t('join.videoinput.label')}
|
||||||
joinLabel={t('join.joinLabel')}
|
joinLabel={t('join.joinLabel')}
|
||||||
userLabel={t('join.userLabel')}
|
userLabel={t('join.userLabel')}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { useRoomContext } from '@livekit/components-react'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { RoomEvent } from 'livekit-client'
|
||||||
|
import { egressStore } from '@/stores/egress.ts'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
|
||||||
|
export const RecordingIndicator = () => {
|
||||||
|
const room = useRoomContext()
|
||||||
|
const [isRecording, setIsRecording] = useState(room.isRecording)
|
||||||
|
|
||||||
|
const egressSnap = useSnapshot(egressStore)
|
||||||
|
const egressIsStopping = egressSnap.egressIsStopping
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleRecordingStatusChanges = (isRecording: boolean) => {
|
||||||
|
if (!isRecording) {
|
||||||
|
egressStore.egressIsStopping = false
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsRecording(isRecording)
|
||||||
|
}
|
||||||
|
room.on(RoomEvent.RecordingStatusChanged, handleRecordingStatusChanges)
|
||||||
|
return () => {
|
||||||
|
room.off(RoomEvent.RecordingStatusChanged, handleRecordingStatusChanges)
|
||||||
|
}
|
||||||
|
}, [room])
|
||||||
|
|
||||||
|
const getStatus = () => {
|
||||||
|
if (egressIsStopping) {
|
||||||
|
return 'saving recording'
|
||||||
|
}
|
||||||
|
if (isRecording) {
|
||||||
|
return 'recording'
|
||||||
|
}
|
||||||
|
if (!isRecording) {
|
||||||
|
return 'available'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexDirection: 'column',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Room status: {getStatus()}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export const buildServerApiUrl = (origin: string, path: string) => {
|
||||||
|
const sanitizedOrigin = origin.replace(/\/$/, '')
|
||||||
|
const sanitizedPath = path.replace(/^\//, '')
|
||||||
|
return `${sanitizedOrigin}/${sanitizedPath}`
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ApiError } from '@/api/ApiError'
|
||||||
|
|
||||||
|
export const fetchServerApi = async <T = Record<string, unknown>>(
|
||||||
|
url: string,
|
||||||
|
token: string,
|
||||||
|
options?: RequestInit
|
||||||
|
): Promise<T> => {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
...options,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
...options?.headers,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const result = await response.json()
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new ApiError(response.status, result)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { fetchServerApi } from './fetchServerApi'
|
||||||
|
import { buildServerApiUrl } from './buildServerApiUrl'
|
||||||
|
import { useRoomData } from '../hooks/useRoomData'
|
||||||
|
|
||||||
|
export const useLowerHandParticipant = () => {
|
||||||
|
const data = useRoomData()
|
||||||
|
|
||||||
|
const lowerHandParticipant = (participant: Participant) => {
|
||||||
|
if (!data || !data?.livekit) {
|
||||||
|
throw new Error('Room data is not available')
|
||||||
|
}
|
||||||
|
const newMetadata = JSON.parse(participant.metadata || '{}')
|
||||||
|
newMetadata.raised = !newMetadata.raised
|
||||||
|
return fetchServerApi(
|
||||||
|
buildServerApiUrl(
|
||||||
|
data.livekit.url,
|
||||||
|
'twirp/livekit.RoomService/UpdateParticipant'
|
||||||
|
),
|
||||||
|
data.livekit.token,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
room: data.livekit.room,
|
||||||
|
identity: participant.identity,
|
||||||
|
metadata: JSON.stringify(newMetadata),
|
||||||
|
permission: participant.permissions,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return { lowerHandParticipant }
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { useLowerHandParticipant } from '@/features/rooms/livekit/api/lowerHandParticipant'
|
||||||
|
|
||||||
|
export const useLowerHandParticipants = () => {
|
||||||
|
const { lowerHandParticipant } = useLowerHandParticipant()
|
||||||
|
|
||||||
|
const lowerHandParticipants = (participants: Array<Participant>) => {
|
||||||
|
try {
|
||||||
|
const promises = participants.map((participant) =>
|
||||||
|
lowerHandParticipant(participant)
|
||||||
|
)
|
||||||
|
return Promise.all(promises)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('An error occurred while lowering hands :', error)
|
||||||
|
throw new Error('An error occurred while lowering hands.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { lowerHandParticipants }
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Participant, Track } from 'livekit-client'
|
||||||
|
import Source = Track.Source
|
||||||
|
import { fetchServerApi } from './fetchServerApi'
|
||||||
|
import { buildServerApiUrl } from './buildServerApiUrl'
|
||||||
|
import { useRoomData } from '../hooks/useRoomData'
|
||||||
|
|
||||||
|
export const useMuteParticipant = () => {
|
||||||
|
const data = useRoomData()
|
||||||
|
|
||||||
|
const muteParticipant = (participant: Participant) => {
|
||||||
|
if (!data || !data?.livekit) {
|
||||||
|
throw new Error('Room data is not available')
|
||||||
|
}
|
||||||
|
const trackSid = participant.getTrackPublication(
|
||||||
|
Source.Microphone
|
||||||
|
)?.trackSid
|
||||||
|
|
||||||
|
if (!trackSid) {
|
||||||
|
throw new Error('Missing audio track')
|
||||||
|
}
|
||||||
|
return fetchServerApi(
|
||||||
|
buildServerApiUrl(
|
||||||
|
data.livekit.url,
|
||||||
|
'twirp/livekit.RoomService/MutePublishedTrack'
|
||||||
|
),
|
||||||
|
data.livekit.token,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
room: data.livekit.room,
|
||||||
|
identity: participant.identity,
|
||||||
|
muted: true,
|
||||||
|
track_sid: trackSid,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return { muteParticipant }
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { fetchServerApi } from './fetchServerApi'
|
||||||
|
import { buildServerApiUrl } from './buildServerApiUrl'
|
||||||
|
import { useRoomData } from '../hooks/useRoomData'
|
||||||
|
import { useParams } from 'wouter'
|
||||||
|
|
||||||
|
export const useRecordRoom = () => {
|
||||||
|
const data = useRoomData()
|
||||||
|
const { roomId: roomSlug } = useParams()
|
||||||
|
|
||||||
|
const recordRoom = () => {
|
||||||
|
if (!data || !data?.livekit) {
|
||||||
|
throw new Error('Room data is not available')
|
||||||
|
}
|
||||||
|
if (!roomSlug) {
|
||||||
|
throw new Error('Room ID is not available')
|
||||||
|
}
|
||||||
|
return fetchServerApi(
|
||||||
|
buildServerApiUrl(
|
||||||
|
data.livekit.url,
|
||||||
|
'/twirp/livekit.Egress/StartRoomCompositeEgress'
|
||||||
|
),
|
||||||
|
data.livekit.token,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
room_name: data.livekit.room,
|
||||||
|
audio_only: true,
|
||||||
|
file_outputs: [
|
||||||
|
{
|
||||||
|
file_extension: 'ogg',
|
||||||
|
filepath: `{room_name}_{time}_${roomSlug}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stopRecordingRoom = (egressId: string) => {
|
||||||
|
if (!data || !data?.livekit) {
|
||||||
|
throw new Error('Room data is not available')
|
||||||
|
}
|
||||||
|
return fetchServerApi(
|
||||||
|
buildServerApiUrl(data.livekit.url, '/twirp/livekit.Egress/StopEgress'),
|
||||||
|
data.livekit.token,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
egressId,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { recordRoom, stopRecordingRoom }
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { useLocalParticipant } from '@livekit/components-react'
|
||||||
|
import { LocalVideoTrack } from 'livekit-client'
|
||||||
|
import { Text, P, ToggleButton, Div, H } from '@/primitives'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { HStack, styled, VStack } from '@/styled-system/jsx'
|
||||||
|
import {
|
||||||
|
BackgroundBlur,
|
||||||
|
BackgroundOptions,
|
||||||
|
ProcessorWrapper,
|
||||||
|
BackgroundTransformer,
|
||||||
|
} from '@livekit/track-processors'
|
||||||
|
|
||||||
|
const Information = styled('div', {
|
||||||
|
base: {
|
||||||
|
backgroundColor: 'orange.50',
|
||||||
|
borderRadius: '4px',
|
||||||
|
padding: '0.75rem 0.75rem',
|
||||||
|
marginTop: '0.8rem',
|
||||||
|
alignItems: 'start',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
enum BlurRadius {
|
||||||
|
NONE = 0,
|
||||||
|
LIGHT = 5,
|
||||||
|
NORMAL = 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Effects = () => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'effects' })
|
||||||
|
const { isCameraEnabled, cameraTrack, localParticipant } =
|
||||||
|
useLocalParticipant()
|
||||||
|
const videoRef = useRef<HTMLVideoElement>(null)
|
||||||
|
const [processorPending, setProcessorPending] = useState(false)
|
||||||
|
|
||||||
|
const localCameraTrack = cameraTrack?.track as LocalVideoTrack
|
||||||
|
|
||||||
|
const getProcessor = () => {
|
||||||
|
return localCameraTrack?.getProcessor() as ProcessorWrapper<BackgroundOptions>
|
||||||
|
}
|
||||||
|
|
||||||
|
const getBlurRadius = (): BlurRadius => {
|
||||||
|
const processor = getProcessor()
|
||||||
|
return (
|
||||||
|
(processor?.transformer as BackgroundTransformer)?.options?.blurRadius ||
|
||||||
|
BlurRadius.NONE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleBlur = async (blurRadius: number) => {
|
||||||
|
if (!isCameraEnabled) await localParticipant.setCameraEnabled(true)
|
||||||
|
if (!localCameraTrack) return
|
||||||
|
|
||||||
|
setProcessorPending(true)
|
||||||
|
|
||||||
|
const processor = getProcessor()
|
||||||
|
const currentBlurRadius = getBlurRadius()
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (blurRadius == currentBlurRadius && processor) {
|
||||||
|
await localCameraTrack.stopProcessor()
|
||||||
|
} else if (!processor) {
|
||||||
|
await localCameraTrack.setProcessor(BackgroundBlur(blurRadius))
|
||||||
|
} else {
|
||||||
|
await processor?.updateTransformerOptions({ blurRadius })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error applying blur:', error)
|
||||||
|
} finally {
|
||||||
|
setProcessorPending(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const videoElement = videoRef.current
|
||||||
|
if (!videoElement) return
|
||||||
|
|
||||||
|
const attachVideoTrack = async () => localCameraTrack?.attach(videoElement)
|
||||||
|
attachVideoTrack()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (!videoElement) return
|
||||||
|
localCameraTrack.detach(videoElement)
|
||||||
|
}
|
||||||
|
}, [localCameraTrack, isCameraEnabled])
|
||||||
|
|
||||||
|
const isSelected = (blurRadius: BlurRadius) => {
|
||||||
|
return isCameraEnabled && getBlurRadius() == blurRadius
|
||||||
|
}
|
||||||
|
|
||||||
|
const tooltipLabel = (blurRadius: BlurRadius) => {
|
||||||
|
return t(`blur.${isSelected(blurRadius) ? 'clear' : 'apply'}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<VStack padding="0 1.5rem" overflowY="scroll">
|
||||||
|
{localCameraTrack && isCameraEnabled ? (
|
||||||
|
<video
|
||||||
|
ref={videoRef}
|
||||||
|
width="100%"
|
||||||
|
muted
|
||||||
|
style={{
|
||||||
|
transform: 'rotateY(180deg)',
|
||||||
|
minHeight: '175px',
|
||||||
|
borderRadius: '8px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '174px',
|
||||||
|
display: 'flex',
|
||||||
|
backgroundColor: 'black',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<P
|
||||||
|
style={{
|
||||||
|
color: 'white',
|
||||||
|
textAlign: 'center',
|
||||||
|
textWrap: 'balance',
|
||||||
|
marginBottom: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('activateCamera')}
|
||||||
|
</P>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Div
|
||||||
|
alignItems={'left'}
|
||||||
|
width={'100%'}
|
||||||
|
style={{
|
||||||
|
border: '1px solid #dadce0',
|
||||||
|
borderRadius: '8px',
|
||||||
|
margin: '0 .625rem',
|
||||||
|
padding: '0.5rem 1rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<H
|
||||||
|
lvl={3}
|
||||||
|
style={{
|
||||||
|
marginBottom: '0.4rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('heading')}
|
||||||
|
</H>
|
||||||
|
{ProcessorWrapper.isSupported ? (
|
||||||
|
<HStack>
|
||||||
|
<ToggleButton
|
||||||
|
size={'sm'}
|
||||||
|
legacyStyle
|
||||||
|
aria-label={tooltipLabel(BlurRadius.LIGHT)}
|
||||||
|
tooltip={tooltipLabel(BlurRadius.LIGHT)}
|
||||||
|
isDisabled={processorPending}
|
||||||
|
onPress={async () => await toggleBlur(BlurRadius.LIGHT)}
|
||||||
|
isSelected={isSelected(BlurRadius.LIGHT)}
|
||||||
|
>
|
||||||
|
{t('blur.light')}
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton
|
||||||
|
size={'sm'}
|
||||||
|
legacyStyle
|
||||||
|
aria-label={tooltipLabel(BlurRadius.NORMAL)}
|
||||||
|
tooltip={tooltipLabel(BlurRadius.NORMAL)}
|
||||||
|
isDisabled={processorPending}
|
||||||
|
onPress={async () => await toggleBlur(BlurRadius.NORMAL)}
|
||||||
|
isSelected={isSelected(BlurRadius.NORMAL)}
|
||||||
|
>
|
||||||
|
{t('blur.normal')}
|
||||||
|
</ToggleButton>
|
||||||
|
</HStack>
|
||||||
|
) : (
|
||||||
|
<Text variant="sm">{t('notAvailable')}</Text>
|
||||||
|
)}
|
||||||
|
<Information>
|
||||||
|
<Text
|
||||||
|
variant="sm"
|
||||||
|
style={{
|
||||||
|
textWrap: 'balance',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
⚠︎ {t('experimental')}
|
||||||
|
</Text>
|
||||||
|
</Information>
|
||||||
|
</Div>
|
||||||
|
</VStack>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { ParticipantTile } from './ParticipantTile'
|
||||||
|
import { FocusLayoutProps } from '@livekit/components-react'
|
||||||
|
|
||||||
|
export function FocusLayout({ trackRef, ...htmlProps }: FocusLayoutProps) {
|
||||||
|
return <ParticipantTile trackRef={trackRef} {...htmlProps} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useTrackMutedIndicator } from '@livekit/components-react'
|
||||||
|
import { Participant, Track } from 'livekit-client'
|
||||||
|
import Source = Track.Source
|
||||||
|
import { Div } from '@/primitives'
|
||||||
|
import { RiMicOffFill } from '@remixicon/react'
|
||||||
|
|
||||||
|
export const MutedMicIndicator = ({
|
||||||
|
participant,
|
||||||
|
}: {
|
||||||
|
participant: Participant
|
||||||
|
}) => {
|
||||||
|
const { isMuted } = useTrackMutedIndicator({
|
||||||
|
participant: participant,
|
||||||
|
source: Source.Microphone,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!isMuted) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Div padding={0.25} backgroundColor="red" borderRadius="4px">
|
||||||
|
<RiMicOffFill size={16} color="white" />
|
||||||
|
</Div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { styled } from '@/styled-system/jsx'
|
||||||
|
import { Avatar } from '@/components/Avatar'
|
||||||
|
import { useIsSpeaking } from '@livekit/components-react'
|
||||||
|
import { getParticipantColor } from '@/features/rooms/utils/getParticipantColor'
|
||||||
|
import { useSize } from '@/features/rooms/livekit/hooks/useResizeObserver'
|
||||||
|
import { useMemo, useRef } from 'react'
|
||||||
|
|
||||||
|
const StyledParticipantPlaceHolder = styled('div', {
|
||||||
|
base: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
backgroundColor: '#3d4043', // fixme - copied from gmeet
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type ParticipantPlaceholderProps = {
|
||||||
|
participant: Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ParticipantPlaceholder = ({
|
||||||
|
participant,
|
||||||
|
}: ParticipantPlaceholderProps) => {
|
||||||
|
const isSpeaking = useIsSpeaking(participant)
|
||||||
|
const participantColor = getParticipantColor(participant)
|
||||||
|
|
||||||
|
const placeholderEl = useRef<HTMLDivElement>(null)
|
||||||
|
const { width, height } = useSize(placeholderEl)
|
||||||
|
|
||||||
|
const minDimension = Math.min(width, height)
|
||||||
|
const avatarSize = useMemo(
|
||||||
|
() => Math.min(Math.round(minDimension * 0.9), 160),
|
||||||
|
[minDimension]
|
||||||
|
)
|
||||||
|
|
||||||
|
const initialSize = useMemo(() => Math.round(avatarSize * 0.3), [avatarSize])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledParticipantPlaceHolder ref={placeholderEl}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
borderRadius: '50%',
|
||||||
|
animation: isSpeaking ? 'pulse 1s infinite' : undefined,
|
||||||
|
height: 'auto',
|
||||||
|
aspectRatio: '1/1',
|
||||||
|
width: '80%',
|
||||||
|
maxWidth: `${avatarSize}px`,
|
||||||
|
fontSize: `${initialSize}px`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/*fixme - participant doesn't update on ParticipantNameChanged event */}
|
||||||
|
<Avatar
|
||||||
|
name={participant.name}
|
||||||
|
bgColor={participantColor}
|
||||||
|
context="placeholder"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</StyledParticipantPlaceHolder>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
import {
|
||||||
|
AudioTrack,
|
||||||
|
ConnectionQualityIndicator,
|
||||||
|
FocusToggle,
|
||||||
|
LockLockedIcon,
|
||||||
|
ParticipantName,
|
||||||
|
ParticipantTileProps,
|
||||||
|
ScreenShareIcon,
|
||||||
|
useEnsureTrackRef,
|
||||||
|
useFeatureContext,
|
||||||
|
useIsEncrypted,
|
||||||
|
useMaybeLayoutContext,
|
||||||
|
useMaybeTrackRefContext,
|
||||||
|
useParticipantTile,
|
||||||
|
VideoTrack,
|
||||||
|
TrackRefContext,
|
||||||
|
ParticipantContextIfNeeded,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import React from 'react'
|
||||||
|
import {
|
||||||
|
isTrackReference,
|
||||||
|
isTrackReferencePinned,
|
||||||
|
TrackReferenceOrPlaceholder,
|
||||||
|
} from '@livekit/components-core'
|
||||||
|
import { Track } from 'livekit-client'
|
||||||
|
import { ParticipantPlaceholder } from '@/features/rooms/livekit/components/ParticipantPlaceholder'
|
||||||
|
import { RiHand } from '@remixicon/react'
|
||||||
|
import { useRaisedHand } from '@/features/rooms/livekit/hooks/useRaisedHand'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { MutedMicIndicator } from '@/features/rooms/livekit/components/MutedMicIndicator'
|
||||||
|
|
||||||
|
export function TrackRefContextIfNeeded(
|
||||||
|
props: React.PropsWithChildren<{
|
||||||
|
trackRef?: TrackReferenceOrPlaceholder
|
||||||
|
}>
|
||||||
|
) {
|
||||||
|
const hasContext = !!useMaybeTrackRefContext()
|
||||||
|
return props.trackRef && !hasContext ? (
|
||||||
|
<TrackRefContext.Provider value={props.trackRef}>
|
||||||
|
{props.children}
|
||||||
|
</TrackRefContext.Provider>
|
||||||
|
) : (
|
||||||
|
<>{props.children}</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ParticipantTileExtendedProps extends ParticipantTileProps {
|
||||||
|
disableMetadata?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ParticipantTile: (
|
||||||
|
props: ParticipantTileExtendedProps & React.RefAttributes<HTMLDivElement>
|
||||||
|
) => React.ReactNode = /* @__PURE__ */ React.forwardRef<
|
||||||
|
HTMLDivElement,
|
||||||
|
ParticipantTileExtendedProps
|
||||||
|
>(function ParticipantTile(
|
||||||
|
{
|
||||||
|
trackRef,
|
||||||
|
children,
|
||||||
|
onParticipantClick,
|
||||||
|
disableSpeakingIndicator,
|
||||||
|
disableMetadata,
|
||||||
|
...htmlProps
|
||||||
|
}: ParticipantTileExtendedProps,
|
||||||
|
ref
|
||||||
|
) {
|
||||||
|
const trackReference = useEnsureTrackRef(trackRef)
|
||||||
|
|
||||||
|
const { elementProps } = useParticipantTile<HTMLDivElement>({
|
||||||
|
htmlProps,
|
||||||
|
disableSpeakingIndicator,
|
||||||
|
onParticipantClick,
|
||||||
|
trackRef: trackReference,
|
||||||
|
})
|
||||||
|
const isEncrypted = useIsEncrypted(trackReference.participant)
|
||||||
|
const layoutContext = useMaybeLayoutContext()
|
||||||
|
|
||||||
|
const autoManageSubscription = useFeatureContext()?.autoSubscription
|
||||||
|
|
||||||
|
const handleSubscribe = React.useCallback(
|
||||||
|
(subscribed: boolean) => {
|
||||||
|
if (
|
||||||
|
trackReference.source &&
|
||||||
|
!subscribed &&
|
||||||
|
layoutContext &&
|
||||||
|
layoutContext.pin.dispatch &&
|
||||||
|
isTrackReferencePinned(trackReference, layoutContext.pin.state)
|
||||||
|
) {
|
||||||
|
layoutContext.pin.dispatch({ msg: 'clear_pin' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[trackReference, layoutContext]
|
||||||
|
)
|
||||||
|
|
||||||
|
const { isHandRaised } = useRaisedHand({
|
||||||
|
participant: trackReference.participant,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={ref} style={{ position: 'relative' }} {...elementProps}>
|
||||||
|
<TrackRefContextIfNeeded trackRef={trackReference}>
|
||||||
|
<ParticipantContextIfNeeded participant={trackReference.participant}>
|
||||||
|
{children ?? (
|
||||||
|
<>
|
||||||
|
{isTrackReference(trackReference) &&
|
||||||
|
(trackReference.publication?.kind === 'video' ||
|
||||||
|
trackReference.source === Track.Source.Camera ||
|
||||||
|
trackReference.source === Track.Source.ScreenShare) ? (
|
||||||
|
<VideoTrack
|
||||||
|
trackRef={trackReference}
|
||||||
|
onSubscriptionStatusChanged={handleSubscribe}
|
||||||
|
manageSubscription={autoManageSubscription}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
isTrackReference(trackReference) && (
|
||||||
|
<AudioTrack
|
||||||
|
trackRef={trackReference}
|
||||||
|
onSubscriptionStatusChanged={handleSubscribe}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
<div className="lk-participant-placeholder">
|
||||||
|
<ParticipantPlaceholder
|
||||||
|
participant={trackReference.participant}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{!disableMetadata && (
|
||||||
|
<div className="lk-participant-metadata">
|
||||||
|
<HStack gap={0.25}>
|
||||||
|
<MutedMicIndicator
|
||||||
|
participant={trackReference.participant}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="lk-participant-metadata-item"
|
||||||
|
style={{
|
||||||
|
minHeight: '24px',
|
||||||
|
backgroundColor: isHandRaised ? 'white' : undefined,
|
||||||
|
color: isHandRaised ? 'black' : undefined,
|
||||||
|
transition: 'background 200ms ease, color 400ms ease',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{trackReference.source === Track.Source.Camera ? (
|
||||||
|
<>
|
||||||
|
{isHandRaised && (
|
||||||
|
<RiHand
|
||||||
|
color="black"
|
||||||
|
size={16}
|
||||||
|
style={{
|
||||||
|
marginInlineEnd: '.25rem', // fixme - match TrackMutedIndicator styling
|
||||||
|
animationDuration: '300ms',
|
||||||
|
animationName: 'wave_hand',
|
||||||
|
animationIterationCount: '2',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{isEncrypted && (
|
||||||
|
<LockLockedIcon
|
||||||
|
style={{ marginRight: '0.25rem' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<ParticipantName />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ScreenShareIcon style={{ marginRight: '0.25rem' }} />
|
||||||
|
<ParticipantName>'s screen</ParticipantName>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</HStack>
|
||||||
|
<ConnectionQualityIndicator className="lk-participant-metadata-item" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!disableMetadata && <FocusToggle trackRef={trackReference} />}
|
||||||
|
</ParticipantContextIfNeeded>
|
||||||
|
</TrackRefContextIfNeeded>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
import { layoutStore } from '@/stores/layout'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { Heading } from 'react-aria-components'
|
||||||
|
import { text } from '@/primitives/Text'
|
||||||
|
import { Box, Button, Div } from '@/primitives'
|
||||||
|
import { RiCloseLine } from '@remixicon/react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { ParticipantsList } from './controls/Participants/ParticipantsList'
|
||||||
|
import { useSidePanel } from '../hooks/useSidePanel'
|
||||||
|
import { ReactNode } from 'react'
|
||||||
|
import { Effects } from './Effects'
|
||||||
|
import { Chat } from '../prefabs/Chat'
|
||||||
|
|
||||||
|
type StyledSidePanelProps = {
|
||||||
|
title: string
|
||||||
|
children: ReactNode
|
||||||
|
onClose: () => void
|
||||||
|
isClosed: boolean
|
||||||
|
closeButtonTooltip: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledSidePanel = ({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
onClose,
|
||||||
|
isClosed,
|
||||||
|
closeButtonTooltip,
|
||||||
|
}: StyledSidePanelProps) => (
|
||||||
|
<Box
|
||||||
|
size="sm"
|
||||||
|
className={css({
|
||||||
|
overflow: 'hidden',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
margin: '1.5rem 1.5rem 1.5rem 0',
|
||||||
|
padding: 0,
|
||||||
|
gap: 0,
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
bottom: '80px',
|
||||||
|
width: '360px',
|
||||||
|
position: 'absolute',
|
||||||
|
transition: '.5s cubic-bezier(.4,0,.2,1) 5ms',
|
||||||
|
})}
|
||||||
|
style={{
|
||||||
|
transform: isClosed ? 'translateX(calc(360px + 1.5rem))' : 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Heading
|
||||||
|
slot="title"
|
||||||
|
level={1}
|
||||||
|
className={text({ variant: 'h2' })}
|
||||||
|
style={{
|
||||||
|
paddingLeft: '1.5rem',
|
||||||
|
paddingTop: '1rem',
|
||||||
|
display: isClosed ? 'none' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Heading>
|
||||||
|
<Div
|
||||||
|
position="absolute"
|
||||||
|
top="5"
|
||||||
|
right="5"
|
||||||
|
style={{
|
||||||
|
display: isClosed ? 'none' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
invisible
|
||||||
|
size="xs"
|
||||||
|
onPress={onClose}
|
||||||
|
aria-label={closeButtonTooltip}
|
||||||
|
tooltip={closeButtonTooltip}
|
||||||
|
>
|
||||||
|
<RiCloseLine />
|
||||||
|
</Button>
|
||||||
|
</Div>
|
||||||
|
{children}
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
|
||||||
|
type PanelProps = {
|
||||||
|
isOpen: boolean
|
||||||
|
children: React.ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
const Panel = ({ isOpen, children }: PanelProps) => (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: isOpen ? 'inherit' : 'none',
|
||||||
|
flexDirection: 'column',
|
||||||
|
overflow: 'hidden',
|
||||||
|
flexGrow: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const SidePanel = () => {
|
||||||
|
const {
|
||||||
|
activePanelId,
|
||||||
|
isParticipantsOpen,
|
||||||
|
isEffectsOpen,
|
||||||
|
isChatOpen,
|
||||||
|
isSidePanelOpen,
|
||||||
|
} = useSidePanel()
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'sidePanel' })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledSidePanel
|
||||||
|
title={t(`heading.${activePanelId}`)}
|
||||||
|
onClose={() => (layoutStore.activePanelId = null)}
|
||||||
|
closeButtonTooltip={t('closeButton', {
|
||||||
|
content: t(`content.${activePanelId}`),
|
||||||
|
})}
|
||||||
|
isClosed={!isSidePanelOpen}
|
||||||
|
>
|
||||||
|
<Panel isOpen={isParticipantsOpen}>
|
||||||
|
<ParticipantsList />
|
||||||
|
</Panel>
|
||||||
|
<Panel isOpen={isEffectsOpen}>
|
||||||
|
<Effects />
|
||||||
|
</Panel>
|
||||||
|
<Panel isOpen={isChatOpen}>
|
||||||
|
<Chat />
|
||||||
|
</Panel>
|
||||||
|
</StyledSidePanel>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import type { ReceivedChatMessage } from '@livekit/components-core'
|
||||||
|
import * as React from 'react'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { Text } from '@/primitives'
|
||||||
|
import { MessageFormatter } from '@livekit/components-react'
|
||||||
|
|
||||||
|
export interface ChatEntryProps extends React.HTMLAttributes<HTMLLIElement> {
|
||||||
|
entry: ReceivedChatMessage
|
||||||
|
hideMetadata?: boolean
|
||||||
|
messageFormatter?: MessageFormatter
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ChatEntry: (
|
||||||
|
props: ChatEntryProps & React.RefAttributes<HTMLLIElement>
|
||||||
|
) => React.ReactNode = /* @__PURE__ */ React.forwardRef<
|
||||||
|
HTMLLIElement,
|
||||||
|
ChatEntryProps
|
||||||
|
>(function ChatEntry(
|
||||||
|
{ entry, hideMetadata = false, messageFormatter, ...props }: ChatEntryProps,
|
||||||
|
ref
|
||||||
|
) {
|
||||||
|
// Fixme - Livekit messageFormatter strips '\n' char
|
||||||
|
const formattedMessage = React.useMemo(() => {
|
||||||
|
return messageFormatter ? messageFormatter(entry.message) : entry.message
|
||||||
|
}, [entry.message, messageFormatter])
|
||||||
|
const time = new Date(entry.timestamp)
|
||||||
|
const locale = navigator ? navigator.language : 'en-US'
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
className={css({
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '0.25rem',
|
||||||
|
})}
|
||||||
|
ref={ref}
|
||||||
|
title={time.toLocaleTimeString(locale, { timeStyle: 'full' })}
|
||||||
|
data-lk-message-origin={entry.from?.isLocal ? 'local' : 'remote'}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{!hideMetadata && (
|
||||||
|
<span
|
||||||
|
className={css({
|
||||||
|
display: 'flex',
|
||||||
|
gap: '0.5rem',
|
||||||
|
paddingTop: '0.75rem',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text bold={true} variant="sm">
|
||||||
|
{entry.from?.name ?? entry.from?.identity}
|
||||||
|
</Text>
|
||||||
|
<Text variant="sm" className={css({ color: 'gray.700' })}>
|
||||||
|
{time.toLocaleTimeString(locale, { timeStyle: 'short' })}
|
||||||
|
</Text>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<Text
|
||||||
|
variant="sm"
|
||||||
|
margin={false}
|
||||||
|
className={css({
|
||||||
|
'& .lk-chat-link': {
|
||||||
|
color: 'blue',
|
||||||
|
textDecoration: 'underline',
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{formattedMessage}
|
||||||
|
</Text>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import { Button } from '@/primitives'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { RiSendPlane2Fill } from '@remixicon/react'
|
||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { TextArea } from '@/primitives/TextArea'
|
||||||
|
import { RefObject } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
|
const MAX_ROWS = 6
|
||||||
|
|
||||||
|
interface ChatInputProps {
|
||||||
|
inputRef: RefObject<HTMLTextAreaElement>
|
||||||
|
onSubmit: (text: string) => void
|
||||||
|
isSending: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ChatInput = ({
|
||||||
|
inputRef,
|
||||||
|
onSubmit,
|
||||||
|
isSending,
|
||||||
|
}: ChatInputProps) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls.chat.input' })
|
||||||
|
const [text, setText] = useState('')
|
||||||
|
const [rows, setRows] = useState(1)
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
onSubmit(text)
|
||||||
|
setText('')
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDisabled = !text.trim() || isSending
|
||||||
|
|
||||||
|
const submitOnEnter = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
if (e.key !== 'Enter' || (e.key === 'Enter' && e.shiftKey)) return
|
||||||
|
e.preventDefault()
|
||||||
|
if (!isDisabled) handleSubmit()
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const resize = () => {
|
||||||
|
if (!inputRef.current) return
|
||||||
|
|
||||||
|
const textAreaLineHeight = 20 // Adjust this value based on your TextArea's line height
|
||||||
|
const previousRows = inputRef.current.rows
|
||||||
|
inputRef.current.rows = 1
|
||||||
|
|
||||||
|
const currentRows = Math.floor(
|
||||||
|
inputRef.current.scrollHeight / textAreaLineHeight
|
||||||
|
)
|
||||||
|
|
||||||
|
if (currentRows === previousRows) {
|
||||||
|
inputRef.current.rows = currentRows
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentRows >= MAX_ROWS) {
|
||||||
|
inputRef.current.rows = MAX_ROWS
|
||||||
|
inputRef.current.scrollTop = inputRef.current.scrollHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentRows < MAX_ROWS) {
|
||||||
|
inputRef.current.style.overflowY = 'hidden'
|
||||||
|
} else {
|
||||||
|
inputRef.current.style.overflowY = 'auto'
|
||||||
|
}
|
||||||
|
|
||||||
|
setRows(currentRows < MAX_ROWS ? currentRows : MAX_ROWS)
|
||||||
|
}
|
||||||
|
|
||||||
|
resize()
|
||||||
|
}, [text, inputRef])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HStack
|
||||||
|
style={{
|
||||||
|
margin: '0.75rem 0 1.5rem',
|
||||||
|
padding: '0.5rem',
|
||||||
|
backgroundColor: '#f3f4f6',
|
||||||
|
borderRadius: 4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextArea
|
||||||
|
ref={inputRef}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
submitOnEnter(e)
|
||||||
|
}}
|
||||||
|
onKeyUp={(e) => e.stopPropagation()}
|
||||||
|
placeholder={t('textArea.placeholder')}
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => {
|
||||||
|
setText(e.target.value)
|
||||||
|
}}
|
||||||
|
rows={rows || 1}
|
||||||
|
style={{
|
||||||
|
border: 'none',
|
||||||
|
resize: 'none',
|
||||||
|
height: 'auto',
|
||||||
|
minHeight: `34px`,
|
||||||
|
lineHeight: 1.25,
|
||||||
|
padding: '7px 10px',
|
||||||
|
overflowY: 'hidden',
|
||||||
|
}}
|
||||||
|
placeholderStyle={'strong'}
|
||||||
|
spellCheck={false}
|
||||||
|
maxLength={500}
|
||||||
|
aria-label={t('textArea.label')}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
square
|
||||||
|
invisible
|
||||||
|
size="sm"
|
||||||
|
onPress={handleSubmit}
|
||||||
|
isDisabled={isDisabled}
|
||||||
|
aria-label={t('button.label')}
|
||||||
|
>
|
||||||
|
<RiSendPlane2Fill />
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiChat1Line } from '@remixicon/react'
|
import { RiChat1Line } from '@remixicon/react'
|
||||||
import { Button } from '@/primitives'
|
|
||||||
import { css } from '@/styled-system/css'
|
|
||||||
import { useLayoutContext } from '@livekit/components-react'
|
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSnapshot } from 'valtio'
|
||||||
import { participantsStore } from '@/stores/participants'
|
import { css } from '@/styled-system/css'
|
||||||
|
import { ToggleButton } from '@/primitives'
|
||||||
|
import { chatStore } from '@/stores/chat'
|
||||||
|
import { useSidePanel } from '../../hooks/useSidePanel'
|
||||||
|
|
||||||
export const ChatToggle = () => {
|
export const ChatToggle = () => {
|
||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls.chat' })
|
||||||
|
|
||||||
const { dispatch, state } = useLayoutContext().widget
|
const chatSnap = useSnapshot(chatStore)
|
||||||
const tooltipLabel = state?.showChat ? 'open' : 'closed'
|
|
||||||
|
|
||||||
const participantsSnap = useSnapshot(participantsStore)
|
const { isChatOpen, toggleChat } = useSidePanel()
|
||||||
const showParticipants = participantsSnap.showParticipants
|
const tooltipLabel = isChatOpen ? 'open' : 'closed'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -22,21 +21,18 @@ export const ChatToggle = () => {
|
|||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Button
|
<ToggleButton
|
||||||
toggle
|
|
||||||
square
|
square
|
||||||
legacyStyle
|
legacyStyle
|
||||||
aria-label={t(`controls.chat.${tooltipLabel}`)}
|
aria-label={t(tooltipLabel)}
|
||||||
tooltip={t(`controls.chat.${tooltipLabel}`)}
|
tooltip={t(tooltipLabel)}
|
||||||
isSelected={state?.showChat}
|
isSelected={isChatOpen}
|
||||||
onPress={() => {
|
onPress={() => toggleChat()}
|
||||||
if (showParticipants) participantsStore.showParticipants = false
|
data-attr={`controls-chat-${tooltipLabel}`}
|
||||||
if (dispatch) dispatch({ msg: 'toggle_chat' })
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<RiChat1Line />
|
<RiChat1Line />
|
||||||
</Button>
|
</ToggleButton>
|
||||||
{!!state?.unreadMessages && (
|
{!!chatSnap.unreadMessages && (
|
||||||
<div
|
<div
|
||||||
className={css({
|
className={css({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { RiHand } from '@remixicon/react'
|
||||||
|
import { ToggleButton } from '@/primitives'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { useRoomContext } from '@livekit/components-react'
|
||||||
|
import { useRaisedHand } from '@/features/rooms/livekit/hooks/useRaisedHand'
|
||||||
|
|
||||||
|
export const HandToggle = () => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls.hand' })
|
||||||
|
|
||||||
|
const room = useRoomContext()
|
||||||
|
const { isHandRaised, toggleRaisedHand } = useRaisedHand({
|
||||||
|
participant: room.localParticipant,
|
||||||
|
})
|
||||||
|
|
||||||
|
const tooltipLabel = isHandRaised ? 'lower' : 'raise'
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={css({
|
||||||
|
position: 'relative',
|
||||||
|
display: 'inline-block',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<ToggleButton
|
||||||
|
square
|
||||||
|
legacyStyle
|
||||||
|
aria-label={t(tooltipLabel)}
|
||||||
|
tooltip={t(tooltipLabel)}
|
||||||
|
isSelected={isHandRaised}
|
||||||
|
onPress={() => toggleRaisedHand()}
|
||||||
|
data-attr={`controls-hand-${tooltipLabel}`}
|
||||||
|
>
|
||||||
|
<RiHand />
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { useConnectionState, useRoomContext } from '@livekit/components-react'
|
||||||
|
import { Button } from '@/primitives'
|
||||||
|
import { navigateTo } from '@/navigation/navigateTo'
|
||||||
|
import { RiPhoneFill } from '@remixicon/react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { ConnectionState } from 'livekit-client'
|
||||||
|
|
||||||
|
export const LeaveButton = () => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls' })
|
||||||
|
const room = useRoomContext()
|
||||||
|
const connectionState = useConnectionState(room)
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
isDisabled={connectionState === ConnectionState.Disconnected}
|
||||||
|
variant={'danger'}
|
||||||
|
tooltip={t('leave')}
|
||||||
|
aria-label={t('leave')}
|
||||||
|
onPress={() => {
|
||||||
|
room
|
||||||
|
.disconnect(true)
|
||||||
|
.catch((e) =>
|
||||||
|
console.error('An error occurred while disconnecting:', e)
|
||||||
|
)
|
||||||
|
.finally(() => {
|
||||||
|
navigateTo('feedback')
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
data-attr="controls-leave"
|
||||||
|
>
|
||||||
|
<RiPhoneFill
|
||||||
|
style={{
|
||||||
|
transform: 'rotate(135deg)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
+25
-14
@@ -1,22 +1,33 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiMore2Line } from '@remixicon/react'
|
import { RiMore2Line } from '@remixicon/react'
|
||||||
import { Button } from '@/primitives'
|
import { Button, Menu } from '@/primitives'
|
||||||
import { OptionsMenu } from '@/features/rooms/livekit/components/controls/Options/OptionsMenu.tsx'
|
|
||||||
import { MenuTrigger } from 'react-aria-components'
|
import { useState } from 'react'
|
||||||
|
import { OptionsMenuItems } from '@/features/rooms/livekit/components/controls/Options/OptionsMenuItems'
|
||||||
|
import { SettingsDialogExtended } from '@/features/settings/components/SettingsDialogExtended'
|
||||||
|
|
||||||
|
export type DialogState = 'username' | 'settings' | null
|
||||||
|
|
||||||
export const OptionsButton = () => {
|
export const OptionsButton = () => {
|
||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms')
|
||||||
|
const [dialogOpen, setDialogOpen] = useState<DialogState>(null)
|
||||||
return (
|
return (
|
||||||
<MenuTrigger>
|
<>
|
||||||
<Button
|
<Menu>
|
||||||
square
|
<Button
|
||||||
legacyStyle
|
square
|
||||||
aria-label={t('options.buttonLabel')}
|
legacyStyle
|
||||||
tooltip={t('options.buttonLabel')}
|
aria-label={t('options.buttonLabel')}
|
||||||
>
|
tooltip={t('options.buttonLabel')}
|
||||||
<RiMore2Line />
|
>
|
||||||
</Button>
|
<RiMore2Line />
|
||||||
<OptionsMenu />
|
</Button>
|
||||||
</MenuTrigger>
|
<OptionsMenuItems onOpenDialog={setDialogOpen} />
|
||||||
|
</Menu>
|
||||||
|
<SettingsDialogExtended
|
||||||
|
isOpen={dialogOpen === 'settings'}
|
||||||
|
onOpenChange={(v) => !v && setDialogOpen(null)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import {
|
|
||||||
RiFeedbackLine,
|
|
||||||
RiQuestionLine,
|
|
||||||
RiSettings3Line,
|
|
||||||
RiUser5Line,
|
|
||||||
} from '@remixicon/react'
|
|
||||||
import { useState } from 'react'
|
|
||||||
import { styled } from '@/styled-system/jsx'
|
|
||||||
import {
|
|
||||||
Menu as RACMenu,
|
|
||||||
MenuItem as RACMenuItem,
|
|
||||||
Popover as RACPopover,
|
|
||||||
Separator as RACSeparator,
|
|
||||||
} from 'react-aria-components'
|
|
||||||
import { SettingsDialog } from '@/features/settings'
|
|
||||||
import { UsernameDialog } from '../../dialogs/UsernameDialog'
|
|
||||||
|
|
||||||
// Styled components to be refactored
|
|
||||||
const StyledMenu = styled(RACMenu, {
|
|
||||||
base: {
|
|
||||||
maxHeight: 'inherit',
|
|
||||||
boxSizing: 'border-box',
|
|
||||||
overflow: 'auto',
|
|
||||||
padding: '2px',
|
|
||||||
minWidth: '150px',
|
|
||||||
outline: 'none',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const StyledMenuItem = styled(RACMenuItem, {
|
|
||||||
base: {
|
|
||||||
margin: '2px',
|
|
||||||
padding: '0.286rem 0.571rem',
|
|
||||||
borderRadius: '6px',
|
|
||||||
outline: 'none',
|
|
||||||
cursor: 'default',
|
|
||||||
color: 'black',
|
|
||||||
fontSize: '1.072rem',
|
|
||||||
position: 'relative',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '20px',
|
|
||||||
forcedColorAdjust: 'none',
|
|
||||||
'&[data-focused]': {
|
|
||||||
color: 'primary.text',
|
|
||||||
backgroundColor: 'primary',
|
|
||||||
outline: 'none!',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const StyledPopover = styled(RACPopover, {
|
|
||||||
base: {
|
|
||||||
border: '1px solid #9ca3af',
|
|
||||||
boxShadow: '0 8px 20px rgba(0, 0, 0, 0.1)',
|
|
||||||
borderRadius: '4px',
|
|
||||||
background: 'white',
|
|
||||||
color: 'var(--text-color)',
|
|
||||||
outline: 'none',
|
|
||||||
minWidth: '112px',
|
|
||||||
width: '300px',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const StyledSeparator = styled(RACSeparator, {
|
|
||||||
base: {
|
|
||||||
height: '1px',
|
|
||||||
background: '#9ca3af',
|
|
||||||
margin: '2px 4px',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
type DialogState = 'username' | 'settings' | null
|
|
||||||
|
|
||||||
export const OptionsMenu = () => {
|
|
||||||
const { t } = useTranslation('rooms')
|
|
||||||
const [dialogOpen, setDialogOpen] = useState<DialogState>(null)
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<StyledPopover>
|
|
||||||
<StyledMenu>
|
|
||||||
<StyledMenuItem onAction={() => setDialogOpen('username')}>
|
|
||||||
<RiUser5Line size={18} />
|
|
||||||
{t('options.items.username')}
|
|
||||||
</StyledMenuItem>
|
|
||||||
<StyledSeparator />
|
|
||||||
<StyledMenuItem
|
|
||||||
href="https://tchap.gouv.fr/#/room/!aGImQayAgBLjSBycpm:agent.dinum.tchap.gouv.fr?via=agent.dinum.tchap.gouv.fr"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<RiQuestionLine size={18} />
|
|
||||||
{t('options.items.support')}
|
|
||||||
</StyledMenuItem>
|
|
||||||
<StyledMenuItem
|
|
||||||
href="https://grist.incubateur.net/o/docs/forms/1YrfNP1QSSy8p2gCxMFnSf/4"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<RiFeedbackLine size={18} />
|
|
||||||
{t('options.items.feedbacks')}
|
|
||||||
</StyledMenuItem>
|
|
||||||
<StyledMenuItem onAction={() => setDialogOpen('settings')}>
|
|
||||||
<RiSettings3Line size={18} />
|
|
||||||
{t('options.items.settings')}
|
|
||||||
</StyledMenuItem>
|
|
||||||
</StyledMenu>
|
|
||||||
</StyledPopover>
|
|
||||||
<UsernameDialog
|
|
||||||
isOpen={dialogOpen === 'username'}
|
|
||||||
onOpenChange={(v) => !v && setDialogOpen(null)}
|
|
||||||
/>
|
|
||||||
<SettingsDialog
|
|
||||||
isOpen={dialogOpen === 'settings'}
|
|
||||||
onOpenChange={(v) => !v && setDialogOpen(null)}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
import { menuItemRecipe } from '@/primitives/menuItemRecipe'
|
||||||
|
import {
|
||||||
|
RiAccountBoxLine,
|
||||||
|
RiMegaphoneLine,
|
||||||
|
RiSettings3Line,
|
||||||
|
} from '@remixicon/react'
|
||||||
|
import { MenuItem, Menu as RACMenu, Section } from 'react-aria-components'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Dispatch, SetStateAction } from 'react'
|
||||||
|
import { DialogState } from './OptionsButton'
|
||||||
|
import { Separator } from '@/primitives/Separator'
|
||||||
|
import { useSidePanel } from '../../../hooks/useSidePanel'
|
||||||
|
import { RecordingMenuItem } from '@/features/rooms/livekit/components/controls/Options/RecordingMenuItem'
|
||||||
|
|
||||||
|
// @todo try refactoring it to use MenuList component
|
||||||
|
export const OptionsMenuItems = ({
|
||||||
|
onOpenDialog,
|
||||||
|
}: {
|
||||||
|
onOpenDialog: Dispatch<SetStateAction<DialogState>>
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'options.items' })
|
||||||
|
const { toggleEffects } = useSidePanel()
|
||||||
|
return (
|
||||||
|
<RACMenu
|
||||||
|
style={{
|
||||||
|
minWidth: '150px',
|
||||||
|
width: '300px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Section>
|
||||||
|
<MenuItem
|
||||||
|
onAction={() => toggleEffects()}
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
>
|
||||||
|
<RiAccountBoxLine size={20} />
|
||||||
|
{t('effects')}
|
||||||
|
</MenuItem>
|
||||||
|
<RecordingMenuItem />
|
||||||
|
</Section>
|
||||||
|
<Separator />
|
||||||
|
<Section>
|
||||||
|
<MenuItem
|
||||||
|
href="https://grist.incubateur.net/o/docs/forms/1YrfNP1QSSy8p2gCxMFnSf/4"
|
||||||
|
target="_blank"
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
>
|
||||||
|
<RiMegaphoneLine size={20} />
|
||||||
|
{t('feedbacks')}
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
onAction={() => onOpenDialog('settings')}
|
||||||
|
>
|
||||||
|
<RiSettings3Line size={20} />
|
||||||
|
{t('settings')}
|
||||||
|
</MenuItem>
|
||||||
|
</Section>
|
||||||
|
</RACMenu>
|
||||||
|
)
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
import { MenuItem } from 'react-aria-components'
|
||||||
|
import { menuItemRecipe } from '@/primitives/menuItemRecipe.ts'
|
||||||
|
import { RiPauseCircleLine, RiRecordCircleLine } from '@remixicon/react'
|
||||||
|
import { useRecordRoom } from '@/features/rooms/livekit/api/recordRoom.ts'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { egressStore } from '@/stores/egress.ts'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
|
||||||
|
export const RecordingMenuItem = () => {
|
||||||
|
const { recordRoom, stopRecordingRoom } = useRecordRoom()
|
||||||
|
|
||||||
|
const egressSnap = useSnapshot(egressStore)
|
||||||
|
const egressId = egressSnap.egressId
|
||||||
|
|
||||||
|
const [isPending, setIsPending] = useState(false)
|
||||||
|
|
||||||
|
const handleAction = async () => {
|
||||||
|
if (egressId) {
|
||||||
|
setIsPending(true)
|
||||||
|
egressStore.egressIsStopping = true
|
||||||
|
const response = await stopRecordingRoom(egressId)
|
||||||
|
console.log(response)
|
||||||
|
egressStore.egressId = undefined
|
||||||
|
setIsPending(false)
|
||||||
|
} else {
|
||||||
|
setIsPending(true)
|
||||||
|
const response = await recordRoom()
|
||||||
|
egressStore.egressId = response['egress_id'] as string
|
||||||
|
setIsPending(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MenuItem
|
||||||
|
isDisabled={isPending}
|
||||||
|
className={menuItemRecipe({ icon: true })}
|
||||||
|
onAction={handleAction}
|
||||||
|
>
|
||||||
|
{egressId ? (
|
||||||
|
<>
|
||||||
|
<RiPauseCircleLine size={18} />
|
||||||
|
Arrêter l'enregistrement
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<RiRecordCircleLine size={18} />
|
||||||
|
Enregistrer la réunion
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</MenuItem>
|
||||||
|
)
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { Text } from '@/primitives/Text'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Avatar } from '@/components/Avatar'
|
||||||
|
import { getParticipantColor } from '@/features/rooms/utils/getParticipantColor'
|
||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { isLocal } from '@/utils/livekit'
|
||||||
|
import { RiHand } from '@remixicon/react'
|
||||||
|
import { useLowerHandParticipant } from '@/features/rooms/livekit/api/lowerHandParticipant.ts'
|
||||||
|
import { Button } from '@/primitives'
|
||||||
|
|
||||||
|
type HandRaisedListItemProps = {
|
||||||
|
participant: Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
export const HandRaisedListItem = ({
|
||||||
|
participant,
|
||||||
|
}: HandRaisedListItemProps) => {
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
const name = participant.name || participant.identity
|
||||||
|
|
||||||
|
const { lowerHandParticipant } = useLowerHandParticipant()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HStack
|
||||||
|
role="listitem"
|
||||||
|
justify="space-between"
|
||||||
|
key={participant.identity}
|
||||||
|
id={participant.identity}
|
||||||
|
className={css({
|
||||||
|
padding: '0.25rem 0',
|
||||||
|
width: 'full',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<HStack>
|
||||||
|
<Avatar name={name} bgColor={getParticipantColor(participant)} />
|
||||||
|
<Text
|
||||||
|
variant={'sm'}
|
||||||
|
className={css({
|
||||||
|
userSelect: 'none',
|
||||||
|
cursor: 'default',
|
||||||
|
display: 'flex',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={css({
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
maxWidth: '120px',
|
||||||
|
display: 'block',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
{isLocal(participant) && (
|
||||||
|
<span
|
||||||
|
className={css({
|
||||||
|
marginLeft: '.25rem',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
({t('participants.you')})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<Button
|
||||||
|
square
|
||||||
|
invisible
|
||||||
|
size="sm"
|
||||||
|
onPress={() => lowerHandParticipant(participant)}
|
||||||
|
tooltip={t('participants.lowerParticipantHand', { name })}
|
||||||
|
data-attr="participants-lower-hand"
|
||||||
|
>
|
||||||
|
<RiHand />
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
)
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
import { Button } from '@/primitives'
|
||||||
|
import { useLowerHandParticipants } from '@/features/rooms/livekit/api/lowerHandParticipants'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
|
||||||
|
type LowerAllHandsButtonProps = {
|
||||||
|
participants: Array<Participant>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LowerAllHandsButton = ({
|
||||||
|
participants,
|
||||||
|
}: LowerAllHandsButtonProps) => {
|
||||||
|
const { lowerHandParticipants } = useLowerHandParticipants()
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
aria-label={t('participants.lowerParticipantsHand')}
|
||||||
|
size="sm"
|
||||||
|
fullWidth
|
||||||
|
variant="text"
|
||||||
|
onPress={() => lowerHandParticipants(participants)}
|
||||||
|
data-attr="participants-lower-hands"
|
||||||
|
>
|
||||||
|
{t('participants.lowerParticipantsHand')}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { Text } from '@/primitives/Text'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Avatar } from '@/components/Avatar'
|
||||||
|
import { getParticipantColor } from '@/features/rooms/utils/getParticipantColor'
|
||||||
|
import { Participant, Track } from 'livekit-client'
|
||||||
|
import { isLocal } from '@/utils/livekit'
|
||||||
|
import {
|
||||||
|
useIsSpeaking,
|
||||||
|
useTrackMutedIndicator,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import Source = Track.Source
|
||||||
|
import { RiMicFill, RiMicOffFill } from '@remixicon/react'
|
||||||
|
import { Button, Dialog, P } from '@/primitives'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useMuteParticipant } from '@/features/rooms/livekit/api/muteParticipant'
|
||||||
|
|
||||||
|
const MuteAlertDialog = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
onSubmit,
|
||||||
|
name,
|
||||||
|
}: {
|
||||||
|
isOpen: boolean
|
||||||
|
onClose: () => void
|
||||||
|
onSubmit: () => void
|
||||||
|
name: string
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
return (
|
||||||
|
<Dialog isOpen={isOpen} role="alertdialog">
|
||||||
|
<P>{t('participants.muteParticipantAlert.description', { name })}</P>
|
||||||
|
<HStack gap={1}>
|
||||||
|
<Button variant="text" size="sm" onPress={onClose}>
|
||||||
|
{t('participants.muteParticipantAlert.cancel')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="text" size="sm" onPress={onSubmit}>
|
||||||
|
{t('participants.muteParticipantAlert.confirm')}
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
type MicIndicatorProps = {
|
||||||
|
participant: Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
const MicIndicator = ({ participant }: MicIndicatorProps) => {
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
const { muteParticipant } = useMuteParticipant()
|
||||||
|
const { isMuted } = useTrackMutedIndicator({
|
||||||
|
participant: participant,
|
||||||
|
source: Source.Microphone,
|
||||||
|
})
|
||||||
|
const isSpeaking = useIsSpeaking(participant)
|
||||||
|
const [isAlertOpen, setIsAlertOpen] = useState(false)
|
||||||
|
const name = participant.name || participant.identity
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
square
|
||||||
|
invisible
|
||||||
|
size="sm"
|
||||||
|
tooltip={
|
||||||
|
isLocal(participant)
|
||||||
|
? t('participants.muteYourself')
|
||||||
|
: t('participants.muteParticipant', {
|
||||||
|
name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
isDisabled={isMuted}
|
||||||
|
onPress={() =>
|
||||||
|
!isMuted && isLocal(participant)
|
||||||
|
? muteParticipant(participant)
|
||||||
|
: setIsAlertOpen(true)
|
||||||
|
}
|
||||||
|
data-attr="participants-mute"
|
||||||
|
>
|
||||||
|
{isMuted ? (
|
||||||
|
<RiMicOffFill color={'gray'} />
|
||||||
|
) : (
|
||||||
|
<RiMicFill
|
||||||
|
style={{
|
||||||
|
animation: isSpeaking ? 'pulse_mic 800ms infinite' : undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
<MuteAlertDialog
|
||||||
|
isOpen={isAlertOpen}
|
||||||
|
onSubmit={() =>
|
||||||
|
muteParticipant(participant).then(() => setIsAlertOpen(false))
|
||||||
|
}
|
||||||
|
onClose={() => setIsAlertOpen(false)}
|
||||||
|
name={name}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParticipantListItemProps = {
|
||||||
|
participant: Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ParticipantListItem = ({
|
||||||
|
participant,
|
||||||
|
}: ParticipantListItemProps) => {
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
const name = participant.name || participant.identity
|
||||||
|
return (
|
||||||
|
<HStack
|
||||||
|
role="listitem"
|
||||||
|
justify="space-between"
|
||||||
|
key={participant.identity}
|
||||||
|
id={participant.identity}
|
||||||
|
className={css({
|
||||||
|
padding: '0.25rem 0',
|
||||||
|
width: 'full',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<HStack>
|
||||||
|
<Avatar name={name} bgColor={getParticipantColor(participant)} />
|
||||||
|
<Text
|
||||||
|
variant={'sm'}
|
||||||
|
className={css({
|
||||||
|
userSelect: 'none',
|
||||||
|
cursor: 'default',
|
||||||
|
display: 'flex',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={css({
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
maxWidth: '120px',
|
||||||
|
display: 'block',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
{isLocal(participant) && (
|
||||||
|
<span
|
||||||
|
className={css({
|
||||||
|
marginLeft: '.25rem',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
({t('participants.you')})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
|
<HStack>
|
||||||
|
<MicIndicator participant={participant} />
|
||||||
|
</HStack>
|
||||||
|
</HStack>
|
||||||
|
)
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { ToggleButton } from 'react-aria-components'
|
||||||
|
import { HStack, styled, VStack } from '@/styled-system/jsx'
|
||||||
|
import { RiArrowUpSLine } from '@remixicon/react'
|
||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
|
const ToggleHeader = styled(ToggleButton, {
|
||||||
|
base: {
|
||||||
|
minHeight: '40px', //fixme hardcoded value
|
||||||
|
paddingRight: '.5rem',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
width: '100%',
|
||||||
|
alignItems: 'center',
|
||||||
|
transition: 'background 200ms',
|
||||||
|
borderTopRadius: '7px',
|
||||||
|
'&[data-hovered]': {
|
||||||
|
backgroundColor: '#f5f5f5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const Container = styled('div', {
|
||||||
|
base: {
|
||||||
|
border: '1px solid #dadce0',
|
||||||
|
borderRadius: '8px',
|
||||||
|
margin: '0 .625rem',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const ListContainer = styled(VStack, {
|
||||||
|
base: {
|
||||||
|
borderTop: '1px solid #dadce0',
|
||||||
|
alignItems: 'start',
|
||||||
|
overflowY: 'scroll',
|
||||||
|
overflowX: 'hidden',
|
||||||
|
minHeight: 0,
|
||||||
|
flexGrow: 1,
|
||||||
|
display: 'flex',
|
||||||
|
paddingY: '0.5rem',
|
||||||
|
paddingX: '1rem',
|
||||||
|
gap: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
type ParticipantsCollapsableListProps = {
|
||||||
|
heading: string
|
||||||
|
participants: Array<Participant>
|
||||||
|
renderParticipant: (participant: Participant) => JSX.Element
|
||||||
|
action?: () => JSX.Element
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ParticipantsCollapsableList = ({
|
||||||
|
heading,
|
||||||
|
participants,
|
||||||
|
renderParticipant,
|
||||||
|
action,
|
||||||
|
}: ParticipantsCollapsableListProps) => {
|
||||||
|
const { t } = useTranslation('rooms')
|
||||||
|
const [isOpen, setIsOpen] = useState(true)
|
||||||
|
const label = t(`participants.collapsable.${isOpen ? 'close' : 'open'}`, {
|
||||||
|
name: heading,
|
||||||
|
})
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<ToggleHeader
|
||||||
|
isSelected={isOpen}
|
||||||
|
aria-label={label}
|
||||||
|
onPress={() => setIsOpen(!isOpen)}
|
||||||
|
style={{
|
||||||
|
borderRadius: !isOpen ? '7px' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<HStack
|
||||||
|
justify="space-between"
|
||||||
|
className={css({
|
||||||
|
margin: '0 1.25rem',
|
||||||
|
width: '100%',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={css({
|
||||||
|
fontSize: '1rem',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{heading}
|
||||||
|
</div>
|
||||||
|
<div>{participants?.length || 0}</div>
|
||||||
|
</HStack>
|
||||||
|
<RiArrowUpSLine
|
||||||
|
size={32}
|
||||||
|
style={{
|
||||||
|
transform: isOpen ? 'rotate(-180deg)' : undefined,
|
||||||
|
transition: 'transform 200ms',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ToggleHeader>
|
||||||
|
{isOpen && (
|
||||||
|
<ListContainer>
|
||||||
|
{action && action()}
|
||||||
|
{participants.map((participant) => renderParticipant(participant))}
|
||||||
|
</ListContainer>
|
||||||
|
)}
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
+54
-138
@@ -1,160 +1,76 @@
|
|||||||
import { css } from '@/styled-system/css'
|
import { css } from '@/styled-system/css'
|
||||||
import * as React from 'react'
|
|
||||||
import { useParticipants } from '@livekit/components-react'
|
import { useParticipants } from '@livekit/components-react'
|
||||||
|
|
||||||
import { Heading } from 'react-aria-components'
|
import { Div, H } from '@/primitives'
|
||||||
import { Box, Button, Div } from '@/primitives'
|
|
||||||
import { HStack, VStack } from '@/styled-system/jsx'
|
|
||||||
import { Text, text } from '@/primitives/Text'
|
|
||||||
import { RiCloseLine } from '@remixicon/react'
|
|
||||||
import { capitalize } from '@/utils/capitalize'
|
|
||||||
import { participantsStore } from '@/stores/participants'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { allParticipantRoomEvents } from '@/features/rooms/livekit/constants/events'
|
import { ParticipantListItem } from '../../controls/Participants/ParticipantListItem'
|
||||||
|
import { ParticipantsCollapsableList } from '../../controls/Participants/ParticipantsCollapsableList'
|
||||||
export type AvatarProps = React.HTMLAttributes<HTMLSpanElement> & {
|
import { HandRaisedListItem } from '../../controls/Participants/HandRaisedListItem'
|
||||||
name: string
|
import { LowerAllHandsButton } from '../../controls/Participants/LowerAllHandsButton'
|
||||||
size?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - extract inline styling in a centralized styling file, and avoid magic numbers
|
|
||||||
export const Avatar = ({ name, size = 32 }: AvatarProps) => (
|
|
||||||
<div
|
|
||||||
className={css({
|
|
||||||
minWidth: `${size}px`,
|
|
||||||
minHeight: `${size}px`,
|
|
||||||
backgroundColor: '#3498db',
|
|
||||||
borderRadius: '50%',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
fontSize: '1.25rem',
|
|
||||||
userSelect: 'none',
|
|
||||||
cursor: 'default',
|
|
||||||
color: 'white',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{name?.trim()?.charAt(0).toUpperCase()}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: Optimize rendering performance, especially for longer participant lists, even though they are generally short.
|
// TODO: Optimize rendering performance, especially for longer participant lists, even though they are generally short.
|
||||||
export const ParticipantsList = () => {
|
export const ParticipantsList = () => {
|
||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms', { keyPrefix: 'participants' })
|
||||||
|
|
||||||
// Preferred using the 'useParticipants' hook rather than the separate remote and local hooks,
|
// Preferred using the 'useParticipants' hook rather than the separate remote and local hooks,
|
||||||
// because the 'useLocalParticipant' hook does not update the participant's information when their
|
// because the 'useLocalParticipant' hook does not update the participant's information when their
|
||||||
// metadata/name changes. The LiveKit team has marked this as a TODO item in the code.
|
// metadata/name changes. The LiveKit team has marked this as a TODO item in the code.
|
||||||
const participants = useParticipants({
|
const participants = useParticipants()
|
||||||
updateOnlyOn: allParticipantRoomEvents,
|
|
||||||
})
|
|
||||||
|
|
||||||
const formattedParticipants = participants.map((participant) => ({
|
const sortedRemoteParticipants = participants
|
||||||
name: participant.name || participant.identity,
|
|
||||||
id: participant.identity,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const sortedRemoteParticipants = formattedParticipants
|
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((participantA, participantB) => {
|
||||||
|
const nameA = participantA.name || participantA.identity
|
||||||
|
const nameB = participantB.name || participantB.identity
|
||||||
|
return nameA.localeCompare(nameB)
|
||||||
|
})
|
||||||
|
|
||||||
const allParticipants = [
|
const sortedParticipants = [
|
||||||
formattedParticipants[0], // first participant returned by the hook, is always the local one
|
participants[0], // first participant returned by the hook, is always the local one
|
||||||
...sortedRemoteParticipants,
|
...sortedRemoteParticipants,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const raisedHandParticipants = participants.filter((participant) => {
|
||||||
|
const data = JSON.parse(participant.metadata || '{}')
|
||||||
|
return data.raised
|
||||||
|
})
|
||||||
|
|
||||||
// TODO - extract inline styling in a centralized styling file, and avoid magic numbers
|
// TODO - extract inline styling in a centralized styling file, and avoid magic numbers
|
||||||
return (
|
return (
|
||||||
<Box
|
<Div overflowY="scroll">
|
||||||
size="sm"
|
<H
|
||||||
minWidth="300px"
|
lvl={2}
|
||||||
className={css({
|
className={css({
|
||||||
overflow: 'hidden',
|
fontSize: '0.875rem',
|
||||||
display: 'flex',
|
fontWeight: 'bold',
|
||||||
flexDirection: 'column',
|
color: '#5f6368',
|
||||||
margin: '1.5rem 1.5rem 1.5rem 0',
|
padding: '0 1.5rem',
|
||||||
})}
|
marginBottom: '0.83em',
|
||||||
>
|
})}
|
||||||
<Heading slot="title" level={3} className={text({ variant: 'h2' })}>
|
>
|
||||||
<span>{t('participants.heading')}</span>{' '}
|
{t('subheading').toUpperCase()}
|
||||||
<span
|
</H>
|
||||||
className={css({
|
{raisedHandParticipants.length > 0 && (
|
||||||
marginLeft: '0.75rem',
|
<Div marginBottom=".9375rem">
|
||||||
fontWeight: 'normal',
|
<ParticipantsCollapsableList
|
||||||
fontSize: '1rem',
|
heading={t('raisedHands')}
|
||||||
})}
|
participants={raisedHandParticipants}
|
||||||
>
|
renderParticipant={(participant) => (
|
||||||
{participants?.length}
|
<HandRaisedListItem participant={participant} />
|
||||||
</span>
|
)}
|
||||||
</Heading>
|
action={() => (
|
||||||
<Div position="absolute" top="5" right="5">
|
<LowerAllHandsButton participants={raisedHandParticipants} />
|
||||||
<Button
|
)}
|
||||||
invisible
|
/>
|
||||||
size="xs"
|
</Div>
|
||||||
onPress={() => (participantsStore.showParticipants = false)}
|
|
||||||
aria-label={t('participants.closeButton')}
|
|
||||||
tooltip={t('participants.closeButton')}
|
|
||||||
>
|
|
||||||
<RiCloseLine />
|
|
||||||
</Button>
|
|
||||||
</Div>
|
|
||||||
{participants?.length && (
|
|
||||||
<VStack
|
|
||||||
role="list"
|
|
||||||
className={css({
|
|
||||||
alignItems: 'start',
|
|
||||||
gap: 'none',
|
|
||||||
overflowY: 'scroll',
|
|
||||||
overflowX: 'hidden',
|
|
||||||
minHeight: 0,
|
|
||||||
flexGrow: 1,
|
|
||||||
display: 'flex',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{allParticipants.map((participant, index) => (
|
|
||||||
<HStack
|
|
||||||
role="listitem"
|
|
||||||
key={participant.id}
|
|
||||||
id={participant.id}
|
|
||||||
className={css({
|
|
||||||
padding: '0.25rem 0',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<Avatar name={participant.name} />
|
|
||||||
<Text
|
|
||||||
variant={'sm'}
|
|
||||||
className={css({
|
|
||||||
userSelect: 'none',
|
|
||||||
cursor: 'default',
|
|
||||||
display: 'flex',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={css({
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
maxWidth: '120px',
|
|
||||||
display: 'block',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{capitalize(participant.name)}
|
|
||||||
</span>
|
|
||||||
{index === 0 && (
|
|
||||||
<span
|
|
||||||
className={css({
|
|
||||||
marginLeft: '.25rem',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
({t('participants.you')})
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
</HStack>
|
|
||||||
))}
|
|
||||||
</VStack>
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
<ParticipantsCollapsableList
|
||||||
|
heading={t('contributors')}
|
||||||
|
participants={sortedParticipants}
|
||||||
|
renderParticipant={(participant) => (
|
||||||
|
<ParticipantListItem participant={participant} />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-20
@@ -1,15 +1,12 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiGroupLine, RiInfinityLine } from '@remixicon/react'
|
import { RiGroupLine, RiInfinityLine } from '@remixicon/react'
|
||||||
import { Button } from '@/primitives'
|
import { ToggleButton } from '@/primitives'
|
||||||
import { css } from '@/styled-system/css'
|
import { css } from '@/styled-system/css'
|
||||||
import { useLayoutContext, useParticipants } from '@livekit/components-react'
|
import { useParticipants } from '@livekit/components-react'
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSidePanel } from '../../../hooks/useSidePanel'
|
||||||
import { participantsStore } from '@/stores/participants'
|
|
||||||
|
|
||||||
export const ParticipantsToggle = () => {
|
export const ParticipantsToggle = () => {
|
||||||
const { t } = useTranslation('rooms')
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls.participants' })
|
||||||
|
|
||||||
const { dispatch, state } = useLayoutContext().widget
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context could not be used due to inconsistent refresh behavior.
|
* Context could not be used due to inconsistent refresh behavior.
|
||||||
@@ -19,10 +16,9 @@ export const ParticipantsToggle = () => {
|
|||||||
const participants = useParticipants()
|
const participants = useParticipants()
|
||||||
const numParticipants = participants?.length
|
const numParticipants = participants?.length
|
||||||
|
|
||||||
const participantsSnap = useSnapshot(participantsStore)
|
const { isParticipantsOpen, toggleParticipants } = useSidePanel()
|
||||||
const showParticipants = participantsSnap.showParticipants
|
|
||||||
|
|
||||||
const tooltipLabel = showParticipants ? 'open' : 'closed'
|
const tooltipLabel = isParticipantsOpen ? 'open' : 'closed'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -31,20 +27,17 @@ export const ParticipantsToggle = () => {
|
|||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Button
|
<ToggleButton
|
||||||
toggle
|
|
||||||
square
|
square
|
||||||
legacyStyle
|
legacyStyle
|
||||||
aria-label={t(`controls.participants.${tooltipLabel}`)}
|
aria-label={t(tooltipLabel)}
|
||||||
tooltip={t(`controls.participants.${tooltipLabel}`)}
|
tooltip={t(tooltipLabel)}
|
||||||
isSelected={showParticipants}
|
isSelected={isParticipantsOpen}
|
||||||
onPress={() => {
|
onPress={() => toggleParticipants()}
|
||||||
if (dispatch && state?.showChat) dispatch({ msg: 'toggle_chat' })
|
data-attr={`controls-participants-${tooltipLabel}`}
|
||||||
participantsStore.showParticipants = !showParticipants
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<RiGroupLine />
|
<RiGroupLine />
|
||||||
</Button>
|
</ToggleButton>
|
||||||
<div
|
<div
|
||||||
className={css({
|
className={css({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { Div, ToggleButton } from '@/primitives'
|
||||||
|
import { RiArrowUpLine, RiCloseFill, RiRectangleLine } from '@remixicon/react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useTrackToggle, UseTrackToggleProps } from '@livekit/components-react'
|
||||||
|
import { Track } from 'livekit-client'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export const ScreenShareToggle = (
|
||||||
|
props: Omit<
|
||||||
|
UseTrackToggleProps<Track.Source.ScreenShare>,
|
||||||
|
'source' | 'captureOptions'
|
||||||
|
>
|
||||||
|
) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'controls.screenShare' })
|
||||||
|
const { buttonProps, enabled } = useTrackToggle({
|
||||||
|
...props,
|
||||||
|
source: Track.Source.ScreenShare,
|
||||||
|
captureOptions: { audio: true, selfBrowserSurface: 'include' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const tooltipLabel = enabled ? 'stop' : 'start'
|
||||||
|
const Icon = enabled ? RiCloseFill : RiArrowUpLine
|
||||||
|
|
||||||
|
// fixme - remove ToggleButton custom styles when we design a proper icon
|
||||||
|
return (
|
||||||
|
<ToggleButton
|
||||||
|
isSelected={enabled}
|
||||||
|
square
|
||||||
|
legacyStyle
|
||||||
|
tooltip={t(tooltipLabel)}
|
||||||
|
onPress={(e) =>
|
||||||
|
buttonProps.onClick?.(
|
||||||
|
e as unknown as React.MouseEvent<HTMLButtonElement, MouseEvent>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
style={{
|
||||||
|
maxWidth: '46px',
|
||||||
|
maxHeight: '46px',
|
||||||
|
}}
|
||||||
|
data-attr={`controls-screenshare-${tooltipLabel}`}
|
||||||
|
>
|
||||||
|
<Div position="relative">
|
||||||
|
<RiRectangleLine size={28} />
|
||||||
|
<Icon
|
||||||
|
size={16}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: '50%',
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Div>
|
||||||
|
</ToggleButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
useMediaDeviceSelect,
|
||||||
|
useTrackToggle,
|
||||||
|
UseTrackToggleProps,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { Button, Menu, MenuList } from '@/primitives'
|
||||||
|
import {
|
||||||
|
RemixiconComponentType,
|
||||||
|
RiArrowDownSLine,
|
||||||
|
RiMicLine,
|
||||||
|
RiMicOffLine,
|
||||||
|
RiVideoOffLine,
|
||||||
|
RiVideoOnLine,
|
||||||
|
} from '@remixicon/react'
|
||||||
|
import { Track } from 'livekit-client'
|
||||||
|
|
||||||
|
import { Shortcut } from '@/features/shortcuts/types'
|
||||||
|
|
||||||
|
import { ToggleDevice } from '@/features/rooms/livekit/components/controls/ToggleDevice.tsx'
|
||||||
|
|
||||||
|
export type ToggleSource = Exclude<
|
||||||
|
Track.Source,
|
||||||
|
Track.Source.ScreenShareAudio | Track.Source.Unknown
|
||||||
|
>
|
||||||
|
|
||||||
|
type SelectToggleSource = Exclude<ToggleSource, Track.Source.ScreenShare>
|
||||||
|
|
||||||
|
export type SelectToggleDeviceConfig = {
|
||||||
|
kind: MediaDeviceKind
|
||||||
|
iconOn: RemixiconComponentType
|
||||||
|
iconOff: RemixiconComponentType
|
||||||
|
shortcut?: Shortcut
|
||||||
|
longPress?: Shortcut
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelectToggleDeviceConfigMap = {
|
||||||
|
[key in SelectToggleSource]: SelectToggleDeviceConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectToggleDeviceConfig: SelectToggleDeviceConfigMap = {
|
||||||
|
[Track.Source.Microphone]: {
|
||||||
|
kind: 'audioinput',
|
||||||
|
iconOn: RiMicLine,
|
||||||
|
iconOff: RiMicOffLine,
|
||||||
|
shortcut: {
|
||||||
|
key: 'd',
|
||||||
|
ctrlKey: true,
|
||||||
|
},
|
||||||
|
longPress: {
|
||||||
|
key: 'Space',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[Track.Source.Camera]: {
|
||||||
|
kind: 'videoinput',
|
||||||
|
iconOn: RiVideoOnLine,
|
||||||
|
iconOff: RiVideoOffLine,
|
||||||
|
shortcut: {
|
||||||
|
key: 'e',
|
||||||
|
ctrlKey: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelectToggleDeviceProps<T extends ToggleSource> =
|
||||||
|
UseTrackToggleProps<T> & {
|
||||||
|
onActiveDeviceChange: (deviceId: string) => void
|
||||||
|
source: SelectToggleSource
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SelectToggleDevice = <T extends ToggleSource>({
|
||||||
|
onActiveDeviceChange,
|
||||||
|
...props
|
||||||
|
}: SelectToggleDeviceProps<T>) => {
|
||||||
|
const config = selectToggleDeviceConfig[props.source]
|
||||||
|
if (!config) {
|
||||||
|
throw new Error('Invalid source')
|
||||||
|
}
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'join' })
|
||||||
|
const trackProps = useTrackToggle(props)
|
||||||
|
|
||||||
|
const { devices, activeDeviceId, setActiveMediaDevice } =
|
||||||
|
useMediaDeviceSelect({ kind: config.kind })
|
||||||
|
|
||||||
|
const selectLabel = t('choose', { keyPrefix: `join.${config.kind}` })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HStack gap={0}>
|
||||||
|
<ToggleDevice {...trackProps} config={config} />
|
||||||
|
<Menu>
|
||||||
|
<Button
|
||||||
|
tooltip={selectLabel}
|
||||||
|
aria-label={selectLabel}
|
||||||
|
groupPosition="right"
|
||||||
|
square
|
||||||
|
>
|
||||||
|
<RiArrowDownSLine />
|
||||||
|
</Button>
|
||||||
|
<MenuList
|
||||||
|
items={devices.map((d) => ({
|
||||||
|
value: d.deviceId,
|
||||||
|
label: d.label,
|
||||||
|
}))}
|
||||||
|
selectedItem={activeDeviceId}
|
||||||
|
onAction={(value) => {
|
||||||
|
setActiveMediaDevice(value as string)
|
||||||
|
onActiveDeviceChange(value as string)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
</HStack>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { ToggleButton } from '@/primitives'
|
||||||
|
import { useRegisterKeyboardShortcut } from '@/features/shortcuts/useRegisterKeyboardShortcut'
|
||||||
|
import { useMemo, useState } from 'react'
|
||||||
|
import { appendShortcutLabel } from '@/features/shortcuts/utils'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { SelectToggleDeviceConfig } from './SelectToggleDevice'
|
||||||
|
import useLongPress from '@/features/shortcuts/useLongPress'
|
||||||
|
import { ActiveSpeaker } from '@/features/rooms/components/ActiveSpeaker'
|
||||||
|
import { useIsSpeaking, useLocalParticipant } from '@livekit/components-react'
|
||||||
|
|
||||||
|
export type ToggleDeviceProps = {
|
||||||
|
enabled: boolean
|
||||||
|
toggle: () => void
|
||||||
|
config: SelectToggleDeviceConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ToggleDevice = ({
|
||||||
|
config,
|
||||||
|
enabled,
|
||||||
|
toggle,
|
||||||
|
}: ToggleDeviceProps) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'join' })
|
||||||
|
|
||||||
|
const { kind, shortcut, iconOn, iconOff, longPress } = config
|
||||||
|
|
||||||
|
const [pushToTalk, setPushToTalk] = useState(false)
|
||||||
|
|
||||||
|
const onKeyDown = () => {
|
||||||
|
if (pushToTalk || enabled) return
|
||||||
|
toggle()
|
||||||
|
setPushToTalk(true)
|
||||||
|
}
|
||||||
|
const onKeyUp = () => {
|
||||||
|
if (!pushToTalk) return
|
||||||
|
toggle()
|
||||||
|
setPushToTalk(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
useRegisterKeyboardShortcut({ shortcut, handler: toggle })
|
||||||
|
useLongPress({ keyCode: longPress?.key, onKeyDown, onKeyUp })
|
||||||
|
|
||||||
|
const toggleLabel = useMemo(() => {
|
||||||
|
const label = t(enabled ? 'disable' : 'enable', {
|
||||||
|
keyPrefix: `join.${kind}`,
|
||||||
|
})
|
||||||
|
return shortcut ? appendShortcutLabel(label, shortcut) : label
|
||||||
|
}, [enabled, kind, shortcut, t])
|
||||||
|
|
||||||
|
const Icon = enabled ? iconOn : iconOff
|
||||||
|
|
||||||
|
const { localParticipant } = useLocalParticipant()
|
||||||
|
const isSpeaking = useIsSpeaking(localParticipant)
|
||||||
|
|
||||||
|
if (kind === 'audioinput' && pushToTalk) {
|
||||||
|
return <ActiveSpeaker isSpeaking={isSpeaking} pushToTalk />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ToggleButton
|
||||||
|
isSelected={enabled}
|
||||||
|
variant={enabled ? undefined : 'danger'}
|
||||||
|
toggledStyles={false}
|
||||||
|
onPress={() => toggle()}
|
||||||
|
aria-label={toggleLabel}
|
||||||
|
tooltip={toggleLabel}
|
||||||
|
groupPosition="left"
|
||||||
|
>
|
||||||
|
<Icon />
|
||||||
|
</ToggleButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import { Field, Form, Dialog, DialogProps } from '@/primitives'
|
|
||||||
import {
|
|
||||||
usePersistentUserChoices,
|
|
||||||
useRoomContext,
|
|
||||||
} from '@livekit/components-react'
|
|
||||||
|
|
||||||
export type UsernameDialogProps = Pick<DialogProps, 'isOpen' | 'onOpenChange'>
|
|
||||||
|
|
||||||
export const UsernameDialog = (props: UsernameDialogProps) => {
|
|
||||||
const { t } = useTranslation('rooms')
|
|
||||||
const { saveUsername } = usePersistentUserChoices()
|
|
||||||
|
|
||||||
const ctx = useRoomContext()
|
|
||||||
return (
|
|
||||||
<Dialog title={t('options.username.heading')} {...props}>
|
|
||||||
<Form
|
|
||||||
onSubmit={(data) => {
|
|
||||||
const { username } = data as { username: string }
|
|
||||||
ctx.localParticipant.setName(username)
|
|
||||||
saveUsername(username)
|
|
||||||
const { onOpenChange } = props
|
|
||||||
if (onOpenChange) {
|
|
||||||
onOpenChange(false)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
submitLabel={t('options.username.submitLabel')}
|
|
||||||
>
|
|
||||||
<Field
|
|
||||||
type="text"
|
|
||||||
name="username"
|
|
||||||
label={t('options.username.label')}
|
|
||||||
description={t('options.username.description')}
|
|
||||||
defaultValue={ctx.localParticipant.name}
|
|
||||||
validate={(value) => {
|
|
||||||
return !value ? (
|
|
||||||
<p>{t('options.username.validationError')}</p>
|
|
||||||
) : null
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Form>
|
|
||||||
</Dialog>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import { RoomEvent } from 'livekit-client'
|
|
||||||
|
|
||||||
// Issue: 'allRemoteParticipantRoomEvents' is not exposed or importable. One event is missing
|
|
||||||
// to trigger the real-time update of participants when they change their name.
|
|
||||||
// This code is duplicated from LiveKit.
|
|
||||||
export const allRemoteParticipantRoomEvents = [
|
|
||||||
RoomEvent.ConnectionStateChanged,
|
|
||||||
RoomEvent.RoomMetadataChanged,
|
|
||||||
|
|
||||||
RoomEvent.ActiveSpeakersChanged,
|
|
||||||
RoomEvent.ConnectionQualityChanged,
|
|
||||||
|
|
||||||
RoomEvent.ParticipantConnected,
|
|
||||||
RoomEvent.ParticipantDisconnected,
|
|
||||||
RoomEvent.ParticipantPermissionsChanged,
|
|
||||||
RoomEvent.ParticipantMetadataChanged,
|
|
||||||
RoomEvent.ParticipantNameChanged, // This element is missing in LiveKit and causes problems
|
|
||||||
|
|
||||||
RoomEvent.TrackMuted,
|
|
||||||
RoomEvent.TrackUnmuted,
|
|
||||||
RoomEvent.TrackPublished,
|
|
||||||
RoomEvent.TrackUnpublished,
|
|
||||||
RoomEvent.TrackStreamStateChanged,
|
|
||||||
RoomEvent.TrackSubscriptionFailed,
|
|
||||||
RoomEvent.TrackSubscriptionPermissionChanged,
|
|
||||||
RoomEvent.TrackSubscriptionStatusChanged,
|
|
||||||
]
|
|
||||||
|
|
||||||
export const allParticipantRoomEvents = [
|
|
||||||
...allRemoteParticipantRoomEvents,
|
|
||||||
RoomEvent.LocalTrackPublished,
|
|
||||||
RoomEvent.LocalTrackUnpublished,
|
|
||||||
]
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { LocalParticipant, Participant } from 'livekit-client'
|
||||||
|
import { useParticipantInfo } from '@livekit/components-react'
|
||||||
|
import { isLocal } from '@/utils/livekit'
|
||||||
|
|
||||||
|
type useRaisedHandProps = {
|
||||||
|
participant: Participant
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRaisedHand({ participant }: useRaisedHandProps) {
|
||||||
|
// fixme - refactor this part to rely on attributes
|
||||||
|
const { metadata } = useParticipantInfo({ participant })
|
||||||
|
const parsedMetadata = JSON.parse(metadata || '{}')
|
||||||
|
|
||||||
|
const toggleRaisedHand = () => {
|
||||||
|
if (isLocal(participant)) {
|
||||||
|
parsedMetadata.raised = !parsedMetadata.raised
|
||||||
|
const localParticipant = participant as LocalParticipant
|
||||||
|
localParticipant.setMetadata(JSON.stringify(parsedMetadata))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { isHandRaised: parsedMetadata.raised, toggleRaisedHand }
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
import * as React from 'react'
|
||||||
|
|
||||||
|
const useLatest = <T>(current: T) => {
|
||||||
|
const storedValue = React.useRef(current)
|
||||||
|
React.useEffect(() => {
|
||||||
|
storedValue.current = current
|
||||||
|
})
|
||||||
|
return storedValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A React hook that fires a callback whenever ResizeObserver detects a change to its size
|
||||||
|
* code extracted from https://github.com/jaredLunde/react-hook/blob/master/packages/resize-observer/src/index.tsx in order to not include the polyfill for resize-observer
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export function useResizeObserver<T extends HTMLElement>(
|
||||||
|
target: React.RefObject<T>,
|
||||||
|
callback: UseResizeObserverCallback
|
||||||
|
) {
|
||||||
|
const resizeObserver = getResizeObserver()
|
||||||
|
const storedCallback = useLatest(callback)
|
||||||
|
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
let didUnsubscribe = false
|
||||||
|
|
||||||
|
const targetEl = target.current
|
||||||
|
if (!targetEl) return
|
||||||
|
|
||||||
|
function cb(entry: ResizeObserverEntry, observer: ResizeObserver) {
|
||||||
|
if (didUnsubscribe) return
|
||||||
|
storedCallback.current(entry, observer)
|
||||||
|
}
|
||||||
|
|
||||||
|
resizeObserver?.subscribe(targetEl as HTMLElement, cb)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
didUnsubscribe = true
|
||||||
|
resizeObserver?.unsubscribe(targetEl as HTMLElement, cb)
|
||||||
|
}
|
||||||
|
}, [target.current, resizeObserver, storedCallback])
|
||||||
|
|
||||||
|
return resizeObserver?.observer
|
||||||
|
}
|
||||||
|
|
||||||
|
function createResizeObserver() {
|
||||||
|
let ticking = false
|
||||||
|
let allEntries: ResizeObserverEntry[] = []
|
||||||
|
|
||||||
|
const callbacks: Map<unknown, Array<UseResizeObserverCallback>> = new Map()
|
||||||
|
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(
|
||||||
|
(entries: ResizeObserverEntry[], obs: ResizeObserver) => {
|
||||||
|
allEntries = allEntries.concat(entries)
|
||||||
|
if (!ticking) {
|
||||||
|
window.requestAnimationFrame(() => {
|
||||||
|
const triggered = new Set<Element>()
|
||||||
|
for (let i = 0; i < allEntries.length; i++) {
|
||||||
|
if (triggered.has(allEntries[i].target)) continue
|
||||||
|
triggered.add(allEntries[i].target)
|
||||||
|
const cbs = callbacks.get(allEntries[i].target)
|
||||||
|
cbs?.forEach((cb) => cb(allEntries[i], obs))
|
||||||
|
}
|
||||||
|
allEntries = []
|
||||||
|
ticking = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
ticking = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
observer,
|
||||||
|
subscribe(target: HTMLElement, callback: UseResizeObserverCallback) {
|
||||||
|
observer.observe(target)
|
||||||
|
const cbs = callbacks.get(target) ?? []
|
||||||
|
cbs.push(callback)
|
||||||
|
callbacks.set(target, cbs)
|
||||||
|
},
|
||||||
|
unsubscribe(target: HTMLElement, callback: UseResizeObserverCallback) {
|
||||||
|
const cbs = callbacks.get(target) ?? []
|
||||||
|
if (cbs.length === 1) {
|
||||||
|
observer.unobserve(target)
|
||||||
|
callbacks.delete(target)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const cbIndex = cbs.indexOf(callback)
|
||||||
|
if (cbIndex !== -1) cbs.splice(cbIndex, 1)
|
||||||
|
callbacks.set(target, cbs)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _resizeObserver: ReturnType<typeof createResizeObserver>
|
||||||
|
|
||||||
|
const getResizeObserver = () =>
|
||||||
|
!_resizeObserver
|
||||||
|
? (_resizeObserver = createResizeObserver())
|
||||||
|
: _resizeObserver
|
||||||
|
|
||||||
|
export type UseResizeObserverCallback = (
|
||||||
|
entry: ResizeObserverEntry,
|
||||||
|
observer: ResizeObserver
|
||||||
|
) => unknown
|
||||||
|
|
||||||
|
export const useSize = (target: React.RefObject<HTMLDivElement>) => {
|
||||||
|
const [size, setSize] = React.useState({ width: 0, height: 0 })
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
if (target.current) {
|
||||||
|
const { width, height } = target.current.getBoundingClientRect()
|
||||||
|
setSize({ width, height })
|
||||||
|
}
|
||||||
|
}, [target.current])
|
||||||
|
|
||||||
|
const resizeCallback = React.useCallback(
|
||||||
|
(entry: ResizeObserverEntry) => setSize(entry.contentRect),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
// Where the magic happens
|
||||||
|
useResizeObserver(target, resizeCallback)
|
||||||
|
return size
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { ApiRoom } from '@/features/rooms/api/ApiRoom'
|
||||||
|
import { useRoomContext } from '@livekit/components-react'
|
||||||
|
import { useParams } from 'wouter'
|
||||||
|
import { keys } from '@/api/queryKeys'
|
||||||
|
import { queryClient } from '@/api/queryClient'
|
||||||
|
|
||||||
|
export const useRoomData = (): ApiRoom | undefined => {
|
||||||
|
const room = useRoomContext()
|
||||||
|
const { roomId } = useParams()
|
||||||
|
const queryKey = [keys.room, roomId, room.localParticipant.name]
|
||||||
|
return queryClient.getQueryData<ApiRoom>(queryKey)
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
import { layoutStore } from '@/stores/layout'
|
||||||
|
|
||||||
|
export enum PanelId {
|
||||||
|
PARTICIPANTS = 'participants',
|
||||||
|
EFFECTS = 'effects',
|
||||||
|
CHAT = 'chat',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSidePanel = () => {
|
||||||
|
const layoutSnap = useSnapshot(layoutStore)
|
||||||
|
const activePanelId = layoutSnap.activePanelId
|
||||||
|
|
||||||
|
const isParticipantsOpen = activePanelId == PanelId.PARTICIPANTS
|
||||||
|
const isEffectsOpen = activePanelId == PanelId.EFFECTS
|
||||||
|
const isChatOpen = activePanelId == PanelId.CHAT
|
||||||
|
const isSidePanelOpen = !!activePanelId
|
||||||
|
|
||||||
|
const toggleParticipants = () => {
|
||||||
|
layoutStore.activePanelId = isParticipantsOpen ? null : PanelId.PARTICIPANTS
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleChat = () => {
|
||||||
|
layoutStore.activePanelId = isChatOpen ? null : PanelId.CHAT
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleEffects = () => {
|
||||||
|
layoutStore.activePanelId = isEffectsOpen ? null : PanelId.EFFECTS
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
activePanelId,
|
||||||
|
toggleParticipants,
|
||||||
|
toggleChat,
|
||||||
|
toggleEffects,
|
||||||
|
isChatOpen,
|
||||||
|
isParticipantsOpen,
|
||||||
|
isEffectsOpen,
|
||||||
|
isSidePanelOpen,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import type { ChatMessage, ChatOptions } from '@livekit/components-core'
|
||||||
|
import * as React from 'react'
|
||||||
|
import {
|
||||||
|
formatChatMessageLinks,
|
||||||
|
useChat,
|
||||||
|
useParticipants,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
import { chatStore } from '@/stores/chat'
|
||||||
|
import { Div, Text } from '@/primitives'
|
||||||
|
import { ChatInput } from '../components/chat/Input'
|
||||||
|
import { ChatEntry } from '../components/chat/Entry'
|
||||||
|
import { useSidePanel } from '../hooks/useSidePanel'
|
||||||
|
|
||||||
|
export interface ChatProps
|
||||||
|
extends React.HTMLAttributes<HTMLDivElement>,
|
||||||
|
ChatOptions {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Chat component adds a basis chat functionality to the LiveKit room. The messages are distributed to all participants
|
||||||
|
* in the room. Only users who are in the room at the time of dispatch will receive the message.
|
||||||
|
*/
|
||||||
|
export function Chat({ ...props }: ChatProps) {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'chat' })
|
||||||
|
|
||||||
|
const inputRef = React.useRef<HTMLTextAreaElement>(null)
|
||||||
|
const ulRef = React.useRef<HTMLUListElement>(null)
|
||||||
|
|
||||||
|
const { send, chatMessages, isSending } = useChat()
|
||||||
|
|
||||||
|
const { isChatOpen } = useSidePanel()
|
||||||
|
const chatSnap = useSnapshot(chatStore)
|
||||||
|
|
||||||
|
// Use useParticipants hook to trigger a re-render when the participant list changes.
|
||||||
|
const participants = useParticipants()
|
||||||
|
|
||||||
|
const lastReadMsgAt = React.useRef<ChatMessage['timestamp']>(0)
|
||||||
|
|
||||||
|
async function handleSubmit(text: string) {
|
||||||
|
if (!send || !text) return
|
||||||
|
await send(text)
|
||||||
|
inputRef?.current?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (chatMessages.length > 0 && ulRef.current) {
|
||||||
|
ulRef.current?.scrollTo({ top: ulRef.current.scrollHeight })
|
||||||
|
}
|
||||||
|
}, [ulRef, chatMessages])
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (chatMessages.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isChatOpen &&
|
||||||
|
lastReadMsgAt.current !== chatMessages[chatMessages.length - 1]?.timestamp
|
||||||
|
) {
|
||||||
|
lastReadMsgAt.current = chatMessages[chatMessages.length - 1]?.timestamp
|
||||||
|
chatStore.unreadMessages = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const unreadMessageCount = chatMessages.filter(
|
||||||
|
(msg) => !lastReadMsgAt.current || msg.timestamp > lastReadMsgAt.current
|
||||||
|
).length
|
||||||
|
|
||||||
|
if (
|
||||||
|
unreadMessageCount > 0 &&
|
||||||
|
chatSnap.unreadMessages !== unreadMessageCount
|
||||||
|
) {
|
||||||
|
chatStore.unreadMessages = unreadMessageCount
|
||||||
|
}
|
||||||
|
}, [chatMessages, chatSnap.unreadMessages, isChatOpen])
|
||||||
|
|
||||||
|
const renderedMessages = React.useMemo(() => {
|
||||||
|
return chatMessages.map((msg, idx, allMsg) => {
|
||||||
|
const hideMetadata =
|
||||||
|
idx >= 1 &&
|
||||||
|
msg.timestamp - allMsg[idx - 1].timestamp < 60_000 &&
|
||||||
|
allMsg[idx - 1].from === msg.from
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChatEntry
|
||||||
|
key={msg.id ?? idx}
|
||||||
|
hideMetadata={hideMetadata}
|
||||||
|
entry={msg}
|
||||||
|
messageFormatter={formatChatMessageLinks}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
// This ensures that the chat message list is updated to reflect any changes in participant information.
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [chatMessages, participants])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Div
|
||||||
|
display={'flex'}
|
||||||
|
padding={'0 1.5rem'}
|
||||||
|
flexGrow={1}
|
||||||
|
flexDirection={'column'}
|
||||||
|
minHeight={0}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
variant="sm"
|
||||||
|
style={{
|
||||||
|
padding: '0.75rem',
|
||||||
|
backgroundColor: '#f3f4f6',
|
||||||
|
borderRadius: 4,
|
||||||
|
marginBottom: '0.75rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('disclaimer')}
|
||||||
|
</Text>
|
||||||
|
<Div
|
||||||
|
flexGrow={1}
|
||||||
|
flexDirection={'column'}
|
||||||
|
minHeight={0}
|
||||||
|
overflowY="scroll"
|
||||||
|
>
|
||||||
|
<ul className="lk-list lk-chat-messages" ref={ulRef}>
|
||||||
|
{renderedMessages}
|
||||||
|
</ul>
|
||||||
|
</Div>
|
||||||
|
<ChatInput
|
||||||
|
inputRef={inputRef}
|
||||||
|
onSubmit={(e) => handleSubmit(e)}
|
||||||
|
isSending={isSending}
|
||||||
|
/>
|
||||||
|
</Div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -4,21 +4,20 @@ import * as React from 'react'
|
|||||||
import { supportsScreenSharing } from '@livekit/components-core'
|
import { supportsScreenSharing } from '@livekit/components-core'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DisconnectButton,
|
|
||||||
LeaveIcon,
|
|
||||||
MediaDeviceMenu,
|
|
||||||
TrackToggle,
|
|
||||||
useMaybeLayoutContext,
|
useMaybeLayoutContext,
|
||||||
usePersistentUserChoices,
|
usePersistentUserChoices,
|
||||||
} from '@livekit/components-react'
|
} from '@livekit/components-react'
|
||||||
|
|
||||||
import { mergeProps } from '@/utils/mergeProps.ts'
|
|
||||||
import { StartMediaButton } from '../components/controls/StartMediaButton'
|
import { StartMediaButton } from '../components/controls/StartMediaButton'
|
||||||
import { useMediaQuery } from '../hooks/useMediaQuery'
|
import { useMediaQuery } from '../hooks/useMediaQuery'
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import { OptionsButton } from '../components/controls/Options/OptionsButton'
|
import { OptionsButton } from '../components/controls/Options/OptionsButton'
|
||||||
import { ParticipantsToggle } from '@/features/rooms/livekit/components/controls/Participants/ParticipantsToggle'
|
import { ParticipantsToggle } from '../components/controls/Participants/ParticipantsToggle'
|
||||||
import { ChatToggle } from '@/features/rooms/livekit/components/controls/ChatToggle'
|
import { ChatToggle } from '../components/controls/ChatToggle'
|
||||||
|
import { HandToggle } from '../components/controls/HandToggle'
|
||||||
|
import { SelectToggleDevice } from '../components/controls/SelectToggleDevice'
|
||||||
|
import { LeaveButton } from '../components/controls/LeaveButton'
|
||||||
|
import { ScreenShareToggle } from '../components/controls/ScreenShareToggle'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export type ControlBarControls = {
|
export type ControlBarControls = {
|
||||||
@@ -37,7 +36,7 @@ export interface ControlBarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
controls?: ControlBarControls
|
controls?: ControlBarControls
|
||||||
/**
|
/**
|
||||||
* If `true`, the user's device choices will be persisted.
|
* If `true`, the user's device choices will be persisted.
|
||||||
* This will enables the user to have the same device choices when they rejoin the room.
|
* This will enable the user to have the same device choices when they rejoin the room.
|
||||||
* @defaultValue true
|
* @defaultValue true
|
||||||
* @alpha
|
* @alpha
|
||||||
*/
|
*/
|
||||||
@@ -64,9 +63,7 @@ export function ControlBar({
|
|||||||
variation,
|
variation,
|
||||||
saveUserChoices = true,
|
saveUserChoices = true,
|
||||||
onDeviceError,
|
onDeviceError,
|
||||||
...props
|
|
||||||
}: ControlBarProps) {
|
}: ControlBarProps) {
|
||||||
const { t } = useTranslation('rooms')
|
|
||||||
const [isChatOpen, setIsChatOpen] = React.useState(false)
|
const [isChatOpen, setIsChatOpen] = React.useState(false)
|
||||||
const layoutContext = useMaybeLayoutContext()
|
const layoutContext = useMaybeLayoutContext()
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -82,28 +79,8 @@ export function ControlBar({
|
|||||||
const defaultVariation = isTooLittleSpace ? 'minimal' : 'verbose'
|
const defaultVariation = isTooLittleSpace ? 'minimal' : 'verbose'
|
||||||
variation ??= defaultVariation
|
variation ??= defaultVariation
|
||||||
|
|
||||||
const showIcon = React.useMemo(
|
|
||||||
() => variation === 'minimal' || variation === 'verbose',
|
|
||||||
[variation]
|
|
||||||
)
|
|
||||||
const showText = React.useMemo(
|
|
||||||
() => variation === 'textOnly' || variation === 'verbose',
|
|
||||||
[variation]
|
|
||||||
)
|
|
||||||
|
|
||||||
const browserSupportsScreenSharing = supportsScreenSharing()
|
const browserSupportsScreenSharing = supportsScreenSharing()
|
||||||
|
|
||||||
const [isScreenShareEnabled, setIsScreenShareEnabled] = React.useState(false)
|
|
||||||
|
|
||||||
const onScreenShareChange = React.useCallback(
|
|
||||||
(enabled: boolean) => {
|
|
||||||
setIsScreenShareEnabled(enabled)
|
|
||||||
},
|
|
||||||
[setIsScreenShareEnabled]
|
|
||||||
)
|
|
||||||
|
|
||||||
const htmlProps = mergeProps({ className: 'lk-control-bar' }, props)
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
saveAudioInputEnabled,
|
saveAudioInputEnabled,
|
||||||
saveVideoInputEnabled,
|
saveVideoInputEnabled,
|
||||||
@@ -124,72 +101,55 @@ export function ControlBar({
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div {...htmlProps}>
|
<div
|
||||||
<div className="lk-button-group">
|
className={css({
|
||||||
<TrackToggle
|
display: 'flex',
|
||||||
source={Track.Source.Microphone}
|
gap: '.5rem',
|
||||||
showIcon={showIcon}
|
alignItems: 'center',
|
||||||
onChange={microphoneOnChange}
|
justifyContent: 'center',
|
||||||
onDeviceError={(error) =>
|
padding: '.75rem',
|
||||||
onDeviceError?.({ source: Track.Source.Microphone, error })
|
borderTop: '1px solid var(--lk-border-color)',
|
||||||
}
|
maxHeight: 'var(--lk-control-bar-height)',
|
||||||
>
|
height: '80px',
|
||||||
{showText && t('controls.microphone')}
|
position: 'absolute',
|
||||||
</TrackToggle>
|
backgroundColor: '#d1d5db',
|
||||||
<div className="lk-button-group-menu">
|
bottom: 0,
|
||||||
<MediaDeviceMenu
|
left: 0,
|
||||||
kind="audioinput"
|
right: 0,
|
||||||
onActiveDeviceChange={(_kind, deviceId) =>
|
})}
|
||||||
saveAudioInputDeviceId(deviceId ?? '')
|
>
|
||||||
}
|
<SelectToggleDevice
|
||||||
/>
|
source={Track.Source.Microphone}
|
||||||
</div>
|
onChange={microphoneOnChange}
|
||||||
</div>
|
onDeviceError={(error) =>
|
||||||
<div className="lk-button-group">
|
onDeviceError?.({ source: Track.Source.Microphone, error })
|
||||||
<TrackToggle
|
}
|
||||||
source={Track.Source.Camera}
|
onActiveDeviceChange={(deviceId) =>
|
||||||
showIcon={showIcon}
|
saveAudioInputDeviceId(deviceId ?? '')
|
||||||
onChange={cameraOnChange}
|
}
|
||||||
onDeviceError={(error) =>
|
/>
|
||||||
onDeviceError?.({ source: Track.Source.Camera, error })
|
<SelectToggleDevice
|
||||||
}
|
source={Track.Source.Camera}
|
||||||
>
|
onChange={cameraOnChange}
|
||||||
{showText && t('controls.camera')}
|
onDeviceError={(error) =>
|
||||||
</TrackToggle>
|
onDeviceError?.({ source: Track.Source.Camera, error })
|
||||||
<div className="lk-button-group-menu">
|
}
|
||||||
<MediaDeviceMenu
|
onActiveDeviceChange={(deviceId) =>
|
||||||
kind="videoinput"
|
saveVideoInputDeviceId(deviceId ?? '')
|
||||||
onActiveDeviceChange={(_kind, deviceId) =>
|
}
|
||||||
saveVideoInputDeviceId(deviceId ?? '')
|
/>
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{browserSupportsScreenSharing && (
|
{browserSupportsScreenSharing && (
|
||||||
<TrackToggle
|
<ScreenShareToggle
|
||||||
source={Track.Source.ScreenShare}
|
|
||||||
captureOptions={{ audio: true, selfBrowserSurface: 'include' }}
|
|
||||||
showIcon={showIcon}
|
|
||||||
onChange={onScreenShareChange}
|
|
||||||
onDeviceError={(error) =>
|
onDeviceError={(error) =>
|
||||||
onDeviceError?.({ source: Track.Source.ScreenShare, error })
|
onDeviceError?.({ source: Track.Source.ScreenShare, error })
|
||||||
}
|
}
|
||||||
>
|
/>
|
||||||
{showText &&
|
|
||||||
t(
|
|
||||||
isScreenShareEnabled
|
|
||||||
? 'controls.stopScreenShare'
|
|
||||||
: 'controls.shareScreen'
|
|
||||||
)}
|
|
||||||
</TrackToggle>
|
|
||||||
)}
|
)}
|
||||||
|
<HandToggle />
|
||||||
<ChatToggle />
|
<ChatToggle />
|
||||||
<ParticipantsToggle />
|
<ParticipantsToggle />
|
||||||
<OptionsButton />
|
<OptionsButton />
|
||||||
<DisconnectButton>
|
<LeaveButton />
|
||||||
{showIcon && <LeaveIcon />}
|
|
||||||
{showText && t('controls.leave')}
|
|
||||||
</DisconnectButton>
|
|
||||||
<StartMediaButton />
|
<StartMediaButton />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
import type {
|
import type { TrackReferenceOrPlaceholder } from '@livekit/components-core'
|
||||||
MessageDecoder,
|
|
||||||
MessageEncoder,
|
|
||||||
TrackReferenceOrPlaceholder,
|
|
||||||
WidgetState,
|
|
||||||
} from '@livekit/components-core'
|
|
||||||
import {
|
import {
|
||||||
isEqualTrackRef,
|
isEqualTrackRef,
|
||||||
isTrackReference,
|
isTrackReference,
|
||||||
@@ -16,25 +11,24 @@ import * as React from 'react'
|
|||||||
import {
|
import {
|
||||||
CarouselLayout,
|
CarouselLayout,
|
||||||
ConnectionStateToast,
|
ConnectionStateToast,
|
||||||
FocusLayout,
|
|
||||||
FocusLayoutContainer,
|
FocusLayoutContainer,
|
||||||
GridLayout,
|
GridLayout,
|
||||||
LayoutContextProvider,
|
LayoutContextProvider,
|
||||||
ParticipantTile,
|
|
||||||
RoomAudioRenderer,
|
RoomAudioRenderer,
|
||||||
MessageFormatter,
|
|
||||||
usePinnedTracks,
|
usePinnedTracks,
|
||||||
useTracks,
|
useTracks,
|
||||||
useCreateLayoutContext,
|
useCreateLayoutContext,
|
||||||
Chat,
|
|
||||||
} from '@livekit/components-react'
|
} from '@livekit/components-react'
|
||||||
|
|
||||||
import { ControlBar } from './ControlBar'
|
import { ControlBar } from './ControlBar'
|
||||||
import { styled } from '@/styled-system/jsx'
|
import { styled } from '@/styled-system/jsx'
|
||||||
import { cva } from '@/styled-system/css'
|
import { cva } from '@/styled-system/css'
|
||||||
import { ParticipantsList } from '@/features/rooms/livekit/components/controls/Participants/ParticipantsList'
|
import { MainNotificationToast } from '@/features/notifications/MainNotificationToast'
|
||||||
import { useSnapshot } from 'valtio'
|
import { FocusLayout } from '../components/FocusLayout'
|
||||||
import { participantsStore } from '@/stores/participants'
|
import { ParticipantTile } from '../components/ParticipantTile'
|
||||||
|
import { SidePanel } from '../components/SidePanel'
|
||||||
|
import { useSidePanel } from '../hooks/useSidePanel'
|
||||||
|
import { RecordingIndicator } from '@/features/rooms/components/RecordingIndicator.tsx'
|
||||||
|
|
||||||
const LayoutWrapper = styled(
|
const LayoutWrapper = styled(
|
||||||
'div',
|
'div',
|
||||||
@@ -43,7 +37,7 @@ const LayoutWrapper = styled(
|
|||||||
position: 'relative',
|
position: 'relative',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: 'calc(100% - var(--lk-control-bar-height))',
|
height: '100%',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -53,9 +47,6 @@ const LayoutWrapper = styled(
|
|||||||
*/
|
*/
|
||||||
export interface VideoConferenceProps
|
export interface VideoConferenceProps
|
||||||
extends React.HTMLAttributes<HTMLDivElement> {
|
extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
chatMessageFormatter?: MessageFormatter
|
|
||||||
chatMessageEncoder?: MessageEncoder
|
|
||||||
chatMessageDecoder?: MessageDecoder
|
|
||||||
/** @alpha */
|
/** @alpha */
|
||||||
SettingsComponent?: React.ComponentType
|
SettingsComponent?: React.ComponentType
|
||||||
}
|
}
|
||||||
@@ -78,17 +69,7 @@ export interface VideoConferenceProps
|
|||||||
* ```
|
* ```
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function VideoConference({
|
export function VideoConference({ ...props }: VideoConferenceProps) {
|
||||||
chatMessageFormatter,
|
|
||||||
chatMessageDecoder,
|
|
||||||
chatMessageEncoder,
|
|
||||||
...props
|
|
||||||
}: VideoConferenceProps) {
|
|
||||||
const [widgetState, setWidgetState] = React.useState<WidgetState>({
|
|
||||||
showChat: false,
|
|
||||||
unreadMessages: 0,
|
|
||||||
showSettings: false,
|
|
||||||
})
|
|
||||||
const lastAutoFocusedScreenShareTrack =
|
const lastAutoFocusedScreenShareTrack =
|
||||||
React.useRef<TrackReferenceOrPlaceholder | null>(null)
|
React.useRef<TrackReferenceOrPlaceholder | null>(null)
|
||||||
|
|
||||||
@@ -100,11 +81,6 @@ export function VideoConference({
|
|||||||
{ updateOnlyOn: [RoomEvent.ActiveSpeakersChanged], onlySubscribed: false }
|
{ updateOnlyOn: [RoomEvent.ActiveSpeakersChanged], onlySubscribed: false }
|
||||||
)
|
)
|
||||||
|
|
||||||
const widgetUpdate = (state: WidgetState) => {
|
|
||||||
log.debug('updating widget state', state)
|
|
||||||
setWidgetState(state)
|
|
||||||
}
|
|
||||||
|
|
||||||
const layoutContext = useCreateLayoutContext()
|
const layoutContext = useCreateLayoutContext()
|
||||||
|
|
||||||
const screenShareTracks = tracks
|
const screenShareTracks = tracks
|
||||||
@@ -171,8 +147,7 @@ export function VideoConference({
|
|||||||
])
|
])
|
||||||
/* eslint-enable react-hooks/exhaustive-deps */
|
/* eslint-enable react-hooks/exhaustive-deps */
|
||||||
|
|
||||||
const participantsSnap = useSnapshot(participantsStore)
|
const { isSidePanelOpen } = useSidePanel()
|
||||||
const showParticipants = participantsSnap.showParticipants
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="lk-video-conference" {...props}>
|
<div className="lk-video-conference" {...props}>
|
||||||
@@ -180,39 +155,55 @@ export function VideoConference({
|
|||||||
<LayoutContextProvider
|
<LayoutContextProvider
|
||||||
value={layoutContext}
|
value={layoutContext}
|
||||||
// onPinChange={handleFocusStateChange}
|
// onPinChange={handleFocusStateChange}
|
||||||
onWidgetChange={widgetUpdate}
|
|
||||||
>
|
>
|
||||||
<div className="lk-video-conference-inner">
|
<div
|
||||||
|
// todo - extract these magic values into constant
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
inset: isSidePanelOpen
|
||||||
|
? 'var(--lk-grid-gap) calc(358px + 3rem) calc(80px + var(--lk-grid-gap)) 16px'
|
||||||
|
: 'var(--lk-grid-gap) var(--lk-grid-gap) calc(80px + var(--lk-grid-gap))',
|
||||||
|
transition: 'inset .5s cubic-bezier(0.4,0,0.2,1) 5ms',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RecordingIndicator />
|
||||||
<LayoutWrapper>
|
<LayoutWrapper>
|
||||||
{!focusTrack ? (
|
<div
|
||||||
<div
|
style={{ display: 'flex', position: 'relative', width: '100%' }}
|
||||||
className="lk-grid-layout-wrapper"
|
>
|
||||||
style={{ height: 'auto' }}
|
{!focusTrack ? (
|
||||||
>
|
<div
|
||||||
<GridLayout tracks={tracks}>
|
className="lk-grid-layout-wrapper"
|
||||||
<ParticipantTile />
|
style={{ height: 'auto' }}
|
||||||
</GridLayout>
|
>
|
||||||
</div>
|
<GridLayout tracks={tracks} style={{ padding: 0 }}>
|
||||||
) : (
|
|
||||||
<div className="lk-focus-layout-wrapper">
|
|
||||||
<FocusLayoutContainer>
|
|
||||||
<CarouselLayout tracks={carouselTracks}>
|
|
||||||
<ParticipantTile />
|
<ParticipantTile />
|
||||||
</CarouselLayout>
|
</GridLayout>
|
||||||
{focusTrack && <FocusLayout trackRef={focusTrack} />}
|
</div>
|
||||||
</FocusLayoutContainer>
|
) : (
|
||||||
</div>
|
<div
|
||||||
)}
|
className="lk-focus-layout-wrapper"
|
||||||
<Chat
|
style={{ height: 'auto' }}
|
||||||
style={{ display: widgetState.showChat ? 'grid' : 'none' }}
|
>
|
||||||
messageFormatter={chatMessageFormatter}
|
<FocusLayoutContainer style={{ padding: 0 }}>
|
||||||
messageEncoder={chatMessageEncoder}
|
<CarouselLayout
|
||||||
messageDecoder={chatMessageDecoder}
|
tracks={carouselTracks}
|
||||||
/>
|
style={{
|
||||||
{showParticipants && <ParticipantsList />}
|
minWidth: '200px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ParticipantTile />
|
||||||
|
</CarouselLayout>
|
||||||
|
{focusTrack && <FocusLayout trackRef={focusTrack} />}
|
||||||
|
</FocusLayoutContainer>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</LayoutWrapper>
|
</LayoutWrapper>
|
||||||
<ControlBar />
|
<MainNotificationToast />
|
||||||
</div>
|
</div>
|
||||||
|
<ControlBar />
|
||||||
|
<SidePanel />
|
||||||
</LayoutContextProvider>
|
</LayoutContextProvider>
|
||||||
)}
|
)}
|
||||||
<RoomAudioRenderer />
|
<RoomAudioRenderer />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ErrorScreen } from '@/components/ErrorScreen'
|
|||||||
import { useUser, UserAware } from '@/features/auth'
|
import { useUser, UserAware } from '@/features/auth'
|
||||||
import { Conference } from '../components/Conference'
|
import { Conference } from '../components/Conference'
|
||||||
import { Join } from '../components/Join'
|
import { Join } from '../components/Join'
|
||||||
|
import { useKeyboardShortcuts } from '@/features/shortcuts/useKeyboardShortcuts'
|
||||||
|
|
||||||
export const Room = () => {
|
export const Room = () => {
|
||||||
const { isLoggedIn } = useUser()
|
const { isLoggedIn } = useUser()
|
||||||
@@ -19,6 +20,8 @@ export const Room = () => {
|
|||||||
const mode = isLoggedIn && history.state?.create ? 'create' : 'join'
|
const mode = isLoggedIn && history.state?.create ? 'create' : 'join'
|
||||||
const skipJoinScreen = isLoggedIn && mode === 'create'
|
const skipJoinScreen = isLoggedIn && mode === 'create'
|
||||||
|
|
||||||
|
useKeyboardShortcuts()
|
||||||
|
|
||||||
const clearRouterState = () => {
|
const clearRouterState = () => {
|
||||||
if (window?.history?.state) {
|
if (window?.history?.state) {
|
||||||
window.history.replaceState({}, '')
|
window.history.replaceState({}, '')
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { Participant } from 'livekit-client'
|
||||||
|
|
||||||
|
export const getParticipantColor = (
|
||||||
|
participant: Participant
|
||||||
|
): undefined | string => {
|
||||||
|
const { metadata } = participant
|
||||||
|
if (!metadata) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return JSON.parse(metadata)['color']
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { useLanguageLabels } from '@/i18n/useLanguageLabels'
|
import { useLanguageLabels } from '@/i18n/useLanguageLabels'
|
||||||
import { A, Badge, Dialog, type DialogProps, Field, H, P } from '@/primitives'
|
import { A, Badge, Dialog, type DialogProps, Field, H, P } from '@/primitives'
|
||||||
import { authUrl, logoutUrl, useUser } from '@/features/auth'
|
import { logoutUrl, useUser } from '@/features/auth'
|
||||||
|
import { ProConnectButton } from '@/components/ProConnectButton'
|
||||||
|
|
||||||
export type SettingsDialogProps = Pick<DialogProps, 'isOpen' | 'onOpenChange'>
|
export type SettingsDialogProps = Pick<DialogProps, 'isOpen' | 'onOpenChange'>
|
||||||
|
|
||||||
@@ -28,9 +29,7 @@ export const SettingsDialog = (props: SettingsDialogProps) => {
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<P>{t('account.youAreNotLoggedIn')}</P>
|
<P>{t('account.youAreNotLoggedIn')}</P>
|
||||||
<P>
|
<ProConnectButton />
|
||||||
<A href={authUrl()}>{t('login', { ns: 'global' })}</A>
|
|
||||||
</P>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<H lvl={2}>{t('language.heading')}</H>
|
<H lvl={2}>{t('language.heading')}</H>
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { Dialog, type DialogProps } from '@/primitives'
|
||||||
|
import { Tab, Tabs, TabList } from '@/primitives/Tabs.tsx'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { text } from '@/primitives/Text.tsx'
|
||||||
|
import { Heading } from 'react-aria-components'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
RiAccountCircleLine,
|
||||||
|
RiSettings3Line,
|
||||||
|
RiSpeakerLine,
|
||||||
|
} from '@remixicon/react'
|
||||||
|
import { AccountTab } from './tabs/AccountTab'
|
||||||
|
import { GeneralTab } from '@/features/settings/components/tabs/GeneralTab.tsx'
|
||||||
|
import { AudioTab } from '@/features/settings/components/tabs/AudioTab.tsx'
|
||||||
|
import { useSize } from '@/features/rooms/livekit/hooks/useResizeObserver'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
|
||||||
|
const tabsStyle = css({
|
||||||
|
maxHeight: '40.625rem', // fixme size copied from meet settings modal
|
||||||
|
width: '50rem', // fixme size copied from meet settings modal
|
||||||
|
marginY: '-1rem', // fixme hacky solution to cancel modal padding
|
||||||
|
maxWidth: '100%',
|
||||||
|
overflow: 'hidden',
|
||||||
|
height: 'calc(100vh - 2rem)',
|
||||||
|
})
|
||||||
|
|
||||||
|
const tabListContainerStyle = css({
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
borderRight: '1px solid lightGray', // fixme poor color management
|
||||||
|
paddingY: '1rem',
|
||||||
|
paddingRight: '1.5rem',
|
||||||
|
})
|
||||||
|
|
||||||
|
const tabPanelContainerStyle = css({
|
||||||
|
display: 'flex',
|
||||||
|
flexGrow: '1',
|
||||||
|
marginTop: '3.5rem',
|
||||||
|
minWidth: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
export type SettingsDialogExtended = Pick<
|
||||||
|
DialogProps,
|
||||||
|
'isOpen' | 'onOpenChange'
|
||||||
|
>
|
||||||
|
|
||||||
|
export const SettingsDialogExtended = (props: SettingsDialogExtended) => {
|
||||||
|
// display only icon on small screen
|
||||||
|
const { t } = useTranslation('settings')
|
||||||
|
|
||||||
|
const dialogEl = useRef<HTMLDivElement>(null)
|
||||||
|
const { width } = useSize(dialogEl)
|
||||||
|
const isWideScreen = !width || width >= 800 // fixme - hardcoded 50rem in pixel
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog innerRef={dialogEl} {...props} role="dialog" type="flex">
|
||||||
|
<Tabs orientation="vertical" className={tabsStyle}>
|
||||||
|
<div
|
||||||
|
className={tabListContainerStyle}
|
||||||
|
style={{
|
||||||
|
flex: isWideScreen ? '0 0 16rem' : undefined,
|
||||||
|
paddingTop: !isWideScreen ? '64px' : undefined,
|
||||||
|
paddingRight: !isWideScreen ? '1rem' : undefined,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isWideScreen && (
|
||||||
|
<Heading slot="title" level={1} className={text({ variant: 'h1' })}>
|
||||||
|
{t('dialog.heading')}
|
||||||
|
</Heading>
|
||||||
|
)}
|
||||||
|
<TabList border={false} aria-label="Chat log orientation example">
|
||||||
|
<Tab icon highlight id="1">
|
||||||
|
<RiAccountCircleLine />
|
||||||
|
{isWideScreen && t('tabs.account')}
|
||||||
|
</Tab>
|
||||||
|
<Tab icon highlight id="2">
|
||||||
|
<RiSpeakerLine />
|
||||||
|
{isWideScreen && t('tabs.audio')}
|
||||||
|
</Tab>
|
||||||
|
<Tab icon highlight id="3">
|
||||||
|
<RiSettings3Line />
|
||||||
|
{isWideScreen && t('tabs.general')}
|
||||||
|
</Tab>
|
||||||
|
</TabList>
|
||||||
|
</div>
|
||||||
|
<div className={tabPanelContainerStyle}>
|
||||||
|
<AccountTab id="1" onOpenChange={props.onOpenChange} />
|
||||||
|
<AudioTab id="2" />
|
||||||
|
<GeneralTab id="3" />
|
||||||
|
</div>
|
||||||
|
</Tabs>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import { A, Badge, Button, DialogProps, Field, H, P } from '@/primitives'
|
||||||
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
usePersistentUserChoices,
|
||||||
|
useRoomContext,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import { logoutUrl, useUser } from '@/features/auth'
|
||||||
|
import { css } from '@/styled-system/css'
|
||||||
|
import { TabPanel, TabPanelProps } from '@/primitives/Tabs'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { ProConnectButton } from '@/components/ProConnectButton'
|
||||||
|
|
||||||
|
export type AccountTabProps = Pick<DialogProps, 'onOpenChange'> &
|
||||||
|
Pick<TabPanelProps, 'id'>
|
||||||
|
|
||||||
|
export const AccountTab = ({ id, onOpenChange }: AccountTabProps) => {
|
||||||
|
const { t } = useTranslation('settings')
|
||||||
|
const { saveUsername } = usePersistentUserChoices()
|
||||||
|
const room = useRoomContext()
|
||||||
|
const { user, isLoggedIn } = useUser()
|
||||||
|
const [name, setName] = useState(room?.localParticipant.name || '')
|
||||||
|
|
||||||
|
const handleOnSubmit = () => {
|
||||||
|
if (room) room.localParticipant.setName(name)
|
||||||
|
saveUsername(name)
|
||||||
|
if (onOpenChange) onOpenChange(false)
|
||||||
|
}
|
||||||
|
const handleOnCancel = () => {
|
||||||
|
if (onOpenChange) onOpenChange(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TabPanel padding={'md'} flex id={id}>
|
||||||
|
<H lvl={2}>{t('account.heading')}</H>
|
||||||
|
<Field
|
||||||
|
type="text"
|
||||||
|
label={t('account.nameLabel')}
|
||||||
|
value={name}
|
||||||
|
onChange={setName}
|
||||||
|
validate={(value) => {
|
||||||
|
return !value ? <p>{'Votre Nom ne peut pas être vide'}</p> : null
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<H lvl={2}>{t('account.authentication')}</H>
|
||||||
|
{isLoggedIn ? (
|
||||||
|
<>
|
||||||
|
<P>
|
||||||
|
<Trans
|
||||||
|
i18nKey="settings:account.currentlyLoggedAs"
|
||||||
|
values={{ user: user?.email }}
|
||||||
|
components={[<Badge />]}
|
||||||
|
/>
|
||||||
|
</P>
|
||||||
|
<P>
|
||||||
|
<A href={logoutUrl()}>{t('logout', { ns: 'global' })}</A>
|
||||||
|
</P>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<P>{t('account.youAreNotLoggedIn')}</P>
|
||||||
|
<ProConnectButton />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<HStack
|
||||||
|
className={css({
|
||||||
|
marginTop: 'auto',
|
||||||
|
marginLeft: 'auto',
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Button onPress={handleOnCancel}>
|
||||||
|
{t('cancel', { ns: 'global' })}
|
||||||
|
</Button>
|
||||||
|
<Button variant={'primary'} onPress={handleOnSubmit}>
|
||||||
|
{t('submit', { ns: 'global' })}
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</TabPanel>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import { DialogProps, Field, H } from '@/primitives'
|
||||||
|
|
||||||
|
import { TabPanel, TabPanelProps } from '@/primitives/Tabs'
|
||||||
|
import {
|
||||||
|
useIsSpeaking,
|
||||||
|
useMediaDeviceSelect,
|
||||||
|
useRoomContext,
|
||||||
|
} from '@livekit/components-react'
|
||||||
|
import { isSafari } from '@/utils/livekit'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { SoundTester } from '@/components/SoundTester'
|
||||||
|
import { HStack } from '@/styled-system/jsx'
|
||||||
|
import { ActiveSpeaker } from '@/features/rooms/components/ActiveSpeaker'
|
||||||
|
import { ReactNode } from 'react'
|
||||||
|
|
||||||
|
type RowWrapperProps = {
|
||||||
|
heading: string
|
||||||
|
children: ReactNode[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const RowWrapper = ({ heading, children }: RowWrapperProps) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<H lvl={2}>{heading}</H>
|
||||||
|
<HStack
|
||||||
|
gap={0}
|
||||||
|
style={{
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: '1 1 215px',
|
||||||
|
minWidth: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children[0]}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '10rem',
|
||||||
|
justifyContent: 'center',
|
||||||
|
display: 'flex',
|
||||||
|
paddingLeft: '1.5rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children[1]}
|
||||||
|
</div>
|
||||||
|
</HStack>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AudioTabProps = Pick<DialogProps, 'onOpenChange'> &
|
||||||
|
Pick<TabPanelProps, 'id'>
|
||||||
|
|
||||||
|
type DeviceItems = Array<{ value: string; label: string }>
|
||||||
|
|
||||||
|
export const AudioTab = ({ id }: AudioTabProps) => {
|
||||||
|
const { t } = useTranslation('settings')
|
||||||
|
const { localParticipant } = useRoomContext()
|
||||||
|
|
||||||
|
const isSpeaking = useIsSpeaking(localParticipant)
|
||||||
|
|
||||||
|
const {
|
||||||
|
devices: devicesOut,
|
||||||
|
activeDeviceId: activeDeviceIdOut,
|
||||||
|
setActiveMediaDevice: setActiveMediaDeviceOut,
|
||||||
|
} = useMediaDeviceSelect({ kind: 'audiooutput' })
|
||||||
|
|
||||||
|
const {
|
||||||
|
devices: devicesIn,
|
||||||
|
activeDeviceId: activeDeviceIdIn,
|
||||||
|
setActiveMediaDevice: setActiveMediaDeviceIn,
|
||||||
|
} = useMediaDeviceSelect({ kind: 'audioinput' })
|
||||||
|
|
||||||
|
const itemsOut: DeviceItems = devicesOut.map((d) => ({
|
||||||
|
value: d.deviceId,
|
||||||
|
label: d.label,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const itemsIn: DeviceItems = devicesIn.map((d) => ({
|
||||||
|
value: d.deviceId,
|
||||||
|
label: d.label,
|
||||||
|
}))
|
||||||
|
|
||||||
|
// The Permissions API is not fully supported in Firefox and Safari, and attempting to use it for microphone permissions
|
||||||
|
// may raise an error. As a workaround, we infer microphone permission status by checking if the list of audio input
|
||||||
|
// devices (devicesIn) is non-empty. If the list has one or more devices, we assume the user has granted microphone access.
|
||||||
|
const isMicEnabled = devicesIn?.length > 0
|
||||||
|
|
||||||
|
const disabledProps = isMicEnabled
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
placeholder: t('audio.permissionsRequired'),
|
||||||
|
isDisabled: true,
|
||||||
|
defaultSelectedKey: undefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
// No API to directly query the default audio device; this function heuristically finds it.
|
||||||
|
// Returns the item with value 'default' if present; otherwise, returns the first item in the list.
|
||||||
|
const getDefaultSelectedKey = (items: DeviceItems) => {
|
||||||
|
if (!items || items.length === 0) return
|
||||||
|
const defaultItem =
|
||||||
|
items.find((item) => item.value === 'default') || items[0]
|
||||||
|
return defaultItem.value
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TabPanel padding={'md'} flex id={id}>
|
||||||
|
<RowWrapper heading={t('audio.microphone.heading')}>
|
||||||
|
<Field
|
||||||
|
type="select"
|
||||||
|
label={t('audio.microphone.label')}
|
||||||
|
items={itemsIn}
|
||||||
|
defaultSelectedKey={
|
||||||
|
activeDeviceIdIn || getDefaultSelectedKey(itemsIn)
|
||||||
|
}
|
||||||
|
onSelectionChange={(key) => setActiveMediaDeviceIn(key as string)}
|
||||||
|
{...disabledProps}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<>
|
||||||
|
{localParticipant.isMicrophoneEnabled ? (
|
||||||
|
<ActiveSpeaker isSpeaking={isSpeaking} />
|
||||||
|
) : (
|
||||||
|
<span>Micro désactivé</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
</RowWrapper>
|
||||||
|
{/* Safari has a known limitation where its implementation of 'enumerateDevices' does not include audio output devices.
|
||||||
|
To prevent errors or an empty selection list, we only render the speakers selection field on non-Safari browsers. */}
|
||||||
|
{!isSafari() && (
|
||||||
|
<RowWrapper heading={t('audio.speakers.heading')}>
|
||||||
|
<Field
|
||||||
|
type="select"
|
||||||
|
label={t('audio.speakers.label')}
|
||||||
|
items={itemsOut}
|
||||||
|
defaultSelectedKey={
|
||||||
|
activeDeviceIdOut || getDefaultSelectedKey(itemsOut)
|
||||||
|
}
|
||||||
|
onSelectionChange={async (key) =>
|
||||||
|
setActiveMediaDeviceOut(key as string)
|
||||||
|
}
|
||||||
|
{...disabledProps}
|
||||||
|
style={{
|
||||||
|
minWidth: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<SoundTester />
|
||||||
|
</RowWrapper>
|
||||||
|
)}
|
||||||
|
</TabPanel>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { Field, H } from '@/primitives'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useLanguageLabels } from '@/i18n/useLanguageLabels'
|
||||||
|
import { TabPanel, TabPanelProps } from '@/primitives/Tabs'
|
||||||
|
|
||||||
|
export type GeneralTabProps = Pick<TabPanelProps, 'id'>
|
||||||
|
|
||||||
|
export const GeneralTab = ({ id }: GeneralTabProps) => {
|
||||||
|
const { t, i18n } = useTranslation('settings')
|
||||||
|
const { languagesList, currentLanguage } = useLanguageLabels()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TabPanel padding={'md'} flex id={id}>
|
||||||
|
<H lvl={2}>{t('language.heading')}</H>
|
||||||
|
<Field
|
||||||
|
type="select"
|
||||||
|
label={t('language.label')}
|
||||||
|
items={languagesList}
|
||||||
|
defaultSelectedKey={currentLanguage.key}
|
||||||
|
onSelectionChange={(lang) => {
|
||||||
|
i18n.changeLanguage(lang as string)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export type Shortcut = {
|
||||||
|
key: string
|
||||||
|
ctrlKey?: boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
import { keyboardShortcutsStore } from '@/stores/keyboardShortcuts'
|
||||||
|
import { isMacintosh } from '@/utils/livekit'
|
||||||
|
import { formatShortcutKey } from './utils'
|
||||||
|
|
||||||
|
export const useKeyboardShortcuts = () => {
|
||||||
|
const shortcutsSnap = useSnapshot(keyboardShortcutsStore)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// This approach handles basic shortcuts but isn't comprehensive.
|
||||||
|
// Issues might occur. First draft.
|
||||||
|
const onKeyDown = (e: KeyboardEvent) => {
|
||||||
|
const { key, metaKey, ctrlKey } = e
|
||||||
|
const shortcutKey = formatShortcutKey({
|
||||||
|
key,
|
||||||
|
ctrlKey: ctrlKey || (isMacintosh() && metaKey),
|
||||||
|
})
|
||||||
|
const shortcut = shortcutsSnap.shortcuts.get(shortcutKey)
|
||||||
|
if (!shortcut) return
|
||||||
|
e.preventDefault()
|
||||||
|
shortcut()
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('keydown', onKeyDown)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', onKeyDown)
|
||||||
|
}
|
||||||
|
}, [shortcutsSnap])
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
|
export type useLongPressProps = {
|
||||||
|
keyCode?: string
|
||||||
|
onKeyDown: () => void
|
||||||
|
onKeyUp: () => void
|
||||||
|
longPressThreshold?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useLongPress = ({
|
||||||
|
keyCode,
|
||||||
|
onKeyDown,
|
||||||
|
onKeyUp,
|
||||||
|
longPressThreshold = 300,
|
||||||
|
}: useLongPressProps) => {
|
||||||
|
const timeoutIdRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.code != keyCode || timeoutIdRef.current) return
|
||||||
|
timeoutIdRef.current = setTimeout(() => {
|
||||||
|
onKeyDown()
|
||||||
|
}, longPressThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeyUp = (event: KeyboardEvent) => {
|
||||||
|
if (event.code != keyCode || !timeoutIdRef.current) return
|
||||||
|
clearTimeout(timeoutIdRef.current)
|
||||||
|
timeoutIdRef.current = null
|
||||||
|
onKeyUp()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keyCode) return
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleKeyDown)
|
||||||
|
window.addEventListener('keyup', handleKeyUp)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', handleKeyDown)
|
||||||
|
window.removeEventListener('keyup', handleKeyUp)
|
||||||
|
}
|
||||||
|
}, [keyCode, onKeyDown, onKeyUp, longPressThreshold])
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useLongPress
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
|
import { keyboardShortcutsStore } from '@/stores/keyboardShortcuts'
|
||||||
|
import { formatShortcutKey } from '@/features/shortcuts/utils'
|
||||||
|
import { Shortcut } from '@/features/shortcuts/types'
|
||||||
|
|
||||||
|
export type useRegisterKeyboardShortcutProps = {
|
||||||
|
shortcut?: Shortcut
|
||||||
|
handler: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useRegisterKeyboardShortcut = ({
|
||||||
|
shortcut,
|
||||||
|
handler,
|
||||||
|
}: useRegisterKeyboardShortcutProps) => {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!shortcut) return
|
||||||
|
keyboardShortcutsStore.shortcuts.set(formatShortcutKey(shortcut), handler)
|
||||||
|
}, [handler, shortcut])
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { isMacintosh } from '@/utils/livekit'
|
||||||
|
import { Shortcut } from '@/features/shortcuts/types'
|
||||||
|
|
||||||
|
export const CTRL = 'ctrl'
|
||||||
|
|
||||||
|
export const formatShortcutKey = (shortcut: Shortcut) => {
|
||||||
|
if (shortcut.ctrlKey) return `${CTRL}+${shortcut.key.toUpperCase()}`
|
||||||
|
return shortcut.key.toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const appendShortcutLabel = (label: string, shortcut: Shortcut) => {
|
||||||
|
if (!shortcut.key) return
|
||||||
|
let formattedKeyLabel = shortcut.key.toLowerCase()
|
||||||
|
if (shortcut.ctrlKey) {
|
||||||
|
formattedKeyLabel = `${isMacintosh() ? '⌘' : 'Ctrl'}+${formattedKeyLabel}`
|
||||||
|
}
|
||||||
|
return `${label} (${formattedKeyLabel})`
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
|
import { Crisp } from 'crisp-sdk-web'
|
||||||
|
import { ApiUser } from '@/features/auth/api/ApiUser'
|
||||||
|
|
||||||
|
export const initializeSupportSession = (user: ApiUser) => {
|
||||||
|
if (!Crisp.isCrispInjected()) return
|
||||||
|
const { id, email } = user
|
||||||
|
Crisp.setTokenId(`meet-${id}`)
|
||||||
|
Crisp.user.setEmail(email)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const terminateSupportSession = () => {
|
||||||
|
if (!Crisp.isCrispInjected()) return
|
||||||
|
Crisp.setTokenId()
|
||||||
|
Crisp.session.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
export type useSupportProps = {
|
||||||
|
id?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure Crisp chat for real-time support across all pages.
|
||||||
|
export const useSupport = ({ id }: useSupportProps) => {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id || Crisp.isCrispInjected()) return
|
||||||
|
Crisp.configure(id)
|
||||||
|
Crisp.setHideOnMobile(true)
|
||||||
|
}, [id])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import { Button, Popover, PopoverList } from '@/primitives'
|
|
||||||
import { useLanguageLabels } from './useLanguageLabels'
|
|
||||||
|
|
||||||
export const LanguageSelector = () => {
|
|
||||||
const { t, i18n } = useTranslation()
|
|
||||||
const { languagesList, currentLanguage } = useLanguageLabels()
|
|
||||||
return (
|
|
||||||
<Popover aria-label={t('languageSelector.popoverLabel')}>
|
|
||||||
<Button
|
|
||||||
aria-label={t('languageSelector.buttonLabel', {
|
|
||||||
currentLanguage: currentLanguage.label,
|
|
||||||
})}
|
|
||||||
size="sm"
|
|
||||||
variant="primary"
|
|
||||||
outline
|
|
||||||
>
|
|
||||||
{i18n.language}
|
|
||||||
</Button>
|
|
||||||
<PopoverList
|
|
||||||
items={languagesList}
|
|
||||||
onAction={(lang) => {
|
|
||||||
i18n.changeLanguage(lang)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user