THP-2-0 / THP2_back

24 stars 6 forks source link

Add a websocket forwarding updates of steps #77

Open zaratan opened 5 years ago

zaratan commented 5 years ago

Why ?

During a lesson we don't want that neither the student nor the teacher had to refresh the page.

There is two way to do that:

What is a websocket: It's… A bi-directonal tube between 2 machine. Both of them can push data in it so the other side will get it.

Must have

This will be fun™.

To be able to properly instanciate websocket connection we have to do it securely. BUT the websocket protocol doesn't allow headers (you see where we are going ?) so we have to secure the connection negociation ourselves.

Then we have to provide the websocket connection.

Then we have to write data in it :D.

We will heavily rely on ActionCable for handling most of the websocket complexity We will use action-cable-testing for testing purposes. This gem will be part of rails 6.

Websocket connection negociation

We need a way to be sure that our user is authorized and we can't really use headers nor cookies. We will rely on temporary tokens to do so.

Now that we can negotiate for a short-lived auth token we can use it to securely create a bi-directional connection \o/

Websocket connection

Now we can open the tube and start thinking about throwing data in it \o/

Data broadcasting

You now have a full flow of websocketing \o/ Adding new channels and infos in your app is easy because you already have the connection flow. Congrats. You have done a hard ticket and you are ready to face the challenges outside of this formation :)

Reading list