Introducing a new way to review your PRs.

Read the announcement

crmne / zapfast

ZapFast: a fast, native WhatsApp client in Rust and egui

View on GitHub

19 documents · Updated Nov 18, 2026

docs / media-and-calling

Media and calling

ZapFast gives chats one media path for capture, preparation, preview, playback, and exchange. It supports photos, videos, voice messages, stickers, emoji, motion photos, and one-to-one or group calls. Local media stays useful while it loads, while call media stays separate from chat playback and follows the live call state.

Media lifecycle

Media moves from a local source or a downloaded attachment to a prepared form, then to a chat preview, a full viewer, or a player. The same broad path covers outgoing attachments and incoming media: the user can inspect what is ready, fetch what is missing, and open supported items without leaving the conversation.

References: src/…/attachment_preview.rs• L12-45 src/image_preview.rs• L15-44 src/…/image_preview.rs• L32-177

flowchart LR
    A[Camera, microphone, paste, or file] --> B[Prepare media]
    B --> C[Stage for sending]
    C --> D[Chat message]
    D --> E[Thumbnail or inline view]
    E --> F[Full viewer or player]
    D --> G[Download when missing]
    G --> E

The attachment review keeps each staged item tied to its chat and account. Photos can enter the picture editor before sending. The viewer keeps the selected item tied to its message and album, so a missing file is shown as missing rather than being replaced by another picture (src/…/attachment_preview.rs• L12-45, src/image_preview.rs• L138-160).

Visual media

Visual media covers still pictures, video clips, motion photos, and camera pictures used in calls. ZapFast keeps aspect ratio, offers previews at useful sizes, and uses an external application when the in-app viewer does not support the file.

Capture and preparation

The camera path chooses a usable mode, converts the result to a common picture form, and keeps the camera's shape. This gives both the call encoder and the local preview the same source without forcing portrait pictures into a landscape frame (src/camera.rs• L1-10, src/camera.rs• L69-116).

Outgoing pictures enter a staged review before they become messages. The editor supports crop and quarter-turn changes, and it leaves the staged source unchanged until the user keeps the edit (src/…/image_editor.rs• L43-50, src/…/image_editor.rs• L84-119).

References: src/camera.rs• L1-10 src/camera.rs• L69-116 src/…/attachment_preview.rs• L39-85 src/…/image_editor.rs• L43-50

Preview and playback

The full-window viewer is a modal for supported photos and videos. It can browse the chat album, show a thumbnail while an attachment is not downloaded, fetch that attachment, and offer copy, save, reply, forward, or external open actions where they apply (src/…/image_preview.rs• L32-177, src/…/image_preview.rs• L753-835).

Videos use the video player in both the chat and the viewer. The player keeps frames ahead of the clock, uses sound when available, follows sound when the two clocks drift, and pauses content that is no longer visible. Unsupported video goes to the system player instead of failing as a still image (src/video.rs• L43-89, src/video.rs• L744-803, src/video.rs• L949-1053).

For the detailed capture, preview, edit, and playback flow, see Media capture, preview, and editing.

References: src/…/image_preview.rs• L32-177 src/…/image_preview.rs• L838-979 src/video.rs• L669-705 src/video.rs• L949-1053

Audio media

Voice messages use a common mono 48 kHz form for recording and playback. Recording shows live loudness, waits for a slow device to start, stops safely when a device stalls, and keeps samples already received (src/audio.rs• L634-670, src/audio.rs• L847-915).

Playback gives one clip a clear state and position. It supports pause, seek, waveform display, and a small set of faster speeds while keeping speech pitch stable. A failed output device can be reopened from the current position, or playback can pause with an error when repeated recovery fails (src/audio.rs• L39-100, src/audio.rs• L304-435, src/audio.rs• L500-535).

The audio path can hold other applications' playing media while ZapFast records or plays. Overlapping holds pause only once and resume only the players ZapFast paused (src/media_pause.rs• L1-19, src/media_pause.rs• L29-49).

For the audio format, voice-message flow, and call audio path, see Calls and audio processing.

Calling

Calling connects chat identity, signaling, local devices, live audio, live video, and call history. The backend owns the call state. The window presents that state and sends user actions back to the account that owns the call (src/calls.rs• L1-14, src/…/call.rs• L1-9).

Call states

Calls move from local placement or an incoming ring through connection to active media, then to an ended or failed result. The active timer starts when the media plane is live, not when the call button is pressed (src/calls.rs• L65-121, src/…/calls.rs• L1-11).

flowchart LR
    A[Place or receive call] --> B[Placing, dialing, or ringing]
    B --> C[Connecting or accepted]
    C --> D[Active audio or video]
    D --> E[Ended or failed]
    B --> E

The app allows one live call across accounts because the call owns shared local media resources. A second offer is refused, while an unsupported group call can remain visible as a phone-only notice rather than taking local devices (src/…/calls.rs• L5-13, src/…/calls.rs• L716-801).

