Experimental bidirectional emulation layer, session for uni transports #515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Experimental bidirectional layer
Here we inherit experimental Centrifuge features - just to make Centrifugo capable to work with the latest client protocol.
This includes our own emulation layer and 2 new transports which work over it
The main idea behind emulation layer: make
centrifuge-js
capable to work with corporate proxies which block WebSocket traffic, fallback automatically with possibility to not use SockJS (and all its overhead) and sticky sessions in setup involving multiple Centrifugo nodes.At this point this all experimental here and only works with client
centrifuge-js
fromv3_dev
branch. These features won't be documented for now, but I'll try to encourage users to check them out to get more feedback.Basically, two main options added here are boolean
sse
which enables SSE/EventSource (transport available on/connection/sse
by default) and booleanhttp_stream
which enables HTTP-streaming (transport available on/connection/http_stream
by default). As soon as enabled we also start emulation handler endpoint (/emulation
by default).After enabling it's possible to use these transports when configuring
centrifuge-js
(again - only from centrifuge-jsv3_dev
branch at this point):Note, that
centrifuge-js
only works using client protocol v2, that's why we force it in the example above usingcf_protocol_version=v2
when connecting to Centrifugo. HTTP-streaming and SSE endpoint only support client protocol v2 – so we can avoid usingcf_protocol_version
in endpoints.This issue is a part of ongoing Centrifugo v4 work and corresponds to latest state described in comment.
Session for unidirectional transports
Also, we support session string field for unidirectional transports here (unique string attached to connection on start, in addition to client ID). It allows to control unidirectional connections using server API. Previously we used client ID for this – but turns out it's not really working approach since client ID can be exposed to other users in Publications, presence, join/leave – so backend can not distinguish whether user passed its own client ID or not. With session which is not shared at all things work in a more secure manner.