1 defmodule Phoenix.Transports.WebSocket.Raw do
8 alias Phoenix.Socket.Transport
14 cowboy: Phoenix.Endpoint.CowboyWebSocket
18 def init(%Plug.Conn{method: "GET"} = conn, {endpoint, handler, transport}) do
19 {_, opts} = handler.__transport__(transport)
24 |> Transport.transport_log(opts[:transport_log])
25 |> Transport.force_ssl(handler, endpoint, opts)
26 |> Transport.check_origin(handler, endpoint, opts)
29 %{halted: false} = conn ->
30 case Transport.connect(endpoint, handler, transport, __MODULE__, nil, conn.params) do
32 {:ok, conn, {__MODULE__, {socket, opts}}}
35 send_resp(conn, :forbidden, "")
45 send_resp(conn, :bad_request, "")
49 def ws_init({socket, config}) do
50 Process.flag(:trap_exit, true)
51 {:ok, %{socket: socket}, config[:timeout]}
54 def ws_handle(op, data, state) do
56 |> apply(:handle, [op, data, state])
59 {:reply, {op, data}, state}
62 {:reply, {op, data}, state}
72 def ws_info({_, _} = tuple, state) do
73 {:reply, tuple, state}
76 def ws_info(_tuple, state), do: {:ok, state}
78 def ws_close(state) do
79 ws_handle(:closed, :normal, state)
82 def ws_terminate(reason, state) do
83 ws_handle(:closed, reason, state)