Consolidate chats from multiple live platforms into a single experience
Tags: chat
Published: 2023-10-27 06:36:38

---
title: Consolidate chats from multiple live platforms into a single experience
published: true
date: 2023-10-25 00:21:00 UTC
tags: Chat
canonical_url: https://reactjsexample.com/consolidate-chats-from-multiple-live-platforms-into-a-single-experience/
---

# Chat Fusion
 ![Consolidate chats from multiple live platforms into a single experience](https://reactjsexample.com/content/images/2023/10/Code_2023-10_22-15-48.jpg)

![Consolidate chats from multiple live platforms into a single experience](https://github.com/Programmer-Network/Chat-Fusion/raw/master/assets/images/chat-fusion.png)

Chat Fusion is a self-hosted solution designed to consolidate chat feeds from multiple platforms into a singular, unified interface. Built with a focus on customization and data privacy, the service does not rely on external services and can be easily tailored to your needs.

<section data-identity="db91c150-6bcc-4243-a644-a9328eed13f3" data-host="https://viewscreen.githubusercontent.com" data-src="https://viewscreen.githubusercontent.com/markdown/mermaid?docs_host=https%3A%2F%2Fdocs.github.com" data-type="mermaid" aria-label="mermaid rendered output container">
<div data-json='{"data":"sequenceDiagram\n participant CE as Chrome Extension\n participant LA as Localhost API (Port 3000)\n participant Client\n\n loop MutationObserver\n CE-&amp;gt;&amp;gt;+Twitch: Observe\n CE-&amp;gt;&amp;gt;+Kick: Observe\n CE-&amp;gt;&amp;gt;+YouTube: Observe\n end\n\n CE-&amp;gt;&amp;gt;LA: POST observed chat data\n\n loop Interval Polling\n Client-&amp;gt;&amp;gt;LA: GET observed chat data\n LA-&amp;gt;&amp;gt;Client: Return aggregated chat data\n end\n"}' data-plain="sequenceDiagram
  participant CE as Chrome Extension
  participant LA as Localhost API (Port 3000)
  participant Client

  loop MutationObserver
    CE-&gt;&gt;+Twitch: Observe
    CE-&gt;&gt;+Kick: Observe
    CE-&gt;&gt;+YouTube: Observe
  end

  CE-&gt;&gt;LA: POST observed chat data

  loop Interval Polling
    Client-&gt;&gt;LA: GET observed chat data
    LA-&gt;&gt;Client: Return aggregated chat data
  end
">
<p></p>
<div>
<pre aria-label="Raw mermaid code">sequenceDiagram
  participant CE as Chrome Extension
  participant LA as Localhost API (Port 3000)
  participant Client

  loop MutationObserver
    CE-&gt;&gt;+Twitch: Observe
    CE-&gt;&gt;+Kick: Observe
    CE-&gt;&gt;+YouTube: Observe
  end

  CE-&gt;&gt;LA: POST observed chat data

  loop Interval Polling
    Client-&gt;&gt;LA: GET observed chat data
    LA-&gt;&gt;Client: Return aggregated chat data
  end
</pre>
<p></p>
</div>
<p></p>
</div>
<p> <span style="min-height:100px" role="presentation"></span></p>
<p>  
</p></section>
## How It Works

Under the hood, Chat Fusion employs a Chrome content script to inject code into the web pages of various chat platforms like Twitch, YouTube, and Kick. The script utilizes the `MutationObserver` API to actively monitor changes to the chat DOM elements.

Once a new chat message arrives, the script collects pertinent information—be it from Twitch, YouTube, or any other supported platform—and normalizes it into a standardized data structure.

```
export interface IMessage {
  id: string;
  platform: string; // The platform where the message originates, e.g., 'Twitch'
  content: string; // The textual content of the chat message
  emojis: string[]; // Any emojis included in the message
  author: string; // The username of the person who sent the message
  badge: string; // A URL pointing to the badge or avatar of the author
}
```

## Why This Matters

The primary advantage is consistency. Regardless of the originating platform, each message is transformed into a common, predictable format. This ensures a seamless contract between the client and the API, facilitating easier integration and providing a streamlined user experience.

## Features

- **Full Customizability** : Change the appearance, behavior, or add new platforms as per your requirements.
- **Data Privacy** : Your data never leaves your server, ensuring complete privacy and security.
- **Universal API Contract** : The uniform `IMessage` structure simplifies client-side development, making it easier to extend features or integrate with other services.

By offering a consistent, user-friendly interface, Chat Fusion makes managing and participating in chats across multiple platforms simpler and more efficient than ever before.

## Setup

```
pnpm i
pnpm build # to build the chrome extension
```

You have to run the client (React) code and the API (fastify) separetly.

```
# In one terminal session
pnpm server-dev # to run an api in development mode with live reload using Nodemon

# In another
cd chat
pnpm dev # to run the chat react app
```

**Chrome Extension**

- In your Chrome Browser, head to `chrome://extensions`
- Enable `Developer mode` in the top right corner
- In the top left corner, click on `Load unpacked` and load this very repository into there. Essentially, `manifest.json`, `src` and `dist` are the extension part of this repository.

To ensure that the Chat Fusion Chrome Extension functions correctly, you’ll need to open each platform chat in either a new tab or a separate window. This is essential because most streaming platforms, like YouTube, embed their chat interfaces within iframes. Due to browser security constraints, Chrome Content Scripts can only access the DOM of the parent page and not any embedded iframes.

Steps to Setup:

- Install the Chat Fusion Chrome Extension.
- Run the API and client.
- Open the chat interface of each streaming platform you’re broadcasting to in a new tab or window.

By doing this, the content script from the Chrome Extension will have the necessary access to query and traverse the DOM of these chats. This enables it to locate the specific elements required for scraping chat data.

## GitHub

[View Github](https://github.com/Programmer-Network/Chat-Fusion?ref=reactjsexample.com)