Connectivity and real-time events
Teams for Linux keeps a Teams session usable across network changes and exposes live Teams state to the desktop and connected services. It combines guarded page reconnects, persistent session data, MQTT event exchange, download feedback, and browser-side hooks that turn Teams activity into stable app events. This page is a companion to Communications and meetings, with related user-facing flows in Notifications and call alerts, Screen sharing and media, and Meeting and chat entrypoints.
Session connectivity
Network recovery
The connection manager protects the main Teams page when the network fails, the machine resumes, or the user selects retry. It checks whether the page is already healthy before it reloads it. This lets Teams continue to use its local page data during a short outage instead of replacing a usable session with a blank page.
When a main-frame load fails with a recoverable network error, the manager marks the page for reload and schedules one debounced refresh. The refresh uses bounded network checks and prevents overlapping reloads. If the checks report no connection, the window shows a network state and waits for a later retry or resume event.
flowchart TD
A[Teams page] --> B{Network or resume event}
B --> C[Debounced refresh]
C --> D{Healthy page already loaded?}
D -->|Yes| E[Keep current session]
D -->|No| F[Bounded connectivity checks]
F -->|Offline| G[Show no connection]
F -->|Online| H[Load or reload Teams]
H --> I{Main-frame load fails?}
I -->|Yes| C
I -->|No| J[Continue Teams session]
References: app/…/index.js• L13-17 app/…/index.js• L32-56 app/…/index.js• L79-145 app/…/index.js• L165-231 app/…/index.js• L234-255
Session data and storage
Persistent session partitions
A session partition is the browser storage boundary that keeps a Teams account's cookies and web data together. The app uses the startup partition and any stored profile partitions so account sessions can remain available across launches and profile changes.
Storage cleanup treats these partitions as separate session owners. It collects the startup partition and every valid profile partition, removes duplicates when the first profile reuses the legacy partition, and attempts cleanup for all partitions even if one fails. This matters because clearing only the active partition can leave another account signed in, while clearing authentication storage during routine cache cleanup can force a new login.
References: app/…/storagePartitions.js• L5-37 app/…/storagePartitions.js• L40-90 app/index.js• L96-107 app/index.js• L702-722
Cache protection
Cache management limits growth in disposable browser data so a large cache does not damage the Teams login flow. When enabled, it checks the app data size on a schedule and removes cache files after the configured limit is exceeded.
The cleanup targets browser cache, GPU cache, code cache, and selected temporary journal files. It preserves IndexedDB and WebStorage because Teams authentication data can live there. A cleanup failure is logged and does not stop the Teams session from running.
References: app/…/index.js• L6-15 app/…/index.js• L27-39 app/…/index.js• L51-115 app/…/index.js• L117-172 app/index.js• L638-652
MQTT event bridge
Broker connection
MQTT is an optional bridge between Teams for Linux and an MQTT broker. When enabled, it publishes the app's availability, Teams presence, and media state, and it can receive a small set of commands from another system.
The bridge publishes a retained connected state so consumers can tell whether the app is available. It reconnects through the MQTT client library, skips outbound messages while disconnected, and publishes a retained offline state during an orderly shutdown. A command topic is optional, which allows a status-only setup.
References: app/…/index.js• L4-16 app/…/index.js• L40-117 app/…/index.js• L126-178 app/…/index.js• L244-257 app/index.js• L445-523
Teams status events
The renderer watches the Teams page for presence changes and sends only status changes to the main process. It uses page signals that are visible to the browser because the Teams session does not provide a usable presence API to this app.
The monitor combines change observation with periodic checks. It maps the visible status to a small set of codes, forwards the change for MQTT publication, and also emits a local browser event for other client-side tools. If Teams changes its page structure, detection can stop until the selectors or fallback rules are updated.
References: app/…/mqttStatusMonitor.js• L1-22 app/…/mqttStatusMonitor.js• L24-71 app/…/mqttStatusMonitor.js• L77-131 app/…/mqttStatusMonitor.js• L133-165 app/…/preload.js• L428-464
Media state events
Media hooks turn call and device activity into MQTT state. The system reports call presence, incoming calls, camera state, microphone state, screen sharing, and a short meeting-start signal. These events connect screen sharing and media with external home automation or other MQTT consumers.
The media service retains the latest state for topics where a current value matters. It suppresses repeated microphone values, clears call and microphone state when a call ends, and resets a meeting-start signal when the user joins or when its short delay expires. The meeting-start signal is a pulse rather than a permanent meeting state because Teams does not provide a matching end event.
References: app/…/mediaStatusService.js• L4-18 app/…/mediaStatusService.js• L36-58 app/…/mediaStatusService.js• L70-123 app/…/mediaStatusService.js• L125-169 app/…/mediaTopics.js• L1-20
Command handling
Inbound MQTT messages can request a small set of meeting actions or a calendar read. The bridge accepts only valid JSON commands whose action is on its allowlist. Shortcut actions are sent to the Teams window, while calendar requests use the app's calendar service and publish the result back to MQTT.
Microphone commands also use the last known microphone control state. The bridge ignores a command that would repeat the current state and requires an explicit force flag before acting when the state is unknown. This prevents stale or incomplete media data from causing an unexpected mute action.
References: app/…/index.js• L24-38 app/…/index.js• L203-242 app/index.js• L433-443 app/index.js• L452-512
Home Assistant discovery
Home Assistant discovery turns the MQTT bridge into named sensors, binary sensors, and optional control buttons. Discovery is sent again after each broker connection so a broker restart does not remove the external view of the Teams device.
The discovered entities use the retained connected topic for availability. Control buttons are exposed only when a command topic exists, which keeps a status-only integration read-only by design.
References: app/…/homeAssistantDiscovery.js• L1-16 app/…/homeAssistantDiscovery.js• L29-51 app/…/homeAssistantDiscovery.js• L53-117 app/…/homeAssistantDiscovery.js• L119-172
Download flow
Download feedback
Download handling makes Teams file transfers visible outside the web page. When enabled, it observes the Teams browser session and reports active progress, completion, cancellation, and interruption through desktop surfaces.
The feedback adapts to the desktop environment. It can use a taskbar or dock indicator, a KDE job view, and a window-title progress prefix. Completion can show a notification and open the containing folder, while an interrupted Microsoft 365 or SharePoint transfer can point the user to the source link when the failure looks like an access policy block. The policy hint changes the message only; it does not bypass access control.
References: app/…/index.js• L83-107 app/…/index.js• L109-148 app/…/index.js• L150-257 app/…/index.js• L341-409 app/…/index.js• L532-624
Download destinations
The download flow supports the default system location, a configured fixed directory, or a native Save As choice. A fixed directory creates a unique file name instead of silently replacing an earlier download. Invalid destination settings fall back to the system default so they do not block the transfer.
The download feature is opt-in. Its notification and progress settings only affect downloads after the main switch is enabled, and the main process attaches the manager after the Teams session partition exists.
References: app/…/index.js• L150-176 app/…/index.js• L277-315 app/…/options.js• L332-369 app/index.js• L734-737
Client-side hooks
Preload bridge
The preload layer is the controlled boundary between the Teams page and the desktop process. It exposes selected actions through electronAPI, starts browser tools after the page is ready, and forwards only the events needed by the main process.
For Teams file uploads, it restores the native path for files received through drag and drop or paste. This supports Teams' upload path without exposing local file paths on login or other non-Teams pages. The same bridge also connects notification, navigation, media, status, and screen-sharing events to their desktop services.
References: app/…/preload.js• L1-77 app/…/preload.js• L79-215 app/…/preload.js• L411-489
WebRTC media hooks
The speaking indicator hook watches WebRTC connections for microphone and camera changes. It uses the local audio track for mute state and audio levels for speaking state, then sends changes to the main process for MQTT publication. When all peer connections close, it marks the call as ended and clears media state.
This hook can run for MQTT call detection even when the visual speaking overlay is disabled. That keeps external call state useful without adding a visual element to the Teams page.
References: app/…/speakingIndicator.js• L1-42 app/…/speakingIndicator.js• L64-83 app/…/speakingIndicator.js• L112-153 app/…/speakingIndicator.js• L170-243 app/…/speakingIndicator.js• L288-313
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the connection manager's recoverable error set aligned with the errors that Teams can report during proxy, DNS, tunnel, and resume failures. A mismatch can leave a failed page without a retry.
- Keep the MQTT media topic defaults, the media event names, and Home Assistant discovery state topics aligned. A topic rename can leave existing external entities subscribed to stale retained values.
- Preserve the retained connected topic contract when changing MQTT startup or shutdown behavior. Home Assistant availability depends on its
trueandfalsepayloads. - Keep the status monitor's status codes aligned with the MQTT status map and any local consumers. A code change can silently publish the wrong presence.
- Treat IndexedDB and WebStorage as authentication data when changing cache cleanup or storage-clear scope. Removing them changes the login contract.
- Keep the download manager's externally managed download marker compatible with features that own their own download flow. Otherwise one transfer can receive duplicate save-path or notification handling.
- Keep preload event names aligned with the main-process IPC handlers. Renderer hooks can continue to run while their desktop effects silently stop if a channel changes on only one side.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A main-frame network failure is not classified as recoverable | Teams remains on a failed page without an automatic refresh | The connection manager uses a shared set of recoverable network error patterns and schedules a debounced refresh. |
| A connectivity probe waits on a stale socket | The refresh guard can remain active and later retries can be skipped | Each probe has a timeout and the full connectivity sweep has a time budget. |
| Cache cleanup removes IndexedDB or WebStorage | Teams authentication tokens are lost and the user may need to sign in again | Cache cleanup limits itself to disposable cache and journal data. |
| MQTT is disconnected during a state change | The state is not published at that time | Publish methods fail closed and the retained connected state reports broker availability. |
| Teams changes the DOM used for presence detection | Presence updates stop reaching MQTT and local browser tools | The monitor has selector, account-control, and title fallbacks plus periodic checks. |
| All WebRTC peer connections close without a React call event | External call state can remain active | The media hook treats the closed-connection check as an authoritative disconnect signal. |
| A SharePoint download is interrupted before any bytes arrive | The user sees only a generic failure unless the likely policy block is identified | The manager uses the source host and received-byte count to offer an advisory browser link. |
| A configured download directory is missing or not writable | A download could be interrupted before it starts | The manager creates the directory when possible and falls back to the system location on error. |
Key files
| File | Why to read it |
|---|---|
| app/…/index.js | Defines the network probe, reload, retry, and resume behavior for the Teams page. |
| app/index.js | Shows when the connectivity-related services, MQTT bridge, cache manager, and download manager join the app lifecycle. |
| app/…/index.js | Defines the broker connection, retained availability, outbound publishing, and inbound command boundary. |
| app/…/mediaStatusService.js | Connects call, meeting, camera, microphone, and screen-sharing events to MQTT state. |
| app/…/homeAssistantDiscovery.js | Describes how MQTT state becomes external Home Assistant entities and controls. |
| app/…/mqttStatusMonitor.js | Shows how the Teams page exposes presence changes to the desktop process. |
| app/…/speakingIndicator.js | Shows how WebRTC activity supplies call, microphone, and camera state. |
| app/…/index.js | Defines the boundary between disposable browser cache and login-preserving storage. |
| app/…/storagePartitions.js | Defines which account session partitions participate in storage cleanup. |
| app/…/index.js | Defines download progress, destination, notification, and interrupted-transfer behavior. |
| app/…/preload.js | Defines the browser-to-desktop event and API boundary used by the client-side hooks. |