Introducing a new way to review your PRs.

Read the announcement

ismaelmartinez / teams-for-linux

Unofficial Microsoft Teams for Linux client

View on GitHub

23 documents · Updated Nov 23, 2026

docs / screen-sharing-and-media

Screen sharing and media

Screen sharing and media connect meeting actions in Teams to desktop capture, local preview, media state, and sound playback. The system lets a user choose a screen or window, sends that choice into the Teams media flow, shows the same capture in an optional preview window, and reports share state to other app services. See the parent page Communications and meetings for the wider meeting model. Related flows are described in connectivity and real-time events, notifications and call alerts, and meeting and chat entry points.

Media workflow

Screen-share lifecycle

The screen-share lifecycle turns a Teams share request into one active desktop capture and keeps that state consistent until the stream ends. The main process owns source selection and share state. The Teams page owns the media request and reports start or stop events back to the application.

When the user starts sharing, the system follows this path:

  1. Teams requests a display or window capture.
  2. The application presents the source picker for the active Teams session.
  3. The picker returns the selected source directly to the media request.
  4. The Teams page receives the capture stream and reports that sharing is active.
  5. The application opens the preview when enabled and publishes the new media state.
  6. Stream end, a stop action, or meeting cleanup clears the active source and closes the preview.

The same source identity must travel from enumeration to selection to capture. This is important on Wayland because a new source lookup can create a new portal session with source IDs that no longer match the picker result.

This diagram shows the handoff between Teams, the picker, the main process, the preview, and media status consumers.

sequenceDiagram
    participant T as Teams media page
    participant P as Source picker
    participant M as Main process
    participant V as Preview window
    participant S as Media status services

    T->>M: Request display media
    M->>P: Load screens and windows
    P-->>M: Return selected source
    M-->>T: Complete media request
    T->>M: Sharing started
    M->>V: Connect preview to active capture
    M->>S: Publish sharing active
    T->>M: Stream ended or user stopped
    M->>V: Close or mark inactive
    M->>S: Publish sharing inactive

References: app/…/index.js• L73-125 app/…/service.js• L110-168 app/…/mediaStatusService.js• L36-49

Screen picker

The screen picker is a focused choice surface for display and window capture. It shows available screens and windows in separate views, provides thumbnails and display details, and prevents a share action until the user selects a source. It also gives the user a quality choice that becomes part of the selected source request.

The picker enriches screen sources with connected-display data so that users can identify the main display, resolution, scale, position, and refresh rate. Window sources support name filtering. Missing source data produces an empty state instead of a partial or unsafe selection.

The picker runs inside the main Teams window as an overlay. A narrow preload bridge exposes only source loading, display lookup, selection, and close actions. This keeps the UI separate from the full Electron IPC surface while allowing the picker to complete the media request.

References: app/…/index.js• L21-65 app/…/browser.js• L149-215 app/…/browser.js• L461-563 app/…/preload.js• L1-18

Preview window

The preview window gives the user a small view of the source that is currently being shared. It is optional and can stay above other windows when configured to do so. Closing or stopping the preview clears the application’s tracked source so the window cannot continue to describe an old share.

The preview uses the active capture already held by the Teams page. The Teams side sends small image snapshots through a message port, and the preview paints those snapshots on a canvas. This single-capture design avoids a second capture request and avoids a second portal prompt on Wayland.

The preview preload provides only status, resize, stop, and message-port forwarding actions. The preview changes its status when sharing stops and releases its message port rather than showing stale media.

References: app/…/index.js• L127-231 app/…/index.js• L747-776 app/…/injectedScreenSharing.js• L206-354 app/…/previewWindowPreload.js• L1-29 app/…/previewWindow.html• L46-149

Teams media integration

Preload and injected sharing code

The sharing boundary has two roles. Preload code exposes small, named actions between renderer pages and the main process. Injected sharing code adapts the Teams page’s media calls and observes the page’s share controls so the desktop shell can follow the real meeting state.

The injected code handles both display-media requests and the desktop-capture form of user-media requests. It disables audio on screen-share capture to prevent the shared stream from creating an echo. It records active tracks and watches for stream end, stop-button changes, and meeting cleanup. A reinjection guard keeps navigation and reload events from stacking multiple media handlers.

The main window injects this logic after a Teams page load. The injection is therefore a compatibility boundary with the Teams web client, not a separate meeting engine. The surrounding media services rely on its start and stop events rather than on the page’s internal UI state alone.

