Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

client: ping/pong with server

+44 -8
+35 -4
client-elixir/lib/sower_client/worker.ex
··· 3 3 4 4 require Logger 5 5 6 - @topic "client:lobby" 6 + @lobby_topic "client:lobby" 7 + 8 + # 9 + # client 10 + # 11 + 12 + def send(message) do 13 + GenServer.call(__MODULE__, message) 14 + end 15 + 16 + @impl Slipstream 17 + def handle_call(:ping, _, %{assigns: %{sid: sid}} = socket) do 18 + {:ok, ref} = push(socket, "client:#{sid}", "ping", %{}) 19 + {:ok, "pong"} = await_reply(ref) 20 + {:reply, {:ok, :pong}, socket} 21 + end 22 + 23 + @impl Slipstream 24 + def handle_call(request, from, socket) do 25 + Logger.debug(msg: "Unsupported call", request: request, from: from) 26 + {:reply, {:error, :unsupported_request}, socket} 27 + end 28 + 29 + # 30 + # server 31 + # 7 32 8 33 def start_link(args) do 9 34 Slipstream.start_link(__MODULE__, args, name: __MODULE__) ··· 31 56 @impl Slipstream 32 57 def handle_connect(socket) do 33 58 Logger.debug(msg: "Connected") 34 - {:ok, join(socket, @topic)} 59 + {:ok, join(socket, @lobby_topic)} 35 60 end 36 61 37 62 @impl Slipstream 38 - def handle_join(@topic, %{"sid" => sid}, socket) do 39 - Logger.debug(msg: "Joined channel topic", topic: @topic) 63 + def handle_reply(ref, message, %{assigns: %{sid: sid}} = socket) do 64 + Logger.debug(msg: "Received reply", ref: ref, message: message, sid: sid) 65 + {:noreply, socket} 66 + end 67 + 68 + @impl Slipstream 69 + def handle_join(@lobby_topic, %{"sid" => sid}, socket) do 70 + Logger.debug(msg: "Joined channel topic", topic: @lobby_topic) 40 71 41 72 socket = socket |> assign(:sid, sid) |> join("client:#{sid}") 42 73
+7 -2
lib/sower_web/client_channel.ex
··· 3 3 4 4 require Logger 5 5 6 - def join("client:lobby", _message, socket = %{assigns: %{sid: sid}}) do 6 + def join("client:lobby", _message, %{assigns: %{sid: sid}} = socket) do 7 7 Logger.debug(msg: "Channel topic joined", topic: "client:all", sid: sid) 8 8 {:ok, %{sid: sid}, socket} 9 9 end 10 10 11 - def join("client:" <> topic_sid = topic, _params, socket = %{assigns: %{sid: sid}}) do 11 + def join("client:" <> topic_sid = topic, _params, %{assigns: %{sid: sid}} = socket) do 12 12 Logger.debug(msg: "Channel topic joined", topic: topic, sid: sid) 13 13 14 14 if sid == topic_sid do ··· 20 20 21 21 def join(_topic, _params, _socket) do 22 22 {:error, %{reason: "unauthorized"}} 23 + end 24 + 25 + def handle_in("ping", _, %{assigns: %{sid: sid}} = socket) do 26 + Logger.debug(msg: "Received ping, ponging", sid: sid) 27 + {:reply, {:ok, :pong}, socket} 23 28 end 24 29 25 30 # def handle_in(
+2 -2
lib/sower_web/client_socket.ex
··· 26 26 end 27 27 28 28 def connect(%{}, socket, _connect_info) do 29 - Logger.debug(msg: "TODO authorized connection") 30 - {:ok, assign(socket, :sid, Sower.Schema.Sid.generate()) |> dbg()} 29 + Logger.error(msg: "TODO non-authorized connection") 30 + {:ok, assign(socket, :sid, Sower.Schema.Sid.generate())} 31 31 end 32 32 33 33 def connect(%{}, _socket, _connect_info) do