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 are identified by unique UserId, which is set by your application. Users have properties such as a display name, profile URL, and email address. They can have additional properties that are stored as custom fields.
Each client should pass a
uuid that represents the user when it connects to PubNub. In most cases, this identifier should be same as the
uuid is needed to ensure that your billing is accurate and for other features like presence and storage to work as expected.
Spaces are virtual chat rooms that users can join to communicate with other users. Spaces are identified by a string called SpaceId, which is set by your application. Spaces can have properties like a name, description, and an image icon, or additional properties that are stored as custom fields on the space. These additional properties can be anything you like, such as a display color, star ratings, moderator names, and more.
When a space is created, a channel is automatically assigned using the
spaceId. This channel can be used to exchange messages between users within that space.
When a user joins a space, an association called a membership is stored between the user and the Space. Application users can immediately see which spaces they belong to, fetch the list of members in a specific space, and access information about other spaces and users.
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 UTF-8 character, single-byte and multi-byte. 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 only 100ms. 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—which is why PubNub built its Data Stream Network 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. The 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 are 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.
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 SDK bridges these two client libraries to provide the capability to manage data transmitted using PubNub inside of applications using Redux. The Redux SDK 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.