Skip to content

jvmiert/visage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goal

Rooms are where groups of people communicate with each other, share memories, and organize happenings. Rooms persist permanently. When creating a room the user needs to pick a URL and invite friends. Communication happens in rooms through text messages or audio/video.

User

I want to be able to create, store, and retrieve user information. I've decided to use MongoDB because I've never used a NoSQL database other than Redis. Next steps are:

  1. Setup application logic to connect to mongodb
    • Add a mongo client to SFU struct
  2. Create user struct
    • Make sure we separate it from how we store user info in Redis
  3. Create endpoint to save a new user
    • Save user to MongoDB
    • Check if user exists already
    • Generate a user id
    • Generate password hash
    • Generate a user session

URLs

Relay

Allow clients to discover which SFU they are geographically closest to. Then connect to this specific SFU. A system needs to be in place that detects if a session contains peers from different geographical regions, and thus different SFUs. When the system detects this it needs to initiate relay and signal to the other SFU. A server to server signalling system needs to be build to exchange offers and answers between SFUs.

  1. Allow clients to connect to the correct SFU based on geographical region
    • Figure out a way to store available backends
      • On backend startup, the server should register in Redis
      • When the server shuts down it should deregister in Redis
      • Use redis key with expiry to automatically have a health check
    • Read backends during signal establishment
    • Select most suitable backend
  2. Keep track of session's geographical situation
    • Store NodeInfo in the redis room property
      • Make sure we use redsync mutex
    • We should store Peer information
      • We can replace the current User information or add the peer into the struct
    • Room global lock wasn't implemented yet
    • Rewrite room.go functions to lock on room creation/retrieval and user leave/join
  3. Monitor above system and act if relay is needed
  4. Create a server-to-server signalling system to establish relay connection
    • Implement redis sub
    • Create new relay peer
    • Send the result of relay offer over Redis pub/sub
    • Process above offer and pass it to answer
    • Return the output of answer back to offer
    • Somehow listen for above reply in the relay offer function
  5. ???
  6. Profit

Session issues

I'm having trouble keeping track of room occupants across multiple nodes. The main issue is that there are multiple ways by which a user can leave a room. Namely:

  1. A user can send a leave command over websocket
  2. The WebRTC connection can close
  3. The WebSocket connection can time out

The problems surfaces when a user refreshes the page. The user sends a leave command and the WebSocket connection closes. At the same time the user rejoins. Now we have a race condition where sometimes the user will join before the WebSocket connection is closed. The server then marks the user as left.

Maybe we can use a unique sessions ID that is linked to the WebSocket connection. Then when we make sure that the newly rejoined session is not closed by old sessions.

The question is how do we properly store the sessions that contain region and node information across multiple nodes. Joining is a 2-part process. First a token is requested during which the user information is stored in the room. Second, the user actually joins the room through the websocket channel with the token gained in the first step. The first and second step are performed in different nodes. To properly store node information the join process:

Joining

  1. A session ID is retrieved from the backend
  2. WebSocket connection is made with the session ID
  3. The node receiving the above WebSocket connection saves the node and user information in Redis
    1. And keeps a local copy of said state?
  4. A user issues a join request to the backend API with the session ID
  5. The backend retrieved the session information from step 3 and writes it to Redis room info
  6. The backend returns the token to the frontend
  7. A WebSocket join is issued with the token

Leaving

  • When a SFU node is shut down, clear local sessions and update Redis
    • Update affected rooms too
  • When a WebSocket connection is disconnected, update sessions and rooms
  • When a leave command is issued, update room

To test

I need to validate the idea that you can get higher quality video conversation by relaying peers through servers instead of a single server.

Figure out if there is meaningful difference between:

  • Ams -> Singapore
  • Ams -> Viettel
  • Ams -> Home

Test is with SFU and use metrics endpoint to gather metrics.

Scenario 1: Peer in EU <- WebRTC -> Singapore <- Relay -> HCM <- WebRTC -> peer in VN

Scenario 2: Peer in EU <- WebRTC -> HCM <- WebRTC -> peer in VN

Scenario 3: Peer in EU <- WebRTC -> Singapore <- WebRTC -> peer in VN

Metrics:

  • Average video mbit for 1 hour
  • Average latency for 1 hour
  • Average jitter for 1 hour

Serf

Serf is a way to create a network of nodes that updates which nodes are offline and where they are. It also enables nodes to communicate with each other.

Tokens

There are a number of different tokens used within the platform. An illustration of the token process below: User authenticates -> user token -> session token -> room token -> join room

  • After authentication a user receives a user token.
  • user token is used to obtain a session token
  • A session token is used to create a room token
  • room token allows the user to connect to the SFU

Random URLs

Random thoughts

External docs

Go URLs

React Native

Server

Dev tools

Phones to possible buy for dev/test

Inspiration

Golang inspiration projects

Mobile platform marketshare

  • iOS: 12.X+ = 80%
  • Android: 8.0+ = 70%

To-do

Important

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published