Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/app/plugins/call/CallEmbed.intent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,20 @@ describe('CallEmbed.getWidget', () => {

expect(url.pathname).toContain('/public/element-call/index.html');
});

it('uses the actual window origin as parentUrl on Tauri, not the canonical app URL', () => {
vi.stubGlobal('window', {
location: {
origin: 'https://tauri.localhost',
protocol: 'https:',
host: 'tauri.localhost',
hostname: 'tauri.localhost',
},
});
const room = createRoom(false);
const widget = CallEmbed.getWidget(mx, room, ElementCallIntent.StartCallVoice, 'dark');
const url = new URL(widget.getCompleteUrl({ currentUserId: '@alice:example.com' }));

expect(url.searchParams.get('parentUrl')).toBe('https://tauri.localhost');
});
});
4 changes: 2 additions & 2 deletions src/app/plugins/call/CallEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'matrix-widget-api';
import { CallWidgetDriver } from './CallWidgetDriver';
import { trimTrailingSlash } from '../../utils/common';
import { getAppOrigin } from '../../utils/platform';
import { getWindowOrigin } from '../../utils/platform';
import type { ElementCallThemeKind, ElementMediaStateDetail } from './types';
import { color, config } from 'folds';
import { ElementCallIntent, ElementWidgetActions } from './types';
Expand Down Expand Up @@ -97,7 +97,7 @@ export class CallEmbed {
): Widget {
const userId = mx.getSafeUserId();
const deviceId = mx.getDeviceId() ?? '';
const clientOrigin = getAppOrigin();
const clientOrigin = getWindowOrigin();
const widgetId = 'call-embed';

const params = new URLSearchParams({
Expand Down
28 changes: 27 additions & 1 deletion src/app/utils/platform.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
import { getAppOrigin } from './platform';
import { getAppOrigin, getWindowOrigin } from './platform';
import { isTauri } from '@tauri-apps/api/core';

vi.mock('@tauri-apps/api/core', () => ({
Expand Down Expand Up @@ -44,3 +44,29 @@ describe('getAppOrigin', () => {
expect(getAppOrigin()).toBe('https://app.sable.moe');
});
});

describe('getWindowOrigin', () => {
afterEach(() => {
vi.unstubAllGlobals();
});

it('returns the real tauri:// origin when window.location.origin is the opaque "null"', () => {
vi.stubGlobal('location', {
origin: 'null',
hostname: 'localhost',
protocol: 'tauri:',
host: 'localhost',
});
expect(getWindowOrigin()).toBe('tauri://localhost');
});

it('returns window.location.origin in a normal web environment', () => {
vi.stubGlobal('location', {
origin: 'https://app.example.com',
hostname: 'app.example.com',
protocol: 'https:',
host: 'app.example.com',
});
expect(getWindowOrigin()).toBe('https://app.example.com');
});
});
9 changes: 9 additions & 0 deletions src/app/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ export function getAppOrigin(): string {
? `${window.location.protocol}//${window.location.host}`
: window.location.origin;
}

// Runtime origin of the current window. getAppOrigin() returns the canonical
// app URL on Tauri, which does not match the parent frame — use this for
// widget parentUrl / postMessage targetOrigin.
export function getWindowOrigin(): string {
return window.location.origin === 'null'
? `${window.location.protocol}//${window.location.host}`
: window.location.origin;
}
Loading