Channels API

Channels are virtual environments where users can communicate with each other and exchange messages. Your application creates channels with a unique id, a name, and a description. You can also save additional properties as custom fields in the channel. These additional properties can be anything you like, such as an image icon, such as a display color, star ratings, moderator names, and more.

State Shape

The data about an individual channel is stored as a slice in a normalized pool of Channels. The following example shows the shape of a list of Channels in the store:

{
"byId": {
"channel_ac4e67b98b34b44c4a39466e93e": {
"id": "channel_ac4e67b98b34b44c4a39466e93e",
"name": "Introductions",
"description": "This channel is for company wide chatter",
"updated": "2019-11-08T21:42:30.661344Z",
"eTag": "AYr89/Sb5KDi4gE"
},
"channel_a652eb6cc340334ff0b244c4a39": {
"id": "channel_a652eb6cc340334ff0b244c4a39",
"name": "London Office",
"description": "London Office 🇬🇧",
"updated": "2019-11-08T21:42:30.965912Z",
"eTag": " AfD93cn945yNTA"
show all 18 lines

Reducers

The PubNub Redux framework provides reducers your app can implement that respond to various actions that update the store. To track the state of a set of objects in the store, combine the reducers you want into the rootReducer for your app.

createChannelDataReducer

createChannelDataReducer instantiates a reducer in the store that responds to actions dispatched to update the state of channels in the store.

createChannelDataReducer();

createChannelsListReducer

createChannelsListReducer instantiates a reducer in the store that responds to actions that put a list of channel IDs (as string values) into the store.

createChannelsListReducer();

Listeners

The PubNub Redux framework includes listeners that monitor PubNub events from the server and dispatch corresponding actions. All listeners are automatically invoked if your app registers the combined PubNub listener. You can register only specific listeners, or implement your own combine listeners function.

createChannelDataListener

createChannelDataListener registers a listener in the store that monitors channel-related events, such as ChannelDataSet and ChannelDataRemoved, and dispatches corresponding actions to update the store.

A sample implementation of a single listener:

pubnub.addListener(createChannelDataListener(store.dispatch));

Commands

The PubNub Redux framework provides commands that your app can dispatch to the store to be managed by the Thunk middleware. Commands interact with the PubNub API and dispatch basic actions which are then processed by reducers to update the state in the store.

setChannelData

Sets the data associated with a channel.

setChannelData( request, [meta] )

setChannelData Arguments

* required
ParameterDescription
request *
Type: ChannelRequest
Channel request parameter object.
[meta]
Type: object
Standard meta options object.

setChannelData ChannelRequest Properties

* required
PropertyDescription
channel *
Type: string
Unique identifier of the channel to be created. You won't be able to change the channel ID.
data *
Type: object
Data for the channel
  [name]
Type: string
Display name of the channel.
  [description]
Type: string
Description of the channel.
  [custom]
Type: object
JSON object of key-value pairs with supported data types. Values must be scalar only; arrays and objects aren't supported.

setChannelData Sample Usage

dispatch(setChannelData({
channel: 'channel_12345',
data: {
name: 'Customer Support',
description: 'Customer Support team member conversations.',
custom: {
location: 'New York',
moderator: 'cwilliams',
space_icon: 'customer_support_icon.png'
}
}
}));

removeChannelData

Removes the specified channel data.

removeChannelData( request, [meta] )

removeChannelData Arguments

* required
ParameterDescription
request *
Type: RemoveChannelRequest
Channel request parameters object.
[meta]
Type: object
Common meta options object.

removeChannelData RemoveChannelRequest Properties

* required
PropertyDescription
channel *
Type: string
Unique identifier of the channel to be deleted.

removeChannelData Sample Usage

dispatch(removeChannelData({
id: 'channel_12345'
}));

fetchChannelData

Fetch the details of a specific channel.

fetchChannelData( request, [meta] )

fetchChannelData Arguments

* required
ParameterDescription
request *
Type: fetchChannelDataRequest
Channel request parameter object.
[meta]
Type: object
Common meta options object.

fetchChannelData fetchChannelDataRequest Properties

* required
PropertyDescription
channel *
Type: string
ID of the channel to fetch.
[include]
Type: object
Include respective additional fields in the response.
  [customFields]
Type: boolean
Whether to fetch custom fields or not.

fetchChannelData Sample Usage

dispatch(fetchChannelData({
channel: 'channel_12345'
}));

fetchAllChannelData

Retrieve a list of channels.

fetchAllChannelData( request, [meta] );

fetchAllChannelData Arguments

* required
ParameterDescription
request *
Type: fetchAllChannelDataRequest
Request object contains custom parameters.
[meta]
Type: object
Common meta options object.

fetchAllChannelData fetchAllChannelDataRequest Properties

* required
ParameterDescription
limit
Type: number
Default:
100
Maximum number of results to return per page
filter
Type: string
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort
Type: string
Default:
n/a
Key-value pair of a property to sort by, and a sort direction. Available options are updated, id, and name.
Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).
For example: {name: 'asc'}
page
Type: object
Default:
n/a
To get the next set of results, specify next.
To get the previous set of results, specify prev.
If you specify both, prev is ignored.
{
    next: "next-page-id",
    prev: "prev-page-id"
}
include
Type: object
Default:
{
    customFields: false,
    totalCountfalse
}
Specifies whether to include custom fields in the response, and whether to include a total result count.

fetchAllChannelData Sample Usage

dispatch(fetchAllChannelData({
limit: 10,
page: {
next: 'Mg'
}
}));
Last updated on