this repo has no description
1defmodule EslHnWeb.API.Socket do 2 @behaviour Phoenix.Socket.Transport 3 4 @impl true 5 def child_spec(_opts), do: :ignore 6 7 @impl true 8 def connect(_connect_info) do 9 {:ok, []} 10 end 11 12 @impl true 13 def init(state) do 14 # No support for `handle_continue/2` so we need to hack it around 15 send(self(), :do_init) 16 EslHn.subscribe_new() 17 18 {:ok, state} 19 end 20 21 @impl true 22 def handle_in({message, opts}, state) do 23 dbg({message, opts}) 24 25 {:ok, state} 26 end 27 28 @impl true 29 def handle_info(:do_init, state) do 30 stories = EslHn.all(1, 50) 31 data = EslHnWeb.API.JSON.index(%{items: stories}) 32 33 {:push, {:text, JSON.encode_to_iodata!(data)}, state} 34 end 35 36 def handle_info({:new_stories, stories}, state) do 37 data = EslHnWeb.API.JSON.index(%{items: stories}) 38 39 {:push, {:text, JSON.encode_to_iodata!(data)}, state} 40 end 41 42 @impl true 43 def terminate(_reason, _state), do: :ok 44end