WebSock

Build StatusDocsHex.pm

WebSock is a library & specification for apps to service WebSocket connections; you can think of it as 'Plug for WebSockets'. WebSock abstracts WebSocket support from servers such as Bandit or Cowboy and exposes a generic WebSocket API to applications. WebSocket-aware applications such as Phoenix can then be hosted within a supported web server simply by defining conformance to the WebSock behaviour, in the same manner as how Plug conformance allows their HTTP aspects to be hosted within an arbitrary web server.

WebSocket consists of two parts:

  1. The WebSock behaviour describes the functions that an application such as Phoenix must implement in order to be WebSock compliant; it is roughly the equivalent of the Plug interface, but for WebSocket connections

  2. The WebSock library implements transparent adapters to translate server-specific APIs into the WebSock behaviour (currently, Bandit and Cowboy are supported)

WebSocket Lifecycle

WebSocket connections go through a well defined lifecycle mediated by WebSock:

For more information, consult the docs.

Installation

The websock package can be installed by adding websock to your list of dependencies in mix.exs:

def deps do
[
{:websock, "~> 0.4.1"}
]
end

Documentation can be found at https://hexdocs.pm/websock.

License

MIT