Merge branch 'dev' into feat/notification-improvements
This commit is contained in:
69 files changed
+12501
-25150
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Added ability to start calls in DMs and rooms. DM calls will trigger a notification popup & ringtone (for other sable users/compatible clients, probably).
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Merge in upstream call things and remove the duplicate new voice room button.
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
# Device names are now dynamic, showing your browser and OS (e.g., "Sable on Firefox for Windows") instead of just "Sable Web".
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Prevent overly wide emotes from taking up the entire screen width.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
fix message forwarding metadata leak when forwarding from private rooms [see issue 190](https://github.com/SableClient/Sable/issues/190)
|
||||
@@ -5,7 +5,7 @@ inputs:
|
||||
install-command:
|
||||
description: Command used to install dependencies.
|
||||
required: false
|
||||
default: npm ci
|
||||
default: pnpm install --frozen-lockfile
|
||||
build:
|
||||
description: Whether to build the app after installing dependencies.
|
||||
required: false
|
||||
@@ -13,16 +13,19 @@ inputs:
|
||||
build-command:
|
||||
description: Command used when build is enabled.
|
||||
required: false
|
||||
default: npm run build
|
||||
default: pnpm run build
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
|
||||
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||
with:
|
||||
node-version-file: '.node-version'
|
||||
cache: 'npm'
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
|
||||
@@ -11,14 +11,26 @@ on:
|
||||
- 'tsconfig.json'
|
||||
- '.github/workflows/cloudflare-web-preview.yml'
|
||||
- '.github/actions/setup/**'
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'index.html'
|
||||
- 'package.json'
|
||||
- 'package-lock.json'
|
||||
- 'vite.config.ts'
|
||||
- 'tsconfig.json'
|
||||
- '.github/workflows/cloudflare-web-preview.yml'
|
||||
- '.github/actions/setup/**'
|
||||
|
||||
concurrency:
|
||||
group: cloudflare-worker-preview-${{ github.event.pull_request.number }}
|
||||
group: cloudflare-worker-preview-${{ github.event.pull_request.number || github.ref_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
if: github.event.pull_request.head.repo.full_name == github.repository
|
||||
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -47,6 +59,18 @@ jobs:
|
||||
with:
|
||||
build: 'true'
|
||||
|
||||
- name: Set deploy alias
|
||||
id: alias
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
echo "alias=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
branch="${{ github.ref_name }}"
|
||||
alias="$(echo "$branch" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g')"
|
||||
echo "alias=${alias}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Upload Worker preview
|
||||
id: deploy
|
||||
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
|
||||
@@ -58,7 +82,7 @@ jobs:
|
||||
command: >
|
||||
versions upload
|
||||
-c dist/wrangler.json
|
||||
--preview-alias pr-${{ github.event.pull_request.number }}
|
||||
--preview-alias ${{ steps.alias.outputs.alias }}
|
||||
--message "$PREVIEW_MESSAGE"
|
||||
|
||||
- name: Resolve preview URL
|
||||
@@ -66,17 +90,16 @@ jobs:
|
||||
env:
|
||||
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
|
||||
COMMAND_OUTPUT: ${{ steps.deploy.outputs.command-output }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
ALIAS: ${{ steps.alias.outputs.alias }}
|
||||
shell: bash
|
||||
run: |
|
||||
alias="pr-${PR_NUMBER}"
|
||||
alias_url_pattern="^https?://${ALIAS}-[^[:space:]]+$"
|
||||
preview_url=""
|
||||
alias_url_pattern="^https?://${alias}-[^[:space:]]+$"
|
||||
|
||||
if printf '%s\n' "$DEPLOYMENT_URL" | grep -Eq "$alias_url_pattern"; then
|
||||
preview_url="$DEPLOYMENT_URL"
|
||||
else
|
||||
preview_url="$(printf '%s\n' "$COMMAND_OUTPUT" | grep -Eo "https?://${alias}-[^[:space:]\"'<>)]+" | head -n 1 || true)"
|
||||
preview_url="$(printf '%s\n' "$COMMAND_OUTPUT" | grep -Eo "https?://${ALIAS}-[^[:space:]\"'<>)]+" | head -n 1 || true)"
|
||||
fi
|
||||
|
||||
if ! printf '%s\n' "$preview_url" | grep -Eq "$alias_url_pattern"; then
|
||||
@@ -84,18 +107,15 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
{
|
||||
echo "preview_alias=${alias}"
|
||||
echo "preview_url=${preview_url}"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
echo "preview_url=${preview_url}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Publish preview URL and write summary
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
|
||||
- name: Publish summary and PR comment
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
||||
env:
|
||||
MARKER: '<!-- cloudflare-worker-preview -->'
|
||||
PREVIEW_URL: ${{ steps.preview.outputs.preview_url }}
|
||||
PREVIEW_ALIAS: ${{ steps.preview.outputs.preview_alias }}
|
||||
SHORT_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
PREVIEW_ALIAS: ${{ steps.alias.outputs.alias }}
|
||||
SHORT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
@@ -120,10 +140,10 @@ jobs:
|
||||
tableRow,
|
||||
].join("\n");
|
||||
|
||||
// Write to step summary (marker stripped — not needed there)
|
||||
await core.summary.addRaw(comment.replace(marker + "\n", "")).write();
|
||||
|
||||
// Always delete and recreate so the comment appears fresh after each push
|
||||
if (context.eventName !== 'pull_request') return;
|
||||
|
||||
const { owner, repo } = context.repo;
|
||||
const issue_number = context.issue.number;
|
||||
const comments = await github.paginate(github.rest.issues.listComments, {
|
||||
|
||||
@@ -5,6 +5,10 @@ on:
|
||||
branches: [dev]
|
||||
tags:
|
||||
- 'sable/v*'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'Dockerfile'
|
||||
- '.github/workflows/docker-publish.yml'
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
@@ -27,6 +31,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
@@ -68,15 +73,13 @@ jobs:
|
||||
|
||||
- name: Setup app
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
install-command: npm ci --ignore-scripts
|
||||
|
||||
- name: Build site
|
||||
env:
|
||||
VITE_BUILD_HASH: ${{ steps.vars.outputs.short_sha }}
|
||||
VITE_IS_RELEASE_TAG: ${{ steps.release_tag.outputs.is_release }}
|
||||
run: |
|
||||
NODE_OPTIONS=--max_old_space_size=4096 npm run build
|
||||
NODE_OPTIONS=--max_old_space_size=4096 pnpm run build
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
||||
@@ -89,7 +92,7 @@ jobs:
|
||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
@@ -99,6 +102,7 @@ jobs:
|
||||
site-dist=./dist
|
||||
|
||||
- name: Generate artifact attestation
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
|
||||
@@ -18,6 +18,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: true
|
||||
token: ${{ secrets.RELEASE_PAT }}
|
||||
|
||||
- uses: fregante/setup-git-user@024bc0b8e177d7e77203b48dab6fb45666854b35 # v2.0.2
|
||||
|
||||
@@ -29,10 +30,10 @@ jobs:
|
||||
run: knope prepare-release --verbose
|
||||
continue-on-error: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
|
||||
|
||||
- name: Enrich changelog with PR attribution
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
@@ -60,6 +61,12 @@ jobs:
|
||||
});
|
||||
const pr = prs.data[0];
|
||||
if (pr) {
|
||||
const isInternal = pr.labels.some(label => label.name.toLowerCase() === 'internal');
|
||||
if (isInternal) {
|
||||
const lineRegex = new RegExp(`^.*.*\\r?\\n?`, 'gm');
|
||||
content = content.replace(lineRegex, '');
|
||||
continue;
|
||||
}
|
||||
replacement = `([#${pr.number}](${pr.html_url}) by @${pr.user.login})`;
|
||||
} else {
|
||||
// Commit exists but has no associated PR (e.g. direct push to dev)
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
uses: ./.github/actions/setup
|
||||
|
||||
- name: Check formatting
|
||||
run: npm run fmt:check
|
||||
run: pnpm run fmt:check
|
||||
|
||||
lint:
|
||||
name: Lint
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
uses: ./.github/actions/setup
|
||||
|
||||
- name: Run ESLint
|
||||
run: npm run lint
|
||||
run: pnpm run lint
|
||||
|
||||
typecheck:
|
||||
name: Typecheck
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
uses: ./.github/actions/setup
|
||||
|
||||
- name: Run TypeScript typecheck
|
||||
run: npm run typecheck -- --pretty false
|
||||
run: pnpm run typecheck --pretty false
|
||||
|
||||
knip:
|
||||
name: Knip
|
||||
@@ -70,8 +70,6 @@ jobs:
|
||||
|
||||
- name: Setup app
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
install-command: npm ci --ignore-scripts
|
||||
|
||||
- name: Run Knip
|
||||
run: npm run knip
|
||||
run: pnpm run knip
|
||||
@@ -18,6 +18,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- uses: knope-dev/action@19617851f9f13ab2f27a05989c55efb18aca3675 # v2.1.2
|
||||
with:
|
||||
@@ -26,4 +27,4 @@ jobs:
|
||||
- name: Create Release
|
||||
run: knope release --verbose
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Manage changeset comment
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
|
||||
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
||||
env:
|
||||
SKIP: ${{ steps.labels.outputs.skip }}
|
||||
CHANGESET_FOUND: ${{ steps.check.outputs.found }}
|
||||
@@ -86,7 +86,7 @@ jobs:
|
||||
|
||||
**How to add a changeset:**
|
||||
|
||||
1. Run \`npm run document-change\` (interactive) and commit the generated file, or
|
||||
1. Run \`pnpm run document-change\` (interactive) and commit the generated file, or
|
||||
2. Manually create \`.changeset/<descriptive-name>.md\`:
|
||||
|
||||
\`\`\`md
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
dist
|
||||
node_modules
|
||||
package.json
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
|
||||
+9
-9
@@ -39,10 +39,10 @@ Also, we use [ESLint](https://eslint.org/) for clean and stylistically consisten
|
||||
|
||||
**Pull requests are not merged unless all quality checks are passing.** At minimum, `format`, `lint`, `typecheck`, and `knip` must all be green before a pull request can be merged. Run these locally before opening or updating a pull request:
|
||||
|
||||
- `npm run fmt:check`
|
||||
- `npm run lint`
|
||||
- `npm run typecheck`
|
||||
- `npm run knip`
|
||||
- `pnpm run fmt:check`
|
||||
- `pnpm run lint`
|
||||
- `pnpm run typecheck`
|
||||
- `pnpm run knip`
|
||||
|
||||
## Restrictions on Generative AI Usage
|
||||
|
||||
@@ -62,7 +62,7 @@ We use [Knope](https://knope.tech/) with the Knope GitHub Bot to manage change d
|
||||
|
||||
If you have used [Changesets](https://github.com/changesets/changesets) before, Knope should feel very similar. The main difference is scope: Changesets is typically used for JavaScript repositories because it relies on `package.json`, while Knope is multi-language.
|
||||
|
||||
If you prefer, you can install the Knope CLI yourself using the [official installation guide](https://knope.tech/installation/). This repo also exposes the CLI through npm scripts, so you can run `npm run knope -- <subcommand>` (for example: `npm run knope -- document-change`). Otherwise, this repo installs Knope for you via `postinstall`, so running `npm i` is enough.
|
||||
If you prefer, you can install the Knope CLI yourself using the [official installation guide](https://knope.tech/installation/). This repo also exposes the CLI through pnpm scripts, so you can run `pnpm run knope -- <subcommand>` (for example: `pnpm run knope -- document-change`). Otherwise, this repo installs Knope for you via `postinstall`, so running `pnpm i` is enough.
|
||||
|
||||
### Documenting a change
|
||||
|
||||
@@ -72,8 +72,8 @@ For user-facing pull requests, add one before requesting review.
|
||||
|
||||
CLI paths:
|
||||
|
||||
- `npm run document-change`
|
||||
- `npm run knope -- document-change`
|
||||
- `pnpm run document-change`
|
||||
- `pnpm run knope -- document-change`
|
||||
- `knope document-change` (if Knope is installed locally)
|
||||
|
||||
All commands open an interactive prompt; fill in the package, change type, and short summary, then commit the generated change file in your PR.
|
||||
@@ -112,11 +112,11 @@ Releases are driven by Knope Bot (`[bot.releases].enabled = true`):
|
||||
|
||||
Maintainers can preview behavior without changing files:
|
||||
|
||||
- `npm run knope -- release --dry-run`
|
||||
- `pnpm run knope -- release --dry-run`
|
||||
|
||||
You can also validate the local Knope config with:
|
||||
|
||||
- `npm run knope -- --validate`
|
||||
- `pnpm run knope -- --validate`
|
||||
|
||||
**For any query or design discussion, join our [Matrix room](https://matrix.to/#/#sable:sable.moe).**
|
||||
|
||||
|
||||
+12
-5
@@ -1,5 +1,12 @@
|
||||
## Base
|
||||
FROM --platform=$BUILDPLATFORM node:24.13.1-alpine AS base
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
RUN corepack enable
|
||||
RUN apk add --no-cache git
|
||||
|
||||
## Builder
|
||||
FROM --platform=$BUILDPLATFORM node:24.13.1-alpine AS builder
|
||||
FROM base AS builder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
@@ -7,12 +14,12 @@ ARG VITE_BUILD_HASH
|
||||
ARG VITE_IS_RELEASE_TAG=false
|
||||
ENV VITE_BUILD_HASH=$VITE_BUILD_HASH
|
||||
ENV VITE_IS_RELEASE_TAG=$VITE_IS_RELEASE_TAG
|
||||
|
||||
COPY .npmrc package.json package-lock.json /src/
|
||||
RUN npm ci --ignore-scripts
|
||||
COPY pnpm-lock.yaml pnpm-workspace.yaml /src/
|
||||
RUN pnpm fetch
|
||||
COPY . /src/
|
||||
RUN pnpm install --offline --frozen-lockfile
|
||||
ENV NODE_OPTIONS=--max_old_space_size=4096
|
||||
RUN npm run build
|
||||
RUN pnpm run build
|
||||
|
||||
## Dist
|
||||
FROM scratch AS site-dist
|
||||
|
||||
@@ -54,8 +54,8 @@ services:
|
||||
To build and serve Sable yourself with nginx, clone this repo and build it:
|
||||
|
||||
```sh
|
||||
npm ci # Installs all dependencies
|
||||
npm run build # Compiles the app into the dist/ directory
|
||||
pnpm i # Installs all dependencies
|
||||
pnpm run build # Compiles the app into the dist/ directory
|
||||
```
|
||||
|
||||
After that, you can copy the dist/ directory to your server and serve it.
|
||||
@@ -71,15 +71,18 @@ After that, you can copy the dist/ directory to your server and serve it.
|
||||
|
||||
Execute the following commands to start a development server:
|
||||
```sh
|
||||
npm ci # Installs all dependencies
|
||||
npm run dev # Serve a development version
|
||||
fnm use --corepack-enabled # Activates the Node version and enables corepack
|
||||
# If you not using fnm, install corepack manually: npm install --global corepack@latest
|
||||
corepack install # Installs the pnpm version specified in package.json
|
||||
pnpm i # Installs all dependencies
|
||||
pnpm run dev # Serve a development version
|
||||
```
|
||||
|
||||
To build the app:
|
||||
```sh
|
||||
npm run build # Compiles the app into the dist/ directory
|
||||
pnpm run build # Compiles the app into the dist/ directory
|
||||
```
|
||||
|
||||
## Deployment and infrastructure
|
||||
Deployment workflows and infrastructure details live in
|
||||
[`infra/README.md`](infra/README.md).
|
||||
[`infra/README.md`](infra/README.md).
|
||||
+4
-4
@@ -6,7 +6,7 @@ production deployment, and the production custom domain.
|
||||
Prerequisites:
|
||||
|
||||
- OpenTofu `1.11.x` installed locally
|
||||
- Node.js/npm installed locally so you can build `dist/` before Worker uploads
|
||||
- Node.js/pnpm installed locally so you can build `dist/` before Worker uploads
|
||||
- A Cloudflare account with the target zone already onboarded to Cloudflare
|
||||
- A GitLab project to store the OpenTofu state
|
||||
- A GitLab access token that can read and write that project's OpenTofu state
|
||||
@@ -52,17 +52,17 @@ Local setup:
|
||||
1. Copy `terraform.tfvars.example` to `terraform.tfvars` and fill in shared values.
|
||||
2. Copy `gitlab.http.tfbackend.example` to `gitlab.http.tfbackend` and fill in the
|
||||
GitLab project ID, state name, and username.
|
||||
3. Run `npm ci` from the repo root.
|
||||
3. Run `pnpm install` from the repo root.
|
||||
4. Export the GitLab access token as the backend password.
|
||||
5. Export the Cloudflare API token for OpenTofu.
|
||||
6. Run `npm run build` before `tofu plan` or `tofu apply`, because
|
||||
6. Run `pnpm run build` before `tofu plan` or `tofu apply`, because
|
||||
`cloudflare_worker_version` uploads the built `dist/` assets.
|
||||
7. Initialize the backend.
|
||||
|
||||
Local OpenTofu production flow from the repo root:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
pnpm run build
|
||||
export TF_HTTP_PASSWORD="<your-gitlab-access-token>"
|
||||
export CLOUDFLARE_API_TOKEN="<your-cloudflare-api-token>"
|
||||
tofu -chdir=infra/web init -reconfigure -backend-config="../gitlab.http.tfbackend"
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
"interface": true,
|
||||
"type": true
|
||||
},
|
||||
"ignoreDependencies": ["buffer", "@element-hq/element-call-embedded", "workbox-precaching"],
|
||||
"ignoreDependencies": [
|
||||
"buffer",
|
||||
"@element-hq/element-call-embedded",
|
||||
"@matrix-org/matrix-sdk-crypto-wasm"
|
||||
],
|
||||
"ignoreBinaries": ["knope"],
|
||||
"rules": {
|
||||
"exports": "off",
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
versioned_files = ["package.json", "package-lock.json"]
|
||||
versioned_files = ["package.json"]
|
||||
changelog = "CHANGELOG.md"
|
||||
extra_changelog_sections = [
|
||||
{ name = "Documentation", types = ["docs"] },
|
||||
|
||||
Generated
-24812
File diff suppressed because it is too large.
Load diff
+7
-13
@@ -3,10 +3,10 @@
|
||||
"version": "1.6.0",
|
||||
"description": "An almost stable Matrix client",
|
||||
"type": "module",
|
||||
"packageManager": "npm@11.11.0",
|
||||
"packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
|
||||
"engines": {
|
||||
"node": "24.x",
|
||||
"npm": "11.x"
|
||||
"pnpm": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
@@ -37,7 +37,7 @@
|
||||
"@use-gesture/react": "10.3.1",
|
||||
"@vanilla-extract/css": "^1.18.0",
|
||||
"@vanilla-extract/recipes": "^0.5.7",
|
||||
"@vanilla-extract/vite-plugin": "^3.9.5",
|
||||
"@vanilla-extract/vite-plugin": "^5.1.4",
|
||||
"await-to-js": "^3.0.0",
|
||||
"badwords-list": "^2.0.1-4",
|
||||
"blurhash": "^2.0.5",
|
||||
@@ -49,9 +49,10 @@
|
||||
"emojibase": "^15.3.1",
|
||||
"emojibase-data": "^15.3.2",
|
||||
"eslint-plugin-react": "7.37.5",
|
||||
"eventemitter3": "^5.0.4",
|
||||
"file-saver": "^2.0.5",
|
||||
"focus-trap-react": "^10.3.1",
|
||||
"folds": "^2.6.1",
|
||||
"folds": "^2.6.2",
|
||||
"framer-motion": "12.34.3",
|
||||
"html-dom-parser": "^5.1.8",
|
||||
"html-react-parser": "^4.2.10",
|
||||
@@ -83,7 +84,8 @@
|
||||
"slate-dom": "^0.123.0",
|
||||
"slate-history": "^0.113.1",
|
||||
"slate-react": "^0.123.0",
|
||||
"ua-parser-js": "^1.0.41"
|
||||
"ua-parser-js": "^1.0.41",
|
||||
"workbox-precaching": "^7.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vite-plugin": "^1.26.0",
|
||||
@@ -120,13 +122,5 @@
|
||||
"vite-plugin-svgr": "4.5.0",
|
||||
"vite-plugin-top-level-await": "^1.6.0",
|
||||
"wrangler": "^4.70.0"
|
||||
},
|
||||
"overrides": {
|
||||
"serialize-javascript": ">=7.0.3",
|
||||
"rollup": ">=4.59.0",
|
||||
"minimatch": ">=10.2.3",
|
||||
"lodash": ">=4.17.23",
|
||||
"esbuild": ">=0.25.0",
|
||||
"brace-expansion": ">=1.1.12"
|
||||
}
|
||||
}
|
||||
Generated
+10779
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,25 @@
|
||||
engineStrict: true
|
||||
minimumReleaseAge: 1440
|
||||
|
||||
allowBuilds:
|
||||
'@swc/core': true
|
||||
esbuild: true
|
||||
sharp: true
|
||||
unrs-resolver: true
|
||||
workerd: true
|
||||
|
||||
overrides:
|
||||
serialize-javascript: '>=7.0.3'
|
||||
rollup: '>=4.59.0'
|
||||
minimatch: '>=10.2.3'
|
||||
lodash: '>=4.17.23'
|
||||
esbuild: '>=0.25.0'
|
||||
brace-expansion: '>=1.1.12'
|
||||
|
||||
peerDependencyRules:
|
||||
allowedVersions:
|
||||
'folds>@vanilla-extract/css': '1.18.0'
|
||||
'folds>@vanilla-extract/recipes': '0.5.7'
|
||||
'folds>classnames': '2.5.1'
|
||||
'folds>react': '18.3.1'
|
||||
'folds>react-dom': '18.3.1'
|
||||
Binary file not shown.
@@ -115,6 +115,11 @@ function isPathWithin(candidatePath, rootPath) {
|
||||
const logger = new PrefixedLogger('[postinstall:knope]');
|
||||
const { dim, red, green } = createTextHelpers({ useColor: logger.useColor });
|
||||
|
||||
if (process.env.GITHUB_ACTIONS && process.env.CI) {
|
||||
logger.info(`${dim('Running in CI environment, skipping knope installation')}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const target = TARGETS[`${process.platform}-${process.arch}`];
|
||||
if (!target) {
|
||||
const supported = Object.keys(TARGETS).join(', ');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ReactNode, useCallback, useRef } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useAutoJoinCall } from '$hooks/useAutoJoinCall';
|
||||
import {
|
||||
CallEmbedContextProvider,
|
||||
CallEmbedRefContextProvider,
|
||||
@@ -7,11 +8,12 @@ import {
|
||||
useCallJoined,
|
||||
useCallThemeSync,
|
||||
useCallMemberSoundSync,
|
||||
} from '../hooks/useCallEmbed';
|
||||
import { callChatAtom, callEmbedAtom } from '../state/callEmbed';
|
||||
import { CallEmbed } from '../plugins/call';
|
||||
import { useSelectedRoom } from '../hooks/router/useSelectedRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '../hooks/useScreenSize';
|
||||
} from '$hooks/useCallEmbed';
|
||||
import { callChatAtom, callEmbedAtom } from '$state/callEmbed';
|
||||
import { CallEmbed } from '$plugins/call';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import { IncomingCallModal } from './IncomingCallModal';
|
||||
|
||||
function CallUtils({ embed }: { embed: CallEmbed }) {
|
||||
const setCallEmbed = useSetAtom(callEmbedAtom);
|
||||
@@ -31,6 +33,12 @@ function CallUtils({ embed }: { embed: CallEmbed }) {
|
||||
type CallEmbedProviderProps = {
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
function AutoJoinManager() {
|
||||
useAutoJoinCall();
|
||||
return null;
|
||||
}
|
||||
|
||||
export function CallEmbedProvider({ children }: CallEmbedProviderProps) {
|
||||
const callEmbed = useAtomValue(callEmbedAtom);
|
||||
const callEmbedRef = useRef<HTMLDivElement>(null);
|
||||
@@ -46,17 +54,20 @@ export function CallEmbedProvider({ children }: CallEmbedProviderProps) {
|
||||
|
||||
return (
|
||||
<CallEmbedContextProvider value={callEmbed}>
|
||||
<IncomingCallModal />
|
||||
{callEmbed && <CallUtils embed={callEmbed} />}
|
||||
<CallEmbedRefContextProvider value={callEmbedRef}>{children}</CallEmbedRefContextProvider>
|
||||
<CallEmbedRefContextProvider value={callEmbedRef}>
|
||||
<AutoJoinManager />
|
||||
{children}
|
||||
</CallEmbedRefContextProvider>
|
||||
|
||||
<div
|
||||
data-call-embed-container
|
||||
style={{
|
||||
visibility: callVisible ? undefined : 'hidden',
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '50%',
|
||||
zIndex: callVisible ? 10 : -1,
|
||||
pointerEvents: callVisible ? 'all' : 'none',
|
||||
}}
|
||||
ref={callEmbedRef}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import {
|
||||
Box,
|
||||
Dialog,
|
||||
Header,
|
||||
IconButton,
|
||||
Icon,
|
||||
Icons,
|
||||
Text,
|
||||
Button,
|
||||
Avatar,
|
||||
config,
|
||||
Overlay,
|
||||
OverlayCenter,
|
||||
OverlayBackdrop,
|
||||
} from 'folds';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
import { getRoomAvatarUrl } from '$utils/room';
|
||||
import { useRoomNavigate } from '$hooks/useRoomNavigate';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useAtom, useSetAtom } from 'jotai';
|
||||
import {
|
||||
autoJoinCallIntentAtom,
|
||||
incomingCallRoomIdAtom,
|
||||
mutedCallRoomIdAtom,
|
||||
} from '$state/callEmbed';
|
||||
import { RoomAvatar } from './room-avatar';
|
||||
|
||||
type IncomingCallInternalProps = {
|
||||
room: any;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function IncomingCallInternal({ room, onClose }: IncomingCallInternalProps) {
|
||||
const mx = useMatrixClient();
|
||||
const roomName = useRoomName(room);
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
const avatarUrl = getRoomAvatarUrl(mx, room, 96);
|
||||
const setAutoJoinIntent = useSetAtom(autoJoinCallIntentAtom);
|
||||
const setMutedRoomId = useSetAtom(mutedCallRoomIdAtom);
|
||||
|
||||
const handleAnswer = () => {
|
||||
setMutedRoomId(room.roomId);
|
||||
setAutoJoinIntent(room.roomId);
|
||||
onClose();
|
||||
navigateRoom(room.roomId);
|
||||
};
|
||||
|
||||
const handleDecline = async () => {
|
||||
setMutedRoomId(room.roomId);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog variant="Surface" style={{ width: '340px' }}>
|
||||
<Header
|
||||
style={{
|
||||
padding: `0 ${config.space.S200} 0 ${config.space.S400}`,
|
||||
borderBottomWidth: config.borderWidth.B300,
|
||||
}}
|
||||
variant="Surface"
|
||||
size="500"
|
||||
>
|
||||
<Box grow="Yes">
|
||||
<Text size="H4">Incoming Call</Text>
|
||||
</Box>
|
||||
<IconButton size="300" onClick={onClose} radii="300">
|
||||
<Icon src={Icons.Cross} />
|
||||
</IconButton>
|
||||
</Header>
|
||||
|
||||
<Box style={{ padding: config.space.S600 }} direction="Column" alignItems="Center" gap="500">
|
||||
<Avatar size="500">
|
||||
<RoomAvatar
|
||||
roomId={room.roomId}
|
||||
src={avatarUrl ?? undefined}
|
||||
alt={roomName}
|
||||
renderFallback={() => <Icon size="200" src={Icons.User} filled />}
|
||||
/>
|
||||
</Avatar>
|
||||
|
||||
<Box direction="Column" alignItems="Center" gap="100">
|
||||
<Text size="L400" align="Center" truncate>
|
||||
{roomName}
|
||||
</Text>
|
||||
<Text priority="400" size="T300" align="Center">
|
||||
Incoming voice chat request
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
<Box gap="300" style={{ width: '100%' }} justifyContent="Center">
|
||||
<Button
|
||||
variant="Critical"
|
||||
fill="Soft"
|
||||
style={{ minWidth: '110px' }}
|
||||
onClick={handleDecline}
|
||||
>
|
||||
<Text size="B400">Decline</Text>
|
||||
</Button>
|
||||
<Button
|
||||
fill="Solid"
|
||||
variant="Primary"
|
||||
style={{ minWidth: '110px' }}
|
||||
onClick={handleAnswer}
|
||||
before={<Icon size="100" src={Icons.Phone} />}
|
||||
>
|
||||
<Text size="B400">Answer</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function IncomingCallModal() {
|
||||
const [ringingRoomId, setRingingRoomId] = useAtom(incomingCallRoomIdAtom);
|
||||
const mx = useMatrixClient();
|
||||
const room = ringingRoomId ? mx.getRoom(ringingRoomId) : null;
|
||||
|
||||
if (!ringingRoomId || !room) return null;
|
||||
|
||||
const close = () => setRingingRoomId(null);
|
||||
|
||||
return (
|
||||
<Overlay open backdrop={<OverlayBackdrop />}>
|
||||
<OverlayCenter>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: close,
|
||||
clickOutsideDeactivates: true,
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<IncomingCallInternal room={room} onClose={close} />
|
||||
</div>
|
||||
</FocusTrap>
|
||||
</OverlayCenter>
|
||||
</Overlay>
|
||||
);
|
||||
}
|
||||
@@ -214,6 +214,8 @@ export function MessageForwardInternal({ room, mEvent, onClose }: MessageForward
|
||||
// we can still include the original message content in the body of the message, so we'll just use a fallback text/plain content with the original message body
|
||||
content = {
|
||||
...mEvent.getContent(),
|
||||
'm.relates_to': null, // remove any relations to avoid confusion in the target room
|
||||
'm.mentions': null, // remove mentions to avoid leaking information about users in the original room
|
||||
...forwardedTextContent,
|
||||
'moe.sable.message.forward': {
|
||||
v: 1,
|
||||
|
||||
@@ -20,6 +20,16 @@ export type AutoDiscoveryInfo = Record<string, unknown> & {
|
||||
'm.identity_server'?: {
|
||||
base_url: string;
|
||||
};
|
||||
'org.matrix.msc2965.authentication'?: {
|
||||
account?: string;
|
||||
issuer?: string;
|
||||
};
|
||||
'org.matrix.msc4143.rtc_foci'?: [
|
||||
{
|
||||
livekit_service_url: string;
|
||||
type: 'livekit';
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
export const autoDiscovery = async (
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { Box, Chip, Icon, IconButton, Icons, Text, Tooltip, TooltipProvider } from 'folds';
|
||||
import { useState } from 'react';
|
||||
import { Box, Chip, Icon, IconButton, Icons, Spinner, Text, Tooltip, TooltipProvider } from 'folds';
|
||||
import { useCallback } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { StatusDivider } from './components';
|
||||
import { CallEmbed, useCallControlState } from '../../plugins/call';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
||||
import { callEmbedAtom } from '../../state/callEmbed';
|
||||
|
||||
type MicrophoneButtonProps = {
|
||||
enabled: boolean;
|
||||
onToggle: () => Promise<unknown>;
|
||||
disabled?: boolean;
|
||||
};
|
||||
function MicrophoneButton({ enabled, onToggle }: MicrophoneButtonProps) {
|
||||
function MicrophoneButton({ enabled, onToggle, disabled }: MicrophoneButtonProps) {
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
@@ -26,6 +30,7 @@ function MicrophoneButton({ enabled, onToggle }: MicrophoneButtonProps) {
|
||||
size="300"
|
||||
onClick={() => onToggle()}
|
||||
outlined
|
||||
disabled={disabled}
|
||||
>
|
||||
<Icon size="100" src={enabled ? Icons.Mic : Icons.MicMute} filled={!enabled} />
|
||||
</IconButton>
|
||||
@@ -37,8 +42,9 @@ function MicrophoneButton({ enabled, onToggle }: MicrophoneButtonProps) {
|
||||
type SoundButtonProps = {
|
||||
enabled: boolean;
|
||||
onToggle: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
function SoundButton({ enabled, onToggle }: SoundButtonProps) {
|
||||
function SoundButton({ enabled, onToggle, disabled }: SoundButtonProps) {
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
@@ -57,6 +63,7 @@ function SoundButton({ enabled, onToggle }: SoundButtonProps) {
|
||||
size="300"
|
||||
onClick={() => onToggle()}
|
||||
outlined
|
||||
disabled={disabled}
|
||||
>
|
||||
<Icon
|
||||
size="100"
|
||||
@@ -72,8 +79,9 @@ function SoundButton({ enabled, onToggle }: SoundButtonProps) {
|
||||
type VideoButtonProps = {
|
||||
enabled: boolean;
|
||||
onToggle: () => Promise<unknown>;
|
||||
disabled?: boolean;
|
||||
};
|
||||
function VideoButton({ enabled, onToggle }: VideoButtonProps) {
|
||||
function VideoButton({ enabled, onToggle, disabled }: VideoButtonProps) {
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
@@ -92,6 +100,7 @@ function VideoButton({ enabled, onToggle }: VideoButtonProps) {
|
||||
size="300"
|
||||
onClick={() => onToggle()}
|
||||
outlined
|
||||
disabled={disabled}
|
||||
>
|
||||
<Icon
|
||||
size="100"
|
||||
@@ -104,9 +113,12 @@ function VideoButton({ enabled, onToggle }: VideoButtonProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function ScreenShareButton() {
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
|
||||
type ScreenShareButtonProps = {
|
||||
enabled: boolean;
|
||||
onToggle: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
function ScreenShareButton({ enabled, onToggle, disabled }: ScreenShareButtonProps) {
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
@@ -123,8 +135,9 @@ function ScreenShareButton() {
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
size="300"
|
||||
onClick={() => setEnabled(!enabled)}
|
||||
onClick={onToggle}
|
||||
outlined
|
||||
disabled={disabled}
|
||||
>
|
||||
<Icon size="100" src={Icons.ScreenShare} filled={enabled} />
|
||||
</IconButton>
|
||||
@@ -133,8 +146,31 @@ function ScreenShareButton() {
|
||||
);
|
||||
}
|
||||
|
||||
export function CallControl({ callEmbed }: { callEmbed: CallEmbed }) {
|
||||
const { microphone, video, sound } = useCallControlState(callEmbed.control);
|
||||
export function CallControl({
|
||||
callEmbed,
|
||||
compact,
|
||||
callJoined,
|
||||
}: {
|
||||
callEmbed: CallEmbed;
|
||||
compact: boolean;
|
||||
callJoined: boolean;
|
||||
}) {
|
||||
const { microphone, video, sound, screenshare } = useCallControlState(callEmbed.control);
|
||||
const setCallEmbed = useSetAtom(callEmbedAtom);
|
||||
|
||||
const [hangupState, hangup] = useAsyncCallback(
|
||||
useCallback(() => callEmbed.hangup(), [callEmbed])
|
||||
);
|
||||
const exiting =
|
||||
hangupState.status === AsyncStatus.Loading || hangupState.status === AsyncStatus.Success;
|
||||
|
||||
const handleHangup = () => {
|
||||
if (!callJoined) {
|
||||
setCallEmbed(undefined);
|
||||
return;
|
||||
}
|
||||
hangup();
|
||||
};
|
||||
|
||||
return (
|
||||
<Box shrink="No" alignItems="Center" gap="300">
|
||||
@@ -142,23 +178,48 @@ export function CallControl({ callEmbed }: { callEmbed: CallEmbed }) {
|
||||
<MicrophoneButton
|
||||
enabled={microphone}
|
||||
onToggle={() => callEmbed.control.toggleMicrophone()}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
<SoundButton enabled={sound} onToggle={() => callEmbed.control.toggleSound()} />
|
||||
<VideoButton enabled={video} onToggle={() => callEmbed.control.toggleVideo()} />
|
||||
{false && <ScreenShareButton />}
|
||||
<SoundButton
|
||||
enabled={sound}
|
||||
onToggle={() => callEmbed.control.toggleSound()}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
{!compact && <StatusDivider />}
|
||||
<VideoButton
|
||||
enabled={video}
|
||||
onToggle={() => callEmbed.control.toggleVideo()}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
{!compact && (
|
||||
<ScreenShareButton
|
||||
enabled={screenshare}
|
||||
onToggle={() => callEmbed.control.toggleScreenshare()}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
<StatusDivider />
|
||||
<Chip
|
||||
variant="Critical"
|
||||
radii="300"
|
||||
radii="Pill"
|
||||
fill="Soft"
|
||||
before={<Icon size="50" src={Icons.PhoneDown} filled />}
|
||||
before={
|
||||
exiting ? (
|
||||
<Spinner variant="Critical" fill="Soft" size="50" />
|
||||
) : (
|
||||
<Icon size="50" src={Icons.PhoneDown} filled />
|
||||
)
|
||||
}
|
||||
disabled={exiting}
|
||||
outlined
|
||||
onClick={() => callEmbed.hangup()}
|
||||
onClick={handleHangup}
|
||||
>
|
||||
<Text as="span" size="L400">
|
||||
End
|
||||
</Text>
|
||||
{!compact && (
|
||||
<Text as="span" size="L400">
|
||||
End
|
||||
</Text>
|
||||
)}
|
||||
</Chip>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -46,18 +46,17 @@ export function CallStatus({ callEmbed }: CallStatusProps) {
|
||||
) : (
|
||||
<Spinner variant="Secondary" size="200" />
|
||||
)}
|
||||
<Box
|
||||
grow="Yes"
|
||||
alignItems="Center"
|
||||
gap="Inherit"
|
||||
justifyContent={compact ? 'Center' : undefined}
|
||||
>
|
||||
<CallRoomName room={room} />
|
||||
{speakers.size > 0 && !compact && (
|
||||
<Box grow="Yes" alignItems="Center" gap="Inherit">
|
||||
{!compact && (
|
||||
<>
|
||||
<StatusDivider />
|
||||
<span data-spacing-node />
|
||||
<MemberSpeaking room={room} speakers={speakers} />
|
||||
<CallRoomName room={room} />
|
||||
{speakers.size > 0 && (
|
||||
<>
|
||||
<StatusDivider />
|
||||
<span data-spacing-node />
|
||||
<MemberSpeaking room={room} speakers={speakers} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
@@ -68,8 +67,13 @@ export function CallStatus({ callEmbed }: CallStatusProps) {
|
||||
)}
|
||||
</Box>
|
||||
{memberVisible && !compact && <StatusDivider />}
|
||||
<Box shrink="No" alignItems="Center" justifyContent="Center" gap="Inherit">
|
||||
<CallControl callEmbed={callEmbed} />
|
||||
<Box shrink="No" alignItems="Center" gap="Inherit">
|
||||
{compact && (
|
||||
<Box grow="Yes">
|
||||
<CallRoomName room={room} />
|
||||
</Box>
|
||||
)}
|
||||
<CallControl callJoined={callJoined} compact={compact} callEmbed={callEmbed} />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -128,7 +128,7 @@ export function LiveChip({ count, room, members }: LiveChipProps) {
|
||||
radii="Pill"
|
||||
onClick={handleOpenMenu}
|
||||
>
|
||||
<Text className={css.LiveChipText} as="span" size="L400">
|
||||
<Text className={css.LiveChipText} as="span" size="L400" truncate>
|
||||
{count} Live
|
||||
</Text>
|
||||
</Chip>
|
||||
|
||||
@@ -13,7 +13,7 @@ export function MemberSpeaking({ room, speakers }: MemberSpeakingProps) {
|
||||
);
|
||||
return (
|
||||
<Box alignItems="Center" gap="100">
|
||||
<Icon size="100" src={Icons.Phone} filled />
|
||||
<Icon size="100" src={Icons.Mic} filled />
|
||||
<Text size="T200" truncate>
|
||||
{speakingNames.length === 1 && (
|
||||
<>
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
import { MouseEventHandler, useCallback, useRef, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
config,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Menu,
|
||||
MenuItem,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Spinner,
|
||||
Text,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { SequenceCard } from '../../components/sequence-card';
|
||||
import * as css from './styles.css';
|
||||
import {
|
||||
ChatButton,
|
||||
ControlDivider,
|
||||
MicrophoneButton,
|
||||
ScreenShareButton,
|
||||
SoundButton,
|
||||
VideoButton,
|
||||
} from './Controls';
|
||||
import { CallEmbed, useCallControlState } from '../../plugins/call';
|
||||
import { stopPropagation } from '../../utils/keyboard';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
||||
import { useRoom } from '../../hooks/useRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
|
||||
type CallControlsProps = {
|
||||
callEmbed: CallEmbed;
|
||||
};
|
||||
export function CallControls({ callEmbed }: CallControlsProps) {
|
||||
const room = useRoom();
|
||||
const controlRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const screenSize = useScreenSizeContext();
|
||||
const compact = screenSize === ScreenSize.Mobile;
|
||||
|
||||
const { microphone, video, sound, screenshare, spotlight } = useCallControlState(
|
||||
callEmbed.control
|
||||
);
|
||||
|
||||
const [cords, setCords] = useState<RectCords>();
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setCords(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
const handleSpotlightClick = () => {
|
||||
callEmbed.control.toggleSpotlight();
|
||||
setCords(undefined);
|
||||
};
|
||||
|
||||
const handleReactionsClick = () => {
|
||||
callEmbed.control.toggleReactions();
|
||||
setCords(undefined);
|
||||
};
|
||||
|
||||
const handleSettingsClick = () => {
|
||||
callEmbed.control.toggleSettings();
|
||||
setCords(undefined);
|
||||
};
|
||||
|
||||
const [hangupState, hangup] = useAsyncCallback(
|
||||
useCallback(() => callEmbed.hangup(), [callEmbed])
|
||||
);
|
||||
const exiting =
|
||||
hangupState.status === AsyncStatus.Loading || hangupState.status === AsyncStatus.Success;
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={controlRef}
|
||||
className={css.CallControlContainer}
|
||||
justifyContent="Center"
|
||||
alignItems="Center"
|
||||
style={{
|
||||
maxWidth: '100%',
|
||||
padding: compact ? `0 ${toRem(8)}` : undefined,
|
||||
overflowX: 'auto',
|
||||
}}
|
||||
>
|
||||
<SequenceCard
|
||||
className={css.ControlCard}
|
||||
variant="SurfaceVariant"
|
||||
gap={compact ? '100' : '200'}
|
||||
radii="500"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
direction="Row"
|
||||
>
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap={compact ? '100' : '200'}
|
||||
direction="Row"
|
||||
>
|
||||
<MicrophoneButton
|
||||
enabled={microphone}
|
||||
onToggle={() => callEmbed.control.toggleMicrophone()}
|
||||
/>
|
||||
<SoundButton enabled={sound} onToggle={() => callEmbed.control.toggleSound()} />
|
||||
</Box>
|
||||
|
||||
{!compact && <ControlDivider />}
|
||||
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap={compact ? '100' : '200'}
|
||||
direction="Row"
|
||||
>
|
||||
<VideoButton enabled={video} onToggle={() => callEmbed.control.toggleVideo()} />
|
||||
<ScreenShareButton
|
||||
enabled={screenshare}
|
||||
onToggle={() => callEmbed.control.toggleScreenshare()}
|
||||
/>
|
||||
</Box>
|
||||
{!compact && <ControlDivider />}
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap={compact ? '100' : '200'}
|
||||
direction="Row"
|
||||
>
|
||||
{room?.isCallRoom() && <ChatButton />}
|
||||
|
||||
<PopOut
|
||||
anchor={cords}
|
||||
position="Top"
|
||||
align="Center"
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => setCords(undefined),
|
||||
clickOutsideDeactivates: true,
|
||||
isKeyForward: (evt: KeyboardEvent) => evt.key === 'ArrowDown',
|
||||
isKeyBackward: (evt: KeyboardEvent) => evt.key === 'ArrowUp',
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu>
|
||||
<Box direction="Column" style={{ padding: config.space.S100 }}>
|
||||
<MenuItem
|
||||
size="300"
|
||||
variant="Surface"
|
||||
radii="300"
|
||||
onClick={handleSpotlightClick}
|
||||
>
|
||||
<Text size="B300" truncate>
|
||||
{spotlight ? 'Grid View' : 'Spotlight View'}
|
||||
</Text>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
size="300"
|
||||
variant="Surface"
|
||||
radii="300"
|
||||
onClick={handleReactionsClick}
|
||||
>
|
||||
<Text size="B300" truncate>
|
||||
Reactions
|
||||
</Text>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
size="300"
|
||||
variant="Surface"
|
||||
radii="300"
|
||||
onClick={handleSettingsClick}
|
||||
>
|
||||
<Text size="B300" truncate>
|
||||
Settings
|
||||
</Text>
|
||||
</MenuItem>
|
||||
</Box>
|
||||
</Menu>
|
||||
</FocusTrap>
|
||||
}
|
||||
>
|
||||
<IconButton
|
||||
variant="Surface"
|
||||
fill="Soft"
|
||||
radii="400"
|
||||
size="400"
|
||||
onClick={handleOpenMenu}
|
||||
outlined
|
||||
aria-pressed={!!cords}
|
||||
>
|
||||
<Icon size="400" src={Icons.VerticalDots} />
|
||||
</IconButton>
|
||||
</PopOut>
|
||||
|
||||
<Button
|
||||
style={{ minWidth: compact ? toRem(48) : toRem(88), padding: compact ? 0 : undefined }}
|
||||
variant="Critical"
|
||||
fill="Solid"
|
||||
onClick={hangup}
|
||||
before={
|
||||
exiting ? (
|
||||
<Spinner variant="Critical" fill="Solid" size="200" />
|
||||
) : (
|
||||
<Icon src={Icons.PhoneDown} size="200" filled />
|
||||
)
|
||||
}
|
||||
disabled={exiting}
|
||||
>
|
||||
{!compact && <Text size="B400">End</Text>}
|
||||
</Button>
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -1,21 +1,42 @@
|
||||
import { useRef } from 'react';
|
||||
import { useCallback, useRef, useState, type RefObject } from 'react';
|
||||
import { Badge, Box, color, Header, Scroll, Text, toRem } from 'folds';
|
||||
import { EventType } from '$types/matrix-sdk';
|
||||
import { useCallEmbed, useCallEmbedPlacementSync, useCallJoined } from '$hooks/useCallEmbed';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||
import { useRoom } from '$hooks/useRoom';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRoom } from '$hooks/useRoom';
|
||||
import { useLivekitSupport } from '$hooks/useLivekitSupport';
|
||||
import { StateEvent } from '$types/matrix/room';
|
||||
import { useCallMembers, useCallSession } from '$hooks/useCall';
|
||||
import { PrescreenControls } from './PrescreenControls';
|
||||
import { CallMemberRenderer } from './CallMemberCard';
|
||||
import { useCallEmbed, useCallEmbedPlacementSync, useCallJoined } from '$hooks/useCallEmbed';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
import * as css from './styles.css';
|
||||
import { CallMemberRenderer } from './CallMemberCard';
|
||||
import { PrescreenControls } from './PrescreenControls';
|
||||
import { CallControls } from './CallControls';
|
||||
|
||||
function JoinMessage({ hasParticipant }: { hasParticipant?: boolean }) {
|
||||
function LivekitServerMissingMessage() {
|
||||
return (
|
||||
<Text style={{ margin: 'auto', color: color.Critical.Main }} size="L400" align="Center">
|
||||
Your homeserver does not support calling. But you can still join call started by others.
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
function JoinMessage({
|
||||
hasParticipant,
|
||||
livekitSupported,
|
||||
}: {
|
||||
hasParticipant?: boolean;
|
||||
livekitSupported?: boolean;
|
||||
}) {
|
||||
if (hasParticipant) return null;
|
||||
|
||||
if (livekitSupported === false) {
|
||||
return <LivekitServerMissingMessage />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Text style={{ margin: 'auto' }} size="L400" align="Center">
|
||||
Voice chat's empty — Be the first to hop in!
|
||||
@@ -39,66 +60,218 @@ function AlreadyInCallMessage() {
|
||||
);
|
||||
}
|
||||
|
||||
export function CallView() {
|
||||
function CallPrescreen() {
|
||||
const mx = useMatrixClient();
|
||||
const room = useRoom();
|
||||
|
||||
const callViewRef = useRef<HTMLDivElement>(null);
|
||||
useCallEmbedPlacementSync(callViewRef);
|
||||
const livekitSupported = useLivekitSupport();
|
||||
|
||||
const powerLevels = usePowerLevelsContext();
|
||||
const creators = useRoomCreators(room);
|
||||
|
||||
const permissions = useRoomPermissions(creators, powerLevels);
|
||||
const canJoin = permissions.event(EventType.GroupCallMemberPrefix, mx.getSafeUserId());
|
||||
const hasPermission = permissions.event(StateEvent.GroupCallMemberPrefix, mx.getSafeUserId());
|
||||
|
||||
const callSession = useCallSession(room);
|
||||
const callMembers = useCallMembers(room, callSession);
|
||||
const hasParticipant = callMembers.length > 0;
|
||||
|
||||
const callEmbed = useCallEmbed();
|
||||
const callJoined = useCallJoined(callEmbed);
|
||||
const inOtherCall = callEmbed && callEmbed.roomId !== room.roomId;
|
||||
|
||||
const currentJoined = callEmbed?.roomId === room.roomId && callJoined;
|
||||
const canJoin = hasPermission && (livekitSupported || hasParticipant);
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={callViewRef}
|
||||
className={ContainerColor({ variant: 'Surface' })}
|
||||
style={{ minWidth: toRem(280) }}
|
||||
grow="Yes"
|
||||
>
|
||||
{!currentJoined && (
|
||||
<Scroll variant="Surface" hideTrack>
|
||||
<Box className={css.CallViewContent} alignItems="Center" justifyContent="Center">
|
||||
<Box style={{ maxWidth: toRem(382), width: '100%' }} direction="Column" gap="100">
|
||||
{hasParticipant && (
|
||||
<Header size="300">
|
||||
<Box grow="Yes" alignItems="Center">
|
||||
<Text size="L400">Participant</Text>
|
||||
</Box>
|
||||
<Badge variant="Critical" fill="Solid" size="400">
|
||||
<Text as="span" size="L400" truncate>
|
||||
{callMembers.length} Live
|
||||
</Text>
|
||||
</Badge>
|
||||
</Header>
|
||||
)}
|
||||
<CallMemberRenderer members={callMembers} />
|
||||
<PrescreenControls canJoin={canJoin} />
|
||||
<Header size="300">
|
||||
{!inOtherCall &&
|
||||
(canJoin ? (
|
||||
<JoinMessage hasParticipant={hasParticipant} />
|
||||
) : (
|
||||
<NoPermissionMessage />
|
||||
))}
|
||||
{inOtherCall && <AlreadyInCallMessage />}
|
||||
</Header>
|
||||
</Box>
|
||||
<Scroll variant="Surface" hideTrack>
|
||||
<Box className={css.CallViewContent} alignItems="Center" justifyContent="Center">
|
||||
<Box style={{ maxWidth: toRem(382), width: '100%' }} direction="Column" gap="100">
|
||||
{hasParticipant && (
|
||||
<Header size="300">
|
||||
<Box grow="Yes" alignItems="Center">
|
||||
<Text size="L400">Participant</Text>
|
||||
</Box>
|
||||
<Badge variant="Critical" fill="Solid" size="400">
|
||||
<Text as="span" size="L400" truncate>
|
||||
{callMembers.length} Live
|
||||
</Text>
|
||||
</Badge>
|
||||
</Header>
|
||||
)}
|
||||
<CallMemberRenderer members={callMembers} />
|
||||
<PrescreenControls canJoin={canJoin} />
|
||||
<Box className={css.PrescreenMessage} alignItems="Center">
|
||||
{!inOtherCall &&
|
||||
(hasPermission ? (
|
||||
<JoinMessage hasParticipant={hasParticipant} livekitSupported={livekitSupported} />
|
||||
) : (
|
||||
<NoPermissionMessage />
|
||||
))}
|
||||
{inOtherCall && <AlreadyInCallMessage />}
|
||||
</Box>
|
||||
</Scroll>
|
||||
</Box>
|
||||
</Box>
|
||||
</Scroll>
|
||||
);
|
||||
}
|
||||
|
||||
type CallJoinedProps = {
|
||||
containerRef: RefObject<HTMLDivElement>;
|
||||
joined: boolean;
|
||||
};
|
||||
|
||||
function CallJoined({ joined, containerRef }: CallJoinedProps) {
|
||||
const callEmbed = useCallEmbed();
|
||||
|
||||
return (
|
||||
<Box grow="Yes" direction="Column" style={{ position: 'relative' }}>
|
||||
<Box grow="Yes" ref={containerRef} style={{ height: '100%', width: '100%' }} />
|
||||
|
||||
{callEmbed && joined && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: toRem(16),
|
||||
left: 0,
|
||||
right: 0,
|
||||
zIndex: 50,
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
<div style={{ pointerEvents: 'all', maxWidth: '100%' }}>
|
||||
<CallControls callEmbed={callEmbed} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
interface CallViewProps {
|
||||
resizable?: boolean;
|
||||
}
|
||||
|
||||
export function CallView({ resizable }: CallViewProps) {
|
||||
const room = useRoom();
|
||||
const screenSize = useScreenSizeContext();
|
||||
const isMobile = screenSize === ScreenSize.Mobile;
|
||||
|
||||
const callViewRef = useRef<HTMLDivElement>(null);
|
||||
const callContainerRef = useRef<HTMLDivElement>(null);
|
||||
useCallEmbedPlacementSync(callContainerRef);
|
||||
|
||||
const callEmbed = useCallEmbed();
|
||||
const callJoined = useCallJoined(callEmbed);
|
||||
|
||||
const currentJoined = callEmbed?.roomId === room.roomId && callJoined;
|
||||
|
||||
const [height, setHeight] = useState(isMobile ? 240 : 380);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const isResizing = useRef(false);
|
||||
|
||||
const handleMove = useCallback(
|
||||
(clientY: number) => {
|
||||
if (!isResizing.current || !callViewRef.current) return;
|
||||
const { top } = callViewRef.current.getBoundingClientRect();
|
||||
setHeight(Math.max(isMobile ? 120 : 150, Math.min(clientY - top, window.innerHeight * 0.8)));
|
||||
},
|
||||
[isMobile]
|
||||
);
|
||||
|
||||
const handleMouseMove = useCallback((e: MouseEvent) => handleMove(e.clientY), [handleMove]);
|
||||
const handleTouchMove = useCallback(
|
||||
(e: TouchEvent) => {
|
||||
if (e.cancelable) e.preventDefault();
|
||||
handleMove(e.touches[0].clientY);
|
||||
},
|
||||
[handleMove]
|
||||
);
|
||||
|
||||
const stopResizing = useCallback(() => {
|
||||
isResizing.current = false;
|
||||
setIsDragging(false);
|
||||
document.removeEventListener('mousemove', handleMouseMove);
|
||||
document.removeEventListener('mouseup', stopResizing);
|
||||
document.removeEventListener('touchmove', handleTouchMove);
|
||||
document.removeEventListener('touchend', stopResizing);
|
||||
document.body.style.userSelect = 'auto';
|
||||
}, [handleMouseMove, handleTouchMove]);
|
||||
|
||||
const startResizing = useCallback(() => {
|
||||
isResizing.current = true;
|
||||
setIsDragging(true);
|
||||
document.addEventListener('mousemove', handleMouseMove);
|
||||
document.addEventListener('mouseup', stopResizing);
|
||||
document.addEventListener('touchmove', handleTouchMove, { passive: false });
|
||||
document.addEventListener('touchend', stopResizing);
|
||||
document.body.style.userSelect = 'none';
|
||||
}, [handleMouseMove, handleTouchMove, stopResizing]);
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={callViewRef}
|
||||
grow="Yes"
|
||||
className={ContainerColor({ variant: 'Surface' })}
|
||||
style={{
|
||||
position: 'relative',
|
||||
minWidth: toRem(280),
|
||||
height: resizable ? `${height}px` : undefined,
|
||||
borderBottom: `1px solid var(--sable-surface-container-line)`,
|
||||
zIndex: 20,
|
||||
backgroundColor: currentJoined ? 'transparent' : undefined,
|
||||
pointerEvents: currentJoined ? 'none' : 'all',
|
||||
}}
|
||||
>
|
||||
{isDragging && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
zIndex: 50,
|
||||
cursor: 'ns-resize',
|
||||
pointerEvents: 'all',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!currentJoined && <CallPrescreen />}
|
||||
<CallJoined joined={currentJoined} containerRef={callContainerRef} />
|
||||
|
||||
{resizable && (
|
||||
<button
|
||||
type="button"
|
||||
onMouseDown={startResizing}
|
||||
onTouchStart={startResizing}
|
||||
aria-label="Resize call view"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: '-12px',
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: '24px',
|
||||
cursor: 'ns-resize',
|
||||
zIndex: 100,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
padding: 0,
|
||||
outline: 'none',
|
||||
pointerEvents: 'all',
|
||||
touchAction: 'none',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: '40px',
|
||||
height: '4px',
|
||||
borderRadius: '2px',
|
||||
background: 'var(--sable-surface-container-line)',
|
||||
opacity: 0.8,
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -113,6 +113,38 @@ export function VideoButton({ enabled, onToggle }: VideoButtonProps) {
|
||||
);
|
||||
}
|
||||
|
||||
type ScreenShareButtonProps = {
|
||||
enabled: boolean;
|
||||
onToggle: () => void;
|
||||
};
|
||||
export function ScreenShareButton({ enabled, onToggle }: ScreenShareButtonProps) {
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Top"
|
||||
delay={500}
|
||||
tooltip={
|
||||
<Tooltip>
|
||||
<Text size="T200">{enabled ? 'Stop Screenshare' : 'Start Screenshare'}</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(anchorRef) => (
|
||||
<IconButton
|
||||
ref={anchorRef}
|
||||
variant={enabled ? 'Success' : 'Surface'}
|
||||
fill="Soft"
|
||||
radii="400"
|
||||
size="400"
|
||||
onClick={() => onToggle()}
|
||||
outlined
|
||||
>
|
||||
<Icon size="400" src={Icons.ScreenShare} filled={enabled} />
|
||||
</IconButton>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export function ChatButton() {
|
||||
const [chat, setChat] = useAtom(callChatAtom);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Box, Button, Icon, Icons, Spinner, Text } from 'folds';
|
||||
import { Box, Button, Icon, Icons, Spinner, Text, toRem } from 'folds';
|
||||
import { SequenceCard } from '../../components/sequence-card';
|
||||
import * as css from './styles.css';
|
||||
import { ChatButton, ControlDivider, MicrophoneButton, SoundButton, VideoButton } from './Controls';
|
||||
import { useIsDirectRoom, useRoom } from '../../hooks/useRoom';
|
||||
import { useCallEmbed, useCallJoined, useCallStart } from '../../hooks/useCallEmbed';
|
||||
import { useCallPreferences } from '../../state/hooks/callPreferences';
|
||||
import { CallControlState } from '../../plugins/call/CallControlState';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
|
||||
type PrescreenControlsProps = {
|
||||
canJoin?: boolean;
|
||||
@@ -16,6 +16,9 @@ export function PrescreenControls({ canJoin }: PrescreenControlsProps) {
|
||||
const callJoined = useCallJoined(callEmbed);
|
||||
const direct = useIsDirectRoom();
|
||||
|
||||
const screenSize = useScreenSizeContext();
|
||||
const compact = screenSize === ScreenSize.Mobile;
|
||||
|
||||
const inOtherCall = callEmbed && callEmbed.roomId !== room.roomId;
|
||||
|
||||
const startCall = useCallStart(direct);
|
||||
@@ -27,41 +30,67 @@ export function PrescreenControls({ canJoin }: PrescreenControlsProps) {
|
||||
useCallPreferences();
|
||||
|
||||
return (
|
||||
<SequenceCard
|
||||
className={css.ControlCard}
|
||||
variant="SurfaceVariant"
|
||||
gap="400"
|
||||
radii="500"
|
||||
<Box
|
||||
justifyContent="Center"
|
||||
alignItems="Center"
|
||||
justifyContent="SpaceBetween"
|
||||
wrap="Wrap"
|
||||
style={{
|
||||
maxWidth: '100%',
|
||||
padding: compact ? `0 ${toRem(8)}` : undefined,
|
||||
overflowX: 'auto',
|
||||
}}
|
||||
>
|
||||
<Box shrink="No" alignItems="Inherit" justifyContent="SpaceBetween" gap="200">
|
||||
<MicrophoneButton enabled={microphone} onToggle={toggleMicrophone} />
|
||||
<SoundButton enabled={sound} onToggle={toggleSound} />
|
||||
</Box>
|
||||
<ControlDivider />
|
||||
<Box shrink="No" alignItems="Inherit" justifyContent="SpaceBetween" gap="200">
|
||||
<VideoButton enabled={video} onToggle={toggleVideo} />
|
||||
<ChatButton />
|
||||
</Box>
|
||||
<Box grow="Yes" direction="Column">
|
||||
<Button
|
||||
variant={disabled ? 'Secondary' : 'Success'}
|
||||
fill={disabled ? 'Soft' : 'Solid'}
|
||||
onClick={() => startCall(room, new CallControlState(microphone, video, sound))}
|
||||
disabled={disabled || joining}
|
||||
before={
|
||||
joining ? (
|
||||
<Spinner variant="Success" fill="Solid" size="200" />
|
||||
) : (
|
||||
<Icon src={Icons.Phone} size="200" filled />
|
||||
)
|
||||
}
|
||||
<SequenceCard
|
||||
className={css.ControlCard}
|
||||
variant="SurfaceVariant"
|
||||
gap={compact ? '100' : '200'}
|
||||
radii="500"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
direction="Row"
|
||||
>
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap={compact ? '100' : '200'}
|
||||
direction="Row"
|
||||
>
|
||||
<Text size="B400">Join</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
<MicrophoneButton enabled={microphone} onToggle={toggleMicrophone} />
|
||||
<SoundButton enabled={sound} onToggle={toggleSound} />
|
||||
</Box>
|
||||
|
||||
{!compact && <ControlDivider />}
|
||||
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap={compact ? '100' : '200'}
|
||||
direction="Row"
|
||||
>
|
||||
<VideoButton enabled={video} onToggle={toggleVideo} />
|
||||
{room?.isCallRoom() && <ChatButton />}
|
||||
</Box>
|
||||
|
||||
<Box shrink="No" alignItems="Center" justifyContent="Center" direction="Row">
|
||||
<Button
|
||||
style={{ minWidth: compact ? toRem(48) : toRem(88), padding: compact ? 0 : undefined }}
|
||||
variant={disabled ? 'Secondary' : 'Success'}
|
||||
fill={disabled ? 'Soft' : 'Solid'}
|
||||
onClick={() => startCall(room, { microphone, video, sound })}
|
||||
disabled={disabled || joining}
|
||||
before={
|
||||
joining ? (
|
||||
<Spinner variant="Success" fill="Solid" size="200" />
|
||||
) : (
|
||||
<Icon src={Icons.Phone} size="200" filled />
|
||||
)
|
||||
}
|
||||
>
|
||||
{!compact && <Text size="B400">Join</Text>}
|
||||
</Button>
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -18,3 +18,11 @@ export const ControlDivider = style({
|
||||
export const CallMemberCard = style({
|
||||
padding: config.space.S300,
|
||||
});
|
||||
|
||||
export const CallControlContainer = style({
|
||||
padding: config.space.S400,
|
||||
});
|
||||
|
||||
export const PrescreenMessage = style({
|
||||
padding: config.space.S200,
|
||||
});
|
||||
@@ -296,15 +296,6 @@ function AddRoomButton({ item }: { item: HierarchyItem }) {
|
||||
>
|
||||
<Text size="T300">Voice Room</Text>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
variant="Primary"
|
||||
fill="None"
|
||||
onClick={() => handleCreateRoom(CreateRoomType.VoiceRoom)}
|
||||
>
|
||||
<Text size="T300">New Voice Room</Text>
|
||||
</MenuItem>
|
||||
<MenuItem size="300" radii="300" fill="None" onClick={handleAddExisting}>
|
||||
<Text size="T300">Existing Room</Text>
|
||||
</MenuItem>
|
||||
|
||||
@@ -60,18 +60,18 @@ import { useRoomName } from '$hooks/useRoomMeta';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { useRoomNavigate } from '$hooks/useRoomNavigate';
|
||||
|
||||
// Upstream Call Hooks
|
||||
// Call Hooks & Plugins
|
||||
import { useCallMembers, useCallSession } from '$hooks/useCall';
|
||||
import { useCallEmbed, useCallStart } from '$hooks/useCallEmbed';
|
||||
import { callChatAtom } from '$state/callEmbed';
|
||||
import { useCallPreferencesAtom } from '$state/hooks/callPreferences';
|
||||
import { CallControlState } from '$plugins/call/CallControlState';
|
||||
import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo';
|
||||
import { livekitSupport } from '$hooks/useLivekitSupport';
|
||||
import { RoomNavUser } from './RoomNavUser';
|
||||
|
||||
/**
|
||||
* Reactively checks whether a room has unread messages, even if the
|
||||
* push-rule notification count is zero (e.g. mentions-only rooms with
|
||||
* new regular messages).
|
||||
* Reactively checks whether a room has unread messages.
|
||||
*/
|
||||
function useRoomHasUnread(room: Room): boolean {
|
||||
const mx = useMatrixClient();
|
||||
@@ -278,25 +278,23 @@ export function RoomNavItem({
|
||||
(receipt) => receipt.userId !== mx.getUserId()
|
||||
);
|
||||
|
||||
// Name Resolution
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const dmUserId = direct ? room.getAvatarFallbackMember()?.userId : undefined;
|
||||
const matrixRoomName = useRoomName(room);
|
||||
const roomName = (dmUserId && nicknames[dmUserId]) || matrixRoomName;
|
||||
|
||||
// Navigation & Context
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
const navigate = useNavigate();
|
||||
const screenSize = useScreenSizeContext();
|
||||
const isMobile = screenSize === ScreenSize.Mobile;
|
||||
|
||||
// Call Hooks (Merged from upstream)
|
||||
const callSession = useCallSession(room);
|
||||
const callMembers = useCallMembers(room, callSession);
|
||||
const startCall = useCallStart(direct);
|
||||
const callEmbed = useCallEmbed();
|
||||
const callPref = useAtomValue(useCallPreferencesAtom());
|
||||
const [isChatOpen, setChatOpen] = useAtom(callChatAtom);
|
||||
const autoDiscoveryInfo = useAutoDiscoveryInfo();
|
||||
|
||||
const isActiveCall = callEmbed?.roomId === room.roomId;
|
||||
|
||||
@@ -316,6 +314,9 @@ export function RoomNavItem({
|
||||
|
||||
const handleNavItemClick: MouseEventHandler<HTMLElement> = (evt) => {
|
||||
if (room.isCallRoom()) {
|
||||
if (!livekitSupport(autoDiscoveryInfo) && callMembers.length === 0) return;
|
||||
if (callEmbed && !isActiveCall) return;
|
||||
|
||||
if (!isMobile) {
|
||||
if (!isActiveCall && !callEmbed) {
|
||||
startCall(
|
||||
@@ -440,11 +441,14 @@ export function RoomNavItem({
|
||||
aria-label={notificationMode}
|
||||
/>
|
||||
)}
|
||||
{room.isCallRoom() && callMembers.length > 0 && !optionsVisible && (
|
||||
{(room.isCallRoom() || direct) && callMembers.length > 0 && !optionsVisible && (
|
||||
<Badge variant="Critical" fill="Solid" size="400">
|
||||
<Text as="span" size="L400" truncate>
|
||||
{callMembers.length} Live
|
||||
</Text>
|
||||
<Box alignItems="Center" gap="100">
|
||||
<Icon size="50" src={Icons.Phone} color="Inherit" />
|
||||
<Text as="span" size="L400" truncate>
|
||||
{direct ? 'Calling' : `${callMembers.length} Live`}
|
||||
</Text>
|
||||
</Box>
|
||||
</Badge>
|
||||
)}
|
||||
</Box>
|
||||
@@ -452,7 +456,7 @@ export function RoomNavItem({
|
||||
</NavButton>
|
||||
{optionsVisible && (
|
||||
<NavItemOptions>
|
||||
{room.isCallRoom() && (
|
||||
{(room.isCallRoom() || (direct && callMembers.length > 0)) && (
|
||||
<TooltipProvider
|
||||
position="Bottom"
|
||||
offset={4}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { IconButton, Icon, Icons, TooltipProvider, Tooltip, Text } from 'folds';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import { useCallStart, useCallJoined } from '$hooks/useCallEmbed';
|
||||
import { callEmbedAtom } from '$state/callEmbed';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
|
||||
interface RoomCallButtonProps {
|
||||
room: Room;
|
||||
}
|
||||
|
||||
export function RoomCallButton({ room }: RoomCallButtonProps) {
|
||||
const startCall = useCallStart();
|
||||
const callEmbed = useAtomValue(callEmbedAtom);
|
||||
const joined = useCallJoined(callEmbed);
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const isJoinedInThisRoom = joined && callEmbed?.roomId === room.roomId;
|
||||
|
||||
if (isJoinedInThisRoom) return null;
|
||||
|
||||
const handleStartCall = async () => {
|
||||
startCall(room);
|
||||
try {
|
||||
const now = Date.now();
|
||||
// TODO not use as any one day someday i swear
|
||||
await mx.sendEvent(room.roomId, 'org.matrix.msc4075.rtc.notification' as any, {
|
||||
notification_type: 'ring',
|
||||
sender_ts: now,
|
||||
lifetime: 30000,
|
||||
'm.mentions': {
|
||||
room: true,
|
||||
},
|
||||
application: 'm.call',
|
||||
call_id: room.roomId,
|
||||
'm.text': [
|
||||
{ body: `Call started by ${mx.getUser(mx.getSafeUserId())?.displayName || 'User'} 🎶` },
|
||||
],
|
||||
});
|
||||
} catch {
|
||||
/* skill issue block */
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<TooltipProvider
|
||||
position="Bottom"
|
||||
offset={4}
|
||||
tooltip={
|
||||
<Tooltip>
|
||||
<Text>Start Voice Call</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(triggerRef) => (
|
||||
<IconButton
|
||||
fill="None"
|
||||
ref={triggerRef}
|
||||
onClick={handleStartCall}
|
||||
aria-label="Start Voice Call"
|
||||
>
|
||||
<Icon size="400" src={Icons.Phone} />
|
||||
</IconButton>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
@@ -290,7 +290,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const isEncrypted = room.hasEncryptionStateEvent();
|
||||
|
||||
useElementSizeObserver(
|
||||
useCallback(() => document.body, []),
|
||||
useCallback(() => fileDropContainerRef.current, [fileDropContainerRef]),
|
||||
useCallback((width) => setHideStickerBtn(width < 500), [])
|
||||
);
|
||||
|
||||
|
||||
@@ -1895,7 +1895,13 @@ export function RoomTimeline({
|
||||
const senderId = mEvent.getSender() ?? '';
|
||||
const senderName = getMemberDisplayName(room, senderId) || getMxIdLocalPart(senderId);
|
||||
|
||||
const callJoined = mEvent.getContent<SessionMembershipData>().application;
|
||||
const content = mEvent.getContent<SessionMembershipData>();
|
||||
const prevContent = mEvent.getPrevContent();
|
||||
|
||||
const callJoined = content.application;
|
||||
if (callJoined && 'application' in prevContent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const timeJSX = (
|
||||
<Time
|
||||
|
||||
@@ -26,6 +26,10 @@ import { RoomSettingsPage } from '$state/roomSettings';
|
||||
import { GlobalModalManager } from '$components/message/modals/GlobalModalManager';
|
||||
import { useDelayedEventsSupport } from '$hooks/useDelayedEventsSupport';
|
||||
import { delayedEventsSupportedAtom } from '$state/scheduledMessages';
|
||||
import { useCallMembers, useCallSession } from '$hooks/useCall';
|
||||
import { callEmbedAtom } from '$state/callEmbed';
|
||||
import { useCallJoined } from '$hooks/useCallEmbed';
|
||||
import { CallView } from '$features/call/CallView';
|
||||
import { useRoom } from '$hooks/useRoom';
|
||||
import { RoomViewFollowing, RoomViewFollowingPlaceholder } from './RoomViewFollowing';
|
||||
import { RoomInput } from './RoomInput';
|
||||
@@ -127,6 +131,12 @@ export function RoomView({ eventId }: { eventId?: string }) {
|
||||
}
|
||||
}, [screenSize, openSettings, room.roomId, space?.roomId]);
|
||||
|
||||
const callSession = useCallSession(room);
|
||||
const callMembers = useCallMembers(room, callSession);
|
||||
const callEmbed = useAtomValue(callEmbedAtom);
|
||||
const isJoinedInThisRoom = useCallJoined(callEmbed) && callEmbed?.roomId === room.roomId;
|
||||
const showCallView = !room.isCallRoom() && (callMembers.length > 0 || isJoinedInThisRoom);
|
||||
|
||||
return (
|
||||
<BackRouteHandler>
|
||||
{(onBack) => (
|
||||
@@ -140,6 +150,11 @@ export function RoomView({ eventId }: { eventId?: string }) {
|
||||
>
|
||||
<SwipeableChatWrapper onOpenSidebar={onBack} onOpenMembers={handleOpenMembers}>
|
||||
<Box grow="Yes" direction="Column">
|
||||
{showCallView && (
|
||||
<Box shrink="No" style={{ width: '100%', position: 'relative' }}>
|
||||
<CallView resizable />
|
||||
</Box>
|
||||
)}
|
||||
<RoomTimeline
|
||||
key={roomId}
|
||||
room={room}
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import { EventTimeline, Room } from '$types/matrix-sdk';
|
||||
|
||||
import { useStateEvent } from '$hooks/useStateEvent';
|
||||
import { PageHeader } from '$components/page';
|
||||
@@ -45,7 +45,7 @@ import {
|
||||
mxcUrlToHttp,
|
||||
removeRoomIdFromMDirect,
|
||||
} from '$utils/matrix';
|
||||
import { SearchPathSearchParams } from '$pages/paths';
|
||||
import { type SearchPathSearchParams } from '$pages/paths';
|
||||
import { useRoomUnread } from '$state/hooks/unread';
|
||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||
import { markAsRead } from '$utils/notifications';
|
||||
@@ -82,6 +82,7 @@ import { RoomSettingsPage } from '$state/roomSettings';
|
||||
import { JumpToTime } from './jump-to-time';
|
||||
import { RoomPinMenu } from './room-pin-menu';
|
||||
import * as css from './RoomViewHeader.css';
|
||||
import { RoomCallButton } from './RoomCallButton';
|
||||
|
||||
const log = createLogger('RoomViewHeader');
|
||||
|
||||
@@ -343,6 +344,11 @@ export function RoomViewHeader({ callView }: { callView?: boolean }) {
|
||||
|
||||
const [chat, setChat] = useAtom(callChatAtom);
|
||||
|
||||
const canUseCalls = room
|
||||
.getLiveTimeline()
|
||||
.getState(EventTimeline.FORWARDS)
|
||||
?.maySendStateEvent('org.matrix.msc3401.call.member', mx.getUserId()!);
|
||||
|
||||
const encryptionEvent = useStateEvent(room, StateEvent.RoomEncryption);
|
||||
const encryptedRoom = !!encryptionEvent;
|
||||
const avatarMxc = useRoomAvatar(room, direct);
|
||||
@@ -577,6 +583,7 @@ export function RoomViewHeader({ callView }: { callView?: boolean }) {
|
||||
</IconButton>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
{canUseCalls && <RoomCallButton room={room} />}
|
||||
<PopOut
|
||||
anchor={pinMenuAnchor}
|
||||
position="Bottom"
|
||||
@@ -648,7 +655,11 @@ export function RoomViewHeader({ callView }: { callView?: boolean }) {
|
||||
offset={4}
|
||||
tooltip={
|
||||
<Tooltip>
|
||||
<Text>{peopleDrawer ? 'Hide Members' : 'Show Members'}</Text>
|
||||
{callView ? (
|
||||
<Text>Members</Text>
|
||||
) : (
|
||||
<Text>{peopleDrawer ? 'Hide Members' : 'Show Members'}</Text>
|
||||
)}
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { Box, Text, IconButton, Icon, Icons, Scroll, Button, config, toRem, Spinner } from 'folds';
|
||||
import { Page, PageContent, PageHeader } from '$components/page';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
@@ -7,7 +8,6 @@ import { clearCacheAndReload } from '$client/initMatrix';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
import { Method } from '$types/matrix-sdk';
|
||||
import { useState } from 'react';
|
||||
import { useOpenBugReportModal } from '$state/hooks/bugReportModal';
|
||||
|
||||
export function HomeserverInfo() {
|
||||
@@ -15,7 +15,6 @@ export function HomeserverInfo() {
|
||||
const [federationUrl, setFederationUrl] = useState<string>(mx.baseUrl);
|
||||
const [version, setVersion] = useState<any>(undefined);
|
||||
|
||||
// By default assume the federationUrl is the same as the baseUrl.
|
||||
if (!version)
|
||||
mx.http
|
||||
.request(Method.Get, '/version', undefined, undefined, {
|
||||
@@ -25,7 +24,6 @@ export function HomeserverInfo() {
|
||||
.then((fetched_version) => setVersion(fetched_version))
|
||||
.catch((error) => {
|
||||
if (federationUrl === mx.baseUrl) {
|
||||
// Maybe they are *not* the same actually.
|
||||
mx.http
|
||||
.request(Method.Get, '/server', undefined, undefined, {
|
||||
prefix: '/.well-known/matrix',
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useCallStart } from '$hooks/useCallEmbed';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { autoJoinCallIntentAtom } from '$state/callEmbed';
|
||||
|
||||
export function useAutoJoinCall() {
|
||||
const mx = useMatrixClient();
|
||||
const selectedRoomId = useSelectedRoom();
|
||||
const [autoJoinIntent, setAutoJoinIntent] = useAtom(autoJoinCallIntentAtom);
|
||||
const startCall = useCallStart();
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedRoomId && autoJoinIntent && selectedRoomId === autoJoinIntent) {
|
||||
const room = mx.getRoom(selectedRoomId);
|
||||
|
||||
if (room) {
|
||||
startCall(room);
|
||||
setAutoJoinIntent(null);
|
||||
}
|
||||
}
|
||||
}, [selectedRoomId, autoJoinIntent, startCall, setAutoJoinIntent, mx]);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { callEmbedAtom } from '../state/callEmbed';
|
||||
import { useResizeObserver } from './useResizeObserver';
|
||||
import { CallControlState } from '../plugins/call/CallControlState';
|
||||
import { useCallMembersChange, useCallSession } from './useCall';
|
||||
import { CallPreferences } from '../state/callPreferences';
|
||||
|
||||
const CallEmbedContext = createContext<CallEmbed | undefined>(undefined);
|
||||
|
||||
@@ -43,7 +44,7 @@ export const createCallEmbed = (
|
||||
dm: boolean,
|
||||
themeKind: ElementCallThemeKind,
|
||||
container: HTMLElement,
|
||||
controlState?: CallControlState
|
||||
pref?: CallPreferences
|
||||
): CallEmbed => {
|
||||
const rtcSession = mx.matrixRTC.getRoomSession(room);
|
||||
const ongoing =
|
||||
@@ -51,6 +52,8 @@ export const createCallEmbed = (
|
||||
|
||||
const intent = CallEmbed.getIntent(dm, ongoing);
|
||||
const widget = CallEmbed.getWidget(mx, room, intent, themeKind);
|
||||
const controlState = pref && new CallControlState(pref.microphone, pref.video, pref.sound);
|
||||
|
||||
const embed = new CallEmbed(mx, room, widget, container, controlState);
|
||||
|
||||
return embed;
|
||||
@@ -63,12 +66,12 @@ export const useCallStart = (dm = false) => {
|
||||
const callEmbedRef = useCallEmbedRef();
|
||||
|
||||
const startCall = useCallback(
|
||||
(room: Room, controlState?: CallControlState) => {
|
||||
(room: Room, pref?: CallPreferences) => {
|
||||
const container = callEmbedRef.current;
|
||||
if (!container) {
|
||||
throw new Error('Failed to start call, No embed container element found!');
|
||||
}
|
||||
const callEmbed = createCallEmbed(mx, room, dm, theme.kind, container, controlState);
|
||||
const callEmbed = createCallEmbed(mx, room, dm, theme.kind, container, pref);
|
||||
|
||||
setCallEmbed(callEmbed);
|
||||
},
|
||||
@@ -141,14 +144,23 @@ export const useCallEmbedPlacementSync = (containerViewRef: RefObject<HTMLDivEle
|
||||
const container = containerViewRef.current;
|
||||
if (!embedEl || !container) return;
|
||||
|
||||
embedEl.style.top = `${container.offsetTop}px`;
|
||||
embedEl.style.left = `${container.offsetLeft}px`;
|
||||
embedEl.style.width = `${container.clientWidth}px`;
|
||||
embedEl.style.height = `${container.clientHeight}px`;
|
||||
const rect = container.getBoundingClientRect();
|
||||
|
||||
embedEl.style.position = 'fixed';
|
||||
embedEl.style.top = `${rect.top}px`;
|
||||
embedEl.style.left = `${rect.left}px`;
|
||||
embedEl.style.width = `${rect.width}px`;
|
||||
embedEl.style.height = `${rect.height}px`;
|
||||
}, [callEmbedRef, containerViewRef]);
|
||||
|
||||
useResizeObserver(
|
||||
syncCallEmbedPlacement,
|
||||
useCallback(() => containerViewRef.current, [containerViewRef])
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
syncCallEmbedPlacement();
|
||||
window.addEventListener('scroll', syncCallEmbedPlacement, true);
|
||||
return () => window.removeEventListener('scroll', syncCallEmbedPlacement, true);
|
||||
}, [syncCallEmbedPlacement]);
|
||||
};
|
||||
@@ -0,0 +1,179 @@
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
import { RoomStateEvent } from 'matrix-js-sdk';
|
||||
import { MatrixRTCSession } from 'matrix-js-sdk/lib/matrixrtc/MatrixRTCSession';
|
||||
import { MatrixRTCSessionManagerEvents } from 'matrix-js-sdk/lib/matrixrtc/MatrixRTCSessionManager';
|
||||
import { useSetAtom, useAtomValue } from 'jotai';
|
||||
import { mDirectAtom } from '$state/mDirectList';
|
||||
import { incomingCallRoomIdAtom, mutedCallRoomIdAtom } from '$state/callEmbed';
|
||||
import RingtoneSound from '$public/sound/ringtone.webm';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
type CallPhase = 'IDLE' | 'RINGING_OUT' | 'RINGING_IN' | 'ACTIVE' | 'ENDED';
|
||||
|
||||
interface SignalState {
|
||||
incoming: string | null;
|
||||
outgoing: string | null;
|
||||
}
|
||||
|
||||
export function useCallSignaling() {
|
||||
const mx = useMatrixClient();
|
||||
const setIncomingCall = useSetAtom(incomingCallRoomIdAtom);
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
|
||||
const incomingAudioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const outgoingAudioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const ringingRoomIdRef = useRef<string | null>(null);
|
||||
const outgoingStartRef = useRef<number | null>(null);
|
||||
const callPhaseRef = useRef<Record<string, CallPhase>>({});
|
||||
|
||||
const mutedRoomId = useAtomValue(mutedCallRoomIdAtom);
|
||||
const setMutedRoomId = useSetAtom(mutedCallRoomIdAtom);
|
||||
|
||||
useEffect(() => {
|
||||
const inc = new Audio(RingtoneSound);
|
||||
inc.loop = true;
|
||||
incomingAudioRef.current = inc;
|
||||
|
||||
const out = new Audio(RingtoneSound);
|
||||
out.loop = true;
|
||||
outgoingAudioRef.current = out;
|
||||
|
||||
return () => {
|
||||
inc.pause();
|
||||
out.pause();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const stopRinging = useCallback(() => {
|
||||
incomingAudioRef.current?.pause();
|
||||
outgoingAudioRef.current?.pause();
|
||||
if (incomingAudioRef.current) incomingAudioRef.current.currentTime = 0;
|
||||
if (outgoingAudioRef.current) outgoingAudioRef.current.currentTime = 0;
|
||||
|
||||
ringingRoomIdRef.current = null;
|
||||
setIncomingCall(null);
|
||||
}, [setIncomingCall]);
|
||||
|
||||
const playOutgoingRinging = useCallback((roomId: string) => {
|
||||
if (outgoingAudioRef.current && ringingRoomIdRef.current !== roomId) {
|
||||
outgoingAudioRef.current.play().catch(() => {});
|
||||
ringingRoomIdRef.current = roomId;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const playRinging = useCallback(
|
||||
(roomId: string) => {
|
||||
if (incomingAudioRef.current && ringingRoomIdRef.current !== roomId) {
|
||||
incomingAudioRef.current.play().catch(() => {});
|
||||
ringingRoomIdRef.current = roomId;
|
||||
setIncomingCall(roomId);
|
||||
}
|
||||
},
|
||||
[setIncomingCall]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mx || !mx.matrixRTC) return undefined;
|
||||
|
||||
const checkDMsForActiveCalls = () => {
|
||||
const myUserId = mx.getUserId();
|
||||
const now = Date.now();
|
||||
|
||||
const signal = Array.from(mDirects).reduce<SignalState>(
|
||||
(acc, roomId) => {
|
||||
if (acc.incoming || mutedRoomId === roomId) return acc;
|
||||
|
||||
const room = mx.getRoom(roomId);
|
||||
if (!room) return acc;
|
||||
|
||||
const session = mx.matrixRTC.getRoomSession(room);
|
||||
const memberships = MatrixRTCSession.sessionMembershipsForRoom(
|
||||
room,
|
||||
session.sessionDescription
|
||||
);
|
||||
|
||||
const remoteMembers = memberships.filter((m: any) => (m.userId || m.sender) !== myUserId);
|
||||
const isSelfInCall = memberships.some((m: any) => (m.userId || m.sender) === myUserId);
|
||||
const currentPhase = callPhaseRef.current[roomId] || 'IDLE';
|
||||
|
||||
// no one here
|
||||
if (!isSelfInCall && remoteMembers.length === 0) {
|
||||
callPhaseRef.current[roomId] = 'IDLE';
|
||||
return acc;
|
||||
}
|
||||
|
||||
// being called
|
||||
if (remoteMembers.length > 0 && !isSelfInCall) {
|
||||
callPhaseRef.current[roomId] = 'RINGING_IN';
|
||||
return { ...acc, incoming: roomId };
|
||||
}
|
||||
|
||||
// multiple people no ringtone
|
||||
if (isSelfInCall && remoteMembers.length > 0) {
|
||||
callPhaseRef.current[roomId] = 'ACTIVE';
|
||||
return acc;
|
||||
}
|
||||
|
||||
// alone in call
|
||||
if (isSelfInCall && remoteMembers.length === 0) {
|
||||
// Check if post call
|
||||
if (currentPhase === 'ACTIVE' || currentPhase === 'ENDED') {
|
||||
callPhaseRef.current[roomId] = 'ENDED';
|
||||
return acc;
|
||||
}
|
||||
|
||||
// Check if new call
|
||||
if (currentPhase === 'IDLE' || currentPhase === 'RINGING_OUT') {
|
||||
if (!outgoingStartRef.current) outgoingStartRef.current = now;
|
||||
|
||||
if (now - outgoingStartRef.current < 30000) {
|
||||
callPhaseRef.current[roomId] = 'RINGING_OUT';
|
||||
return { ...acc, outgoing: roomId };
|
||||
}
|
||||
|
||||
callPhaseRef.current[roomId] = 'ENDED';
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
{ incoming: null, outgoing: null }
|
||||
);
|
||||
|
||||
if (signal.incoming) {
|
||||
playRinging(signal.incoming);
|
||||
} else if (signal.outgoing) {
|
||||
playOutgoingRinging(signal.outgoing);
|
||||
} else {
|
||||
stopRinging();
|
||||
if (!signal.outgoing) outgoingStartRef.current = null;
|
||||
}
|
||||
};
|
||||
|
||||
const interval = setInterval(checkDMsForActiveCalls, 1000);
|
||||
|
||||
const handleUpdate = () => checkDMsForActiveCalls();
|
||||
|
||||
const handleSessionEnded = (roomId: string) => {
|
||||
if (mutedRoomId === roomId) setMutedRoomId(null);
|
||||
callPhaseRef.current[roomId] = 'IDLE';
|
||||
checkDMsForActiveCalls();
|
||||
};
|
||||
|
||||
mx.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, handleUpdate);
|
||||
mx.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, handleSessionEnded);
|
||||
mx.on(RoomStateEvent.Events, handleUpdate);
|
||||
|
||||
checkDMsForActiveCalls();
|
||||
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
mx.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, handleUpdate);
|
||||
mx.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionEnded, handleSessionEnded);
|
||||
mx.off(RoomStateEvent.Events, handleUpdate);
|
||||
stopRinging();
|
||||
};
|
||||
}, [mx, mDirects, playRinging, stopRinging, mutedRoomId, setMutedRoomId, playOutgoingRinging]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { AutoDiscoveryInfo } from '../cs-api';
|
||||
import { useAutoDiscoveryInfo } from './useAutoDiscoveryInfo';
|
||||
|
||||
export const livekitSupport = (autoDiscoveryInfo: AutoDiscoveryInfo): boolean => {
|
||||
const rtcFoci = autoDiscoveryInfo['org.matrix.msc4143.rtc_foci'];
|
||||
|
||||
return (
|
||||
Array.isArray(rtcFoci) && rtcFoci.some((info) => typeof info.livekit_service_url === 'string')
|
||||
);
|
||||
};
|
||||
|
||||
export const useLivekitSupport = (): boolean => {
|
||||
const autoDiscoveryInfo = useAutoDiscoveryInfo();
|
||||
|
||||
return livekitSupport(autoDiscoveryInfo);
|
||||
};
|
||||
@@ -1,10 +1,17 @@
|
||||
import { useCallEmbed } from '../hooks/useCallEmbed';
|
||||
import { CallStatus } from '../features/call-status';
|
||||
import { useSelectedRoom } from '../hooks/router/useSelectedRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '../hooks/useScreenSize';
|
||||
|
||||
export function CallStatusRenderer() {
|
||||
const callEmbed = useCallEmbed();
|
||||
const selectedRoom = useSelectedRoom();
|
||||
|
||||
const screenSize = useScreenSizeContext();
|
||||
|
||||
if (!callEmbed) return null;
|
||||
|
||||
if (screenSize === ScreenSize.Mobile && callEmbed.roomId === selectedRoom) return null;
|
||||
|
||||
return <CallStatus callEmbed={callEmbed} />;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import { PasswordInput } from '$components/password-input';
|
||||
import { getResetPasswordPath } from '$pages/pathUtils';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { FieldError } from '$pages/auth/FiledError';
|
||||
import { deviceDisplayName } from '$utils/user-agent';
|
||||
import {
|
||||
CustomLoginResponse,
|
||||
LoginError,
|
||||
@@ -133,7 +134,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
user: username,
|
||||
},
|
||||
password,
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -151,7 +152,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
user: mxIdUsername,
|
||||
},
|
||||
password,
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
};
|
||||
const handleEmailLogin = (email: string, password: string) => {
|
||||
@@ -163,7 +164,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
address: email,
|
||||
},
|
||||
password,
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { useCallback, useEffect } from 'react';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { deviceDisplayName } from '$utils/user-agent';
|
||||
import { CustomLoginResponse, LoginError, login, useLoginComplete } from './loginUtil';
|
||||
|
||||
function LoginTokenError({ message }: { message: string }) {
|
||||
@@ -57,7 +58,7 @@ export function TokenLogin({ token }: TokenLoginProps) {
|
||||
startLogin(baseUrl, {
|
||||
type: 'm.login.token',
|
||||
token,
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
}, [baseUrl, token, startLogin]);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import { ConfirmPasswordMatch } from '$components/ConfirmPasswordMatch';
|
||||
import { UIAFlowOverlay } from '$components/UIAFlowOverlay';
|
||||
import { RequestEmailTokenCallback, RequestEmailTokenResponse } from '$hooks/types';
|
||||
import { FieldError } from '$pages/auth/FiledError';
|
||||
import { deviceDisplayName } from '$utils/user-agent';
|
||||
import { RegisterError, RegisterResult, register, useRegisterComplete } from './registerUtil';
|
||||
|
||||
export const SUPPORTED_REGISTER_STAGES = [
|
||||
@@ -109,7 +110,7 @@ function RegisterUIAFlow({
|
||||
auth: authDict,
|
||||
password,
|
||||
username,
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
},
|
||||
[onRegister, formData]
|
||||
@@ -250,7 +251,7 @@ export function PasswordRegisterForm({
|
||||
auth: {
|
||||
session: authData.session,
|
||||
},
|
||||
initial_device_display_name: 'Sable Web',
|
||||
initial_device_display_name: deviceDisplayName(),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ReactNode, useCallback, useMemo } from 'react';
|
||||
import { AutoDiscoveryInfoProvider } from '../../hooks/useAutoDiscoveryInfo';
|
||||
import { AsyncStatus, useAsyncCallbackValue } from '../../hooks/useAsyncCallback';
|
||||
import { autoDiscovery, AutoDiscoveryInfo } from '../../cs-api';
|
||||
import { getMxIdServer } from '../../utils/matrix';
|
||||
|
||||
type AutoDiscoveryProps = {
|
||||
userId: string;
|
||||
baseUrl: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
export function AutoDiscovery({ userId, baseUrl, children }: AutoDiscoveryProps) {
|
||||
const [state] = useAsyncCallbackValue(
|
||||
useCallback(async () => {
|
||||
const server = getMxIdServer(userId);
|
||||
return autoDiscovery(fetch, server ?? userId);
|
||||
}, [userId])
|
||||
);
|
||||
|
||||
const [, info] = state.status === AsyncStatus.Success ? state.data : [];
|
||||
|
||||
const fallback: AutoDiscoveryInfo = useMemo(
|
||||
() => ({
|
||||
'm.homeserver': {
|
||||
base_url: baseUrl,
|
||||
},
|
||||
}),
|
||||
[baseUrl]
|
||||
);
|
||||
|
||||
return <AutoDiscoveryInfoProvider value={info ?? fallback}>{children}</AutoDiscoveryInfoProvider>;
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { useSlidingSyncActiveRoom } from '$hooks/useSlidingSyncActiveRoom';
|
||||
import { getSlidingSyncManager } from '$client/initMatrix';
|
||||
import { NotificationBanner } from '$components/notification-banner';
|
||||
import { useCallSignaling } from '$hooks/useCallSignaling';
|
||||
import { getInboxInvitesPath } from '../pathUtils';
|
||||
import { BackgroundNotifications } from './BackgroundNotifications';
|
||||
|
||||
@@ -634,6 +635,7 @@ function PresenceFeature() {
|
||||
}
|
||||
|
||||
export function ClientNonUIFeatures({ children }: ClientNonUIFeaturesProps) {
|
||||
useCallSignaling();
|
||||
return (
|
||||
<>
|
||||
<SystemEmojiFeature />
|
||||
|
||||
@@ -36,7 +36,12 @@ import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useSyncState } from '$hooks/useSyncState';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { AuthMetadataProvider } from '$hooks/useAuthMetadata';
|
||||
import { sessionsAtom, activeSessionIdAtom, Session, SessionsAction } from '$state/sessions';
|
||||
import {
|
||||
sessionsAtom,
|
||||
activeSessionIdAtom,
|
||||
type Session,
|
||||
type SessionsAction,
|
||||
} from '$state/sessions';
|
||||
import { createLogger } from '$utils/debug';
|
||||
import { useSyncNicknames } from '$hooks/useNickname';
|
||||
import { useAppVisibility } from '$hooks/useAppVisibility';
|
||||
@@ -45,6 +50,7 @@ import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { pushSessionToSW } from '../../../sw-session';
|
||||
import { SyncStatus } from './SyncStatus';
|
||||
import { SpecVersions } from './SpecVersions';
|
||||
import { AutoDiscovery } from './AutoDiscovery';
|
||||
|
||||
const log = createLogger('ClientRoot');
|
||||
|
||||
@@ -171,7 +177,7 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
const activeSession: Session | undefined =
|
||||
sessions.find((s) => s.userId === activeSessionId) ?? sessions[0];
|
||||
|
||||
const { baseUrl } = activeSession ?? {};
|
||||
const { baseUrl, userId } = activeSession ?? {};
|
||||
|
||||
const loadedUserIdRef = useRef<string | undefined>(undefined);
|
||||
|
||||
@@ -193,7 +199,9 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
return newMx;
|
||||
}, [activeSession, activeSessionId, setActiveSessionId])
|
||||
);
|
||||
|
||||
const mx = loadState.status === AsyncStatus.Success ? loadState.data : undefined;
|
||||
|
||||
const [startState, startMatrix] = useAsyncCallback<void, Error, [MatrixClient]>(
|
||||
useCallback(
|
||||
(m) =>
|
||||
@@ -216,7 +224,6 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
activeSession.userId,
|
||||
'— reloading client'
|
||||
);
|
||||
// Update the SW immediately so media requests use the new account's token
|
||||
pushSessionToSW(activeSession.baseUrl, activeSession.accessToken);
|
||||
if (mx?.clientRunning) {
|
||||
stopClient(mx);
|
||||
@@ -278,48 +285,57 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
}
|
||||
}, [])
|
||||
);
|
||||
|
||||
return (
|
||||
<SpecVersions baseUrl={baseUrl}>
|
||||
{mx && <SyncStatus mx={mx} />}
|
||||
{loading && <ClientRootOptions mx={mx} onLogout={handleLogout} />}
|
||||
{(loadState.status === AsyncStatus.Error || startState.status === AsyncStatus.Error) && (
|
||||
<SplashScreen>
|
||||
<Box direction="Column" grow="Yes" alignItems="Center" justifyContent="Center" gap="400">
|
||||
<Dialog>
|
||||
<Box direction="Column" gap="400" style={{ padding: config.space.S400 }}>
|
||||
{loadState.status === AsyncStatus.Error && (
|
||||
<Text>{`Failed to load. ${loadState.error.message}`}</Text>
|
||||
)}
|
||||
{startState.status === AsyncStatus.Error && (
|
||||
<Text>{`Failed to start. ${startState.error.message}`}</Text>
|
||||
)}
|
||||
<Button variant="Critical" onClick={mx ? () => startMatrix(mx) : loadMatrix}>
|
||||
<Text as="span" size="B400">
|
||||
Retry
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
</Box>
|
||||
</SplashScreen>
|
||||
)}
|
||||
{loading || !mx ? (
|
||||
<ClientRootLoading />
|
||||
) : (
|
||||
<MatrixClientProvider value={mx}>
|
||||
<ServerConfigsLoader>
|
||||
{(serverConfigs) => (
|
||||
<CapabilitiesProvider value={serverConfigs.capabilities ?? {}}>
|
||||
<MediaConfigProvider value={serverConfigs.mediaConfig ?? {}}>
|
||||
<AuthMetadataProvider value={serverConfigs.authMetadata}>
|
||||
{children}
|
||||
</AuthMetadataProvider>
|
||||
</MediaConfigProvider>
|
||||
</CapabilitiesProvider>
|
||||
)}
|
||||
</ServerConfigsLoader>
|
||||
</MatrixClientProvider>
|
||||
)}
|
||||
</SpecVersions>
|
||||
<AutoDiscovery userId={userId} baseUrl={baseUrl}>
|
||||
<SpecVersions baseUrl={baseUrl}>
|
||||
{mx && <SyncStatus mx={mx} />}
|
||||
{loading && <ClientRootOptions mx={mx} onLogout={handleLogout} />}
|
||||
{(loadState.status === AsyncStatus.Error || startState.status === AsyncStatus.Error) && (
|
||||
<SplashScreen>
|
||||
<Box
|
||||
direction="Column"
|
||||
grow="Yes"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap="400"
|
||||
>
|
||||
<Dialog>
|
||||
<Box direction="Column" gap="400" style={{ padding: config.space.S400 }}>
|
||||
{loadState.status === AsyncStatus.Error && (
|
||||
<Text>{`Failed to load. ${loadState.error.message}`}</Text>
|
||||
)}
|
||||
{startState.status === AsyncStatus.Error && (
|
||||
<Text>{`Failed to start. ${startState.error.message}`}</Text>
|
||||
)}
|
||||
<Button variant="Critical" onClick={mx ? () => startMatrix(mx) : loadMatrix}>
|
||||
<Text as="span" size="B400">
|
||||
Retry
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
</Box>
|
||||
</SplashScreen>
|
||||
)}
|
||||
{loading || !mx ? (
|
||||
<ClientRootLoading />
|
||||
) : (
|
||||
<MatrixClientProvider value={mx}>
|
||||
<ServerConfigsLoader>
|
||||
{(serverConfigs) => (
|
||||
<CapabilitiesProvider value={serverConfigs.capabilities ?? {}}>
|
||||
<MediaConfigProvider value={serverConfigs.mediaConfig ?? {}}>
|
||||
<AuthMetadataProvider value={serverConfigs.authMetadata}>
|
||||
{children}
|
||||
</AuthMetadataProvider>
|
||||
</MediaConfigProvider>
|
||||
</CapabilitiesProvider>
|
||||
)}
|
||||
</ServerConfigsLoader>
|
||||
</MatrixClientProvider>
|
||||
)}
|
||||
</SpecVersions>
|
||||
</AutoDiscovery>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ClientWidgetApi } from 'matrix-widget-api';
|
||||
import EventEmitter from 'events';
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { CallControlState } from './CallControlState';
|
||||
import { ElementMediaStateDetail, ElementMediaStatePayload, ElementWidgetActions } from './types';
|
||||
|
||||
@@ -14,12 +14,58 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
|
||||
private iframe: HTMLIFrameElement;
|
||||
|
||||
private controlMutationObserver: MutationObserver;
|
||||
|
||||
private get document(): Document | undefined {
|
||||
return this.iframe.contentDocument ?? this.iframe.contentWindow?.document;
|
||||
}
|
||||
|
||||
private get screenshareButton(): HTMLElement | undefined {
|
||||
const screenshareBtn = this.document?.querySelector(
|
||||
'[data-testid="incall_screenshare"]'
|
||||
) as HTMLElement | null;
|
||||
|
||||
return screenshareBtn ?? undefined;
|
||||
}
|
||||
|
||||
private get settingsButton(): HTMLElement | undefined {
|
||||
const leaveBtn = this.document?.querySelector('[data-testid="incall_leave"]');
|
||||
|
||||
const settingsButton = leaveBtn?.previousElementSibling as HTMLElement | null;
|
||||
|
||||
return settingsButton ?? undefined;
|
||||
}
|
||||
|
||||
private get reactionsButton(): HTMLElement | undefined {
|
||||
const reactionsButton = this.settingsButton?.previousElementSibling as HTMLElement | null;
|
||||
|
||||
return reactionsButton ?? undefined;
|
||||
}
|
||||
|
||||
private get spotlightButton(): HTMLInputElement | undefined {
|
||||
const spotlightButton = this.document?.querySelector(
|
||||
'input[value="spotlight"]'
|
||||
) as HTMLInputElement | null;
|
||||
|
||||
return spotlightButton ?? undefined;
|
||||
}
|
||||
|
||||
private get gridButton(): HTMLInputElement | undefined {
|
||||
const gridButton = this.document?.querySelector(
|
||||
'input[value="grid"]'
|
||||
) as HTMLInputElement | null;
|
||||
|
||||
return gridButton ?? undefined;
|
||||
}
|
||||
|
||||
constructor(state: CallControlState, call: ClientWidgetApi, iframe: HTMLIFrameElement) {
|
||||
super();
|
||||
|
||||
this.state = state;
|
||||
this.call = call;
|
||||
this.iframe = iframe;
|
||||
|
||||
this.controlMutationObserver = new MutationObserver(this.onControlMutation.bind(this));
|
||||
}
|
||||
|
||||
public getState(): CallControlState {
|
||||
@@ -38,6 +84,14 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
return this.state.sound;
|
||||
}
|
||||
|
||||
public get screenshare(): boolean {
|
||||
return this.state.screenshare;
|
||||
}
|
||||
|
||||
public get spotlight(): boolean {
|
||||
return this.state.spotlight;
|
||||
}
|
||||
|
||||
public async applyState() {
|
||||
await this.setMediaState({
|
||||
audio_enabled: this.microphone,
|
||||
@@ -47,6 +101,26 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
this.emitStateUpdate();
|
||||
}
|
||||
|
||||
public startObserving() {
|
||||
this.controlMutationObserver.disconnect();
|
||||
|
||||
const screenshareBtn = this.screenshareButton;
|
||||
if (screenshareBtn) {
|
||||
this.controlMutationObserver.observe(screenshareBtn, {
|
||||
attributes: true,
|
||||
attributeFilter: ['data-kind'],
|
||||
});
|
||||
}
|
||||
const spotlightBtn = this.spotlightButton;
|
||||
if (spotlightBtn) {
|
||||
this.controlMutationObserver.observe(spotlightBtn, {
|
||||
attributes: true,
|
||||
});
|
||||
}
|
||||
|
||||
this.onControlMutation();
|
||||
}
|
||||
|
||||
public applySound() {
|
||||
this.setSound(this.sound);
|
||||
}
|
||||
@@ -72,7 +146,9 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
const state = new CallControlState(
|
||||
data.audio_enabled ?? this.microphone,
|
||||
data.video_enabled ?? this.video,
|
||||
this.sound
|
||||
this.sound,
|
||||
this.screenshare,
|
||||
this.spotlight
|
||||
);
|
||||
|
||||
this.state = state;
|
||||
@@ -83,6 +159,20 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
}
|
||||
}
|
||||
|
||||
public onControlMutation() {
|
||||
const screenshare: boolean = this.screenshareButton?.getAttribute('data-kind') === 'primary';
|
||||
const spotlight: boolean = this.spotlightButton?.checked ?? false;
|
||||
|
||||
this.state = new CallControlState(
|
||||
this.microphone,
|
||||
this.video,
|
||||
this.sound,
|
||||
screenshare,
|
||||
spotlight
|
||||
);
|
||||
this.emitStateUpdate();
|
||||
}
|
||||
|
||||
public toggleMicrophone() {
|
||||
const payload: ElementMediaStatePayload = {
|
||||
audio_enabled: !this.microphone,
|
||||
@@ -104,7 +194,13 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
|
||||
this.setSound(sound);
|
||||
|
||||
const state = new CallControlState(this.microphone, this.video, sound);
|
||||
const state = new CallControlState(
|
||||
this.microphone,
|
||||
this.video,
|
||||
sound,
|
||||
this.screenshare,
|
||||
this.spotlight
|
||||
);
|
||||
this.state = state;
|
||||
this.emitStateUpdate();
|
||||
|
||||
@@ -113,6 +209,30 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
}
|
||||
}
|
||||
|
||||
public toggleScreenshare() {
|
||||
this.screenshareButton?.click();
|
||||
}
|
||||
|
||||
public toggleSpotlight() {
|
||||
if (this.spotlight) {
|
||||
this.gridButton?.click();
|
||||
return;
|
||||
}
|
||||
this.spotlightButton?.click();
|
||||
}
|
||||
|
||||
public toggleReactions() {
|
||||
this.reactionsButton?.click();
|
||||
}
|
||||
|
||||
public toggleSettings() {
|
||||
this.settingsButton?.click();
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this.controlMutationObserver.disconnect();
|
||||
}
|
||||
|
||||
private emitStateUpdate() {
|
||||
this.emit(CallControlEvent.StateUpdate);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,21 @@ export class CallControlState {
|
||||
|
||||
public readonly sound: boolean;
|
||||
|
||||
constructor(microphone: boolean, video: boolean, sound: boolean) {
|
||||
public readonly screenshare: boolean;
|
||||
|
||||
public readonly spotlight: boolean;
|
||||
|
||||
constructor(
|
||||
microphone: boolean,
|
||||
video: boolean,
|
||||
sound: boolean,
|
||||
screenshare = false,
|
||||
spotlight = false
|
||||
) {
|
||||
this.microphone = microphone;
|
||||
this.video = video;
|
||||
this.sound = sound;
|
||||
this.screenshare = screenshare;
|
||||
this.spotlight = spotlight;
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export class CallEmbed {
|
||||
|
||||
let initialMediaEvent = true;
|
||||
this.disposables.push(
|
||||
this.listenEvent<ElementMediaStateDetail>(ElementWidgetActions.DeviceMute, (evt) => {
|
||||
this.listenAction<ElementMediaStateDetail>(ElementWidgetActions.DeviceMute, (evt) => {
|
||||
if (initialMediaEvent) {
|
||||
initialMediaEvent = false;
|
||||
this.control.applyState();
|
||||
@@ -177,18 +177,27 @@ export class CallEmbed {
|
||||
return this.call.transport.send(ElementWidgetActions.HangupCall, {});
|
||||
}
|
||||
|
||||
public listenEvent<T>(type: string, callback: (event: CustomEvent<T>) => void) {
|
||||
this.call.on(`action:${type}`, callback);
|
||||
return () => {
|
||||
this.call.off(`action:${type}`, callback);
|
||||
};
|
||||
public onPreparing(callback: () => void) {
|
||||
return this.listenEvent('preparing', callback);
|
||||
}
|
||||
|
||||
public onPreparingError(callback: (error: any) => void) {
|
||||
return this.listenEvent('error:preparing', callback);
|
||||
}
|
||||
|
||||
public onReady(callback: () => void) {
|
||||
return this.listenEvent('ready', callback);
|
||||
}
|
||||
|
||||
public onCapabilitiesNotified(callback: () => void) {
|
||||
return this.listenEvent('capabilitiesNotified', callback);
|
||||
}
|
||||
|
||||
private start() {
|
||||
// Room widgets get locked to the room they were added in
|
||||
this.call.setViewedRoomId(this.roomId);
|
||||
this.disposables.push(
|
||||
this.listenEvent(ElementWidgetActions.JoinCall, this.onCallJoined.bind(this))
|
||||
this.listenAction(ElementWidgetActions.JoinCall, this.onCallJoined.bind(this))
|
||||
);
|
||||
|
||||
// Populate the map of "read up to" events for this widget with the current event in every room.
|
||||
@@ -220,6 +229,7 @@ export class CallEmbed {
|
||||
});
|
||||
this.call.stop();
|
||||
this.container.removeChild(this.iframe);
|
||||
this.control.dispose();
|
||||
|
||||
this.mx.off(ClientEvent.Event, this.onEvent.bind(this));
|
||||
this.mx.off(MatrixEventEvent.Decrypted, this.onEventDecrypted.bind(this));
|
||||
@@ -233,6 +243,21 @@ export class CallEmbed {
|
||||
|
||||
private onCallJoined(): void {
|
||||
this.joined = true;
|
||||
this.applyStyles();
|
||||
this.control.startObserving();
|
||||
}
|
||||
|
||||
private applyStyles(): void {
|
||||
const doc = this.document;
|
||||
if (!doc) return;
|
||||
|
||||
doc.body.style.setProperty('background', 'none', 'important');
|
||||
const controls = doc.body.querySelector('[data-testid="incall_leave"]')?.parentElement
|
||||
?.parentElement;
|
||||
if (controls) {
|
||||
controls.style.setProperty('position', 'absolute');
|
||||
controls.style.setProperty('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
|
||||
private onEvent(ev: MatrixEvent): void {
|
||||
@@ -359,4 +384,15 @@ export class CallEmbed {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public listenAction<T>(type: string, callback: (event: CustomEvent<T>) => void) {
|
||||
return this.listenEvent(`action:${type}`, callback);
|
||||
}
|
||||
|
||||
public listenEvent<T>(type: string, callback: (event: T) => void) {
|
||||
this.call.on(type, callback);
|
||||
return () => {
|
||||
this.call.off(type, callback);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,11 @@ export const getRecentEmojis = (mx: MatrixClient, limit?: number): IEmoji[] => {
|
||||
|
||||
export function addRecentEmoji(mx: MatrixClient, unicode: string) {
|
||||
const recentEmojiEvent = getAccountData(mx, AccountDataEvent.ElementRecentEmoji);
|
||||
const recentEmoji = recentEmojiEvent?.getContent<IRecentEmojiContent>().recent_emoji ?? [];
|
||||
const recentEmojiContent = recentEmojiEvent?.getContent<IRecentEmojiContent>();
|
||||
const recentEmoji =
|
||||
recentEmojiContent && Array.isArray(recentEmojiContent.recent_emoji)
|
||||
? structuredClone(recentEmojiContent.recent_emoji)
|
||||
: [];
|
||||
|
||||
const emojiIndex = recentEmoji.findIndex(([u]) => u === unicode);
|
||||
let entry: [EmojiUnicode, EmojiUsageCount];
|
||||
|
||||
@@ -18,3 +18,7 @@ export const callEmbedAtom = atom<CallEmbed | undefined, [CallEmbed | undefined]
|
||||
);
|
||||
|
||||
export const callChatAtom = atom<boolean>(false);
|
||||
|
||||
export const incomingCallRoomIdAtom = atom<string | null>(null);
|
||||
export const autoJoinCallIntentAtom = atom<string | null>(null);
|
||||
export const mutedCallRoomIdAtom = atom<string | null>(null);
|
||||
@@ -238,6 +238,7 @@ export const EmoticonImg = style([
|
||||
{
|
||||
height: '1em',
|
||||
cursor: 'default',
|
||||
maxWidth: '800px',
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
@@ -87,16 +87,16 @@ export const scaleYDimension = (x: number, scaledX: number, y: number): number =
|
||||
};
|
||||
|
||||
export const parseGeoUri = (location: string) => {
|
||||
if (!location) return null;
|
||||
if (!location) return undefined;
|
||||
|
||||
const [, data] = location.split(':');
|
||||
if (!data) return null;
|
||||
if (!data) return undefined;
|
||||
|
||||
const [cords] = data.split(';');
|
||||
if (!cords) return null;
|
||||
if (!cords) return undefined;
|
||||
|
||||
const [latitude, longitude] = cords.split(',');
|
||||
if (!latitude || !longitude) return null;
|
||||
if (!latitude || !longitude) return undefined;
|
||||
|
||||
return {
|
||||
latitude,
|
||||
@@ -112,8 +112,8 @@ export const trimTrailingSlash = (str: string): string => str.replace(END_SLASHE
|
||||
export const trimSlash = (str: string): string => trimLeadingSlash(trimTrailingSlash(str));
|
||||
|
||||
export const nameInitials = (str: string | undefined | null, len = 1): string => {
|
||||
if (!str) return '�';
|
||||
return [...str].slice(0, len).join('') || '�';
|
||||
if (!str) return '';
|
||||
return [...str].slice(0, len).join('') || '';
|
||||
};
|
||||
|
||||
export const randomStr = (len = 12): string => {
|
||||
|
||||
@@ -14,3 +14,10 @@ const isMac = result.os.name === 'Mac OS';
|
||||
export const ua = () => result;
|
||||
export const isMacOS = () => isMac;
|
||||
export const mobileOrTablet = () => isMobileOrTablet;
|
||||
|
||||
export const deviceDisplayName = (): string => {
|
||||
const browser = result.browser.name;
|
||||
const os = result.os.name;
|
||||
if (!browser || !os) return 'Sable Web';
|
||||
return `Sable on ${browser} for ${os}`;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference lib="WebWorker" />
|
||||
// eslint-disable-next-line import-x/no-extraneous-dependencies
|
||||
|
||||
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
|
||||
|
||||
import { createPushNotifications } from './sw/pushNotification';
|
||||
@@ -358,6 +358,8 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
||||
scope,
|
||||
});
|
||||
|
||||
const isCall = data?.isCall === true;
|
||||
|
||||
// Build a canonical deep-link URL.
|
||||
//
|
||||
// Room messages: /to/:user_id/:room_id/:event_id?
|
||||
@@ -373,9 +375,10 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
||||
if (pushUserId) u.searchParams.set('uid', pushUserId);
|
||||
targetUrl = u.href;
|
||||
} else if (pushUserId && pushRoomId) {
|
||||
const callParam = isCall ? '?joinCall=true' : '';
|
||||
const segments = pushEventId
|
||||
? `to/${encodeURIComponent(pushUserId)}/${encodeURIComponent(pushRoomId)}/${encodeURIComponent(pushEventId)}/`
|
||||
: `to/${encodeURIComponent(pushUserId)}/${encodeURIComponent(pushRoomId)}/`;
|
||||
? `to/${encodeURIComponent(pushUserId)}/${encodeURIComponent(pushRoomId)}/${encodeURIComponent(pushEventId)}/${callParam}`
|
||||
: `to/${encodeURIComponent(pushUserId)}/${encodeURIComponent(pushRoomId)}/${callParam}`;
|
||||
targetUrl = new URL(segments, scope).href;
|
||||
} else {
|
||||
// Fallback: no room ID or no user ID in payload.
|
||||
@@ -410,6 +413,7 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
||||
roomId: pushRoomId,
|
||||
eventId: pushEventId,
|
||||
isInvite,
|
||||
isCall,
|
||||
});
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await wc.focus();
|
||||
|
||||
@@ -49,6 +49,29 @@ export const createPushNotifications = (
|
||||
await self.registration.showNotification(title, notifOptions as NotificationOptions);
|
||||
};
|
||||
|
||||
const handleCallNotification = async (pushData: any) => {
|
||||
const content = pushData?.content;
|
||||
if (content?.notification_type !== 'ring') return;
|
||||
|
||||
const senderDisplayName = pushData?.sender_display_name;
|
||||
const roomName = pushData?.room_name;
|
||||
const title = 'Incoming Call';
|
||||
const body = senderDisplayName
|
||||
? `${senderDisplayName} is calling you ${roomName ? `in ${roomName}` : ''}`
|
||||
: 'Incoming voice chat';
|
||||
|
||||
const data = {
|
||||
type: pushData?.type,
|
||||
room_id: pushData?.room_id,
|
||||
user_id: pushData?.user_id,
|
||||
timestamp: Date.now(),
|
||||
isCall: true,
|
||||
...pushData.data,
|
||||
};
|
||||
|
||||
await showNotificationWithData(title, body, data, resolveSilent(), pushData?.room_avatar_url);
|
||||
};
|
||||
|
||||
const handleRoomMessageNotification = async (pushData: any) => {
|
||||
const data = {
|
||||
type: pushData?.type,
|
||||
@@ -158,6 +181,10 @@ export const createPushNotifications = (
|
||||
if (!(pushData?.content?.membership === 'invite')) break;
|
||||
await handleInvitationNotification(pushData);
|
||||
break;
|
||||
case 'org.matrix.msc4075.call.notify':
|
||||
case 'org.matrix.msc4075.rtc.notification':
|
||||
await handleCallNotification(pushData);
|
||||
break;
|
||||
default:
|
||||
// no voip support in app anyway
|
||||
break;
|
||||
|
||||
+23
-23
@@ -1,5 +1,5 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import type { ViteDevServer } from 'vite';
|
||||
import type { ViteDevServer, PluginOption } from 'vite';
|
||||
import { execSync } from 'child_process';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
@@ -15,6 +15,7 @@ import { constants as zlibConstants } from 'zlib';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { cloudflare } from '@cloudflare/vite-plugin';
|
||||
import { createRequire } from 'module';
|
||||
import buildConfig from './build.config';
|
||||
|
||||
const packageJson = JSON.parse(
|
||||
@@ -89,30 +90,25 @@ const copyFiles = {
|
||||
],
|
||||
};
|
||||
|
||||
function serverMatrixSdkCryptoWasm(wasmFilePath: string) {
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
function serverMatrixSdkCryptoWasm() {
|
||||
return {
|
||||
name: 'vite-plugin-serve-matrix-sdk-crypto-wasm',
|
||||
configureServer(server: ViteDevServer) {
|
||||
const resolvedPath = path.join(
|
||||
path.dirname(require.resolve('@matrix-org/matrix-sdk-crypto-wasm')),
|
||||
'pkg/matrix_sdk_crypto_wasm_bg.wasm'
|
||||
);
|
||||
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url === wasmFilePath) {
|
||||
const resolvedPath = path.join(
|
||||
path.resolve(),
|
||||
'/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm'
|
||||
);
|
||||
|
||||
if (fs.existsSync(resolvedPath)) {
|
||||
res.setHeader('Content-Type', 'application/wasm');
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
|
||||
const fileStream = fs.createReadStream(resolvedPath);
|
||||
fileStream.pipe(res);
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end('File not found');
|
||||
}
|
||||
} else {
|
||||
if (!req.url?.endsWith('matrix_sdk_crypto_wasm_bg.wasm')) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/wasm');
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
fs.createReadStream(resolvedPath).pipe(res);
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -151,7 +147,7 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
serverMatrixSdkCryptoWasm('/node_modules/.vite/deps/pkg/matrix_sdk_crypto_wasm_bg.wasm'),
|
||||
serverMatrixSdkCryptoWasm(),
|
||||
topLevelAwait({
|
||||
// The export name of top-level await promise for each chunk module
|
||||
promiseExportName: '__tla',
|
||||
@@ -160,7 +156,7 @@ export default defineConfig({
|
||||
}),
|
||||
viteStaticCopy(copyFiles),
|
||||
vanillaExtractPlugin({ identifiers: 'debug' }),
|
||||
wasm(),
|
||||
wasm() as PluginOption,
|
||||
react(),
|
||||
svgr(),
|
||||
VitePWA({
|
||||
@@ -199,7 +195,11 @@ export default defineConfig({
|
||||
force: true,
|
||||
// Keep matrix-widget-api prebundled so matrix-js-sdk can import its named exports in dev.
|
||||
// Force CJS interop for stability across optimizer cache rebuilds.
|
||||
include: ['matrix-widget-api'],
|
||||
include: [
|
||||
'matrix-widget-api',
|
||||
'workbox-precaching',
|
||||
'@vanilla-extract/recipes/createRuntimeFn',
|
||||
],
|
||||
needsInterop: ['matrix-widget-api'],
|
||||
esbuildOptions: {
|
||||
define: {
|
||||
@@ -219,7 +219,7 @@ export default defineConfig({
|
||||
sourcemap: true,
|
||||
copyPublicDir: false,
|
||||
rollupOptions: {
|
||||
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
|
||||
plugins: [inject({ Buffer: ['buffer', 'Buffer'] }) as PluginOption],
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user