Red5 + PubNub Integration for Real-Time Chat and Video
Combine Red5 Cloud sub-250ms video streaming with PubNub sub-100ms chat. Retrieve auto-provisioned keys and integrate across HTML5, iOS, and Android SDKs.
Red5 Cloud and PubNub form a composable real-time stack: Red5 delivers sub-250ms video via WebRTC through the Experience Delivery Network, while PubNub handles sub-100ms chat messages, reactions, and presence signals. Because both systems operate in parallel on the same stream, your users see frame-synchronized chat and interactions rather than the noticeable drift common in loosely coupled architectures. Red5 Cloud provisions your PubNub API keys automatically when you create an account, so you can start integrating immediately without managing a separate PubNub account.
When you create a Red5 Cloud account, the platform automatically generates a dedicated PubNub keyset for you. These keys are scoped to your account and pre-configured to work with the Red5 SDK sample code and TrueTime Meetings.
Red5’s SDKs handle audio/video via WebRTC, while PubNub manages messaging, presence, and signaling. Use your stream name as the PubNub channel name so that viewers watching a stream are automatically placed in the correct chat room.
HTML5
iOS (Swift)
Android (Java/Kotlin)
The HTML5 integration uses the Red5 WHIPClient (or RTCSubscriber) for video alongside the PubNub JavaScript SDK for chat. Initialize both with your stream name and use it as the PubNub channel.
<!-- Include the PubNub JS SDK --><script src="https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.5.min.js"></script>
import { WHIPClient } from '@red5pro/red5pro-webrtc-sdk';// 1. Start the Red5 video publisherconst publisher = new WHIPClient();await publisher.init({ host: 'xxx.red5pro.net', app: 'live', streamName: 'myStream', mediaElementId: 'red5pro-publisher'});await publisher.publish();// 2. Initialize PubNub with the same stream name as the channelconst pubnub = new PubNub({ publishKey: 'YOUR_PUBNUB_PUBLISH_KEY', subscribeKey: 'YOUR_PUBNUB_SUBSCRIBE_KEY', userId: 'user-' + Date.now()});pubnub.subscribe({ channels: ['myStream'] });pubnub.addListener({ message: ({ message }) => { console.log('Chat message received:', message); }});// 3. Send a chat messageawait pubnub.publish({ channel: 'myStream', message: { text: 'Hello from the publisher!' }});
Use the same streamName value for both the Red5 connection and the PubNub channel. This ensures that all participants watching a stream share a single chat room automatically.
The Red5 Pro iOS SDK exposes PubNub configuration directly on the Red5WebrtcClientBuilder, so you pass your keys at build time without managing a separate PubNub client instance.
Video is configured via the R5Configuration object as usual.
Chat messages are delivered to your ChatEventListener implementation.
Channel sync — the SDK uses the stream name as the PubNub channel automatically.
Retrieve pubnubPublishKey and pubnubSubscribeKey from the Dev Resources page of your Red5 Cloud Management Console and store them in your app’s configuration object.
The Red5 Pro Android SDK builder accepts PubNub keys alongside your license key and user ID. The SDK wires the PubNub client to the video stream internally.
import com.red5pro.webrtc.IRed5WebrtcClient;IRed5WebrtcClient webrtcClient = IRed5WebrtcClient.builder() .setActivity(this) .setLicenseKey(YOUR_SDK_LICENSE_KEY) // Unique identifier for this chat participant. // Required for auth-enabled chat token generation. .setChatUserId(USER_ID) // If chat authentication is enabled, supply a token from // your backend — see https://github.com/red5pro/red5-bcs-node // .setChatToken("") .setPubnubPublishKey(YOUR_PUBNUB_PUBLISH_KEY) .setPubnubSubscribeKey(YOUR_PUBNUB_SUBSCRIBE_KEY) .setEventListener(this) .build();
Setup checklist:
Add both the Red5 Pro Android SDK and PubNub Java/Kotlin SDK to your build.gradle dependencies.
Start the Red5 R5Stream to begin publishing or subscribing to video.
In the same Activity, call build() on the client as shown above.
Use PubNub Messages in your setEventListener implementation to update the chat UI overlaid on the Red5 SurfaceView.
TrueTime Meetings is Red5’s flagship conferencing app and the fastest way to see the Red5 + PubNub stack in action. It comes pre-wired to your account’s PubNub keys — no glue code required.
Zero-config chat
TrueTime Meetings reads your PubNub keys directly from your Red5 Cloud account. Deploy the app and chat is immediately active.
Presence
PubNub’s presence feature automatically tracks who is online in each meeting room, powering the participant list.
Signaling
Raise-hand events and participant controls are delivered over PubNub, keeping the video path free of control traffic.
If you deploy TrueTime Meetings from the Red5 Cloud Management Console, PubNub is configured automatically. You do not need to set any PubNub keys manually.