2017-11-11 14:59:25 +01:00
|
|
|
defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
|
|
|
|
use Phoenix.Socket
|
|
|
|
|
2017-11-11 20:00:11 +01:00
|
|
|
transport :streaming, Phoenix.Transports.WebSocket.Raw,
|
|
|
|
timeout: :infinity # We never receive data.
|
2017-11-11 14:59:25 +01:00
|
|
|
|
|
|
|
def connect(params, socket) do
|
2017-11-11 20:00:11 +01:00
|
|
|
if params["stream"] == "public" do
|
|
|
|
socket = socket
|
|
|
|
|> assign(:topic, params["stream"])
|
|
|
|
Pleroma.Web.Streamer.add_socket(params["stream"], socket)
|
|
|
|
{:ok, socket}
|
|
|
|
else
|
|
|
|
:error
|
|
|
|
end
|
2017-11-11 14:59:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def id(socket), do: nil
|
|
|
|
|
|
|
|
def handle(:text, message, state) do
|
|
|
|
IO.inspect message
|
|
|
|
#| :ok
|
|
|
|
#| state
|
|
|
|
#| {:text, message}
|
|
|
|
#| {:text, message, state}
|
|
|
|
#| {:close, "Goodbye!"}
|
|
|
|
{:text, message}
|
|
|
|
end
|
|
|
|
|
2017-11-11 20:00:11 +01:00
|
|
|
def handle(:closed, reason, %{socket: socket}) do
|
|
|
|
topic = socket.assigns[:topic]
|
|
|
|
Pleroma.Web.Streamer.remove_socket(topic, socket)
|
2017-11-11 14:59:25 +01:00
|
|
|
end
|
|
|
|
end
|