Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

client-elixir: init and wire up to server

+203 -4
+3
client-elixir/.formatter.exs
··· 1 + [ 2 + inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"] 3 + ]
+23
client-elixir/.gitignore
··· 1 + # The directory Mix will write compiled artifacts to. 2 + /_build/ 3 + 4 + # If you run "mix test --cover", coverage assets end up here. 5 + /cover/ 6 + 7 + # The directory Mix downloads your dependencies sources to. 8 + /deps/ 9 + 10 + # Where third-party dependencies like ExDoc output generated docs. 11 + /doc/ 12 + 13 + # If the VM crashes, it generates a dump, let's ignore it too. 14 + erl_crash.dump 15 + 16 + # Also ignore archive artifacts (built via "mix archive.build"). 17 + *.ez 18 + 19 + # Ignore package tarball (built via "mix hex.build"). 20 + sower_client-*.tar 21 + 22 + # Temporary files, for example, from tests. 23 + /tmp/
+21
client-elixir/README.md
··· 1 + # SowerClient 2 + 3 + **TODO: Add description** 4 + 5 + ## Installation 6 + 7 + If [available in Hex](https://hex.pm/docs/publish), the package can be installed 8 + by adding `sower_client` to your list of dependencies in `mix.exs`: 9 + 10 + ```elixir 11 + def deps do 12 + [ 13 + {:sower_client, "~> 0.1.0"} 14 + ] 15 + end 16 + ``` 17 + 18 + Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) 19 + and published on [HexDocs](https://hexdocs.pm). Once published, the docs can 20 + be found at <https://hexdocs.pm/sower_client>. 21 +
+3
client-elixir/config/config.exs
··· 1 + import Config 2 + 3 + import_config "#{config_env()}.exs"
+5
client-elixir/config/dev.exs
··· 1 + import Config 2 + 3 + config :sower_client, SowerClient.SocketClient, 4 + uri: "ws://localhost:7150/client/websocket", 5 + reconnect_after_msec: [200, 500, 1_000, 2_000]
+5
client-elixir/config/test.exs
··· 1 + import Config 2 + 3 + config :sower_client, SocketClient, 4 + uri: "ws://example.org/socket/websocket", 5 + reconnect_after_msec: [200, 500, 1_000, 2_000]
+18
client-elixir/lib/sower_client.ex
··· 1 + defmodule SowerClient do 2 + @moduledoc """ 3 + Documentation for `SowerClient`. 4 + """ 5 + 6 + @doc """ 7 + Hello world. 8 + 9 + ## Examples 10 + 11 + iex> SowerClient.hello() 12 + :world 13 + 14 + """ 15 + def hello do 16 + :world 17 + end 18 + end
+20
client-elixir/lib/sower_client/application.ex
··· 1 + defmodule SowerClient.Application do 2 + # See https://hexdocs.pm/elixir/Application.html 3 + # for more information on OTP Applications 4 + @moduledoc false 5 + 6 + use Application 7 + 8 + @impl true 9 + def start(_type, _args) do 10 + children = [ 11 + # Starts a worker by calling: SowerClient.Worker.start_link(arg) 12 + {SowerClient.SocketClient, []} 13 + ] 14 + 15 + # See https://hexdocs.pm/elixir/Supervisor.html 16 + # for other strategies and supported options 17 + opts = [strategy: :one_for_one, name: SowerClient.Supervisor] 18 + Supervisor.start_link(children, opts) 19 + end 20 + end
+36
client-elixir/lib/sower_client/worker.ex
··· 1 + defmodule SowerClient.SocketClient do 2 + use Slipstream 3 + 4 + require Logger 5 + 6 + @topic "client:lobby" 7 + 8 + def start_link(args) do 9 + Slipstream.start_link(__MODULE__, args, name: __MODULE__) 10 + end 11 + 12 + @impl Slipstream 13 + def init(_args) do 14 + config = Application.fetch_env!(:sower_client, __MODULE__) 15 + 16 + case connect(config) do 17 + {:ok, socket} -> 18 + Logger.debug(msg: "Connecting") 19 + {:ok, socket} 20 + 21 + {:error, reason} -> 22 + Logger.error( 23 + "Could not start #{__MODULE__} because of " <> 24 + "validation failure: #{inspect(reason)}" 25 + ) 26 + 27 + :ignore 28 + end 29 + end 30 + 31 + @impl Slipstream 32 + def handle_connect(socket) do 33 + Logger.debug(msg: "Connected") 34 + {:ok, join(socket, @topic)} 35 + end 36 + end
+29
client-elixir/mix.exs
··· 1 + defmodule SowerClient.MixProject do 2 + use Mix.Project 3 + 4 + def project do 5 + [ 6 + app: :sower_client, 7 + version: "0.1.0", 8 + elixir: "~> 1.18", 9 + start_permanent: Mix.env() == :prod, 10 + deps: deps() 11 + ] 12 + end 13 + 14 + # Run "mix help compile.app" to learn about applications. 15 + def application do 16 + [ 17 + extra_applications: [:logger], 18 + mod: {SowerClient.Application, []} 19 + ] 20 + end 21 + 22 + # Run "mix help deps" to learn about dependencies. 23 + defp deps do 24 + [ 25 + {:slipstream, "~> 1.0"}, 26 + {:igniter, "~> 0.6", only: [:dev, :test]} 27 + ] 28 + end 29 + end
+20
client-elixir/mix.lock
··· 1 + %{ 2 + "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, 3 + "glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"}, 4 + "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"}, 5 + "igniter": {:hex, :igniter, "0.6.5", "0b16a37e1aaaefc39777c6250980a314df8ba02a8ae81063d786a7bddb40dbf0", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:owl, "~> 0.11", [hex: :owl, repo: "hexpm", optional: false]}, {:phx_new, "~> 1.7", [hex: :phx_new, repo: "hexpm", optional: true]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}, {:rewrite, ">= 1.1.1 and < 2.0.0-0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "21dec3066f372f49f391d00a2067769eb20f7a2213513e022593e4b51bad93e2"}, 6 + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, 7 + "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"}, 8 + "mint": {:hex, :mint, "1.7.1", "113fdb2b2f3b59e47c7955971854641c61f378549d73e829e1768de90fc1abf1", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "fceba0a4d0f24301ddee3024ae116df1c3f4bb7a563a731f45fdfeb9d39a231b"}, 9 + "mint_web_socket": {:hex, :mint_web_socket, "1.0.4", "0b539116dbb3d3f861cdf5e15e269a933cb501c113a14db7001a3157d96ffafd", [:mix], [{:mint, ">= 1.4.1 and < 2.0.0-0", [hex: :mint, repo: "hexpm", optional: false]}], "hexpm", "027d4c5529c45a4ba0ce27a01c0f35f284a5468519c045ca15f43decb360a991"}, 10 + "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, 11 + "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, 12 + "owl": {:hex, :owl, "0.12.2", "65906b525e5c3ef51bab6cba7687152be017aebe1da077bb719a5ee9f7e60762", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "6398efa9e1fea70a04d24231e10dcd66c1ac1aa2da418d20ef5357ec61de2880"}, 13 + "req": {:hex, :req, "0.5.10", "a3a063eab8b7510785a467f03d30a8d95f66f5c3d9495be3474b61459c54376c", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "8a604815743f8a2d3b5de0659fa3137fa4b1cffd636ecb69b30b2b9b2c2559be"}, 14 + "rewrite": {:hex, :rewrite, "1.1.2", "f5a5d10f5fed1491a6ff48e078d4585882695962ccc9e6c779bae025d1f92eda", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "7f8b94b1e3528d0a47b3e8b7bfeca559d2948a65fa7418a9ad7d7712703d39d4"}, 15 + "slipstream": {:hex, :slipstream, "1.2.0", "f4e820752339d86d2f15f4103e163f538e3bb9c7fe353225afd1255178e1f051", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mint_web_socket, "~> 0.2 or ~> 1.0", [hex: :mint_web_socket, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.1 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f2fceddbb3c97331d348586e77c6425f4d150242dfaf392d22e8bd22f93d1f1e"}, 16 + "sourceror": {:hex, :sourceror, "1.10.0", "38397dedbbc286966ec48c7af13e228b171332be1ad731974438c77791945ce9", [:mix], [], "hexpm", "29dbdfc92e04569c9d8e6efdc422fc1d815f4bd0055dc7c51b8800fb75c4b3f1"}, 17 + "spitfire": {:hex, :spitfire, "0.2.1", "29e154873f05444669c7453d3d931820822cbca5170e88f0f8faa1de74a79b47", [:mix], [], "hexpm", "6eeed75054a38341b2e1814d41bb0a250564092358de2669fdb57ff88141d91b"}, 18 + "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, 19 + "text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"}, 20 + }
+8
client-elixir/test/sower_client_test.exs
··· 1 + defmodule SowerClientTest do 2 + use ExUnit.Case 3 + doctest SowerClient 4 + 5 + test "greets the world" do 6 + assert SowerClient.hello() == :world 7 + end 8 + end
+1
client-elixir/test/test_helper.exs
··· 1 + ExUnit.start()
+5 -4
lib/sower_web/client_channel.ex
··· 1 1 defmodule SowerWeb.ClientChannel do 2 + use Phoenix.Channel 3 + 2 4 require Logger 3 - use Phoenix.Channel 4 5 5 - def join("client:all", _message, socket) do 6 - send(self(), :push_tree_id_to_client) 7 - # Logger.debug(~s"client:all joined by #{socket.assigns.tree_id}") 6 + def join("client:lobby", _message, socket) do 7 + # send(self(), :push_tree_id_to_client) 8 + Logger.debug(msg: "Channel topic joined", topic: "client:all", sid: socket.assigns.sid) 8 9 {:ok, socket} 9 10 end 10 11
+6
lib/sower_web/client_socket.ex
··· 25 25 end 26 26 end 27 27 28 + def connect(%{}, socket, _connect_info) do 29 + Logger.debug(msg: "TODO authorized connection") 30 + {:ok, assign(socket, :sid, Sower.Schema.Sid.generate()) |> dbg()} 31 + end 32 + 28 33 def connect(%{}, _socket, _connect_info) do 34 + Logger.debug(msg: "unauthorized connection") 29 35 {:error, "unauthorized. authentication token required"} 30 36 end 31 37