> For the complete documentation index, see [llms.txt](https://moataz-salahs-organization.gitbook.io/chatter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moataz-salahs-organization.gitbook.io/chatter/chatter-features/advanced-topics.md).

# Advanced Topics

<mark style="color:blue;">**1. Laravel Echo & Pusher Deep Dive**</mark>

In Chatter, real-time functionality is powered by Laravel Echo and Pusher. Laravel Echo acts as a bridge between your application and Pusher, handling the complexity of subscribing to channels and listening for events. Here’s a deeper dive into how we’ve integrated these technologies:

**Understanding Laravel Echo with Pusher:** Laravel Echo simplifies the process of subscribing to and listening for real-time events broadcasted by Laravel. With Echo, we can effortlessly handle real-time updates such as new messages and notifications sent and when a message is read, ensuring that our users experience instant feedback and interaction.

**Creating and Managing Channels:** Channels are central to how events are broadcasted in Chatter. We use three types of channels:

* **Public Channels:** Accessible to everyone. ( from updates for the future )
* **Private Channels:** Require user authentication.
* **Presence Channels:** Allow us to see which users are online within a channel.  ( from updates for the future )

Channels are defined and managed in `routes/channels.php`, where we set up the rules for each channel and ensure secure and efficient broadcasting.

**Customizing Broadcasting Configuration:** Our broadcasting configuration, found in `config/broadcasting.php`, is tailored to work seamlessly with Pusher. Here, we’ve configured key settings like app key, secret, and channel behavior. Adjustments to these settings allow us to meet our specific needs and optimize performance.

<mark style="color:blue;">**Customizing Livewire Polling**</mark>

Livewire’s polling feature keeps our application responsive by periodically checking for updates but is not preferred for good performance so, We’ve not used polling and utilized Pusher & laravel-echo to balance performance and real-time responsiveness and to guarantee very good performance.

<mark style="color:blue;">**Handling Edge Cases**</mark>

We’ve anticipated and addressed various edge cases to ensure a robust user experience:

**Message & conversation  Duplication:** To prevent duplicate messages or conversations, we implement checks using unique IDs. This approach ensures that once a message or a conversation is processed, it won’t be duplicated in the user interface.

**Pusher Actions and Events**: Pusher provides a robust set of tools for managing real-time events and actions. Here's how we handle them:

* **Connection Issues**: Pusher offers detailed information about connection statuses through its client library. We monitor these statuses to handle any issues effectively through <mark style="color:blue;">Pusher</mark> dashboard.
* **Connection State Changes**: We listen for connection state changes (e.g., `connected`,    `disconnected`, `failed`) and handle them appropriately. When a connection is lost, we implement a retry mechanism to re-establish connectivity.

<figure><img src="/files/dOR4SONBn1v18gkihA6R" alt=""><figcaption></figcaption></figure>

#### <mark style="color:blue;">Message Loading with Chunks</mark>

Our chat application implements a chunk-based approach to loading messages. This technique improves performance by fetching messages incrementally rather than loading all messages at once.

How It Works?

**Loading Messages**: As users scroll up in a conversation, more messages are loaded from the database in chunks. This approach prevents long loading times and excessive memory usage.

**Scroll Behavior**: When a user scrolls to the top of the chat window, additional messages are fetched until the earliest message between the two users is reached.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://moataz-salahs-organization.gitbook.io/chatter/chatter-features/advanced-topics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
