Pleroma/lib/pleroma/web/mastodon_api/mastodon_socket.ex

35 lines
813 B
Elixir
Raw Normal View History

2017-11-11 14:59:25 +01:00
defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
use Phoenix.Socket
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
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
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