Optional Element Call origin via config.json elementCallUrl (#43) #243
Generated
+4
-4
@@ -81,7 +81,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@axe-core/playwright": "4.13.0",
|
"@axe-core/playwright": "4.13.0",
|
||||||
"@lotusguild/element-call-embedded": "0.25.0-lotus.20",
|
"@lotusguild/element-call-embedded": "0.25.0-lotus.21",
|
||||||
"@playwright/test": "1.63.0",
|
"@playwright/test": "1.63.0",
|
||||||
"@rollup/plugin-inject": "5.0.5",
|
"@rollup/plugin-inject": "5.0.5",
|
||||||
"@rollup/plugin-wasm": "6.2.2",
|
"@rollup/plugin-wasm": "6.2.2",
|
||||||
@@ -2695,9 +2695,9 @@
|
|||||||
"integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA=="
|
"integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA=="
|
||||||
},
|
},
|
||||||
"node_modules/@lotusguild/element-call-embedded": {
|
"node_modules/@lotusguild/element-call-embedded": {
|
||||||
"version": "0.25.0-lotus.20",
|
"version": "0.25.0-lotus.21",
|
||||||
"resolved": "https://code.lotusguild.org/api/packages/LotusGuild/npm/%40lotusguild%2Felement-call-embedded/-/0.25.0-lotus.20/element-call-embedded-0.25.0-lotus.20.tgz",
|
"resolved": "https://code.lotusguild.org/api/packages/LotusGuild/npm/%40lotusguild%2Felement-call-embedded/-/0.25.0-lotus.21/element-call-embedded-0.25.0-lotus.21.tgz",
|
||||||
"integrity": "sha512-USac8cunc+nlkyivxV0dXshzJoSWTyNHc6Aq/xIpphKbkON05NzhEWBX+qNwgwdyVWacdmYAEX97z6jHA5J+Kw==",
|
"integrity": "sha512-Phtjop2qdKRrCLqAhzipRaJaVnU3MjK9CV4QwHkwU/Xlj8oguZBfjOlV7zTqOTzAr57OteOfLcyxLsmv5+u9tg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@matrix-org/matrix-sdk-crypto-wasm": {
|
"node_modules/@matrix-org/matrix-sdk-crypto-wasm": {
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@axe-core/playwright": "4.13.0",
|
"@axe-core/playwright": "4.13.0",
|
||||||
"@lotusguild/element-call-embedded": "0.25.0-lotus.20",
|
"@lotusguild/element-call-embedded": "0.25.0-lotus.21",
|
||||||
"@playwright/test": "1.63.0",
|
"@playwright/test": "1.63.0",
|
||||||
"@rollup/plugin-inject": "5.0.5",
|
"@rollup/plugin-inject": "5.0.5",
|
||||||
"@rollup/plugin-wasm": "6.2.2",
|
"@rollup/plugin-wasm": "6.2.2",
|
||||||
|
|||||||
@@ -115,7 +115,12 @@ export function CallSoundboard({ callEmbed }: CallSoundboardProps) {
|
|||||||
try {
|
try {
|
||||||
const url = await resolveClipObjectUrl(mx, flat.clip.url);
|
const url = await resolveClipObjectUrl(mx, flat.clip.url);
|
||||||
const vol = (flat.clip.volume / 100) * master;
|
const vol = (flat.clip.volume / 100) * master;
|
||||||
const result = await callEmbed.control.injectAudio(url, vol);
|
// [Gitea #43] Send the bytes too: the call page may be on another
|
||||||
|
// origin, where this blob: URL can't be fetched.
|
||||||
|
const clipBytes = await fetch(url)
|
||||||
|
.then((r) => r.arrayBuffer())
|
||||||
|
.catch(() => undefined);
|
||||||
|
const result = await callEmbed.control.injectAudio(url, vol, clipBytes);
|
||||||
if (!result.played) {
|
if (!result.played) {
|
||||||
// [EC#13] Refused fork-side (only reason today: local mic muted) —
|
// [EC#13] Refused fork-side (only reason today: local mic muted) —
|
||||||
// don't play it locally either, or the user would think it went out.
|
// don't play it locally either, or the user would think it went out.
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ export type ClientConfig = {
|
|||||||
|
|
||||||
hashRouter?: HashRouterConfig;
|
hashRouter?: HashRouterConfig;
|
||||||
gifApiKey?: string;
|
gifApiKey?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Gitea #43] Absolute https URL of the Element Call page on its own origin.
|
||||||
|
* Unset: the bundled copy on this origin. Ignored in the desktop app.
|
||||||
|
*/
|
||||||
|
elementCallUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
||||||
|
|||||||
+22
-17
@@ -36,6 +36,7 @@ import { applyCustomAccent, removeCustomAccent } from '../utils/accentColor';
|
|||||||
import { zIndices } from '../styles/zIndex';
|
import { zIndices } from '../styles/zIndex';
|
||||||
import { OIDC_CALLBACK_PATH } from './paths';
|
import { OIDC_CALLBACK_PATH } from './paths';
|
||||||
import { OidcCallback } from './auth/oidc/OidcCallback';
|
import { OidcCallback } from './auth/oidc/OidcCallback';
|
||||||
|
import { resolveCallPageUrl, setCallPageUrl } from '../plugins/call/callPageUrl';
|
||||||
|
|
||||||
// The emoji families (Twemoji when "Twitter emoji" is on, Twemoji flags on
|
// The emoji families (Twemoji when "Twitter emoji" is on, Twemoji flags on
|
||||||
// Windows — see SystemEmojiFeature) must sit before the generic family, or the
|
// Windows — see SystemEmojiFeature) must sit before the generic family, or the
|
||||||
@@ -220,23 +221,27 @@ function App() {
|
|||||||
<ConfigConfigError error={err} retry={retry} ignore={ignore} />
|
<ConfigConfigError error={err} retry={retry} ignore={ignore} />
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{(clientConfig) => (
|
{(clientConfig) => {
|
||||||
<ClientConfigProvider value={clientConfig}>
|
// [Gitea #43] Idempotent: where the call page is loaded from.
|
||||||
<QueryClientProvider client={queryClient}>
|
setCallPageUrl(resolveCallPageUrl(clientConfig.elementCallUrl, isTauri()));
|
||||||
<JotaiProvider>
|
return (
|
||||||
<AppearanceEffects />
|
<ClientConfigProvider value={clientConfig}>
|
||||||
<TauriEffects />
|
<QueryClientProvider client={queryClient}>
|
||||||
<DesktopChrome>
|
<JotaiProvider>
|
||||||
<RouterProvider router={createRouter(clientConfig, screenSize)} />
|
<AppearanceEffects />
|
||||||
</DesktopChrome>
|
<TauriEffects />
|
||||||
<SeasonalEffect />
|
<DesktopChrome>
|
||||||
<NightLightOverlay />
|
<RouterProvider router={createRouter(clientConfig, screenSize)} />
|
||||||
<LotusToastContainer />
|
</DesktopChrome>
|
||||||
</JotaiProvider>
|
<SeasonalEffect />
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
<NightLightOverlay />
|
||||||
</QueryClientProvider>
|
<LotusToastContainer />
|
||||||
</ClientConfigProvider>
|
</JotaiProvider>
|
||||||
)}
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
|
</QueryClientProvider>
|
||||||
|
</ClientConfigProvider>
|
||||||
|
);
|
||||||
|
}}
|
||||||
</ClientConfigLoader>
|
</ClientConfigLoader>
|
||||||
</FeatureCheck>
|
</FeatureCheck>
|
||||||
</ScreenSizeProvider>
|
</ScreenSizeProvider>
|
||||||
|
|||||||
@@ -564,19 +564,27 @@ export class CallControl extends EventEmitter implements CallControlState {
|
|||||||
* track (`io.lotus.inject_audio`) rather than splicing the mic. `url` must be
|
* 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
|
* an https/blob URL the widget can fetch WITHOUT credentials — the host
|
||||||
* resolves an mxc clip to a `blob:` object URL first (authenticated media
|
* 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
|
* The local user does not hear their own published track, so callers should
|
||||||
* also play the clip locally for feedback.
|
* 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
|
// [EC#13] The fork now refuses while the local mic is muted and replies
|
||||||
// { played:false, reason:"muted" }; older forks reply {} (treated as played).
|
// { 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
|
return this.call.transport
|
||||||
.send<{ url: string; volume: number }, { played?: boolean; reason?: string }>(
|
.send<
|
||||||
'io.lotus.inject_audio',
|
{ url: string; volume: number; audio?: ArrayBuffer },
|
||||||
{ url, volume },
|
{ played?: boolean; reason?: string }
|
||||||
)
|
>('io.lotus.inject_audio', audio ? { url, volume, audio } : { url, volume })
|
||||||
.then((r) => ({ played: r?.played !== false, reason: r?.reason }))
|
.then((r) => ({ played: r?.played !== false, reason: r?.reason }))
|
||||||
.catch(() => ({ played: true }));
|
.catch(() => ({ played: true }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import { CallControl } from './CallControl';
|
|||||||
import { CallControlState } from './CallControlState';
|
import { CallControlState } from './CallControlState';
|
||||||
import { verifyDenoiseAssets } from './denoiseSmokeCheck';
|
import { verifyDenoiseAssets } from './denoiseSmokeCheck';
|
||||||
import { canDelegateCapability } from './utils';
|
import { canDelegateCapability } from './utils';
|
||||||
|
import { getCallPageUrl } from './callPageUrl';
|
||||||
import { restrictWidgetMessages } from '../widgetTransport';
|
import { restrictWidgetMessages } from '../widgetTransport';
|
||||||
|
|
||||||
// Maximum time to wait for the embedded Element Call iframe to progress from
|
// 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');
|
params.append('sendNotificationType', CallEmbed.dmCall(intent) ? 'ring' : 'notification');
|
||||||
}
|
}
|
||||||
|
|
||||||
const widgetUrl = new URL(
|
// [Gitea #43] On its own origin when config.json sets elementCallUrl.
|
||||||
`${trimTrailingSlash(import.meta.env.BASE_URL)}/public/element-call/index.html`,
|
const externalPage = getCallPageUrl();
|
||||||
window.location.origin,
|
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();
|
widgetUrl.search = params.toString();
|
||||||
|
|
||||||
const options: IWidget = {
|
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