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],
]
Source

Summary

ack(conn, priv_topic, msgs)

Ack’s a list of message refs back to the Phoenix.LongPoller.Server

action(conn, options)
call(conn, action)

Callback implementation of Plug.call/2

dispatch(conn, priv_topic, msg)

Dispatches deserialized %Phoenix.Socket.Message{} from client to Phoenix.LongPoller.Server

init(action)

Callback implementation of Plug.init/1

options(conn, params)

Responds to pre-flight CORS requests with Allow-Origin-* headers

poll(conn, params)

Listens for %Phoenix.Socket.Message{}‘s from Phoenix.LongPoller.Server

publish(conn, message)

Publishes a %Phoenix.Socket.Message{} to a channel

resume_session(conn)

Finds the Phoenix.LongPoller.Server server from the session

start_session(conn)

Starts the Phoenix.LongPoller.Server and stores the serialized pid in the session

verify_longpoll_topic(conn)

Retrieves the serialized Phoenix.LongPoller.Server pid from the encrypted token

Functions

ack(conn, priv_topic, msgs)

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.

Source
action(conn, options)
Source
call(conn, action)

Callback implementation of Plug.call/2.

Source
dispatch(conn, priv_topic, msg)

Dispatches deserialized %Phoenix.Socket.Message{} from client to Phoenix.LongPoller.Server

Source
init(action)

Callback implementation of Plug.init/1.

Source
options(conn, params)

Responds to pre-flight CORS requests with Allow-Origin-* headers.

Source
poll(conn, params)

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.

Source
publish(conn, message)

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.

Source
resume_session(conn)

Finds the Phoenix.LongPoller.Server server from the session.

Source
start_session(conn)

Starts the Phoenix.LongPoller.Server and stores the serialized pid in the session.

Source
verify_longpoll_topic(conn)

Retrieves the serialized Phoenix.LongPoller.Server pid from the encrypted token.

Source