References: src/calls.rs• L65-121 src/…/calls.rs• L1-11 src/…/call.rs• L373-395 src/…/calls.rs• L5-13 src/…/calls.rs• L255-271 src/…/calls.rs• L716-801

Call media

Call audio uses the same platform audio layer as other app audio while the call engine works with its own stable media channels. Changing a microphone or speaker replaces the local stream without changing the call itself (src/calls.rs• L466-471).

Call video carries camera frames to the peer and decoded peer frames to the UI. The capture path preserves camera orientation, adapts picture rate and size to path conditions, and sends keyframes when the peer needs to recover. The UI receives local, one-to-one remote, or group-member pictures as separate frame types (src/calls.rs• L520-539, src/calls.rs• L692-713).

References: src/calls.rs• L520-539 src/calls.rs• L692-713 src/camera.rs• L62-116 src/…/calls.rs• L654-713

The call surface shows the peer picture, the local preview, group tiles, device choices, mute and camera state, and clear notes when a device or peer audio path is unavailable. Hiding the surface leaves the call active in a bottom strip; hanging up is the action that ends it (src/…/call.rs• L35-159, src/…/call.rs• L162-283, src/…/call.rs• L504-655).

References: src/calls.rs• L466-471 src/calls.rs• L520-539 src/calls.rs• L692-713 src/…/call.rs• L35-159 src/…/call.rs• L162-283

Call records

When a call ends, ZapFast files a local call entry unless the phone's own call record already covers it. The Calls page reads these entries together with synced phone call records, folds alike consecutive calls, and offers voice or video callback actions where a chat supports them (src/…/calls.rs• L985-1074, src/…/calls.rs• L132-169, src/…/calls.rs• L316-407).

References: src/…/calls.rs• L985-1074 src/…/calls.rs• L132-169 src/…/calls.rs• L316-407

Stickers and emoji

Emoji provide both in-message visual symbols and the search language for stickers. Stickers carry pack and emoji metadata, so a user can find them by the pictured emoji, an emoji name, or a pack name (src/sticker_meta.rs• L1-7, src/sticker_search.rs• L1-5).

Sticker metadata is kept with the WebP file. ZapFast reads and writes the pack fields and emoji list, and cleans typed emoji to unique emoji entries when it creates metadata (src/sticker_meta.rs• L14-37, src/sticker_meta.rs• L194-241). Search combines recent, favorite, packed, and received stickers without duplicates, with emoji matches before pack-name matches (src/sticker_search.rs• L39-105).

Emoji rendering uses the platform's color emoji font with a bundled fallback. Text layout keeps character positions usable while the colored emoji picture is painted over the placeholder (src/emoji.rs• L1-11, src/emoji.rs• L43-89).

References: src/sticker_meta.rs• L1-7 src/sticker_meta.rs• L14-37 src/sticker_search.rs• L39-105 src/emoji.rs• L1-11 src/emoji.rs• L43-89

For sticker packs, sticker previews, metadata, and emoji search, see Stickers and emoji.

Change checklist

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

  • Keep the supported-file rule shared by the album, viewer, and player. A file that enters one path but not the others can open in the wrong decoder.
  • Keep call phase claims aligned between backend updates, call history entries, and the screen timer. In particular, only live media starts the duration.
  • Keep camera orientation and frame-rate decisions aligned between local preview, encoder input, and peer tile output.
  • Keep sticker emoji metadata compatible with both file metadata and search normalization.
  • Keep audio device fallback visible in the call state so a picker does not claim that a missing device is still active.

Important failure modes

TriggerConsequenceGuard
A video format is not supported by the in-app playerThe clip cannot play in the viewerRoute it to the system player (src/video.rs• L73-89, src/video.rs• L985-1010)
A selected call device disappearsThe stream falls back and the call remains activeReconcile devices and report the lost selection (src/…/calls.rs• L899-977)
A camera cannot start for a video callThe call must not claim to send video it cannot provideValidate the video path before signaling (src/calls.rs• L502-513)
Peer video loses its decode referenceNew delta frames cannot produce a pictureRequest a peer keyframe (src/…/calls.rs• L654-660)
A voice recording device stallsThe recording can hang or lose its end statePoll for stop and stall limits while retaining received samples (src/audio.rs• L923-1005)

Key files

FileWhy to read it
src/audio.rsShared voice recording and playback behavior
src/video.rsShared video playback, timing, sound, and frame delivery
src/camera.rsCamera discovery, format choice, conversion, and sizing
src/calls.rsCall state and the bridge between devices, media, and the UI
src/…/calls.rsCall lifecycle, signaling, media events, device recovery, and history filing
src/…/image_preview.rsViewer state, album choice, zoom, and media routing
src/…/image_editor.rsOutgoing picture crop and rotation flow
src/…/call.rsLive call surface, previews, group tiles, and controls
src/sticker_meta.rsSticker file metadata contract
src/sticker_search.rsSticker search behavior
src/emoji.rsColor emoji rendering and fallback behavior