Our goal at Red5 has always been to give developers the tools they need to deliver real-time streaming without complexity, bottlenecks, or hidden limitations. The Red5 integration with PubNub represents a major step toward that mission, combining sub-250 ms video streaming with sub-100 ms data delivery to power chat, reactions, synchronized metadata, and other interactive features at global scale.
The Red5 Pro WebRTC SDK provides an easy way to integrate PubNub messaging into your web-based application with the PubNubClient.
This example demonstrates how to do so.
A PubNubClient can be used singularly without taking advantage of the streaming capabilities of the WHIPClient and WHEPClient clients of the SDK.
// import { PubNubClient } from red5pro-webrtc-sdk
// OR, if loaded from CDN
const { PubNubClient } = red5prosdk
...
const config = {
publishKey: 'pub-c-XXXX',
subscribeKey: 'sub-c-XXXX',
userId: 'user-1234',
channelId: 'red5',
authToken: 'XXXX='
}
const pubnubClient = new PubNubClient()
pubnub.on('*', (event) => {
const { type, data } = event
console.log(`[PubNub]:: ${type}`, data)
})
await pubnub.init(pubnubConfig)
await pubnub.subscribe(channelId)When using the init() call of a PubNubClient, the following initialization properties are available:
| Property | Required | Default | Description |
|---|---|---|---|
pubnub |
[x] | window.PubNub |
Reference to the PubNub library to utilize. |
publishKey |
[x] | None | The registered publish key from PubNub. |
subscribeKey |
[x] | None | The registered subscribe key from PubNub. |
userId |
[x] | Auto-generated if not provided. | The associated User ID for PubNub. |
channelId |
[x] | red5 |
Default Channel ID to subscribe to in PubNub messaging. |
expiryMinutes |
[-] | 120 |
Default expiration of issued token associated with client. |
authToken |
[-] | None | Optional authentication token issues from PubNub - if known. |
backendUrl |
[-] | None | Optional full URL of service endpoint to access authToken from PubNub system. See documentation on deploying your own service. |
logLevel |
[-] | trace |
The default log level of the PubNub client. |
The PubNubClient requires an authentication token to connect to the PubNub system for messaging. If a valid token is generated by a means outside of the SDK, you can define the token on the authToken attribute of the init configuration.
If the authToken is not known prior to initialization, provide a custom service endpoint to access an auth token.
The following methods relate to the Message API of the PubNubClient that integrates with the PubNub service.
Request to subscribe to messages on the given channel. In most cases, this will be the same as the channelId provided in the init() configuration, as that is used to generate a valid token in the system.
Request to deliver a message on the target channel. In most cases, this will be the same as the channelId provided in the init() configuration, as that is used to generate a valid token in the system.
Request to stop receiving messages on the given channel.