feat(call): optional Element Call origin via config.json elementCallUrl (#43)
CI / Build & Quality Checks (pull_request) Successful in 3m31s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 12s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m27s
CI / Build & Quality Checks (pull_request) Successful in 3m31s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 12s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m27s
Groundwork for serving the call page from its own origin (call.chat.lotusguild.org). Inert until config.json sets `elementCallUrl`: without it the bundled same-origin page is used exactly as today. - callPageUrl: resolves `elementCallUrl` — absolute https only (http only on localhost for development); anything else, and the desktop app, fall back to the bundled page so a bad value can't break calls. Set once from the loaded client config. - CallEmbed builds the widget URL from it; the widget origin (used by the message guard and Capability Delegation) follows automatically. - Soundboard: a host blob: URL can't be fetched from another origin, so io.lotus.inject_audio now also carries the clip's bytes (`audio`). Forks that predate it ignore the field and use `url`, so this is safe on the released fork. Needs element-call's lotus-call-origin branch (host-origin message check + inject_audio bytes) released and pinned before `elementCallUrl` is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
df395776b4
commit
4dcc5176e2
@@ -564,19 +564,27 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
* track (`io.lotus.inject_audio`) rather than splicing the mic. `url` must be
|
||||
* an https/blob URL the widget can fetch WITHOUT credentials — the host
|
||||
* resolves an mxc clip to a `blob:` object URL first (authenticated media
|
||||
* can't be fetched cross-realm by the widget). `volume` is 0–1.
|
||||
* can't be fetched cross-realm by the widget) — and `audio` the same clip's
|
||||
* bytes, which the fork prefers. `volume` is 0–1.
|
||||
*
|
||||
* The local user does not hear their own published track, so callers should
|
||||
* also play the clip locally for feedback.
|
||||
*/
|
||||
public injectAudio(url: string, volume = 1): Promise<{ played: boolean; reason?: string }> {
|
||||
public injectAudio(
|
||||
url: string,
|
||||
volume = 1,
|
||||
audio?: ArrayBuffer,
|
||||
): Promise<{ played: boolean; reason?: string }> {
|
||||
// [EC#13] The fork now refuses while the local mic is muted and replies
|
||||
// { played:false, reason:"muted" }; older forks reply {} (treated as played).
|
||||
// [Gitea #43] `audio` carries the clip's bytes: a `blob:` URL only works on
|
||||
// this origin, so a call page on its own origin can't fetch it. Forks that
|
||||
// predate `audio` ignore it and use `url`.
|
||||
return this.call.transport
|
||||
.send<{ url: string; volume: number }, { played?: boolean; reason?: string }>(
|
||||
'io.lotus.inject_audio',
|
||||
{ url, volume },
|
||||
)
|
||||
.send<
|
||||
{ url: string; volume: number; audio?: ArrayBuffer },
|
||||
{ played?: boolean; reason?: string }
|
||||
>('io.lotus.inject_audio', audio ? { url, volume, audio } : { url, volume })
|
||||
.then((r) => ({ played: r?.played !== false, reason: r?.reason }))
|
||||
.catch(() => ({ played: true }));
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import { CallControl } from './CallControl';
|
||||
import { CallControlState } from './CallControlState';
|
||||
import { verifyDenoiseAssets } from './denoiseSmokeCheck';
|
||||
import { canDelegateCapability } from './utils';
|
||||
import { getCallPageUrl } from './callPageUrl';
|
||||
import { restrictWidgetMessages } from '../widgetTransport';
|
||||
|
||||
// Maximum time to wait for the embedded Element Call iframe to progress from
|
||||
@@ -254,10 +255,14 @@ export class CallEmbed {
|
||||
params.append('sendNotificationType', CallEmbed.dmCall(intent) ? 'ring' : 'notification');
|
||||
}
|
||||
|
||||
const widgetUrl = new URL(
|
||||
`${trimTrailingSlash(import.meta.env.BASE_URL)}/public/element-call/index.html`,
|
||||
window.location.origin,
|
||||
);
|
||||
// [Gitea #43] On its own origin when config.json sets elementCallUrl.
|
||||
const externalPage = getCallPageUrl();
|
||||
const widgetUrl = externalPage
|
||||
? new URL(externalPage)
|
||||
: new URL(
|
||||
`${trimTrailingSlash(import.meta.env.BASE_URL)}/public/element-call/index.html`,
|
||||
window.location.origin,
|
||||
);
|
||||
widgetUrl.search = params.toString();
|
||||
|
||||
const options: IWidget = {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { resolveCallPageUrl } from './callPageUrl';
|
||||
|
||||
const URL_OK = 'https://call.chat.example.org/public/element-call/index.html';
|
||||
|
||||
test('uses an absolute https URL on the web', () => {
|
||||
assert.equal(resolveCallPageUrl(URL_OK, false), URL_OK);
|
||||
});
|
||||
|
||||
test('strips a query or hash (the app adds its own parameters)', () => {
|
||||
assert.equal(resolveCallPageUrl(`${URL_OK}?x=1#y`, false), URL_OK);
|
||||
});
|
||||
|
||||
test('allows http only on localhost (development)', () => {
|
||||
assert.equal(
|
||||
resolveCallPageUrl('http://127.0.0.1:5174/public/element-call/index.html', false),
|
||||
'http://127.0.0.1:5174/public/element-call/index.html',
|
||||
);
|
||||
assert.equal(resolveCallPageUrl('http://call.example.org/index.html', false), undefined);
|
||||
});
|
||||
|
||||
test('desktop keeps the bundled page', () => {
|
||||
assert.equal(resolveCallPageUrl(URL_OK, true), undefined);
|
||||
});
|
||||
|
||||
test('anything else falls back to the bundled page', () => {
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
42,
|
||||
'',
|
||||
' ',
|
||||
'not a url',
|
||||
'/public/element-call/index.html',
|
||||
'http://call.chat.example.org/index.html',
|
||||
['javascript', 'alert(1)'].join(':'),
|
||||
'data:text/html,x',
|
||||
].forEach((v) => assert.equal(resolveCallPageUrl(v, false), undefined, String(v)));
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* [Gitea #43] Where the Element Call page is loaded from.
|
||||
*
|
||||
* By default it's the copy bundled with this app (same origin). With
|
||||
* `elementCallUrl` in config.json (e.g.
|
||||
* "https://call.chat.lotusguild.org/public/element-call/index.html") the web
|
||||
* app loads it from that origin instead, so the call frame can no longer
|
||||
* reach this origin's storage (login token, crypto store) or service worker.
|
||||
*
|
||||
* Web only: the desktop app keeps its bundled copy (its CSP doesn't allow
|
||||
* another frame origin, and a network copy could drift from the bundle).
|
||||
* Anything that isn't an absolute https URL (http only on localhost, for
|
||||
* development) is ignored, so a bad value falls
|
||||
* back to the bundled page instead of breaking calls.
|
||||
*/
|
||||
export const resolveCallPageUrl = (value: unknown, desktop: boolean): string | undefined => {
|
||||
if (desktop || typeof value !== 'string' || value.trim() === '') return undefined;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
// http only for local development (localhost is a secure context).
|
||||
const local = url.hostname === 'localhost' || url.hostname === '127.0.0.1';
|
||||
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && local)) return undefined;
|
||||
url.search = '';
|
||||
url.hash = '';
|
||||
return url.href;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
let callPageUrl: string | undefined;
|
||||
|
||||
export const setCallPageUrl = (url: string | undefined): void => {
|
||||
callPageUrl = url;
|
||||
};
|
||||
|
||||
export const getCallPageUrl = (): string | undefined => callPageUrl;
|
||||
Reference in New Issue
Block a user