Phoenix.Channel.Transport

Handles dispatching incoming and outgoing Channel messages

The Transport Adapter Contract

The Transport layer dispatches %Phoenix.Socket.Message{}‘s from remote clients, backed by different Channel transport implementations and serializations.

Server

To implement a Transport adapter, the Server must broker the following actions:

See Phoenix.Transports.WebSocket for an example transport server implementation.

Remote Client

Phoenix includes a JavaScript client for WebSocket and Longpolling support using JSON encodings.

However, a client can be implemented for other protocols and encodings by abiding by the Phoenix.Socket.Message format

See assets/cs/phoenix.coffee for an example transport client implementation.

Source

Summary

dispatch(message, sockets, adapter_pid, router)

Dispatches %Phoenix.Socket.Message{} in response to a heartbeat message sent from the client

dispatch_info(sockets, data)

Arbitrary Elixir processes are received by adapters and forwarded through this function to be dispatched as "info" events on each socket channel

dispatch_info(socket, channel, data)
dispatch_leave(sockets, reason)

Whenever a remote client disconnects, the adapter must forward the event through this function to be dispatched as "leave" events on each socket channel

Functions

dispatch(message, sockets, adapter_pid, router)

Dispatches %Phoenix.Socket.Message{} in response to a heartbeat message sent from the client.

The Message format sent to phoenix requires the following key / values:

  • channel - The String value “phoenix”
  • topic - The String value “conn”
  • event - The String value “heartbeat”
  • message - An empty JSON message payload, ie {}

The server will respond to heartbeats with the same message

Source
dispatch_info(sockets, data)

Arbitrary Elixir processes are received by adapters and forwarded through this function to be dispatched as "info" events on each socket channel.

The returned HashDict of %Phoenix.Socket{}s must be held by the adapter

Source
dispatch_info(socket, channel, data)
Source
dispatch_leave(sockets, reason)

Whenever a remote client disconnects, the adapter must forward the event through this function to be dispatched as "leave" events on each socket channel.

Most adapters shutdown after this dispatch as they client has disconnected

Source