Coder Social home page Coder Social logo

chat-with-me's Introduction

Chat with me

This project was meant to be a school project, developped in React and Node.JS, with which you can simulate a chat application on your machine.
In this project, they are no databases, but a .txt file is created and modified, in order to store the conversation.


Configuration needed

The only thing that you need is a .env file inside client folder. Paste the following inside :

// Change {PORT} with the port where your server will be running

REACT_APP_PROXY=http://localhost:{PORT}

Available Scripts

In the project directory, you can run:

npm start

Runs the app in development mode.

in client/:
Open http://localhost:3000 to view the client side in your browser.

in server/:
Open http://localhost:{PORT} to launch the server side in your console.


Dependencies

npm

server/

  • socket.io for managing realtime update server-side
  • socket.io-client for managing realtime update client-side in a React file
  • express for creating api routes
  • fs for managing local file (not usefull if the messages are delocated (DB, localStorage in navigator, etc..) )
  • cors for enabling CORS with various options

client/

  • react-router-dom for managing client-side routes

cdn

  • UIkit for styling components

API Routes

GET

/api/getConversation

Response : {
    conversation: String,
}

/api/sendMessage

Params (passed as instance of URLSearchParams): 
-   sender : String
-   message : String
Response : {
    sent: Boolean,
}

/api/getAllUserLogged

Response : {
    users: [
        {
            pseudo: String,
            socketID: String,
        },
    ]
}

Socket Events (Listener, Utility, Emission)

newUser, (data = {user.pseudo, user.socketID})
Add the new user to an array of users logged
emit('users', usersConnected)

isWriting, (data = {user.pseudo, user.socketID})
Append the user data to an array of users that are currently writing, only if the user is not already in the array.
broadcast.emit('userWriting',usersWriting)

isNotWriting, (data = {user.pseudo, user.socketID})
Remove the user from the usersWriting array.
broadcast.emit('userWriting',usersWriting)

message, (data = {user.pseudo, user.socketID})
Send the information to all client that a new message has been sent.
emit('messageResponse',data)

disconnnect, ()
Remove the user from the usersConnected and usersWriting arrays. Then, disconnect the client from the socket.
emit('users', usersConnected)

chat-with-me's People

Contributors

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