diff --git a/lib/crane/application.ex b/lib/crane/application.ex index 480659e..37f50c8 100644 --- a/lib/crane/application.ex +++ b/lib/crane/application.ex @@ -2,12 +2,12 @@ defmodule Crane.Application do use Application def start(_type, _args) do - live_reload = Application.get_env(:phoenix_playground, :live_reload) + # live_reload = Application.get_env(:phoenix_playground, :live_reload) phx_port = System.get_env("PHX_PORT", "4100") |> make_integer() children = [ - {PhoenixPlayground, plug: Crane.Phoenix.Router, live_reload: live_reload, open_browser: false, ip: {0, 0, 0, 0}, port: phx_port}, + # {PhoenixPlayground, plug: Crane.Phoenix.Router, live_reload: live_reload, open_browser: false, ip: {0, 0, 0, 0}, port: phx_port}, {Crane, []}, ] diff --git a/lib/crane/browser/window/console.ex b/lib/crane/browser/window/console.ex index f1b0f47..582f491 100644 --- a/lib/crane/browser/window/console.ex +++ b/lib/crane/browser/window/console.ex @@ -23,7 +23,7 @@ defmodule Crane.Browser.Window.Console do List.insert_at(entries, -1, message) end) - Phoenix.PubSub.broadcast(PhoenixPlayground.PubSub, "logger", {:foobar, "123"}) + # Phoenix.PubSub.broadcast(PhoenixPlayground.PubSub, "logger", {:foobar, "123"}) {:noreply, %__MODULE__{console | logs: logs}} end diff --git a/lib/crane/browser/window/websocket.ex b/lib/crane/browser/window/websocket.ex index 1d9051e..1227a8d 100644 --- a/lib/crane/browser/window/websocket.ex +++ b/lib/crane/browser/window/websocket.ex @@ -13,13 +13,14 @@ defmodule Crane.Browser.Window.WebSocket do {:ok, websocket, {:continue, {:init, opts}}} = super(opts) {:ok, opts} = Keyword.validate(opts, [url: nil, headers: []]) - opts = Keyword.update(opts, :url, nil, fn + opts = Keyword.update(opts, :url, nil, fn "localhost" <> _tail = url -> "http://" <> url url -> url end) uri = URI.parse(opts[:url]) + dbg ws_path(uri) with {:ok, conn} <- Mint.HTTP.connect(http_scheme(uri), uri.host, uri.port), {:ok, conn, ref} <- Mint.WebSocket.upgrade(ws_scheme(uri), conn, ws_path(uri), opts[:headers]), http_reply_message <- receive(do: (message -> message)), @@ -30,7 +31,7 @@ defmodule Crane.Browser.Window.WebSocket do conn: conn, ref: ref, socket: socket, - } + } {:ok, websocket} else @@ -61,12 +62,14 @@ defmodule Crane.Browser.Window.WebSocket do defp ws_path(%URI{path: nil}), do: "/" - defp ws_path(%URI{path: path}), + defp ws_path(%URI{path: path, query: nil}), do: path + defp ws_path(%URI{path: path, query: query}), + do: path <> "?" <> query defp parse_stream_responses(responses, ref) do Enum.reduce(responses, [], fn - {:status, ^ref, status}, acc -> [{:status, status} | acc] + {:status, ^ref, status}, acc -> [{:status, status} | acc] {:headers, ^ref, headers}, acc -> [{:headers, headers} | acc] _other, acc -> acc end) diff --git a/lib/crane/fuse.ex b/lib/crane/fuse.ex index b1f004c..7e3720f 100644 --- a/lib/crane/fuse.ex +++ b/lib/crane/fuse.ex @@ -2,7 +2,7 @@ defmodule Crane.Fuse do alias Req.Response def run_middleware(:visit, %Response{status: 200, body: body}) do - document = GenDOM.Parser.parse_from_string(body, nil, []) + document = GenDOM.Parser.parse_from_string(body, "text/html", []) # {:ok, document} = LiveViewNative.Template.Parser.parse_document(body, # strip_comments: true, # text_as_node: true, diff --git a/lib/crane/utils.ex b/lib/crane/utils.ex index 5ff0598..0a3801b 100644 --- a/lib/crane/utils.ex +++ b/lib/crane/utils.ex @@ -53,9 +53,9 @@ defmodule Crane.Utils do def subscribe(topic) when is_atom(topic), do: Atom.to_string(topic) |> subscribe() - def subscribe(topic) do - pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) - :ok = Phoenix.PubSub.subscribe(pubsub, topic) + def subscribe(topic) do + # pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) + # :ok = Phoenix.PubSub.subscribe(pubsub, topic) end def unsubscribe(%{name: topic}), @@ -65,8 +65,8 @@ defmodule Crane.Utils do do: Atom.to_string(topic) |> unsubscribe() def unsubscribe(topic) do - pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) - :ok = Phoenix.PubSub.unsubscribe(pubsub, topic) + # pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) + # :ok = Phoenix.PubSub.unsubscribe(pubsub, topic) end def broadcast(%{name: topic}, message), @@ -76,7 +76,7 @@ defmodule Crane.Utils do do: Atom.to_string(topic) |> broadcast(message) def broadcast(topic, message) do - pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) - :ok = Phoenix.PubSub.broadcast(pubsub, topic, message) + # pubsub = Application.get_env(:crane, :pubsub, PhoenixPlayground.PubSub) + # :ok = Phoenix.PubSub.broadcast(pubsub, topic, message) end end diff --git a/mix.exs b/mix.exs index 0758b9a..cf68107 100644 --- a/mix.exs +++ b/mix.exs @@ -44,7 +44,7 @@ defmodule Crane.MixProject do [ {:req, "~> 0.5"}, {:inflex, "~> 2.0"}, - {:phoenix_playground, github: "bcardarella/phoenix_playground", branch: "bc-release-compat"}, + # {:phoenix_playground, github: "bcardarella/phoenix_playground", branch: "bc-release-compat"}, {:mint_web_socket, "~> 1.0.4"}, {:floki, "~> 0.37"}, {:websockex, "~> 0.4"}, @@ -60,7 +60,7 @@ defmodule Crane.MixProject do {:gen_dom, github: "liveview-native/gen_dom"}, - {:elixirkit, github: "liveview-native/elixirkit", branch: "main"}, + {:elixir_pack, github: "liveview-native/elixir_pack", branch: "main"}, {:slipstream, "~> 1.2"}, {:plug_crypto, github: "elixir-plug/plug_crypto", branch: "main", override: true}, diff --git a/mix.lock b/mix.lock index cdbde59..20a5e71 100644 --- a/mix.lock +++ b/mix.lock @@ -7,11 +7,12 @@ "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.15.0", "3c97a318a933962d1c12b96ab7c1d728267d2c523c25a5b57b0f93392b6e9e25", [:make, :rebar3], [], "hexpm", "4f00c879a64b4fe7c8fcb42a4281925e9ffdb928820b03c3ad325a617e857532"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, + "elixir_pack": {:git, "https://github.com/liveview-native/elixir_pack.git", "6a5d73c4d64d85797b70d98343b174980110c982", [branch: "main"]}, "elixirkit": {:git, "https://github.com/liveview-native/elixirkit.git", "de095465606bbf408dc44b7969e670db0f1da526", [branch: "main"]}, "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, "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"}, "floki": {:hex, :floki, "0.38.0", "62b642386fa3f2f90713f6e231da0fa3256e41ef1089f83b6ceac7a3fd3abf33", [:mix], [], "hexpm", "a5943ee91e93fb2d635b612caf5508e36d37548e84928463ef9dd986f0d1abd9"}, - "gen_dom": {:git, "https://github.com/liveview-native/gen_dom.git", "66e4df37dd6232a7e16a303c4d2e9efbc0af288c", []}, + "gen_dom": {:git, "https://github.com/liveview-native/gen_dom.git", "b766b43a9a0854f4b3f77239fcedc0975719efcf", []}, "grpc": {:git, "https://github.com/elixir-grpc/grpc.git", "5239816cac1d5eacfeee6dffa2f3df154c4de97c", []}, "gun": {:hex, :gun, "2.1.0", "b4e4cbbf3026d21981c447e9e7ca856766046eff693720ba43114d7f5de36e87", [:make, :rebar3], [{:cowlib, "2.13.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "52fc7fc246bfc3b00e01aea1c2854c70a366348574ab50c57dfe796d24a0101d"}, "hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"},