Chat API-Server, default Port: 3000
export interface command {
action: string; //always needed
user: user; //used for creating/joining a room and updating the websocket session
roomName?: string; //used for joining/creating a room as well as getting rooms/messages/users
message?: message; //used for posting messages
}
export interface message {
user: user;
roomName: string;
text: string;
timestamp: Date;
meta?: any;
}
export interface room {
roomName: string,
created: Date,
owners: user[], //creator and admins of room
users: user[], //useres subscribed to the room
messages?: message[],
password?: string
}
export interface user {
userName: string
}
- [GET] /api/chats
- returns a list of all chat-rooms (names) WORKS
- [GET] /api/chats/:room
- returns a list of messages for :room WORKS
- [POST] /api/chats/:room
- posts a message in :room and returns all messages of that room COMING
- [GET] /api/chats/:room/users
- returns a list of users who have posted in :room WORKS
- [POST] /api/chats/users/:user DEFINITELY NOT COMING
- post a private message to :user and return all messages with that :user, sorted by time
WORKING
Connect to Websocket Endpoint ws://bigbluewhale:3000/
Websocket are in JSON format. Declare a property named 'action' to invoke functionalities:
- Posting Message in Room:
{
action: "postMessage",
message: {
user: user,
roomName: "Lobby",
text: "Hello world!",
timestamp: "2018-01-01T00:00:00.000Z",
meta: {}
}
}
returns the message posted and broadcasts the message to users via websocket in this format:
{
action: "postMessage",
message: {
"user": {
"userName": "TestUser"
},
roomName: "Lobby",
text: "Hello world!",
timestamp: "2018-01-01T00:00:00.000Z",
meta: {}
}
}
or an error of the format
{ error: reason }
- List all chat rooms:
{
action: "getChatRooms",
}
- returns an object of this format:
{
action: "getChatRooms"
chatRooms: room[]
}
- List all Users in Room:
{
action: "getUsersInRoom",
roomName: "roomName"
}
- in this format
{
action: "getUsersInRoom",
roomName: "roomName",
users: user[]
}
- List all Messages in Room:
{
action: "getMessagesInRoom",
roomName: "roomName"
}
- in this format
{
action: "getMessagesInRoom",
roomName: "roomName"
messages: message[]
}
- Join a room
{
action: "joinChatRoom",
roomName: "Lobby",
user: user
}
- Create a new room
{
action: "createChatRoom",
roomName: "My own Lobby - with black jack and hookers!",
user: user
}
COMING