User { id, name, email, password, ask[],reply[], room[](created & joined)}
Ask { id, question, user_id (ref), timestamp, upvote, reply, roomRef }
Reply { id, repliedTo[ask | reply]ref , userRef, reply, timestamp, upvote }
Room {id,joinCode, title, desc, speakerName (UserRef), Attendees[] (Psuedonym<-userRefs), Asks[] (askRefs)}
- Client sends the Sec-Websocket-Protocol Header, containing token.
- Token is Decrypted, and we get {_id, email} of the use who is seeking a connection.
- We check in the Database that the User is valid. If not, closing Socket.
- Now we have user {_id, email} and socket
- Client sends message
{ "type":"join", "payload":{ "joinCode":123456, } } - Check for the Room in DB(verifyRoom), if not there, close the socket.
- Checking if the room with joinCode already exists in ROOMS
- If YES:
- Push the socket of this user into the ROOMS.attendee[]
- If NO:
- If the Socket belong to room.speaker === user._id
- Init Room.speaker = {socket, id};
- push into ROOMS
- Else push the user's socket into ROOMS[joinCode].attendee
- If the Socket belong to room.speaker === user._id
- Sends the JoinPing to all the sockets
{ "type":"joinPing", "payload":{ "attendees":109 } } - Send Notify User
{ "type":"joinNotify", "payload":{ "message":"You have joined the Room", "asks": [] } }
- User send the message
{ "type":"ask", "payload":{ "question":"What is DAPP?", "joinCode":"0000000", } } - ROOMS.filter(joinCode), check if that room exists, if NOT => socket.close().
- If that socket is not present in the ROOMS[joinCode].attendee, socket.close().
- Push the ask in the ROOMS
{ "ROOMS" : [ "123456": { "speaker":{ "socket":"SOCKET", "_id":"ID" }, "attendees":[ { "socket":"SOCKET", "_id":"ID" }, { "socket":"SOCKET", "_id":"ID" } ], "asks":[ { "ask":"What is DAPP", "upvote":0, "answered": false } ] } ] } - BroadCast Ask into the Attendees and speaker
{ "type":"askPing", "payload":{ "ask":"What is DAPP?", "id":"LENGTH OF ASK ARRAY - 1" "upvote":"0" } } - Push the Ask into the DB.Ask
- User send the message
{ "type":"upvote", "payload":{ "askId":"1", "joinCode":"0000000", "upvote":"1 OR -1" } } - ROOMS.filter(joinCode), check if that room exists, if NOT => socket.close().
- If that socket is not present in the ROOMS[joinCode].attendee, socket.close().
- Filter the Ask based on the askID and add the upvote in the ask object.
- Ping all the Attendees and Speaker with Ask:
{ "type":"upvotePing", "payload":{ "id":"ASKID" "upvote":"1" } }
- User send the message
{ "type":"answered", "payload":{ "askId":"1", "joinCode":"0000000" } } - ROOMS.filter(joinCode), check if that room exists, if NOT => socket.close().
- If that socket is not present in the ROOMS[joinCode].attendee, socket.close().
- Filter the Ask based on the askID and answered!=answered
- Ping all the Attendees and Speaker with Ask:
{ "type":"answeredPing", "payload":{ "id":"ASKID" } }
- Host asks to end room
{ "type":"endRoom", "payload":{ "joinCode":"0000000" } } - ROOMS.filter(joinCode), check if that room exists, if NOT => socket.close().
- If that socket is not present in the ROOMS[joinCode].attendee, socket.close().
- If the socket is not the speaker, socket.close().
- Remove the Room from the ROOMS
- Ping all the Attendees and Speaker
{ "type":"endRoomPing", "payload":{ "message":"Room has been Ended by the Speaker" } } - Notify the Speaker
{ "type":"endRoomNotify", "payload":{ "message":"Room has been Ended" } } - Close the Socket
- User send the message
{ "type":"leave", "payload":{ "joinCode":"0000000" } } - ROOMS.filter(joinCode), check if that room exists, if NOT => socket.close().
- If that socket is not present in the ROOMS[joinCode].attendee, socket.close().
- Remove the socket from the ROOMS[joinCode].attendee
- Ping all the Attendees and Speaker
{ "type":"leavePing", "payload":{ "message":"User has left the Room", "attendees":108 } } - Close the Socket