-
Notifications
You must be signed in to change notification settings - Fork 6
Socket IO Architecture
We are using Socket.IO, a JavaScript library that enables real-time, bidirectional and event-based communication, to implement a chat service for Tufts Ears 4 Peers.
TODO: add description
We will have two types of clients connecting to the server: Users and Admins. Users use the E4P service to chat with an Ear. Admins are the Ears on duty, who respond to User requests to chat.
- Initial user connect
- User's unique socket ID is routed to every admin connected to the server
- User is added to a waiting list (front-end team)
- Admin pick up
- Admin picks up a user who has connected to the server
- All other admins notified via socket broadcasting that the user has been connected to an admin
- User is taken off the waiting list
- Chat
- Messages are sent between the admin and user in a private room until the user chooses to disconnect
- User disconnect
- TODO need to architect admin disconnect event
- Admin is notified user disconnected
- If no admin had been matched, remove user from admin waiting lists
TODO: fix numbers in diagram, add a description
- 'user connect'
- 'user waiting', user room id, icon
- 'accept user', user room id
- 'user matched', user room id
- 'admin matched'
- 'user chat', message, user room id
- 'admin chat', message
- 'user unmatch', conversation object
When an admin connects to the server, they are placed in the admin room. This allows broadcasting among admins only, not other users (e.g. can notify only admins that a new user has connected). When an admin picks up a user to being chatting (Phase 2), the admin will join the user's room so that the conversation will be private. The user will be notified that the admin has joined the chat. Note: admins can be in multiple rooms (i.e. chatting with multiple users) at once.
send_message(id, m)
receive_message(from, m, time)
new_chat(id)
Conversations are stored on the server in an array with the following object structure:
conversationObject : {
user: string,
icon: string,
room: string,
accepted: boolean,
connected: boolean,
connected_admin: string
}