PAM Native Realtime
Start here
Section titled “Start here”Every PAM Native product runs on the PAM runtime. Install and verify PAM first, create a Native application, and add this package through PAM Composer:
curl -fsSL https://github.com/push-in/pam/releases/latest/download/install.sh | shpam doctorpam init my-app --template nativecd my-apppam composer require pushinbr/pam-native-realtimepam doctorpam native devpushinbr/pam-native-realtime 0.4 keeps the socket, channel authorization,
heartbeats, reconnects with backoff, network recovery, re-subscription and
whisper throttling native (OkHttp 5.3.0 on Android, URLSessionWebSocketTask
on iOS). Events reach PHP in coalesced batches: a burst costs one callback and
one render. Requires PAM Native >=1.0.35 <2.0.0.
use Pam\Native\Realtime\{PresenceMember, Realtime, RealtimeMessage, RealtimeStatus, Secret};
Realtime::reverb('ws.example.com', 'app-key') // or Realtime::pusher('wss://…', key: 'app-key') ->auth('https://api.example.com/broadcasting/auth', Secret::value($token)) ->terminalRetry(300) // Reverb 4009: retry after 5 minutes ->onConnected(fn (RealtimeStatus $s) => $this->catchUp()) // first connect and every reconnect ->onDropped(fn (int $count) => $this->resync()) ->connect();
Realtime::private('chat.42') ->listen('message.sent', fn (RealtimeMessage $m) => $this->append($m->data)) ->listenForWhisper('typing', fn (RealtimeMessage $m) => $this->typing($m->userId));
Realtime::join('chat-typing.42') ->here(fn (array $members) => $this->online = count($members)) ->joining(fn (PresenceMember $m) => $this->online++) ->leaving(fn (PresenceMember $m) => $this->online--) ->whisper('typing', ['typing' => true]); // sent as client-typing, throttled natively
Realtime::token($refreshed); // new bearer; 401/403 channels retry at onceRealtime::leave('chat.42');- Connection states:
Connecting,Connected,Unavailable(reconnect scheduled),Disconnected,Failed(Pusher 4000–4099, retried afterterminalRetry()).Realtime::status()returns channels and a 40-entry diagnostic journal for support screens. - Only
wss://endpoints and anhttps://auth endpoint are accepted;private-encrypted-*channels are rejected. RealtimeSocketkeeps the raw RFC 6455 API (connect, send text/binary, poll, state, close) for non-Pusher protocols. It replaced the 0.2Realtimesocket API in 0.3.
Android merges INTERNET and ACCESS_NETWORK_STATE; iOS needs no capability.
Zé Chat runs its Reverb channels on this package and calls
Realtime::reconnect() when the app becomes active to skip a pending backoff.