PubNub Chat SDKs are built on top of the core PubNub Network, a globally distributed Data Stream Network with 15+ points of presence across the globe with response times of <100ms and 99.999% uptime guarantees.
Users are entities who connect to the platform via applications. In the case of a chat application, users are actual people, and you may also want to add chatbots. Users can optionally store properties such as a display name, profile URL, and email address. They can have additional properties that are stored as custom fields.
Users are uniquely identified by
uuid which is set by your application. The
uuid is needed to ensure that your billing is accurate and for other features like presence and storage to work as expected.
Channels are virtual chat rooms that users join to communicate with other users. Messages are always sent through PubNub on a channel. You don't have to define channels in advance; they're automatically created by the act of publishing a message to them. Channels can optionally be stored with properties like a name, description, and an image icon. They can also have additional properties that are stored as custom fields.
Channels are uniquely identified by a
channel ID which is set by your application. That
channel ID is used in all other operations such as publish, subscribe, history, and so on to send and receive messages.
You subscribe to channels to receive messages on them. Subscribing initiates a realtime connection with PubNub. This connection stays open for as long as the user stays subscribed from a client application. Any user subscribed to a channel receives messages in under 100 ms, regardless of the global region in which the message is published.
Messages are the actual packages of data that get published to a channel. They can contain any serializable data, including objects, arrays, numbers, and strings. String content can include any single- or multi-byte UTF-8 character. PubNub's maximum size for a single message is 32 KiB.
While messages can be in any format, JSON is usually the best choice. The data can be any serializable JSON object; the PubNub SDKs automatically stringify JSON objects before publishing. When you use JSON, the keys and values are up to you.
Your application should communicate directly with PubNub to allow messages to be delivered efficiently with an average latency of under 100 ms. Adding a message broker or application server between PubNub and the client can cause significant delays in message delivery, due to the added latency of communicating with the message broker.
Security, data ownership, and access control are critical to any chat application, and PubNub's Data Stream Network is built around these core tenets. PubNub has security measures at the network, message, channel, user, and key levels, spanning multiple categories:
Encryption. PubNub supports point-to-point network TLS encryption and end-to-end AES message encryption. This is critical for medical and financial chat applications. In this case, PubNub won't have access to message data.
Authorization. PubNub Access Manager provides granular read and write access control with optional expiration and the ability to revoke permissions. Access can be controlled for individual users and specific channels.
Message Validation. PubNub Functions allow messages sent by untrusted clients to be validated before they're accepted into message history or transmitted to other users. For example, profanity can be sanitized in transit, spam can be rejected, or some users can be rejected.
Legislative. PubNub is HIPAA-compliant, ensuring all legal requirements are met for transporting medical data. PubNub is also EU-US Privacy Shield-compliant, and supports geographical limitations on where messages are stored.
Attack Prevention. No inbound open ports are required. All connections to PubNub are outbound from the client. Additionally, PubNub has intelligent data center routing in place to thwart any regional attacks.
Mobile Push Notifications
PubNub's Mobile Push Gateway enables you to integrate with third-party push notification services including FCM (Google's Firebase Cloud Messaging) and APNS (Apple Push Notification Service).
Ideally, mobile clients would always be connected to the PubNub network to receive messages in real time. However, there are situations where this isn't possible (for example, when an app is closed or running in the background). The Mobile Push Gateway makes it easy to fall back to push notifications when the client isn't connected to PubNub.
To send and manage push notifications, refer to [Sending Mobile Push Notifications]](/docs/chat/reference/push-notifications).
Client State Management
Redux as bridge
The PubNub SDKs (see the list here) are designed to transmit realtime data over the PubNub Data Stream Network, and Redux is designed to manage client application state. The PubNub Redux framework bridges these two client libraries to provide the capability to manage data transmitted using PubNub inside of applications using Redux. The Redux framework allows PubNub-defined data to coexist with customer-defined data.
Functions, our serverless Function-as-a-Service platform allows you to build your own microservices and incorporate realtime logic for routing, augmenting, filtering, transforming, and aggregation of messages. PubNub Functions seamlessly handles scaling, global deployment, redundancy, and many other operations-related tasks for you.
By providing the ability to program the network, PubNub Functions simplifies deploying custom, realtime logic on a reliable, serverless architecture.