Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Bugfix handle room deleted (#72)
Browse files Browse the repository at this point in the history
* Modify handle_call add_peer

* Fixes

* Fix add_peer method

* Fix tests
  • Loading branch information
Rados13 authored Apr 23, 2024
1 parent f10550f commit 6d21195
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
21 changes: 19 additions & 2 deletions lib/videoroom/meeting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Videoroom.Meeting do

alias Jellyfish.Component
alias Jellyfish.Room
alias Jellyfish.Notification.{PeerCrashed, RoomCrashed}
alias Jellyfish.Notification.{PeerCrashed, RoomCrashed, RoomDeleted}

alias Videoroom.RoomRegistry

Expand Down Expand Up @@ -51,6 +51,18 @@ defmodule Videoroom.Meeting do

{:error,
"Failed to call add peer to meeting #{meeting_name} because of error: #{inspect(error)}"}

:exit, {:room_not_exist, _} ->
Logger.error(
"Failed to call add peer because room created by #{meeting_name} doesn't exist on jellyfish"
)

{:error,
"Failed to call add peer because room created by #{meeting_name} doesn't exist on jellyfish"}

:exit, {:normal, _} ->
Logger.error("Failed to call add peer because meeting is removed")
{:error, "Meeting is being removed"}
end
end

Expand Down Expand Up @@ -151,7 +163,7 @@ defmodule Videoroom.Meeting do
"Failed to add peer, because of room #{state.room_id} does not exist on jellyfish: #{state.jellyfish_address}"
)

{:stop, :normal, {:error, "Failed to add peer"}, state}
{:stop, :room_not_exist, {:error, "Failed to add peer"}, state}

error ->
Logger.error(
Expand Down Expand Up @@ -197,6 +209,11 @@ defmodule Videoroom.Meeting do
{:stop, :normal, state}
end

defp handle_notification(%RoomDeleted{}, state) do
Logger.info("Room #{state.room_id} was deleted")
{:stop, :normal, state}
end

defp handle_notification(notification, state) do
Logger.info("Notification: #{inspect(notification)}")
{:noreply, state}
Expand Down
20 changes: 1 addition & 19 deletions lib/videoroom/room_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Videoroom.RoomService do
{Videoroom.Meeting, %{name: room_name, jellyfish_address: jellyfish_address}}
) do
{:error, {:already_started, _}} ->
nil
Logger.debug("Room with name #{room_name} is already started")

{:error, error} ->
Logger.error("During spawning child error occurs: #{inspect(error)}")
Expand Down Expand Up @@ -83,24 +83,6 @@ defmodule Videoroom.RoomService do
{:noreply, state}
end

@impl true
def handle_info({:jellyfish, %Jellyfish.Notification.RoomDeleted{room_id: room_id}}, state) do
case RoomRegistry.lookup_room(room_id) do
{:ok, room} ->
Meeting.stop(room)

{:error, :unregistered} ->
Logger.debug("""
Received RoomDeleted notification but room doesn't exist in registry,
that means we already removed it
""")

nil
end

{:noreply, state}
end

@impl true
def handle_info({:DOWN, _ref, :process, _object, _reason}, state) do
Logger.warning("Jellyfish WSNotifier exited. Starting new notifier")
Expand Down
2 changes: 1 addition & 1 deletion test/videoroom_web/controllers/room_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule VideoroomWeb.RoomJsonTest do
assert_receive {:jellyfish, %RoomDeleted{room_id: ^jf_room_id}}, @timeout

conn = get(conn, ~p"/api/room/#{meeting_name}")
assert json_response(conn, 503)["errors"] == "Failed to add peer"
assert json_response(conn, 503)["errors"] == "Meeting is being removed"

{_name, _token} = add_peer(conn, meeting_name)
end
Expand Down

0 comments on commit 6d21195

Please sign in to comment.