Phoenix v1.2.0-rc.1 Phoenix.Transports.WebSocket

Socket transport for websocket clients.

Configuration

The websocket is configurable in your socket:

transport :websocket, Phoenix.Transports.WebSocket,
  timeout: :infinity,
  serializer: Phoenix.Transports.WebSocketSerializer,
  transport_log: false
  • :timeout - the timeout for keeping websocket connections open after it last received data, defaults to 60_000ms

  • :transport_log - if the transport layer itself should log and, if so, the level

  • :serializer - the serializer for websocket messages

  • :check_origin - if we should check the origin of requests when the origin header is present. It defaults to true and, in such cases, it will check against the host value in YourApp.Endpoint.config(:url)[:host]. It may be set to false (not recommended) or to a list of explicitly allowed origins

  • :code_reloader - optionally override the default :code_reloader value from the socket’s endpoint

Serializer

By default, JSON encoding is used to broker messages to and from clients. A custom serializer may be given as module which implements the encode!/1 and decode!/2 functions defined by the Phoenix.Transports.Serializer behaviour.

The encode!/1 function must return a tuple in the format {:socket_push, :text | :binary, String.t | binary}.

Summary

Functions

default_config()

Callback implementation for Phoenix.Socket.Transport.default_config/0.