Phoenix.Transports.LongPoller
Handles LongPoller clients for the Channel Transport layer.
Configuration
The long poller is configurable via the Endpoint’s transport configuration:
config :my_app, MyApp.Endpoint, transports: [
longpoller_window_ms: 10_000,
longpoller_pubsub_timeout_ms: 1000,
longpoller_crypto: [iterations: 1000,
length: 32,
digest: :sha256,
cache: Plug.Keys],
]
:longpoller_window_ms
- how long the client can wait for new messages in it’s poll request.:longpoller_pubsub_timeout_ms
- how long a request can wait for the pubsub layer to respond.:longpoller_crypto
- configuration for the key generated to sign the private topic used for the long poller session (seePlug.Crypto.KeyGenerator
).
Summary↑
ack(conn, priv_topic, msgs) | Ack’s a list of message refs back to the |
action(conn, options) | |
call(conn, action) | Callback implementation of |
dispatch(conn, priv_topic, msg) | Dispatches deserialized |
init(action) | Callback implementation of |
options(conn, params) | Responds to pre-flight CORS requests with Allow-Origin-* headers |
poll(conn, params) | Listens for |
publish(conn, message) | Publishes a |
resume_session(conn) | Finds the |
start_session(conn) | Starts the |
verify_longpoll_topic(conn) | Retrieves the serialized |
Functions
Ack’s a list of message refs back to the Phoenix.LongPoller.Server
.
To be called after buffered messages have been relayed to the client.
Callback implementation of Plug.call/2
.
Dispatches deserialized %Phoenix.Socket.Message{}
from client to
Phoenix.LongPoller.Server
Callback implementation of Plug.init/1
.
Responds to pre-flight CORS requests with Allow-Origin-* headers.
Listens for %Phoenix.Socket.Message{}
‘s from Phoenix.LongPoller.Server
.
As soon as messages are received, they are encoded as JSON and sent down
to the longpolling client, which immediately repolls. If a timeout occurs,
a :no_content
response is returned, and the client should immediately repoll.
Publishes a %Phoenix.Socket.Message{}
to a channel.
If the message was authorized by the Channel, a 200 OK response is returned, otherwise a 401 Unauthorized response is returned.
Finds the Phoenix.LongPoller.Server
server from the session.
Starts the Phoenix.LongPoller.Server
and stores the serialized pid in the session.
Retrieves the serialized Phoenix.LongPoller.Server
pid from the encrypted token.