> ## Documentation Index
> Fetch the complete documentation index at: https://red5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

## How keys are provisioned

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.

### Retrieve your keys

<Steps>
  <Step title="Log in to the Red5 Cloud Management Console">
    Go to [red5.net](https://red5.net) and sign in to your account.
  </Step>

  <Step title="Open Dev Resources">
    Click **Dev Resources** in the main dashboard navigation.
  </Step>

  <Step title="Copy your PubNub keys">
    Locate the **PubNub Chat Integration** section. Copy your **Publish Key** and **Subscribe Key** — you will need both in your application code.
  </Step>
</Steps>

<Note>
  Your PubNub keys are pre-configured for use with Red5 sample code. You do not need a separate PubNub account to start building.
</Note>

## Integration by platform

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.

<Tabs>
  <Tab title="HTML5">
    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.

    ```html theme={null}
    <!-- Include the PubNub JS SDK -->
    <script src="https://cdn.pubnub.com/sdk/javascript/pubnub.7.4.5.min.js"></script>
    ```

    ```javascript theme={null}
    import { WHIPClient } from '@red5pro/red5pro-webrtc-sdk';

    // 1. Start the Red5 video publisher
    const 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 channel
    const 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 message
    await pubnub.publish({
      channel: 'myStream',
      message: { text: 'Hello from the publisher!' }
    });
    ```

    <Tip>
      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.
    </Tip>
  </Tab>

  <Tab title="iOS (Swift)">
    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.

    ```swift theme={null}
    import Red5Pro

    let webrtcClient = Red5WebrtcClientBuilder()
        .setPubnubPublishKey(config.pubnubPublishKey ?? "")
        .setPubnubSubscribeKey(config.pubnubSubscribeKey ?? "")
        .setLicenseKey(config.licenseKey ?? "")
        .setEventListener(ChatEventListener(chatView: self))
        .build()
    ```

    * **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.

    <Note>
      Retrieve `pubnubPublishKey` and `pubnubSubscribeKey` from the Dev Resources page of your Red5 Cloud Management Console and store them in your app's configuration object.
    </Note>
  </Tab>

  <Tab title="Android (Java/Kotlin)">
    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.

    ```java theme={null}
    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:**

    1. Add both the Red5 Pro Android SDK and PubNub Java/Kotlin SDK to your `build.gradle` dependencies.
    2. Start the Red5 `R5Stream` to begin publishing or subscribing to video.
    3. In the same `Activity`, call `build()` on the client as shown above.
    4. Use PubNub `Messages` in your `setEventListener` implementation to update the chat UI overlaid on the Red5 `SurfaceView`.
  </Tab>
</Tabs>

## TrueTime Meetings: zero-config PubNub

[TrueTime Meetings](/red5-cloud/development/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.

<CardGroup cols={3}>
  <Card title="Zero-config chat" icon="bolt">
    TrueTime Meetings reads your PubNub keys directly from your Red5 Cloud account. Deploy the app and chat is immediately active.
  </Card>

  <Card title="Presence" icon="users">
    PubNub's presence feature automatically tracks who is online in each meeting room, powering the participant list.
  </Card>

  <Card title="Signaling" icon="tower-broadcast">
    Raise-hand events and participant controls are delivered over PubNub, keeping the video path free of control traffic.
  </Card>
</CardGroup>

<Info>
  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.
</Info>

## Key benefits

| Capability  | Red5 Cloud                    | PubNub                             |
| ----------- | ----------------------------- | ---------------------------------- |
| Latency     | Sub-250ms video via XDN       | Sub-100ms messages                 |
| Protocol    | WebRTC / RTMP                 | Publish/Subscribe                  |
| Scale       | Auto-scaling edge nodes       | Global PubNub network              |
| Credentials | Managed in Red5 Cloud Console | Auto-provisioned with Red5 account |

## Next steps

<CardGroup cols={2}>
  <Card title="TrueTime Meetings" icon="video" href="/red5-cloud/development/truetime-meetings">
    Deploy a full-featured video conferencing app with PubNub chat already wired in.
  </Card>

  <Card title="Stream Manager API" icon="server" href="/red5-cloud/development/stream-manager-api">
    Use the REST API to manage streams, resolve server endpoints, and create transcoding provisions.
  </Card>
</CardGroup>
