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 Pleroma.Integration.WebsocketClient do
6 # https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs
9 Starts the WebSocket server for given ws URL. Received Socket.Message's
10 are forwarded to the sender pid
12 def start_link(sender, url, headers \\ []) do
16 :websocket_client.start_link(
17 String.to_charlist(url),
20 extra_headers: headers
32 Sends a low-level text message to the client.
34 def send_text(server_pid, msg) do
35 send(server_pid, {:text, msg})
39 def init([sender], _conn_state) do
40 {:ok, %{sender: sender}}
44 def websocket_handle(frame, _conn_state, state) do
45 send(state.sender, frame)
50 def websocket_info({:text, msg}, _conn_state, state) do
51 {:reply, {:text, msg}, state}
54 def websocket_info(:close, _conn_state, _state) do
55 {:close, <<>>, "done"}
59 def websocket_terminate(_reason, _conn_state, _state) do