1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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 handler.connect(%{
37 options: [serializer: nil],
41 {:ok, conn, {__MODULE__, {socket, opts}}}
44 send_resp(conn, :forbidden, "")
54 send_resp(conn, :bad_request, "")
58 def ws_init({socket, config}) do
59 Process.flag(:trap_exit, true)
60 {:ok, %{socket: socket}, config[:timeout]}
63 def ws_handle(op, data, state) do
65 |> apply(:handle, [op, data, state])
68 {:reply, {op, data}, state}
71 {:reply, {op, data}, state}
81 def ws_info({_, _} = tuple, state) do
82 {:reply, tuple, state}
85 def ws_info(_tuple, state), do: {:ok, state}
87 def ws_close(state) do
88 ws_handle(:closed, :normal, state)
91 def ws_terminate(reason, state) do
92 ws_handle(:closed, reason, state)