A simple chat for socket.io
$ npm install
$ node index.js
And point your browser to http://localhost:3000
. Optionally, specify
a port by supplying the PORT
env variable.
Messages sent to server:
Register a user in the chat.
{
username: String,
avatar: String?
})
When the user start typing. No need to send when the user stops.
###message new
When a new message has to ben sent to the chat
message String
Messages sent to client:
When new users has joined/left the room
{
type: String<join|left>
user: User,
users: Array<User>
}
When you client got registered (after sending user register
)
When a user start/stop typing
typing Boolean
When a new message is sent in the room
{
message: {
user: User,
text: String,
created: Date
},
messages: Array<Message>
}
When a command has been issued
{
command: String,
value: String
}
When an error has been thrown (see error codes)
{
code: Number,
message: String
}
100
: You are already connected with a username101
: Username is already taken102
: Username is invalid200
: The message is invalid201
: You are spamming too much, calm down!