Skip to content

feat: play video and images into calls - #201889

Open
alpersamur3 wants to merge 6 commits into
wwebjs:mainfrom
alpersamur3:feat/call-video-injection
Open

alpersamur3 wants to merge 6 commits into
wwebjs:mainfrom
alpersamur3:feat/call-video-injection

Conversation

@alpersamur3

Copy link
Copy Markdown

Description

Builds on #201825 (call answering and audio injection) and adds video to calls: show a still image or play a video clip to the other party, in landscape or portrait, at a chosen resolution.

New Call methods:

  • showImage(media) shows a still image to the other party for the duration of the call
  • playVideo(media, { loop }) plays a video clip into the call; resolves when it finishes, or immediately when looping
  • setVideoResolution(px) changes the outgoing video resolution mid-call

New options on Client.call / Call.accept:

  • orientation: 'landscape' (default), 'portrait', or 'auto' (follows the first source). Fixed for the whole call.
  • resolution: the short side of the frame in pixels (default 720).

Injected audio (playAudio from #201825) works during video calls too, so you can show video and speak at the same time.

How

The outgoing camera is acquired through navigator.mediaDevices.getUserMedia, which is patched to serve a canvas-backed stream instead of a physical camera. A draw loop paints the current source (a still image or a looping video) onto the canvas, and canvas.captureStream() produces the outgoing frames. No camera is required and it works headless.

Notes

Testing Summary

Verified live end-to-end against a real phone: showing a still image, playing a looping portrait video, injected audio playing over the video at the same time, and a mid-call resolution change. Unit tests for the call API are in tests/call.js.

adds the ability to answer incoming calls, place outgoing calls and inject
audio into an active call, plus fixes that make call handling work on
current WhatsApp Web.

call:
- accept() answers a call (audio only by default, even for video calls)
- end() hangs up an ongoing call
- playAudio(media) streams a MessageMedia/base64 audio clip to the other party
- isConnected() reports whether the other party has answered

client:
- call(chatId, { video, waitForAnswer, answerTimeout }) places an outgoing call
- getActiveCall() returns the ongoing call, if any

fixes:
- Incoming "call" event: current WhatsApp Web reports calls through
  WAWebCallCollection's activeCall attribute; the previous internal-map hook
  no longer fires. The map hook is kept as a fallback.
- Call.reject() now goes through the voip stack, which the previous signaling
  stanza no longer triggers on current WhatsApp Web.

audio is captured through a synthetic Web Audio stream, so no microphone is
required and it works headless. Adds the browser flags needed for this.
whatsapp Web now asks for confirmation before any call that is not flagged
as a user gesture, so startWAWebVoipCall waited on a popup and the call was
never placed. Pass the same entry point and trust flag the call buttons use.
builds on the call audio injection so a call can now show a still image or
play a video clip to the other party, in a chosen frame orientation.

- Call.showImage(media) and Call.playVideo(media, { loop }) draw onto a
  canvas that is fed through navigator.mediaDevices.getUserMedia, the
  camera entry point WhatsApp uses (separate from the microphone one)
- Client.call and Call.accept accept orientation ('landscape', 'portrait'
  or 'auto') and resolution; the orientation is fixed for the call and a
  portrait frame is pre-rotated so WhatsApp displays it upright
- Call.setVideoResolution changes the resolution during a call
- Requires Google Chrome for H.264; works headless and without a camera
@alpersamur3
alpersamur3 force-pushed the feat/call-video-injection branch from 3d1efc6 to 9fc4020 Compare September 24, 2026 13:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications tests Test related typings Type definitions utility Utility code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant