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:
- Handle receiving incoming, encoded
%Phoenix.Socket.Message{}
‘s from remote clients, then deserialing and fowarding message throughPhoenix.Transport.dispatch/2
. Finish by keeping state of returned HashDict of%Phoenix.Socket{}
s. - Handle receiving outgoing
%Phoenix.Socket.Message{}
s as Elixir process messages, then encoding and fowarding to connected remote client. - Handle receiving arbitrary Elixir messages and fowarding through
Phoenix.Transport.dispatch_info/2
. Finish by keeping state of returned HashDict of%Phoenix.Socket{}
s. - Handle remote client disconnects and relaying event through
Phoenix.Transport.dispatch_leave/2
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.
Summary
dispatch(message, sockets, adapter_pid, router) | Dispatches |
dispatch_info(sockets, data) | Arbitrary Elixir processes are received by adapters and forwarded through
this function to be dispatched as |
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 |
Functions
Dispatches %Phoenix.Socket.Message{}
to Channel. All serialized, remote client messages
should be deserialized and forwarded through this function by adapters.
The following return signatures must be handled by transport adapters:
{:ok, sockets}
- Successful dispatch, with updatedHashDict
of sockets{:error, sockets, reason}
- Failed dispatched with updatdHashDict
of sockets
The returned HashDict
of %Phoenix.Socket{}
s must be held by the adapter
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