Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(multi-screen): render a meeting surface on a second screen via the iframe API (#17527)

Emil Ivove5536dfe7e8c
diff --git a/config.js b/config.js
index 3ecbe9737a..41c46a046e 100644
--- a/config.js
+++ b/config.js
@@ -1578,6 +1578,15 @@ var config = {
// If true, tile view will not be enabled automatically when the participants count threshold is reached.
// disableTileView: true,
+ // Multi-screen support: lets an embedder (via the iframe External API `setSecondScreen` command)
+ // render a meeting surface (the active-speaker stage, the screenshare, or a pinned participant) on
+ // a second display, in its own fullscreen window. Disabled by default; it is Chromium-only and
+ // intended for managed/kiosk room appliances, which must also delegate `allow="window-management;
+ // fullscreen"` to the iframe and grant the window-management + automatic-fullscreen permissions.
+ // secondScreen: {
+ // enabled: false
+ // },
+
// If true, the tiles will be displayed contained within the available space rather than enlarged to cover it,
// with a 16:9 aspect ratio (old behaviour).
// disableTileEnlargement: true,
diff --git a/modules/API/API.js b/modules/API/API.js
index 38528f743c..ce279ad22f 100755
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -99,6 +99,7 @@ import {
resizeLargeVideo
} from '../../react/features/large-video/actions.web';
import { answerKnockingParticipant, toggleLobbyMode } from '../../react/features/lobby/actions';
+import { setSecondScreen } from '../../react/features/multi-screen/actions.web';
import { setNoiseSuppressionEnabled } from '../../react/features/noise-suppression/actions';
import { hideNotification, showNotification } from '../../react/features/notifications/actions';
import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../../react/features/notifications/constants';
@@ -545,6 +546,9 @@ function initCommands() {
APP.store.dispatch(toggleTileView());
},
+ 'set-second-screen': (options = {}) => {
+ APP.store.dispatch(setSecondScreen(options.id ?? 'default', options.source, options.screen));
+ },
'set-tile-view': enabled => {
APP.store.dispatch(setTileView(enabled));
},
@@ -2419,6 +2423,47 @@ class API {
});
}
+ /**
+ * Notify external application (if API is enabled) that a second-screen window now renders a
+ * given source/participant.
+ *
+ * @param {Object} data - The event payload ({ id, source, participantId }).
+ * @returns {void}
+ */
+ notifySecondScreenSourceChanged(data) {
+ this._sendEvent({
+ name: 'second-screen-source-changed',
+ ...data
+ });
+ }
+
+ /**
+ * Notify external application (if API is enabled) that a second-screen window was closed.
+ *
+ * @param {Object} data - The event payload ({ id }).
+ * @returns {void}
+ */
+ notifySecondScreenClosed(data) {
+ this._sendEvent({
+ name: 'second-screen-closed',
+ ...data
+ });
+ }
+
+ /**
+ * Notify external application (if API is enabled) that a second-screen window could not be
+ * opened/updated (e.g. popup blocked or the feature disabled).
+ *
+ * @param {Object} data - The event payload ({ id, error }).
+ * @returns {void}
+ */
+ notifySecondScreenError(data) {
+ this._sendEvent({
+ name: 'second-screen-error',
+ ...data
+ });
+ }
+
/**
* Notify external application ( if API is enabled) that a participant menu button was clicked.
*
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index 7e754f1e94..49c2e013dc 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -70,6 +70,7 @@ const commands = {
setMeetingTimer: 'set-meeting-timer',
setNoiseSuppressionEnabled: 'set-noise-suppression-enabled',
setParticipantVolume: 'set-participant-volume',
+ setSecondScreen: 'set-second-screen',
setSubtitles: 'set-subtitles',
setTileView: 'set-tile-view',
setVideoQuality: 'set-video-quality',
@@ -110,6 +111,9 @@ const events = {
'_pip-requested': '_pipRequested',
'pip-entered': 'pipEntered',
'pip-left': 'pipLeft',
+ 'second-screen-source-changed': 'secondScreenSourceChanged',
+ 'second-screen-closed': 'secondScreenClosed',
+ 'second-screen-error': 'secondScreenError',
'avatar-changed': 'avatarChanged',
'audio-availability-changed': 'audioAvailabilityChanged',
'audio-mute-status-changed': 'audioMuteStatusChanged',
@@ -362,17 +366,31 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
const frameName = `jitsiConferenceFrame${id}`;
this._frame = document.createElement('iframe');
- this._frame.allow = [
+
+ const allow = [
'autoplay',
'camera',
'clipboard-write',
'compute-pressure',
'display-capture',
+ 'fullscreen',
'hid',
'microphone',
'screen-wake-lock',
'speaker-selection'
- ].join('; ');
+ ];
+
+ // Needed by the multi-screen feature (`setSecondScreen`) to enumerate displays and place
+ // a window on a second screen. Only delegates the capability; the actual permission is
+ // still user/policy-gated (granted on managed/kiosk devices). Gated to engines that expose
+ // the Window Management API (Chromium): elsewhere the directive is unrecognized and logs a
+ // console warning. Checking for the API directly avoids pulling a browser-detection library
+ // into this (size-limited) embedder bundle.
+ if ('getScreenDetails' in window) {
+ allow.push('window-management');
+ }
+
+ this._frame.allow = allow.join('; ');
this._frame.name = frameName;
this._frame.id = frameName;
this._setSize(height, width);
diff --git a/package-lock.json b/package-lock.json
index 3d4142d8aa..909a123b2c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -162,6 +162,7 @@
"@types/uuid": "8.3.4",
"@types/w3c-image-capture": "1.0.6",
"@types/w3c-web-hid": "1.0.3",
+ "@types/webscreens-window-placement": "0.1.3",
"@types/zxcvbn": "4.4.1",
"@wdio/allure-reporter": "9.27.0",
"@wdio/cli": "9.27.0",
@@ -8060,6 +8061,13 @@
"integrity": "sha512-+F0Ozq+ksnKtjcMHujSgb4A1Vjt0b4wvvxP3/pTnXKsIrLo34EgHh2z3qJq3ntX4dbK6ytxpY1rzO/4Z8rVrHg==",
"dev": true
},
+ "node_modules/@types/webscreens-window-placement": {
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/@types/webscreens-window-placement/-/webscreens-window-placement-0.1.3.tgz",
+ "integrity": "sha512-OunHLGJkmAuNlvd7PrRbQy/VleLyxxP3NKwuUo9OS412vO/tzKGwW2K3FqvnM1yebTkCM0W+gszr08m9oDz0lg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@types/which/-/which-2.0.2.tgz",
@@ -32733,6 +32741,12 @@
"integrity": "sha512-+F0Ozq+ksnKtjcMHujSgb4A1Vjt0b4wvvxP3/pTnXKsIrLo34EgHh2z3qJq3ntX4dbK6ytxpY1rzO/4Z8rVrHg==",
"dev": true
},
+ "@types/webscreens-window-placement": {
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/@types/webscreens-window-placement/-/webscreens-window-placement-0.1.3.tgz",
+ "integrity": "sha512-OunHLGJkmAuNlvd7PrRbQy/VleLyxxP3NKwuUo9OS412vO/tzKGwW2K3FqvnM1yebTkCM0W+gszr08m9oDz0lg==",
+ "dev": true
+ },
"@types/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@types/which/-/which-2.0.2.tgz",
diff --git a/package.json b/package.json
index 3eae7b7f2d..17e2499871 100644
--- a/package.json
+++ b/package.json
@@ -168,6 +168,7 @@
"@types/uuid": "8.3.4",
"@types/w3c-image-capture": "1.0.6",
"@types/w3c-web-hid": "1.0.3",
+ "@types/webscreens-window-placement": "0.1.3",
"@types/zxcvbn": "4.4.1",
"@wdio/allure-reporter": "9.27.0",
"@wdio/cli": "9.27.0",
diff --git a/react/features/app/middlewares.web.ts b/react/features/app/middlewares.web.ts
index d9b40dd299..829671adb0 100644
--- a/react/features/app/middlewares.web.ts
+++ b/react/features/app/middlewares.web.ts
@@ -9,6 +9,7 @@ import '../dynamic-branding/middleware';
import '../e2ee/middleware';
import '../external-api/middleware';
import '../keyboard-shortcuts/middleware';
+import '../multi-screen/middleware.web';
import '../no-audio-signal/middleware';
import '../notifications/middleware';
import '../noise-detection/middleware';
diff --git a/react/features/app/reducers.web.ts b/react/features/app/reducers.web.ts
index 20d94e7428..9e5e48ef35 100644
--- a/react/features/app/reducers.web.ts
+++ b/react/features/app/reducers.web.ts
@@ -6,6 +6,7 @@ import '../e2ee/reducer';
import '../face-landmarks/reducer';
import '../feedback/reducer';
import '../keyboard-shortcuts/reducer';
+import '../multi-screen/reducer';
import '../no-audio-signal/reducer';
import '../noise-detection/reducer';
import '../participants-pane/reducer';
diff --git a/react/features/app/types.ts b/react/features/app/types.ts
index 89d16097f8..f4f2f6de61 100644
--- a/react/features/app/types.ts
+++ b/react/features/app/types.ts
@@ -53,6 +53,7 @@ import { IMobileAudioModeState } from '../mobile/audio-mode/reducer';
import { IMobileBackgroundState } from '../mobile/background/reducer';
import { ICallIntegrationState } from '../mobile/call-integration/reducer';
import { IMobileExternalApiState } from '../mobile/external-api/reducer';
+import { IMultiScreenState } from '../multi-screen/reducer';
import { INoAudioSignalState } from '../no-audio-signal/reducer';
import { INoiseDetectionState } from '../noise-detection/reducer';
import { INoiseSuppressionState } from '../noise-suppression/reducer';
@@ -144,6 +145,7 @@ export interface IReduxState {
'features/mobile/audio-mode': IMobileAudioModeState;
'features/mobile/background': IMobileBackgroundState;
'features/mobile/external-api': IMobileExternalApiState;
+ 'features/multi-screen': IMultiScreenState;
'features/no-audio-signal': INoAudioSignalState;
'features/noise-detection': INoiseDetectionState;
'features/noise-suppression': INoiseSuppressionState;
diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.ts
index 1396c53151..707b4256c0 100644
--- a/react/features/base/config/configType.ts
+++ b/react/features/base/config/configType.ts
@@ -653,6 +653,17 @@ export interface IConfig {
enabled?: boolean;
mode?: 'always' | 'recording';
};
+
+ /**
+ * Multi-screen support. When enabled, an embedder can use the iframe External
+ * API `setSecondScreen` command to render a meeting surface (the stage, the
+ * screenshare, or a pinned participant) on a second display in its own
+ * fullscreen window. Chromium-only; intended for managed/kiosk room
+ * appliances. Disabled by default.
+ */
+ secondScreen?: {
+ enabled?: boolean;
+ };
securityUi?: {
disableLobbyPassword?: boolean;
hideLobbyButton?: boolean;
diff --git a/react/features/base/config/configWhitelist.ts b/react/features/base/config/configWhitelist.ts
index 19b4f0a659..24b6ea4c76 100644
--- a/react/features/base/config/configWhitelist.ts
+++ b/react/features/base/config/configWhitelist.ts
@@ -219,6 +219,7 @@ export default [
'replaceParticipant',
'resolution',
'screenshotCapture',
+ 'secondScreen',
'securityUi',
'showChatPermissionsModeratorSetting',
'speakerStats',
diff --git a/react/features/multi-screen/actionTypes.ts b/react/features/multi-screen/actionTypes.ts
new file mode 100644
index 0000000000..13104fff7e
--- /dev/null
+++ b/react/features/multi-screen/actionTypes.ts
@@ -0,0 +1,45 @@
+/**
+ * The type of (redux) action which opens or updates a second-screen window with
+ * a given source descriptor.
+ *
+ * {
+ * type: SET_SECOND_SCREEN,
+ * id: string,
+ * source: ISecondScreenSource,
+ * screenId?: number
+ * }
+ */
+export const SET_SECOND_SCREEN = 'SET_SECOND_SCREEN';
+
+/**
+ * The type of (redux) action which attaches the live window handle (the
+ * {@code Window}, its {@code <video>} and tracks) to a second-screen entry,
+ * once the middleware has opened the window.
+ *
+ * {
+ * type: SET_SECOND_SCREEN_WINDOW,
+ * id: string,
+ * handle: unknown
+ * }
+ */
+export const SET_SECOND_SCREEN_WINDOW = 'SET_SECOND_SCREEN_WINDOW';
+
+/**
+ * The type of (redux) action which closes a single second-screen window.
+ *
+ * {
+ * type: REMOVE_SECOND_SCREEN,
+ * id: string
+ * }
+ */
+export const REMOVE_SECOND_SCREEN = 'REMOVE_SECOND_SCREEN';
+
+/**
+ * The type of (redux) action which closes all second-screen windows (e.g. when
+ * the conference ends).
+ *
+ * {
+ * type: RESET_SECOND_SCREENS
+ * }
+ */
+export const RESET_SECOND_SCREENS = 'RESET_SECOND_SCREENS';
diff --git a/react/features/multi-screen/actions.web.ts b/react/features/multi-screen/actions.web.ts
new file mode 100644
index 0000000000..298d0ac590
--- /dev/null
+++ b/react/features/multi-screen/actions.web.ts
@@ -0,0 +1,71 @@
+import {
+ REMOVE_SECOND_SCREEN,
+ RESET_SECOND_SCREENS,
+ SET_SECOND_SCREEN,
+ SET_SECOND_SCREEN_WINDOW
+} from './actionTypes';
+import { ISecondScreenSource } from './types';
+
+/**
+ * Opens or updates the second-screen window identified by {@code id} to render
+ * the given source. Passing an empty/invalid source closes that window instead.
+ *
+ * @param {string} id - The window identifier (allows more than one second screen).
+ * @param {ISecondScreenSource} source - What to render.
+ * @param {number} screenId - Optional physical screen index to place the window on.
+ * @returns {Object}
+ */
+export function setSecondScreen(id: string, source?: ISecondScreenSource, screenId?: number) {
+ if (!source || (!source.role && !source.participant)) {
+ return { type: REMOVE_SECOND_SCREEN, id };
+ }
+
+ return {
+ type: SET_SECOND_SCREEN,
+ id,
+ source,
+ screenId
+ };
+}
+
+/**
+ * Attaches the live window handle to a second-screen entry once the middleware
+ * has opened the window. The handle is typed opaquely ({@code unknown}) because
+ * it holds DOM/media objects the shared/native build cannot type; see
+ * {@code functions.web.ts}.
+ *
+ * @param {string} id - The window identifier.
+ * @param {unknown} handle - The live window handle.
+ * @returns {{ type: SET_SECOND_SCREEN_WINDOW, id: string, handle: unknown }}
+ */
+export function setSecondScreenWindow(id: string, handle: unknown) {
+ return {
+ type: SET_SECOND_SCREEN_WINDOW,
+ id,
+ handle
+ };
+}
+
+/**
+ * Closes a single second-screen window.
+ *
+ * @param {string} id - The window identifier.
+ * @returns {{ type: REMOVE_SECOND_SCREEN, id: string }}
+ */
+export function removeSecondScreen(id: string) {
+ return {
+ type: REMOVE_SECOND_SCREEN,
+ id
+ };
+}
+
+/**
+ * Closes all second-screen windows.
+ *
+ * @returns {{ type: RESET_SECOND_SCREENS }}
+ */
+export function resetSecondScreens() {
+ return {
+ type: RESET_SECOND_SCREENS
+ };
+}
diff --git a/react/features/multi-screen/constants.ts b/react/features/multi-screen/constants.ts
new file mode 100644
index 0000000000..489177a745
--- /dev/null
+++ b/react/features/multi-screen/constants.ts
@@ -0,0 +1,4 @@
+/**
+ * The default window id used when the embedder does not specify one.
+ */
+export const DEFAULT_SECOND_SCREEN_ID = 'default';
diff --git a/react/features/multi-screen/functions.web.ts b/react/features/multi-screen/functions.web.ts
new file mode 100644
index 0000000000..01702e1912
--- /dev/null
+++ b/react/features/multi-screen/functions.web.ts
@@ -0,0 +1,491 @@
+import { IReduxState, IStore } from '../app/types';
+import { MEDIA_TYPE, VIDEO_TYPE } from '../base/media/constants';
+import { getParticipantById, getParticipantDisplayName } from '../base/participants/functions';
+import { IParticipant } from '../base/participants/types';
+import { getTrackByMediaTypeAndParticipant, getVideoTrackByParticipant } from '../base/tracks/functions.any';
+import { getLargeVideoParticipant } from '../large-video/functions';
+import { renderAvatarOnCanvas } from '../pip/functions';
+
+import { removeSecondScreen, setSecondScreenWindow } from './actions.web';
+import logger from './logger';
+import { ISecondScreenSource } from './types';
+
+// The Window Management API typings (Window.getScreenDetails, ScreenDetails, ScreenDetailed) come
+// from the `@types/webscreens-window-placement` devDependency.
+
+/**
+ * A second-screen window, constructed via {@code window.open} in the same
+ * origin/process as the meeting so its {@code <video>} can render the meeting's
+ * tracks by reference.
+ */
+type ISecondScreenWindow = Window & { MediaStream: typeof MediaStream; };
+
+/**
+ * A canvas {@code captureStream} track exposes a non-standard {@code requestFrame}
+ * used to push a single frame on demand.
+ */
+type IFrameRequestingTrack = MediaStreamTrack & { requestFrame?: () => void; };
+
+/**
+ * The live, non-serializable handles backing a single second-screen window. This
+ * object is stored on the redux entry (typed opaquely there as {@code unknown}
+ * because the shared/native build has no DOM lib) and mutated in place as the
+ * rendered source changes — the same way the rest of the app keeps mutable
+ * lib-jitsi-meet objects in redux.
+ */
+interface ISecondScreenHandle {
+
+ /**
+ * The off-screen canvas used to render a participant's avatar when their
+ * video is unavailable (created lazily, reused across redraws).
+ */
+ avatarCanvas?: HTMLCanvasElement;
+
+ /**
+ * The second window's {@code MediaStream} wrapping the avatar canvas track
+ * (what {@code video.srcObject} points at while the avatar is shown).
+ */
+ avatarSrc?: MediaStream;
+
+ /**
+ * The avatar canvas {@code captureStream} track (kept to push frames and to
+ * stop it on teardown).
+ */
+ avatarTrack?: IFrameRequestingTrack;
+
+ /**
+ * The clone of the currently rendered meeting track (the meeting keeps its
+ * own copy; the clone is stopped when swapped out or on teardown).
+ */
+ clone?: MediaStreamTrack;
+
+ /**
+ * The {@code <video>} in the second window.
+ */
+ video: HTMLVideoElement;
+
+ /**
+ * The second-screen window itself.
+ */
+ win: Window;
+}
+
+/**
+ * The avatar canvas is rendered at a modest 4:3 size and scaled up by the
+ * full-bleed {@code <video>} (object-fit: contain) on the second screen.
+ */
+const AVATAR_CANVAS_WIDTH = 640;
+const AVATAR_CANVAS_HEIGHT = 480;
+
+/**
+ * Avatar colours, matched to the black second-screen window background.
+ */
+const AVATAR_BACKGROUND = '#000';
+const AVATAR_TEXT_COLOR = '#fff';
+const AVATAR_FONT_FAMILY = 'Inter, sans-serif';
+
+/**
+ * Returns the live window handle for a second screen, or {@code undefined} if
+ * its window has not been opened yet.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @param {string} id - The window id.
+ * @returns {ISecondScreenHandle | undefined}
+ */
+function getHandle(state: IReduxState, id: string): ISecondScreenHandle | undefined {
+ return state['features/multi-screen'].screens[id]?.handle as ISecondScreenHandle | undefined;
+}
+
+/**
+ * Whether second-screen windows can be opened in this environment. The feature
+ * requires the Window Management API (Chromium) so it can enumerate displays and
+ * place the window on a second screen; without it we have no control over the
+ * second screen, so we do not support the feature.
+ *
+ * @returns {boolean}
+ */
+export function isSecondScreenSupported(): boolean {
+ return typeof window !== 'undefined' && 'getScreenDetails' in window;
+}
+
+/**
+ * Whether the multi-screen feature is enabled (config flag + support).
+ *
+ * @param {IReduxState} state - The redux state.
+ * @returns {boolean}
+ */
+export function isSecondScreenEnabled(state: IReduxState): boolean {
+ return Boolean(state['features/base/config'].secondScreen?.enabled) && isSecondScreenSupported();
+}
+
+/**
+ * Resolves a source descriptor to a native {@code MediaStreamTrack} (when the
+ * backing participant has live, unmuted video) and the participant backing it.
+ * When there is no usable video track, {@code track} is {@code null} and the
+ * caller falls back to rendering the participant's avatar.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @param {ISecondScreenSource} source - The source descriptor.
+ * @returns {Object} The resolved native track (or {@code null}) and backing participant.
+ */
+function resolveSource(state: IReduxState, source: ISecondScreenSource) {
+ const tracks = state['features/base/tracks'];
+ let iTrack;
+ let participant: IParticipant | undefined;
+
+ if (source.role === 'stage') {
+ participant = getLargeVideoParticipant(state);
+ iTrack = getVideoTrackByParticipant(state, participant);
+ } else if (source.role === 'screenshare') {
+ iTrack = tracks.find(t => t.videoType === VIDEO_TYPE.DESKTOP && !t.muted && Boolean(t.jitsiTrack));
+ participant = iTrack ? getParticipantById(state, iTrack.participantId) : undefined;
+ } else if (source.participant) {
+ participant = getParticipantById(state, source.participant);
+ const mediaType = source.media === 'desktop' ? MEDIA_TYPE.SCREENSHARE : MEDIA_TYPE.VIDEO;
+
+ iTrack = getTrackByMediaTypeAndParticipant(tracks, mediaType, source.participant);
+ }
+
+ const track = iTrack && !iTrack.muted
+ ? (iTrack.jitsiTrack?.getTrack?.() as MediaStreamTrack) ?? null
+ : null;
+
+ return {
+ participant,
+ track
+ };
+}
+
+/**
+ * A stable signature of what every second-screen window should currently render.
+ * When it changes — the active speaker switches, a source mutes/unmutes, or an
+ * avatar finishes loading — the subscriber re-applies the sources, swapping the
+ * window content in place. Includes the avatar identity (id/url/name) so the
+ * fallback avatar redraws even while no track is present.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @returns {string}
+ */
+export function getSecondScreenSignature(state: IReduxState): string {
+ const { screens } = state['features/multi-screen'];
+
+ return Object.keys(screens).sort()
+ .map(id => {
+ const { track, participant } = resolveSource(state, screens[id].source);
+ const key = track
+ ? track.id
+ : `avatar:${participant?.id ?? ''}:${participant?.loadableAvatarUrl ?? ''}:${participant?.name ?? ''}`;
+
+ return `${id}:${key}`;
+ })
+ .join('|');
+}
+
+/**
+ * Computes the {@code window.open} features string, placing the window on a
+ * physical screen via the Window Management API. Rejects if the API is
+ * unavailable/denied (the feature requires it).
+ *
+ * @param {number} screenId - Optional target screen index.
+ * @returns {Promise<string>}
+ */
+async function computeFeatures(screenId?: number): Promise<string> {
+ const details = await window.getScreenDetails();
+ const target = (typeof screenId === 'number' && details.screens[screenId])
+ || details.screens.find(s => s.left !== details.currentScreen.left || s.top !== details.currentScreen.top)
+ || details.currentScreen;
+
+ // No avail* offsets: the window is auto-fullscreened, so the full screen bounds are what matter.
+ return `popup,left=${target.left},top=${target.top},width=${target.width},height=${target.height}`;
+}
+
+/**
+ * Builds the (empty) second-screen document: a full-bleed video on black. Uses
+ * element styles (not a stylesheet/inline script) to stay CSP-safe.
+ *
+ * @param {Window} win - The opened window.
+ * @returns {HTMLVideoElement}
+ */
+function buildWindow(win: Window): HTMLVideoElement {
+ const doc = win.document;
+
+ doc.title = 'Jitsi Meet';
+ Object.assign(doc.documentElement.style, { height: '100%' });
+ Object.assign(doc.body.style, { margin: '0', height: '100%', background: '#000', overflow: 'hidden' });
+
+ const video = doc.createElement('video');
+
+ video.autoplay = true;
+ video.muted = true;
+ video.setAttribute('playsinline', '');
+ Object.assign(video.style, {
+ position: 'fixed', inset: '0', width: '100%', height: '100%', objectFit: 'contain', background: '#000'
+ });
+ doc.body.appendChild(video);
+
+ return video;
+}
+
+/**
+ * Renders a meeting track into a window's video by reference (cloning so the
+ * meeting keeps its own copy), stopping any previously rendered clone.
+ *
+ * @param {ISecondScreenHandle} handle - The window handle.
+ * @param {MediaStreamTrack} track - The track to render.
+ * @returns {void}
+ */
+function renderTrack(handle: ISecondScreenHandle, track: MediaStreamTrack) {
+ if (handle.clone) {
+ handle.clone.stop();
+ handle.clone = undefined;
+ }
+ const clone = track.clone();
+
+ handle.clone = clone;
+ handle.video.srcObject = new (handle.win as ISecondScreenWindow).MediaStream([ clone ]);
+}
+
+/**
+ * Renders a participant's avatar (image, initials, or default) into a window's
+ * video as a fallback when there is no usable video track (e.g. the source muted
+ * their camera). Reuses the PiP feature's canvas-avatar rendering and feeds it to
+ * the window by reference, mirroring {@link renderTrack}.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @param {ISecondScreenHandle} handle - The window handle.
+ * @param {IParticipant | undefined} participant - The participant whose avatar to render.
+ * @returns {void}
+ */
+function renderAvatar(state: IReduxState, handle: ISecondScreenHandle, participant: IParticipant | undefined) {
+ if (handle.clone) {
+ handle.clone.stop();
+ handle.clone = undefined;
+ }
+
+ let canvas = handle.avatarCanvas;
+
+ if (!canvas) {
+ canvas = document.createElement('canvas');
+ canvas.width = AVATAR_CANVAS_WIDTH;
+ canvas.height = AVATAR_CANVAS_HEIGHT;
+
+ // captureStream(0): on-demand; we push a frame via requestFrame() after each draw.
+ const track = canvas.captureStream(0).getVideoTracks()[0] as IFrameRequestingTrack;
+
+ handle.avatarCanvas = canvas;
+ handle.avatarTrack = track;
+
+ // The track is created in this (meeting) document; wrap it in the second window's
+ // MediaStream so its <video> renders it by reference (same trick as renderTrack()).
+ handle.avatarSrc = new (handle.win as ISecondScreenWindow).MediaStream([ track ]);
+ }
+
+ if (handle.video.srcObject !== handle.avatarSrc) {
+ handle.video.srcObject = handle.avatarSrc ?? null;
+ }
+
+ const ctx = canvas.getContext('2d');
+
+ if (!ctx) {
+ return;
+ }
+
+ const displayName = participant?.id ? getParticipantDisplayName(state, participant.id) : '';
+ const customAvatarBackgrounds = state['features/dynamic-branding']?.avatarBackgrounds ?? [];
+
+ // Reuses the PiP feature's canvas-avatar rendering (image → initials → default icon).
+ renderAvatarOnCanvas(
+ canvas, ctx, participant, displayName, customAvatarBackgrounds,
+ null, AVATAR_BACKGROUND, AVATAR_FONT_FAMILY, AVATAR_TEXT_COLOR, AVATAR_TEXT_COLOR)
+ .then(() => handle.avatarTrack?.requestFrame?.())
+ .catch(e => logger.warn('Failed to render second-screen avatar', e));
+}
+
+/**
+ * Notifies the iframe embedder that a window's resolved source changed.
+ *
+ * @param {string} id - The window id.
+ * @param {ISecondScreenSource} source - The window's source descriptor.
+ * @param {string | null} participantId - The participant currently backing it.
+ * @returns {void}
+ */
+function notifySourceChanged(id: string, source: ISecondScreenSource, participantId: string | null) {
+ APP.API?.notifySecondScreenSourceChanged?.({ id, source, participantId });
+}
+
+/**
+ * Resolves and renders the current source for a window, and notifies the
+ * embedder. Reads the window's configuration and live handle from redux (the
+ * single source of truth). Falls back to the participant's avatar when there is
+ * no live video.
+ *
+ * @param {IStore} store - The redux store.
+ * @param {string} id - The window id.
+ * @returns {void}
+ */
+function applySource(store: IStore, id: string) {
+ const state = store.getState();
+ const entry = state['features/multi-screen'].screens[id];
+ const handle = getHandle(state, id);
+
+ if (!entry || !handle || handle.win.closed) {
+ return;
+ }
+ const { track, participant } = resolveSource(state, entry.source);
+
+ if (track) {
+ renderTrack(handle, track);
+ } else {
+ renderAvatar(state, handle, participant);
+ }
+ notifySourceChanged(id, entry.source, participant?.id ?? null);
+}
+
+/**
+ * Stops a handle's tracks and (optionally) closes its window. Pure cleanup of
+ * the live objects; the redux entry is removed by the caller's action.
+ *
+ * @param {ISecondScreenHandle} handle - The window handle.
+ * @param {boolean} closeWindow - Whether to also close the OS window.
+ * @returns {void}
+ */
+function teardownHandle(handle: ISecondScreenHandle, closeWindow: boolean) {
+ // MediaStreamTrack.stop() is infallible per spec, so no try/catch.
+ handle.clone?.stop();
+ handle.avatarTrack?.stop();
+
+ if (closeWindow && !handle.win.closed) {
+ handle.win.close();
+ }
+}
+
+/**
+ * Handles the user closing a second-screen window directly: remove it from
+ * state, which tears it down and notifies the embedder via the REMOVE handler.
+ *
+ * @param {IStore} store - The redux store.
+ * @param {string} id - The window id.
+ * @returns {void}
+ */
+function handleWindowClosed(store: IStore, id: string) {
+ if (!getHandle(store.getState(), id)) {
+ return;
+ }
+ store.dispatch(removeSecondScreen(id));
+}
+
+/**
+ * Opens a new second-screen window (or updates an existing one) to render its
+ * configured source. The window is placed on a physical screen via the Window
+ * Management API and auto-fullscreened; both require the window-management and
+ * AutomaticFullscreen permissions on a managed/kiosk device.
+ *
+ * @param {IStore} store - The redux store.
+ * @param {string} id - The window id.
+ * @param {number} screenId - Optional target screen index.
+ * @returns {Promise<void>}
+ */
+export async function openOrUpdateSecondScreen(store: IStore, id: string, screenId?: number): Promise<void> {
+ if (!isSecondScreenEnabled(store.getState())) {
+ APP.API?.notifySecondScreenError?.({ id, error: 'second-screen-disabled' });
+
+ return;
+ }
+
+ const existing = getHandle(store.getState(), id);
+
+ if (existing) {
+ if (!existing.win.closed) {
+ applySource(store, id);
+
+ return;
+ }
+
+ // The window was closed without us being notified; stop its tracks before reopening
+ // (its handle is overwritten by the dispatch below), so nothing leaks.
+ teardownHandle(existing, false);
+ }
+
+ let features;
+
+ try {
+ features = await computeFeatures(screenId);
+ } catch (e) {
+ logger.warn(`Window Management API unavailable; cannot place second-screen window "${id}"`, e);
+ APP.API?.notifySecondScreenError?.({ id, error: 'window-management-unavailable' });
+ store.dispatch(removeSecondScreen(id));
+
+ return;
+ }
+
+ const win = window.open('', `jitsiSecondScreen_${id}`, features);
+
+ if (!win) {
+ logger.warn(`Failed to open second-screen window "${id}" (popup blocked?)`);
+ APP.API?.notifySecondScreenError?.({ id, error: 'popup-blocked' });
+ store.dispatch(removeSecondScreen(id));
+
+ return;
+ }
+
+ const handle: ISecondScreenHandle = { win, video: buildWindow(win) };
+
+ store.dispatch(setSecondScreenWindow(id, handle));
+ win.addEventListener('pagehide', () => handleWindowClosed(store, id), { once: true });
+
+ try {
+ await win.document.documentElement.requestFullscreen();
+ } catch (e) {
+ logger.debug(`Auto-fullscreen not granted for second screen "${id}"`, e);
+ }
+
+ applySource(store, id);
+}
+
+/**
+ * Closes a single second-screen window: tears down its live handle and notifies
+ * the embedder. Called by the middleware as the window's entry is removed from
+ * state, so it does not dispatch itself.
+ *
+ * @param {IStore} store - The redux store.
+ * @param {string} id - The window id.
+ * @returns {void}
+ */
+export function closeSecondScreen(store: IStore, id: string) {
+ const handle = getHandle(store.getState(), id);
+
+ if (!handle) {
+ return;
+ }
+ teardownHandle(handle, true);
+ APP.API?.notifySecondScreenClosed?.({ id });
+}
+
+/**
+ * Closes every second-screen window.
+ *
+ * @param {IStore} store - The redux store.
+ * @returns {void}
+ */
+export function closeAllSecondScreens(store: IStore) {
+ Object.keys(store.getState()['features/multi-screen'].screens).forEach(id => closeSecondScreen(store, id));
+}
+
+/**
+ * Re-resolves and re-renders every open second-screen window. Called by the
+ * subscriber when the active speaker / tracks change.
+ *
+ * @param {IStore} store - The redux store.
+ * @returns {void}
+ */
+export function refreshSecondScreens(store: IStore) {
+ Object.keys(store.getState()['features/multi-screen'].screens).forEach(id => {
+ const handle = getHandle(store.getState(), id);
+
+ if (handle?.win.closed) {
+ handleWindowClosed(store, id);
+ } else if (handle) {
+ applySource(store, id);
+ }
+ });
+}
diff --git a/react/features/multi-screen/logger.ts b/react/features/multi-screen/logger.ts
new file mode 100644
index 0000000000..5c66e08d91
--- /dev/null
+++ b/react/features/multi-screen/logger.ts
@@ -0,0 +1,3 @@
+import { getLogger } from '../base/logging/functions';
+
+export default getLogger('app:multi-screen');
diff --git a/react/features/multi-screen/middleware.web.ts b/react/features/multi-screen/middleware.web.ts
new file mode 100644
index 0000000000..423a4be3e7
--- /dev/null
+++ b/react/features/multi-screen/middleware.web.ts
@@ -0,0 +1,51 @@
+import { IStore } from '../app/types';
+import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../base/conference/actionTypes';
+import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
+
+import { REMOVE_SECOND_SCREEN, RESET_SECOND_SCREENS, SET_SECOND_SCREEN } from './actionTypes';
+import { resetSecondScreens } from './actions.web';
+import { closeAllSecondScreens, closeSecondScreen, openOrUpdateSecondScreen } from './functions.web';
+import logger from './logger';
+
+import './subscriber.web';
+
+/**
+ * Middleware that reconciles the live second-screen windows with the requested
+ * state, and tears them all down when the conference ends.
+ *
+ * @param {IStore} store - The redux store.
+ * @returns {Function}
+ */
+MiddlewareRegistry.register((store: IStore) => next => action => {
+ switch (action.type) {
+ case SET_SECOND_SCREEN: {
+ const result = next(action);
+
+ openOrUpdateSecondScreen(store, action.id, action.screenId)
+ .catch(e => logger.error('Failed to open second screen', e));
+
+ return result;
+ }
+ case REMOVE_SECOND_SCREEN:
+
+ // Tear down before next(action) removes the entry, since the live handle is read from state.
+ closeSecondScreen(store, action.id);
+
+ return next(action);
+ case RESET_SECOND_SCREENS:
+
+ // Same ordering: close the windows while their entries are still in state.
+ closeAllSecondScreens(store);
+
+ return next(action);
+ case CONFERENCE_FAILED:
+ case CONFERENCE_LEFT:
+
+ // Resetting closes every second-screen window (via the RESET_SECOND_SCREENS
+ // case above), so there is no need to close them explicitly here.
+ store.dispatch(resetSecondScreens());
+ break;
+ }
+
+ return next(action);
+});
diff --git a/react/features/multi-screen/reducer.ts b/react/features/multi-screen/reducer.ts
new file mode 100644
index 0000000000..deb64defc1
--- /dev/null
+++ b/react/features/multi-screen/reducer.ts
@@ -0,0 +1,73 @@
+import ReducerRegistry from '../base/redux/ReducerRegistry';
+
+import {
+ REMOVE_SECOND_SCREEN,
+ RESET_SECOND_SCREENS,
+ SET_SECOND_SCREEN,
+ SET_SECOND_SCREEN_WINDOW
+} from './actionTypes';
+import { ISecondScreenEntry } from './types';
+
+export interface IMultiScreenState {
+
+ /**
+ * The second-screen windows, keyed by window id. This is the single source
+ * of truth for the feature: each entry holds both the configuration (source
+ * + target screen) and the live window handle. Redux state is never
+ * serialized for storage here, so the non-serializable handle (the
+ * {@code Window}, its {@code <video>} and tracks) lives on the entry too,
+ * rather than in a separate module-scoped map; the middleware reconciles the
+ * live windows to this state.
+ */
+ screens: { [id: string]: ISecondScreenEntry; };
+}
+
+const DEFAULT_STATE: IMultiScreenState = {
+ screens: {}
+};
+
+ReducerRegistry.register<IMultiScreenState>('features/multi-screen',
+(state = DEFAULT_STATE, action): IMultiScreenState => {
+ switch (action.type) {
+ case SET_SECOND_SCREEN:
+
+ // Merge so a re-configuration of an existing window keeps its live handle.
+ return {
+ ...state,
+ screens: {
+ ...state.screens,
+ [action.id]: {
+ ...state.screens[action.id],
+ source: action.source,
+ screenId: action.screenId
+ }
+ }
+ };
+ case SET_SECOND_SCREEN_WINDOW: {
+ const entry = state.screens[action.id];
+
+ if (!entry) {
+ return state;
+ }
+
+ return {
+ ...state,
+ screens: {
+ ...state.screens,
+ [action.id]: { ...entry, handle: action.handle }
+ }
+ };
+ }
+ case REMOVE_SECOND_SCREEN: {
+ const screens = { ...state.screens };
+
+ delete screens[action.id];
+
+ return { ...state, screens };
+ }
+ case RESET_SECOND_SCREENS:
+ return { ...state, screens: {} };
+ }
+
+ return state;
+});
diff --git a/react/features/multi-screen/subscriber.web.ts b/react/features/multi-screen/subscriber.web.ts
new file mode 100644
index 0000000000..f974ca530b
--- /dev/null
+++ b/react/features/multi-screen/subscriber.web.ts
@@ -0,0 +1,18 @@
+import StateListenerRegistry from '../base/redux/StateListenerRegistry';
+
+import { getSecondScreenSignature, refreshSecondScreens } from './functions.web';
+
+/**
+ * Re-applies the second-screen sources whenever what they should render changes
+ * — most importantly when the active speaker switches (the {@code role: 'stage'}
+ * source resolves to a different track), so the window's {@code srcObject} is
+ * swapped in place without ever re-opening it.
+ */
+StateListenerRegistry.register(
+ /* selector */ state => getSecondScreenSignature(state),
+ /* listener */ (signature, store) => {
+ if (signature) {
+ refreshSecondScreens(store);
+ }
+ }
+);
diff --git a/react/features/multi-screen/types.ts b/react/features/multi-screen/types.ts
new file mode 100644
index 0000000000..1494b19996
--- /dev/null
+++ b/react/features/multi-screen/types.ts
@@ -0,0 +1,52 @@
+/**
+ * Describes what a second-screen window should render. Resolved to an actual
+ * media track by the feature and kept live (e.g. {@code role: 'stage'} follows
+ * the active speaker). Because an iframe embedder has no access to the media
+ * tracks (they live in the meeting document), an explicit selection can only
+ * name a participant — never a stream — which the feature resolves internally.
+ */
+export interface ISecondScreenSource {
+
+ /**
+ * The media type of an explicitly pinned participant. Defaults to camera.
+ */
+ media?: 'camera' | 'desktop';
+
+ /**
+ * The id of an explicitly pinned participant to render.
+ */
+ participant?: string;
+
+ /**
+ * A role to follow: the active-speaker stage, or the current screenshare.
+ */
+ role?: 'stage' | 'screenshare';
+}
+
+/**
+ * A single second-screen entry: its configuration plus its live window handle.
+ * This is the single source of truth for the feature; the middleware reconciles
+ * the real windows to it.
+ */
+export interface ISecondScreenEntry {
+
+ /**
+ * The live, non-serializable window handle (the {@code Window}, its
+ * {@code <video>} and the cloned/avatar tracks), populated by the middleware
+ * once the window is open. Typed opaquely here because the shared (and
+ * React Native) build has no DOM lib; its real shape is {@code ISecondScreenHandle}
+ * in {@code functions.web.ts}, where it is read back with a cast.
+ */
+ handle?: unknown;
+
+ /**
+ * The (optional) index of the physical screen to place the window on, as
+ * reported by the Window Management API.
+ */
+ screenId?: number;
+
+ /**
+ * What the window renders.
+ */
+ source: ISecondScreenSource;
+}