WebRTC for JumPHP: peer-to-peer data channels and screen video from PHP (read-only split of extensions/webrtc of JumPHP)
- PHP 53.1%
- Python 45%
- Dockerfile 1.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Two peers on one screen (PING / PONG with the round trip, a cursor over an unreliable channel) and a star-catching duel peer to peer, against a bot (a second WebRTC peer of the game) or online (LobbyScene, signals through the relay). Own menu (keys, mouse, touch), TTF fonts with Noto Sans subsets for ja / zh / ko, a simulated backend where WebRTC is missing (headless tests), game tests, a site in 14 languages, thumbnail and icon. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
| bin | ||
| doc | ||
| docker | ||
| src | ||
| composer.json | ||
| LICENSE | ||
| README.md | ||
jumphp/webrtc
WebRTC for JumPHP games and apps: peer-to-peer connections from PHP, the same code in the browser and on the desktop.
A JumPHP engine extension (docs/extensions.md): composer require jumphp/webrtc, nothing to wire.
public function __construct(private WebRtc $webrtc) {} // a scene
$peer = $this->webrtc->peer();
$peer->on('signal', fn (array $s) => $net->sendJson(250, $s)); // offer / answer / ICE: send them to the other side, any way you like
// ... when the other side's signal arrives: $peer->signal($s);
$chat = $peer->channel('chat'); // reliable + ordered (a 'pos' channel: ordered: false, retransmits: 0 = like UDP)
$chat->on('message', fn (string $text) => $this->log[] = $text);
$chat->send('hello');
$peer->offer(); // one side offers, the other answers by itself
- Browser: the page's
RTCPeerConnection(engine page modulejumphp-webrtc.js, through the JsBridge). - Desktop: a native peer, GStreamer
webrtcbindriven as a sidecar process (bin/webrtc-gst.py); runs with the computer's python3 + GStreamer, or in Docker (image built the first time). Linux for now. - Screen streaming (desktop, Linux X11):
$peer->screen(['fps' => 60, 'kbps' => 8000])sends the computer's screen as H.264 (GPU encoder: VA-API / NVENC, or x264 zero-latency) with aninputdata channel (mouse, wheel, keys, Unicode text, injected with XTest). The JumPHP IDE's Screen on a phone is built on it, with the viewer JumPHP Screen (https://jumphp.net/jumphp-screen). Signaling::overNet($net, $peer, $otherPlayer): the signals through the multiplayer relay of a LobbyScene room, then peer to peer.
Documentation: doc/index.md, the sidecar protocol doc/sidecar.md, a tutorial doc/tutorial.md, samples doc/samples/
(LoopbackSample: two peers in one game; OnlineSample: two players meet on the relay then talk peer to peer). Example game: games/webrtc-demo.