Here's a simple diagram to start with.
There's indeed a single WS flow created and materialized for every WS connection, i.e. for every browser window/tab. This happens when the UserActor
receives WatchStocks
- the created flow is then passed back to the HomeController
.
Now, a WS flow consists of two endpoints: a sink which accepts the data that comes from the browser and a source which emits the data that is sent to the browser. So, to create a WS flow you need to have those two and combine them with Flow.fromSinkAndSourceCoupled
.
In this example, those endpoints are:
- the sink is the
jsonSink
, which accepts a stock name and, in turn, creates and runs a source with some random values for this stock (the purple ones in the diagram); the source is then attached to thehubSink
(the yellow part in the diagram) - the source is the
hubSource
(the green part in the diagram), which emits all values o