PAM Native WebRTC
Start here
Section titled “Start here”pam composer require pushinbr/pam-native-webrtcpam doctor --fixpushinbr/pam-native-webrtc 0.3 wraps WebRTC M124 (org.jitsi:webrtc on
Android, GoogleWebRTC through the stasel/WebRTC Swift package on iOS). PHP
exchanges SDP and ICE through your signalling channel; events arrive through
one pending native completion per session, and video frames never cross into
PHP. Requires PAM Native >=1.0.35 <2.0.0, Android API 26+ and iOS 15+.
use Pam\Native\WebRtc\{IceCandidate, IceServer, PeerConnection, RtcConnectionState, SessionDescription};
$pc = PeerConnection::create([ IceServer::stun('stun:stun.l.google.com:19302'), IceServer::turn('turn:turn.example.com:3478', $user, $credential), ], $sessionId) ->video() ->onIceCandidate(fn (IceCandidate $c) => $signaling->send('ice', $c->toArray())) ->onConnectionState(fn (RtcConnectionState $s) => $this->state = $s);
$pc->startLocal(function (bool $ok, string $error) use ($pc, $signaling): void { $pc->offer(fn (?SessionDescription $offer, string $error) => $signaling->send('offer', $offer?->toArray()));});
// When the answer and remote candidates arrive:$pc->setRemote(SessionDescription::fromArray($answer));$pc->addIceCandidate(IceCandidate::fromArray($candidate));Configure (video, facing, resolution, relayOnly) before the first
operation; the native session is created lazily. Buffer remote ICE candidates
until setRemote() succeeds.
Group calls
Section titled “Group calls”A mesh call keeps one PeerConnection per remote participant. Since 0.3 they
share one LocalMedia stream: the camera and microphone open once and the
same tracks are added to every peer.
use Pam\Native\WebRtc\{CameraFacing, LocalMedia, PeerConnection, RtcVideoView};
$media = LocalMedia::create()->video()->resolution(640, 480, 24)->start();
$peer = PeerConnection::create($iceServers, "grp-{$remoteId}") ->localMedia($media) // no second capture ->onIceCandidate(fn ($c) => $signaling->send('ice', $c->toArray(), $remoteId));$peer->startLocal(fn (bool $ok) => $ok && $this->offerTo($remoteId));
$media->enableMicrophone(false); // every peer$media->enableCamera(false); // stops the camera, tracks stay negotiated$media->switchCamera(fn (?CameraFacing $f) => $this->facing = $f);
$peer->close(); // a participant left; the capture keeps running$media->close(); // end of callPeers that join later get the live tracks at startLocal(). Toggles called on
a peer that uses a stream act on the stream, so 1:1 code is unchanged. Render
the single preview with RtcVideoView::preview($media) or
<RtcVideoView :media="$media" />.
Video and call audio
Section titled “Video and call audio”<RtcVideoView :session="$sessionId" track="remote" fit="cover" class="remote-video" /><RtcVideoView :session="$sessionId" track="local" mirror="true" class="local-preview" />use Pam\Native\WebRtc\{CallAudio, CallAudioMode, CallAudioRoute};
$audio = CallAudio::start(CallAudioMode::Voice) // earpiece + proximity; Video → speaker ->ringback() // while the callee rings ->onRouteChange(fn (CallAudioRoute $r) => $this->route = $r);$audio->ringback(false);CallAudio::stopActive();CallAudio replaces react-native-incall-manager: communication focus and
mode, Bluetooth → wired → speaker → earpiece routing with route events,
ringback, ringtone with vibration, microphone mute and the proximity
screen-off.
Setup and permissions
Section titled “Setup and permissions”- Android (merged):
INTERNET,ACCESS_NETWORK_STATE,CAMERA,RECORD_AUDIO,MODIFY_AUDIO_SETTINGS,WAKE_LOCK,VIBRATE,BLUETOOTH(API ≤ 30). Request camera and microphone beforestartLocal(). - iOS (merged):
audiobackground mode,NSCameraUsageDescriptionandNSMicrophoneUsageDescription(identical topam-native-mediaso both can be installed; 0.2.1+), frameworksAVFoundationandAudioToolbox. - For incoming calls and the system call UI, combine it with Calls.
Reference
Section titled “Reference”- README: complete API, event contract, errors, Zé Chat call screen
- Runnable loopback-call example (1:1 and group mesh)
- The iOS implementation mirrors the Android loopback suite in XCTest and awaits device validation.