https://github.com/paradoxinversion/chat-server-sockets
A chat server using socketio
https://github.com/paradoxinversion/chat-server-sockets
Last synced: about 1 year ago
JSON representation
A chat server using socketio
- Host: GitHub
- URL: https://github.com/paradoxinversion/chat-server-sockets
- Owner: paradoxinversion
- Created: 2020-01-27T04:42:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T13:59:59.000Z (over 3 years ago)
- Last Synced: 2025-01-20T05:51:12.395Z (over 1 year ago)
- Language: JavaScript
- Size: 253 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chat Server
This is a server for a simple chat room, using socketio.
## Development
Install dependencies via `npm` or `yarn`.
### Scripts
#### start:dev
Starts the server in development mode
#### start:debug
Starts the server in debug mode. For more info on inspecting node server scripts as they execute, see the [node docs](https://nodejs.org/de/docs/guides/debugging-getting-started/)
## Socket Events VS Rest API
The app uses a mix of socket events and a rest API for functionality. The general operating rule is: If the `thing` directly impacts chat, it should be an event (ie, bans, users joining/leaving, username changes). If it does not, it should be a REST call (ie, sign up, log in, change password).
## Socket Events
Below are events used by socketio, along with which interface is used. If `socket`, it should only affect the user connected to that socket. If `io`, it should affect all connected sockets.
### on-events
`connection` (io): Add a new chat client
`chat-message-sent` (socket): A chat message has been sent from the client and recieved by the server. Create a message object with the data recieved and emit `chat-message-broadcast`
`private-chat-initiated` (socket): Adds the socket and the socket matching the supplied ID to a new room for private messaging via `socket.join`.
`set-username` (socket): Changes the socket client's username
`disconnect` (socket): Remove the socket's chat client from the list. (Do I actually _need_ the list?)
### emit-events
`user-connected` (socket): Return a user object for the socket
`room-user-change` (io): Emits when a user is connected or disconnected. Sends back a list of chat users (by mapping the stored clients) and an announcement of which user entered/left.
`private-chat-initiated` (socket): Sends the name of the private chat room (pm space) to the users in that room.
`pm` (socket): Used to emit private messages between users.
`chat-message-broadcast` (io): Used to emit public/general room messages with all connected sockets.