Skip to content

Socket IO Architecture

ajohns619 edited this page Feb 19, 2019 · 8 revisions

Socket.IO Documentation

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

TODO: add description

Architecture Overview

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.

Event Phases

  1. 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)
  2. 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
  3. Chat
    • Messages are sent between the admin and user in a private room until the user chooses to disconnect
  4. 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

Message Names

TODO: fix numbers in diagram, add a description

  1. 'user connect'
  2. 'user waiting', user room id, icon
  3. 'accept user', user room id
  4. 'user matched', user room id
  5. 'admin matched'
  6. 'user chat', message, user room id
  7. 'admin chat', message
  8. 'user unmatch', conversation object

Socket Rooms

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.

Methods

  • send_message(id, m)
  • receive_message(from, m, time)
  • new_chat(id)

Conversations

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
}