# Protocols

The Persona Chat SDK supports multiple communication protocols to provide flexibility and performance. These protocols can work together, sharing the same session and data, to ensure the best possible experience.

## Protocols Overview

### REST

- **Description**: A simple and reliable protocol for sending and receiving data.
- **Use Case**: Ideal for applications where real-time communication is not critical.

### WebSocket

- **Description**: A full-duplex communication protocol that enables real-time interaction between the client and server.
- **Use Case**: Suitable for scenarios requiring low-latency communication, such as live chat applications.

### WebRTC

- **Description**: A peer-to-peer communication protocol designed primarily for ultra-fast audio sessions, while also supporting high-speed messaging with minimal latency.
- **Use Case**: Perfect for real-time, interactive applications where rapid audio communication and responsiveness are critical.
- **Why WebRTC?**: By creating direct peer-to-peer connections, WebRTC eliminates unnecessary server delays, ensuring the fastest possible audio sessions and seamless message exchanges.

**Pro Tip**: For optimal audio performance, make sure WebRTC is enabled in the `protocols` configuration of your application.

---

## How Protocols Work Together

The Persona Chat SDK runtime is designed to use multiple protocols simultaneously, ensuring flexibility and reliability. Here’s how it works:

1. **Shared Session**: All protocols share the same session and operate on the same data, ensuring consistency across communication channels.
2. **Protocol Selection**: The runtime automatically selects the fastest and most reliable protocol from the list of enabled protocols. For example:
   - If WebRTC is available and started, it will be prioritized for its ultra-low latency.
   - If WebRTC is not available, WebSocket will be used for real-time communication.
   - REST will act as a fallback for non-real-time communication.
3. **WebRTC Startup**: WebRTC requires manual startup by the user (e.g., clicking a microphone icon to enable audio/video). Once started, WebRTC participates in the list of reliable protocols and is used for the fastest communication.
4. **Seamless Integration**: Even if WebRTC is not started, other protocols like WebSocket and REST will continue to function, ensuring uninterrupted communication.

This design allows the Persona Chat SDK to adapt dynamically to the available protocols, providing the best possible performance and reliability.
