       end
 
       ## Incoming from client / browser
+      @doc ~S"""
+      Handles incoming messages from the websocket client.
+
+      The `message` is parsed and passed on to the client, which responds with an update `state` and possible reply.
+
+      The `req` is ignored.
+      """
       @spec websocket_handle(
         {:text, String.t},
         req :: :cowboy_req.req,

    send_response({:reply, type, nil, state}, socket_state, req)
  end

  @spec setup_proxy(proxy :: String.t, state :: map, req :: :cowboy_req.req) ::
    {:reply, {:text, String.t}, :cowboy_req.req, map}
    | {:ok, :cowboy_req.req, map}

  # Helpers

  ## Command
  @doc ~S"""
  Parses the JSON `payload` to an atom command and map data.
  """
  @spec parse_command(payload :: String.t) :: atom | {atom, any}
  def parse_command(payload) do
    command_data = Poison.decode!(payload)
