From ad61063c0dd1d5ed0841797c6848997e91863623 Mon Sep 17 00:00:00 2001 From: Silas Date: Sat, 25 Nov 2023 09:36:28 -0500 Subject: [PATCH] fix bug where document genserver hasn't started by the time the client connects to its channel --- lib/poex_web/channels/pad_channel.ex | 5 +++++ lib/poex_web/live/pad/pad_live.ex | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/poex_web/channels/pad_channel.ex b/lib/poex_web/channels/pad_channel.ex index fef1fac..d37f3da 100644 --- a/lib/poex_web/channels/pad_channel.ex +++ b/lib/poex_web/channels/pad_channel.ex @@ -1,5 +1,8 @@ defmodule PoexWeb.PadChannel do use Phoenix.Channel + alias Poex.Pads.DocumentDynamicSupervisor + alias Poex.Repo + alias Poex.Pads.Document alias Poex.Pads.DocumentServer @moduledoc """ @@ -11,6 +14,8 @@ defmodule PoexWeb.PadChannel do end def join("pad:" <> document_id, _params, socket) do + document = Repo.get!(Document, document_id) + DocumentDynamicSupervisor.start_document_server(document) contents = DocumentServer.get_contents(document_id) {:ok, %{uuid: socket.assigns.uuid, contents: contents}, diff --git a/lib/poex_web/live/pad/pad_live.ex b/lib/poex_web/live/pad/pad_live.ex index 8279ff2..38171fd 100644 --- a/lib/poex_web/live/pad/pad_live.ex +++ b/lib/poex_web/live/pad/pad_live.ex @@ -24,6 +24,7 @@ defmodule PoexWeb.PadLive do contents: contents } = document = Repo.get!(Document, id) + # TODO: do we need to start the server here? DocumentDynamicSupervisor.start_document_server(document) # init editor and assigns with latest state from doc