Messages are always sent through PubNub on a channel. You don't have to define channels in advance; the act of publishing a message creates the channel if it doesn't already exist. Some common uses of channels are to carry direct messages, group chats, broadcasts, fan-in message patterns, and more.
PubNub supports an unlimited number of channels. A channel name can be any alphanumeric string up to 92 characters. There are a few invalid characters, and some that are reserved for special features.
Channels can represent any place where messages are sent. For example, a channel meant for 1-to-1 direct chat simply means that there are only two users using that channel. A group channel means there are two or more users using that channel.
Here are some useful channel configurations:
Direct channels for 1-to-1 messaging between two users. You can make these channels private to keep the messages secure between the users.
Group channels for group messaging between multiple users. For instance, a chat room for your family, or for a group of friends. You can make these channels made public to allow anyone to join, or make them private and only allow select users to join them.
Broadcast channels for announcements, polls, and other situations in which you want to broadcast messages in a one-to-many arrangement.
Unicast channels for responses, sensor inputs, location data, and other situations in which you want to aggregate messages in a many-to-one arrangement.
You can optionally store channel metadata such as a name and description. You can also use a custom field to store additional data for each user. Some examples of custom data could include a channel's type, purpose, or owner.
|No||The channel's name. If provided, must not be an empty string or consist only of whitespace characters.|
|No||The description of the channel.|
|No||JSON object of key-value pairs with supported data types. Values must be scalar only; arrays and objects aren't supported.|
Set channel metadata
This operation enables you to store channel metadata in PubNub and optionally include custom data. You can use it to add new or update existing metadata properties. The method returns the updated channel metadata, including the channel's custom data.
Note: If you update the
custom property, you must completely replace it; partial updates to
custom property aren't supported.
When channel metadata is set, SDK emits a 'set' action for a 'channel' event in objects listener. Refer to Objects Events for details on receiving these events.
Get channel metadata
Returns metadata for a specific channel, including the channel's custom data.
Get metadata for all channels
Returns a paginated list with metadata for all channels, optionally including each channel's custom data object.
Remove channel metadata
This method removes the specified channel's metadata.
When channel metadata is removed, SDK emits a 'remove' action for a 'channel' event in objects listener. Refer to Objects Events for details on receiving these events.