Open BrainBuzzer opened 4 years ago
I think there should be a universal WebSocket that receives all the different payloads that frontend needs to process. The widget WebSocket will still be separated from this one.
I'm not very sure on how to implement the part where the user's connection on /connect_github
and the websocket connection on frontend
are to be matched.
For now I'm thinking that the consumer object would have to be stored in memory and index-able with the user id. Will have to check if Django allows globals to be shared between different connections.
Do you have an idea on this?
I'm not sure about the internals of Django, but here's what I was thinking. There will be a websocket at ws://domain/user/<user_id>
just like there is one with the widget.
The front-end will establish a connection with this websocket as user logs in. Now, when I hit the /connect_github
, if the action is completed successfully, the payload will be submitted from django to that websocket.
This is more for a smoother front-end experience. So there will be a few more different payloads that will need to be submitted to that websocket as we go further.
Yeah I've understood that. But the backend cannot open a websocket connection to the frontend itself. So it will have to keep track of all the open websocket connections to use the appropriate one later on.
Moreover as the user's http connection to /connect_github will be totally separate from the websocket (I'm imagining the user with hyperlog.io on one tab, clicks on connect_github
there and opens the backend/connect_github in another tab. Then the websocket will send some info and the frontend will be updated when user returns to previous tab) so we'll have to send information from one http connection to another ws connection. So I was thinking that after the process of one github connection, the backend would need a handle on the right websocket connection.
I just remembered that there was one CHANNELS_LAYER
functionality in django-channels which can act kindof like PUB-SUB over some Redis-like backend. So the http connection would publish updates and the websockets can listen on it. Maybe that would be the standard way to go.
There shall be a payload sent to the WebSocket for the user which tells if the provider has been connected. This will be executed right after the GitHub connection is successful.