Coder Social home page Coder Social logo

hcservercore's Introduction

hack.chat server core

The hack.chat chat service runs on a hackable (extendable & flexible) websocket server library. This is the core server. Note: This is not the chat server. This is a minimal boilerplate intended to jump start your own websocket based project. It provides the following features out of the box:

  • Hot Reload - Update your server's code without disconnecting currently connected clients
  • Integrated Config Script - An included "setup wizard" using Prompt style questions allow you to quickly deploy or distribute your application
  • Modules - Server code is module-based, making development & debugging easier
  • Client Search Functions - The server.broadcast method makes gathering target clients easy
  • Config Managment - Arbitrary config data can be saved at any time and will be automatically reloaded on server start
  • Simple Stats - Included stats engine tracks whatever you ask of it
  • Rate Limiter - Built in ratelimiting prevents clients from preforming automated server floods
  • Stable and Graceful - Field tested at 2k+ unique connected clients (each sending large amounts of data) with minimal lag. Module errors are reported but won't (typically) prevent the server from running
  • Module Hooks - Pre and post processing hooks are available, allowing one module to change data before it reaches a different module, or to change outgoing data before it reaches the client

Limitations: Server only accepts JSON encoded communication. Each message must contain a cmd field. There is a built-in limit of 65,536 character messages. ( All of this is easily changed by modifying the MainServer.js). WSS is currently not supported out-of-the-box, requiring a reverse proxy. This may change in the future.

Installation

Prerequisites

Install & Setup

  1. Clone the repository: https://github.com/hack-chat/hcServerCore.git
  2. Change the directory: cd hcServerCore
  3. Install the dependencies: npm install
  4. Launch: npm run config
  5. Launch: npm start

Development

Command modules are kept in src\commands. After adding or modifying a module, a connected client would send: { cmd: 'reload' } for the changes to take effect.

This readme is a work in progress, for examples on how to work with the server, see the main repository.

OOBE

If you were to follow the Install & Setup steps above, a simple way to test the server would be to open your favorite browser's development tools and paste the following:

let join = () => {
  window.ws = new WebSocket('ws://127.0.0.1:6060/');

  window.ws.onopen = () => {
    console.log('Connected.');
  }

  window.ws.onclose = () => {
    console.log('Lost Connection!');

    window.setTimeout(function () {
      join();
    }, 1);
  }

  window.ws.onmessage = (message) => {
    var args = JSON.parse(message.data);
    console.log(args);
  }
}

send = (data) => {
  if (window.ws && window.ws.readyState == window.ws.OPEN) {
    window.ws.send(JSON.stringify(data));
  }
}

join();

The only command supported out of the box is echo, which can be issued like: send({ cmd: 'echo', text: 'Hello cliche world!' })

A hook is left in place allowing you to view how many message have been sent: send({ cmd: 'echo', text: 'messages-sent' })

Credits

License

This project is licensed under the WTFPL License.

hcservercore's People

Contributors

marzavec 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.