1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Phoenix.Transports.WebSocket.Raw do
12 alias Phoenix.Socket.Transport
18 cowboy: Phoenix.Endpoint.CowboyWebSocket
22 def init(%Plug.Conn{method: "GET"} = conn, {endpoint, handler, transport}) do
23 {_, opts} = handler.__transport__(transport)
28 |> Transport.transport_log(opts[:transport_log])
29 |> Transport.force_ssl(handler, endpoint, opts)
30 |> Transport.check_origin(handler, endpoint, opts)
33 %{halted: false} = conn ->
34 case Transport.connect(endpoint, handler, transport, __MODULE__, nil, conn.params) do
36 {:ok, conn, {__MODULE__, {socket, opts}}}
39 send_resp(conn, :forbidden, "")
49 send_resp(conn, :bad_request, "")
53 def ws_init({socket, config}) do
54 Process.flag(:trap_exit, true)
55 {:ok, %{socket: socket}, config[:timeout]}
58 def ws_handle(op, data, state) do
60 |> apply(:handle, [op, data, state])
63 {:reply, {op, data}, state}
66 {:reply, {op, data}, state}
76 def ws_info({_, _} = tuple, state) do
77 {:reply, tuple, state}
80 def ws_info(_tuple, state), do: {:ok, state}
82 def ws_close(state) do
83 ws_handle(:closed, :normal, state)
86 def ws_terminate(reason, state) do
87 ws_handle(:closed, reason, state)