Giter VIP home page Giter VIP logo

roulette's Introduction

Message Roulette

Running application example can be found on https://mroulette.herokuapp.com

Project Setup on local machine

git clone https://github.com/varvar/roulette.git
cd to folder roulette
npm install
npm update

Run

npm start

Once server started it will be accessible on http://localhost:8080/

HTTP API Reference

Register User

Login User

  • URL

    https://mroulette.herokuapp.com/api/users/login

  • Method:

    POST

  • Data Params

      {
        "email":"[email protected]",
        "password":"123456"
      }
    
    

    Please note, that all properties are required and not optional

  • Success Response:

    • Code: 200
      Content:
      {
        "code": 200,
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwibmFtZSI6InRlc3QyIiwiZW1haWwiOiJ0ZXN0MkBtYWlsLmNvbSIsInBhc3N3b3JkIjoiJDJiJDEwJGVLQVBBYXpWMm0wcDZyaHRFUVBvN082SnpES3F0cjd2UmhWZGFSaEE0Ry5KLnVIUGJVSW9LIiwiaXAiOm51bGwsImxhc3RMb2dpbiI6bnVsbCwibG9naW5Db3VudCI6bnVsbCwiY3JlYXRlZEF0IjoiMjAyMC0wNS0xMVQxMTo1OToxOS4wMDBaIiwidXBkYXRlZEF0IjoiMjAyMC0wNS0xMVQxMTo1OToxOS4wMDBaIiwiaWF0IjoxNTg5MTk4NDA2LCJleHAiOjE1ODkxOTg3MDZ9.tu27GFxtZJk-MjVgj5hMkPV7qnNoCoHmyJauV-Mmizk"
      

    }

    
    
  • Notes:

    Token returned in login response is JWT token and should be used for authentication in socket.io API

SOCKET.IO API Reference

  • User connection to socket API requires JWT token and socket server URL should look like this:

https://mroulette.herokuapp.com/?token={JWT token}

  • Server emits everything to "messages" channel, so all connected users should listen to this channel.

Blast

Emit message to all users except sender

  • Server Event Name

blast

  • Data supported

Any type of messages as plain text

Spin

Emit message to a random user except sender

  • Server Event Name

spin

  • Data supported

Any type of messages as plain text

Wild

Emit a message to X random users except sender. X can be determined by the user. The default value in case it's not provided by user is 5.

  • Server Event Name

wild

  • Data supported

JSON as following:

{
  "usersNumber":3,// number
  "messsage": "Hello world" // any string
}

DB schema

The only table is used in application is "users":

CREATE TABLE `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(255) DEFAULT NULL,
 `email` varchar(255) NOT NULL,
 `password` varchar(255) DEFAULT NULL,
 `ip` varchar(255) DEFAULT NULL,
 `last_login` datetime DEFAULT NULL,
 `login_count` int(11) DEFAULT NULL,
 `createdAt` datetime NOT NULL,
 `updatedAt` datetime NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

"last_login","ip" and "login_count" are optional fields and used to provide additional info for user connected to socket. Those fields can be used for statistic information and for adding restrictions for IP addresses and login attempts.

roulette's People

Contributors

varvar avatar

Watchers

 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.