Giter Club home page Giter Club logo

little_chaty's Introduction

Chat app

Simple back end app for chat. Provides API to login/logout and chating.

API overview

API available on http://chaty.st.lviv.ua/api. For chat functionality with websockets, use http://chaty.st.lviv.ua address.

General flow of using API:

  1. (Optional) Checking, if choosen name is available. [API]
  2. Loging user (with name, sex, etc.) [API]
  3. Open WebSocket for chat [WS]
  4. Send initial message (enterChat) [WS]
  5. Send and receive chat messages and user statuses [WS]
  6. Close socket and/or logout user. [API/WS]

*API - use via XMLHttpRequest, WS - WebSocket

API objects

All objects should be send and will be received in JSON.

userObject

{
    name: "someName"
    sex: ["male"/"female"]
    image: STILL IN PROGRESS! (sorry for that :))
}

secureUserObject

{
    id: "23fasdbas323rfsadf32fawe32f2" (hash)
    name: "someName"
    sex: ["male"/"female"]
    image: STILL IN PROGRESS! (sorry for that :))
}

userIDObject

{
    id: "23fasdbas323rfsadf32fawe32f2" (hash)
}

messageObject

{
    user: "someUserName",
    message: "Some message text",
    [isYourMessage: true] - if you posted this message
}

successObject

{
    success: true/false
}

errorObject

{
    message: "Some error message. Also HTTP status code will be available."
}

##API methods

[GET] /users/isLoggedIn/:userName

Check, if user is online.
Output: successObject.

[GET] /users/[:userName]

Get particular user object, if userName provided or array of users, which is online.
Output: userObject/[userObject].

[POST] /users/login

Login user.
Input: userObject.
Output: secureUserObject.

[POST] /users/logout

Logout user.
Input: userIDObject or secureUserObject.
Output: successObject.

Chat

Chat functionality implemented with socket.io. So, it's recommended to use it on client side, unless you are using native WebSocket API or another lib. In this case, you have to mimic socket.io protocol.

[client event] enterChat

Join your socket to chat room.
Input: userObject.
Also, it triggers server event chatEntered event for you, and userOnline for all users online. Example:

var socket = io.connect(chatUrl);

socket.on("connect", function(){
    socket.emit("enterChat", user);
    socket.on("chatEntered", function(){
        // some code to notify user, that chat is available: blink button, popup, alert :)
    });
});

[client event] postMessage

Post your message in the chat.
Input: messageObject

[server event] chatEntered

Triggers after you entered the chat. Only YOU will be notified.
Output nothing :)

[server event] message

Notify ALL about new message in the chat.
Output: messageObject.

[server event] userOnline

Notify ALL about new user in chat.
Output: userObject.

[server event] userOffline

Notify ALL about some user has left the chat.
Output: userObject.

[server event] error

If something is wrong, server will emit error event.
Output: errorObject.

Just to be make sure, that difference between client event and server one is crystal clear:
Send data to the server by emiting (.emit()) client events (enterChat, postMessage, ...).
Receive data from the server by listening (.on()) server events (userOnline, message...)

Good luck!

If something went wrong (server is down, bugs (I'm sure, they are there), or this doc sucks) email me!

little_chaty's People

Contributors

stopster avatar

Watchers

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