diff options
| author | Melonai <einebeere@gmail.com> | 2021-08-16 18:17:06 +0200 |
|---|---|---|
| committer | Melonai <einebeere@gmail.com> | 2021-08-16 18:17:06 +0200 |
| commit | a7af012b92f0dfd90cc3eb570e03144016646180 (patch) | |
| tree | f73d402f1d74459195967928346d26ad195a2a73 /lib/rook_web | |
| parent | 877f2aa4cc5890214f0c58813c4b498f8be1236d (diff) | |
| download | rook-a7af012b92f0dfd90cc3eb570e03144016646180.tar.zst rook-a7af012b92f0dfd90cc3eb570e03144016646180.zip | |
Ability to pass request info through pipeline
Diffstat (limited to 'lib/rook_web')
| -rw-r--r-- | lib/rook_web/channels/request_channel.ex | 12 | ||||
| -rw-r--r-- | lib/rook_web/channels/user_socket.ex | 5 | ||||
| -rw-r--r-- | lib/rook_web/endpoint.ex | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/rook_web/channels/request_channel.ex b/lib/rook_web/channels/request_channel.ex index cc84b0f..9773d30 100644 --- a/lib/rook_web/channels/request_channel.ex +++ b/lib/rook_web/channels/request_channel.ex @@ -1,10 +1,18 @@ defmodule RookWeb.RequestChannel do use RookWeb, :channel - def join("request:" <> token, %{"share" => share_token}, socket) do + def join("request:" <> token, %{"share" => share_token, "user_agent" => user_agent}, socket) do if Rook.Token.match?(token, socket) do if Rook.Share.exists?(share_token) do - Rook.Request.Actions.start(token, share_token) + ip = socket.assigns[:ip] + + info = %{ + ip: ip, + location: Rook.Identity.get_location_from_ip(ip), + client: Rook.Identity.get_client_from_user_agent(user_agent) + } + + Rook.Request.Actions.start(token, share_token, info) {:ok, socket} else {:error, %{reason: "No such share exists."}} diff --git a/lib/rook_web/channels/user_socket.ex b/lib/rook_web/channels/user_socket.ex index d6ce9c4..1a4dbd0 100644 --- a/lib/rook_web/channels/user_socket.ex +++ b/lib/rook_web/channels/user_socket.ex @@ -18,9 +18,10 @@ defmodule RookWeb.UserSocket do # See `Phoenix.Token` documentation for examples in # performing token verification on connect. @impl true - def connect(_params, socket, _connect_info) do + def connect(_params, socket, connect_info) do token = Rook.Token.token() - {:ok, assign(socket, :token, token)} + ip = Rook.Identity.get_ip_from_connect_info(connect_info) + {:ok, assign(socket, token: token, ip: ip)} end # Socket id's are topics that allow you to identify all sockets for a given user: diff --git a/lib/rook_web/endpoint.ex b/lib/rook_web/endpoint.ex index dd847f7..31c9790 100644 --- a/lib/rook_web/endpoint.ex +++ b/lib/rook_web/endpoint.ex @@ -11,7 +11,7 @@ defmodule RookWeb.Endpoint do ] socket "/socket", RookWeb.UserSocket, - websocket: true, + websocket: [connect_info: [:peer_data, :x_headers]], longpoll: false # Serve at "/" the static files from "priv/static" directory. |
