From e520ffc5dd791bee4e2d03d362b89cc1915254ef Mon Sep 17 00:00:00 2001 From: Jakub Pisarek <99591440+sgfn@users.noreply.github.com> Date: Fri, 11 Aug 2023 14:53:50 +0200 Subject: [PATCH] Review fixes --- lib/jellyfish/room.ex | 12 ++++++------ .../controllers/component_controller.ex | 2 +- lib/jellyfish_web/controllers/peer_controller.ex | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jellyfish/room.ex b/lib/jellyfish/room.ex index 6abb9e5d..bf71e36d 100644 --- a/lib/jellyfish/room.ex +++ b/lib/jellyfish/room.ex @@ -72,9 +72,9 @@ defmodule Jellyfish.Room do end end - @spec add_peer(id(), Peer.peer(), map() | nil) :: + @spec add_peer(id(), Peer.peer(), map()) :: {:ok, Peer.t()} | :error | {:error, :reached_peers_limit} - def add_peer(room_id, peer_type, options) do + def add_peer(room_id, peer_type, options \\ %{}) do GenServer.call(registry_id(room_id), {:add_peer, peer_type, options}) end @@ -95,9 +95,9 @@ defmodule Jellyfish.Room do GenServer.call(registry_id(room_id), {:remove_peer, peer_id}) end - @spec add_component(id(), Component.component(), map() | nil) :: + @spec add_component(id(), Component.component(), map()) :: {:ok, Component.t()} | :error | {:error, :incompatible_codec} - def add_component(room_id, component_type, options) do + def add_component(room_id, component_type, options \\ %{}) do GenServer.call(registry_id(room_id), {:add_component, component_type, options}) end @@ -138,7 +138,7 @@ defmodule Jellyfish.Room do network_options: state.network_options, video_codec: state.config.video_codec }, - if(is_nil(options), do: %{}, else: options) + options ) with {:ok, peer} <- Peer.new(peer_type, options) do @@ -223,7 +223,7 @@ defmodule Jellyfish.Room do options = Map.merge( %{engine_pid: state.engine_pid, room_id: state.id}, - if(is_nil(options), do: %{}, else: options) + options ) with :ok <- check_video_codec(video_codec, component_type), diff --git a/lib/jellyfish_web/controllers/component_controller.ex b/lib/jellyfish_web/controllers/component_controller.ex index 02fa2b72..2a4da461 100644 --- a/lib/jellyfish_web/controllers/component_controller.ex +++ b/lib/jellyfish_web/controllers/component_controller.ex @@ -59,7 +59,7 @@ defmodule JellyfishWeb.ComponentController do ] def create(conn, %{"room_id" => room_id} = params) do - with component_options <- Map.get(params, "options"), + with component_options <- Map.get(params, "options", %{}), {:ok, component_type_string} <- Map.fetch(params, "type"), {:ok, component_type} <- Component.parse_type(component_type_string), {:ok, _room_pid} <- RoomService.find_room(room_id), diff --git a/lib/jellyfish_web/controllers/peer_controller.ex b/lib/jellyfish_web/controllers/peer_controller.ex index b6fb4162..429ed11d 100644 --- a/lib/jellyfish_web/controllers/peer_controller.ex +++ b/lib/jellyfish_web/controllers/peer_controller.ex @@ -65,7 +65,7 @@ defmodule JellyfishWeb.PeerController do # pid and adding a new peer to it # in such a case, the controller will fail # and Phoenix will return 500 - with peer_options <- Map.get(params, "options"), + with peer_options <- Map.get(params, "options", %{}), {:ok, peer_type_string} <- Map.fetch(params, "type"), {:ok, peer_type} <- Peer.parse_type(peer_type_string), {:ok, _room_pid} <- RoomService.find_room(room_id),