From bb1c98eb3c4f26cd85319fd5c5e748b69c1a3356 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Wed, 1 Mar 2023 22:08:26 -0500 Subject: [PATCH 1/3] Broadcast host_changed events when hub.host changes --- lib/ret/hub.ex | 6 ++++++ lib/ret_web/channels/hub_channel.ex | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/ret/hub.ex b/lib/ret/hub.ex index f0ae72bbf..aa21402db 100644 --- a/lib/ret/hub.ex +++ b/lib/ret/hub.ex @@ -656,6 +656,12 @@ defmodule Ret.Hub do if host && host != hub.host do hub |> changeset_for_new_host(host) |> Repo.update!() + + RetWeb.Endpoint.broadcast("hub:" <> hub.hub_sid, "host_changed", %{ + host: host, + port: Hub.janus_port(), + turn: Hub.generate_turn_info() + }) else hub end diff --git a/lib/ret_web/channels/hub_channel.ex b/lib/ret_web/channels/hub_channel.ex index 951741b39..389526073 100644 --- a/lib/ret_web/channels/hub_channel.ex +++ b/lib/ret_web/channels/hub_channel.ex @@ -834,6 +834,11 @@ defmodule RetWeb.HubChannel do {:noreply, socket} end + def handle_out("host_changed" = event, payload, socket) do + push(socket, event, payload) + {:noreply, socket} + end + defp maybe_push_naf( socket, event, From 59362e6ea46f8480b143a1f3cd2a5b8b9e970c4d Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Wed, 1 Mar 2023 22:23:11 -0500 Subject: [PATCH 2/3] Add methods to trigger a host change --- lib/ret/hub.ex | 12 ++++++++++++ lib/ret_web/channels/hub_channel.ex | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/lib/ret/hub.ex b/lib/ret/hub.ex index aa21402db..ccd8cd3a8 100644 --- a/lib/ret/hub.ex +++ b/lib/ret/hub.ex @@ -668,6 +668,18 @@ defmodule Ret.Hub do end end + def test_change_host(hub) do + host = RoomAssigner.get_available_host(hub.host) + + hub |> changeset_for_new_host(host) |> Repo.update!() + + RetWeb.Endpoint.broadcast("hub:" <> hub.hub_sid, "host_changed", %{ + host: host, + port: Hub.janus_port(), + turn: Hub.generate_turn_info() + }) + end + # Remove the host entry from any rooms that are older than a day old and have no presence def vacuum_hosts do Ret.Locking.exec_if_lockable(:hub_vacuum_hosts, fn -> diff --git a/lib/ret_web/channels/hub_channel.ex b/lib/ret_web/channels/hub_channel.ex index 389526073..dc80f34df 100644 --- a/lib/ret_web/channels/hub_channel.ex +++ b/lib/ret_web/channels/hub_channel.ex @@ -712,6 +712,11 @@ defmodule RetWeb.HubChannel do end end + def handle_in("test_change_host", _payload, socket) do + Hub.test_change_host(hub_for_socket(socket)) + {:noreply, socket} + end + def handle_in(_message, _payload, socket) do {:noreply, socket} end From 37a01f1cbd31fb0ec2f1ec32f6b20c2be8b674b7 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Wed, 1 Mar 2023 22:37:31 -0500 Subject: [PATCH 3/3] Remove test_change_host --- lib/ret/hub.ex | 12 ------------ lib/ret_web/channels/hub_channel.ex | 5 ----- 2 files changed, 17 deletions(-) diff --git a/lib/ret/hub.ex b/lib/ret/hub.ex index ccd8cd3a8..aa21402db 100644 --- a/lib/ret/hub.ex +++ b/lib/ret/hub.ex @@ -668,18 +668,6 @@ defmodule Ret.Hub do end end - def test_change_host(hub) do - host = RoomAssigner.get_available_host(hub.host) - - hub |> changeset_for_new_host(host) |> Repo.update!() - - RetWeb.Endpoint.broadcast("hub:" <> hub.hub_sid, "host_changed", %{ - host: host, - port: Hub.janus_port(), - turn: Hub.generate_turn_info() - }) - end - # Remove the host entry from any rooms that are older than a day old and have no presence def vacuum_hosts do Ret.Locking.exec_if_lockable(:hub_vacuum_hosts, fn -> diff --git a/lib/ret_web/channels/hub_channel.ex b/lib/ret_web/channels/hub_channel.ex index dc80f34df..389526073 100644 --- a/lib/ret_web/channels/hub_channel.ex +++ b/lib/ret_web/channels/hub_channel.ex @@ -712,11 +712,6 @@ defmodule RetWeb.HubChannel do end end - def handle_in("test_change_host", _payload, socket) do - Hub.test_change_host(hub_for_socket(socket)) - {:noreply, socket} - end - def handle_in(_message, _payload, socket) do {:noreply, socket} end