xy_channel.ex 740 Bytes
Newer Older
Jens-Christian Fischer's avatar
Jens-Christian Fischer committed
1
2
3
4
5
defmodule Grains.XyChannel do
  use Grains.Web, :channel

  require Logger

6
7
  alias Grains.{StatefulMap, MsgCounterAgent}

Jens-Christian Fischer's avatar
Jens-Christian Fischer committed
8
9
10
11
12
13
14
15
16
17
18

  def join("xy:" <> _xy_id, _params, socket) do
    Logger.info("joined xy")

    uuid = socket.assigns.user_uuid
    nr = StatefulMap.get(uuid)
    resp = %{dot_id: nr}
    {:ok, resp, socket}
  end

  def handle_in("xy", params, socket) do
19
    nr = MsgCounterAgent.click()
Jens-Christian Fischer's avatar
Jens-Christian Fischer committed
20
21
22
23
24
25
26
27
28
29
    uuid = socket.assigns.user_uuid
    x   = params["x"]
    y   = params["y"]

    Grengine.Performance.set_values(uuid, %{
          x: x,
          y: y,
                                    }
    )

30
    Grains.Endpoint.broadcast "visuals:data", "velocity", %{user: uuid, dx: x, dy: y, msgs: nr}
Jens-Christian Fischer's avatar
Jens-Christian Fischer committed
31
32
33
34
35
36
37
38
39


    {:reply, :ok, socket}

  end



end