Giter VIP home page Giter VIP logo

mixer-chat's Introduction

Mixer Chat

This is a new module which allows you to connect to Mixer Chat Servers.

Some of the code is based of the original chat code from beam-client-node which did it's job but being stuck with the bulky module and bugs. It was easier to create this to just handle chat connections and have better error handling/methods. We plan on expanding this to contain more features and better hooks for developers to use. But for now it's the basic module to connect to chat and stay connected with built in reconnection logic.

There are an array of options you can change with the socket connection. Of which are all typed so please explore the code or mess around in TypeScript to see what's on offer.

To Do

  • Built in channel manager. (To enable users to just request a new channel and the module will connect/manage and send up events)
  • Verbose error handling (Enable more error handling from both Mixer and CloudFlare to enable better reconnecting)
  • In build endpoint handling. (To allow the module to auto refresh the endpoints/authkey for chat connections)

Setup

  • Install the module using npm i mixer-chat --save

Usage

This is a simple usage to connect to a channel chat.

import { ChatSocket, IChatMessage, IUserUpdate } from 'mixer-chat';

/**
 * You will need the channelId of the channel you wish to connect too; and the userId of the user you want to
 * connect to chat as. You can find information about how to do this here: https://dev.mixer.com/reference/chat/index.html#chat__introduction
 **/

async function connect(channelId: number, userId: number, authKey: string) {
    // Create the chat socket.
    const endpoints: string[] = []; // List of endpoints taken from the `chats/:id` endpoint.
    const chat = new ChatSocket(endpoints).boot();

    // Authenticate to the server
    const isAuthed = await chat.auth(channelId, userId, authKey); // Returns the userRoles and if authenticated.

    // You'll now get events from the server on new messages/events etc...
    chat.on('ChatMessage', (message: IChatMessage) => {
        console.log(message);
    });
    chat.on('UserUpdate', (update: IUserUpdate) => {
        console.log(update);
    });
    // Etc...
}

// Connect to a channel chat.
connect(1, 2, 'jnoh986');

mixer-chat's People

Contributors

artdude543 avatar

Stargazers

2Cubed avatar ProbablePrime avatar James Causon avatar

Watchers

James Cloos avatar James Causon avatar  avatar Alf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.