This is an example of websocket connection with server using shared worker.
Check out client/*.ts to grasp structure of websocket connection.
Apps like github provide users with real-time reponses, I can see changes without refreshing the page when something in server is changed.
To implement this, polling or websocket are used.
Github uses websocket, but I can't see any websocket connections.
Where are the websocket connections?
The websocket connections are maded in shared worker. You can see it at chrome://inspect/#workers
When using a shared worker, all tabs and windows shared the context of worker. It means that even if many tabs are opened, the connection through the worker is made only once. It can reduce the load on the server.
When many tabs are opened, The changes should be reflected into all tabs. Using BroadCastChannel makes this easier. BroadCastChannel sends a message to all tabs at the same time.
You get some advantages when making websocket connections with server using shared worker, Also the BroadCastChannel is good choice to reflect the change into all tabs.
The context of shared worker persists until all tabs are closed. Even if an additional tab is opened, it uses websocket connections that was maded before.