Phoenix.Transports.LongPoll

Handles LongPoll clients for the Channel Transport layer.

Configuration

The long poller is configurable in your Socket’s transport configuration:

transport :longpoll, Phoenix.Transports.LongPoll,
  window_ms: 10_000,
  pubsub_timeout_ms: 1000,
  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.LongPoll.Server

call(conn, opts)

Callback implementation for c:Plug.call/2

default_config()

Provides the deault transport configuration to sockets

init(opts)

Callback implementation for c: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.LongPoll.Server

publish(conn, message)

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

resume_session(conn)

Finds the Phoenix.LongPoll.Server server from the session

start_session(conn, socket)

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

transport_dispatch(conn, priv_topic, msg)

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

verify_longpoll_topic(conn)

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

Functions

ack(conn, priv_topic, msgs)

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

To be called after buffered messages have been relayed to the client.

Source
call(conn, opts)

Callback implementation for c:Plug.call/2.

Source
default_config()

Provides the deault transport configuration to sockets.

  • :serializer - The Phoenix.Socket.Message serializer
  • :pubsub_timeout_ms - The timeout to wait for the LongPoll.Server ack
  • :log - The log level, for example :info. Disabled by default
  • :timeout - The connection timeout in milliseconds, defaults to :infinity
  • :crypto - The list of encryption options for the Plug.Session
Source
init(opts)

Callback implementation for c: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.LongPoll.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.LongPoll.Server server from the session.

Source
start_session(conn, socket)

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

Source
transport_dispatch(conn, priv_topic, msg)

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

Source
verify_longpoll_topic(conn)

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

Source