References: app/…/index.js• L980-1017 app/…/injectedScreenSharing.js• L1-145 app/…/injectedScreenSharing.js• L148-204 app/…/injectedScreenSharing.js• L363-489

Share-source services

The share-source services provide the application-side contract for desktop capture. They enumerate screens and windows, expose connected-display information, accept the picker result, track the active source, and provide start, stop, status, and preview controls to other windows.

The service is initialized with the application and shares its events with more than one consumer. The main window uses them to manage the preview. The media status service uses them to publish screen-sharing state to configured external media topics. The IPC security allowlist treats these channels as one protected group, which keeps short-lived picker and preview windows within the approved media surface.

References: app/…/service.js• L4-33 app/…/service.js• L60-107 app/…/ipcValidator.js• L21-39 app/…/mediaStatusService.js• L166-169 app/…/mediaTopics.js• L7-20

Audio playback

Meeting sound playback

Meeting-related sound playback covers notification sounds that accompany messages and meeting events. It is separate from screen-share capture audio: screen-share capture deliberately excludes audio, while notification playback uses a local system player so it can work when the Teams page is in the background.

The main process selects an available platform player and reuses that choice for sound requests. The notification service chooses a sound by event type and can suppress it when configuration disables sounds or when the user is not available. The startup command line also permits background playback without a prior page gesture, which is needed for alerts that arrive outside direct user action.

If no supported system player exists, the request is logged and the meeting workflow continues without a sound. This makes audio playback an optional alert channel rather than a dependency for calls or screen sharing.

References: app/…/player.js• L8-75 app/…/service.js• L229-265 app/…/commandLine.js• L5-12 app/…/preload.js• L258-283

Configuration boundary

Screen-sharing settings

Screen-sharing settings control the user-facing preview without changing the underlying Teams capture request. The default behavior shows a preview and keeps it above other windows. The same settings group also contains the method used to prevent the system from locking during an active share.

The preview setting is read when a share starts. Disabling it leaves Teams capture and share-state reporting in place but removes the extra preview window and its message-port connection.

References: app/…/options.js• L38-64 app/…/index.js• L127-157

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the source ID returned by the picker aligned with the ID passed to the display-media callback. Do not add a second source enumeration between those steps.
  • Keep picker and preview preload methods aligned with the IPC allowlist. A new media action needs both a narrow renderer bridge and an approved channel.
  • Preserve the start and stop event contract. Preview management, internal share state, and MQTT screen-sharing state all consume the same events.
  • Keep the injected media wrapper idempotent across Teams navigations. Duplicate wrappers can create duplicate stream and preview work.
  • If the preview message format changes, update both the Teams-side relay and the preview canvas consumer together.
  • If the screenSharing.thumbnail settings change, update the generated configuration contract and the preview creation behavior together.

Important failure modes

TriggerConsequenceGuard
The desktop source list is empty because capture permissions or the Wayland portal is unavailableThe picker cannot offer a source and sharing does not startReturn an empty source list and show a clear picker empty state.
The selected source is looked up again after the picker closesWayland source IDs can no longer match the active portal session, so capture failsPass the picker’s source directly to the display-media callback.
Sharing code is injected more than onceMultiple media wrappers and snapshot relays can race and create duplicate workUse the injection guard and one active preview relay.
The preview requests a second captureThe user can receive another portal prompt and the preview can fail independently of TeamsRelay snapshots from the existing capture through a message port.
No platform sound player is installedNotification audio is missing, but the meeting and call workflow remains availableDetect supported players once and treat playback as optional.
A screen-share stop event is missedThe preview or external status can remain stale after the meeting endsTrack stream and video-track end events and check the Teams stop control.

Key files

FileWhy to read it
app/…/index.jsShows the media request handler, direct source handoff, preview lifecycle, and message-port wiring.
app/…/service.jsDefines the application-wide source and active-share state contract.
app/…/index.jsExplains how the picker is attached to the main Teams window and closed safely.
app/…/browser.jsIllustrates the user flow for choosing screens and windows.
app/…/injectedScreenSharing.jsDefines the boundary between Teams media calls and desktop share state.
app/…/previewWindow.htmlShows how the preview consumes the shared capture without recapturing it.
app/…/previewWindowPreload.jsDefines the preview’s limited status and control bridge.
app/…/mediaStatusService.jsShows how local screen-sharing state reaches external media status consumers.
app/…/player.jsShows the cross-platform fallback used for local notification sound playback.
app/…/service.jsShows when meeting and message sounds are selected or suppressed.