Channels
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 linesReducers
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
Parameter | Type | Required | Description |
---|---|---|---|
request | ChannelRequest | Yes | Channel request parameter object. |
[meta] | object | Optional | Standard meta options object. |
setChannelData ChannelRequest Properties
Property | Type | Required | Description |
---|---|---|---|
channel | string | Yes | Unique identifier of the channel to be created. You won't be able to change the channel ID. |
data | object | Yes | Data for the channel |
[name] | string | Optional | Display name of the channel. |
[description] | string | Optional | Description of the channel. |
[custom] | object | Optional | 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
Parameter | Type | Required | Description |
---|---|---|---|
request | RemoveChannelRequest | Yes | Channel request parameters object. |
[meta] | object | Optional | Common meta options object. |
removeChannelData RemoveChannelRequest Properties
Property | Type | Required | Description |
---|---|---|---|
channel | string | Yes | 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
Parameter | Type | Required | Description |
---|---|---|---|
request | fetchChannelDataRequest | Yes | Channel request parameter object. |
[meta] | object | Optional | Common meta options object. |
fetchChannelData fetchChannelDataRequest Properties
Property | Type | Required | Description |
---|---|---|---|
channel | string | Yes | ID of the channel to fetch. |
[include] | object | Optional | Include respective additional fields in the response. |
[customFields] | boolean | Optional | 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
Parameter | Type | Required | Description |
---|---|---|---|
request | fetchAllChannelDataRequest | Yes | Request object contains custom parameters. |
[meta] | object | Optional | Common meta options object. |
fetchAllChannelData fetchAllChannelDataRequest Properties
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
limit | number | Optional | 100 | Maximum number of results to return per page |
filter | string | Optional | 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 | string | Optional | 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 | object | Optional | 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 | object | Optional | { customFields: false, totalCount : false } | 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'
}
}));