diff --git a/lib/phoenix_live_session.ex b/lib/phoenix_live_session.ex index 10f5214..3f47db8 100644 --- a/lib/phoenix_live_session.ex +++ b/lib/phoenix_live_session.ex @@ -180,8 +180,8 @@ defmodule PhoenixLiveSession do defp put_meta(data, sid, opts) do data - |> Map.put(:__sid__, sid) - |> Map.put(:__opts__, opts) + |> Map.put("__sid__", sid) + |> Map.put("__opts__", opts) end defp maybe_clean(opts) do @@ -225,13 +225,10 @@ defmodule PhoenixLiveSession do """ @spec maybe_subscribe(Phoenix.LiveView.Socket.t(), Plug.Session.Store.session()) :: Phoenix.LiveView.Socket.t() - def maybe_subscribe(socket, session) do + def maybe_subscribe(socket, %{"__sid__" => sid, "__opts__" => opts}) do if LiveView.connected?(socket) do - sid = Map.fetch!(session, :__sid__) - opts = Map.fetch!(session, :__opts__) pub_sub = Keyword.fetch!(opts, :pub_sub) - channel = "live_session:#{sid}" - PubSub.subscribe(pub_sub, channel) + PubSub.subscribe(pub_sub, "live_session:#{sid}") put_in(socket.private[:live_session], id: sid, opts: opts) else @@ -239,6 +236,8 @@ defmodule PhoenixLiveSession do end end + def maybe_subscribe(socket, _), do: socket + @doc """ This function can be called in two ways:any() @@ -263,8 +262,8 @@ defmodule PhoenixLiveSession do socket end - @spec put_session(%{__sid__: String.t(), __opts__: list()}, String.t() | atom(), term()) :: %{} - def put_session(%{__sid__: sid, __opts__: opts}, key, value) do + @spec put_session(map(), String.t() | atom(), term()) :: %{} + def put_session(%{"__sid__" => sid, "__opts__" => opts}, key, value) do put_in(sid, to_string(key), value, opts) get(nil, sid, opts) diff --git a/mix.exs b/mix.exs index b337ff5..39eaceb 100644 --- a/mix.exs +++ b/mix.exs @@ -28,7 +28,7 @@ defmodule PhoenixLiveSession.MixProject do %{ description: "In-memory live sessions for LiveViews and Phoenix controllers.", licenses: ["Apache-2.0"], - links: %{"GitHub" => "https://github.com/pentacent/phoenix_live_session"}, + links: %{"GitHub" => "https://github.com/pentacent/phoenix_live_session"} } end