Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgfn committed Aug 11, 2023
1 parent e8683be commit e520ffc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/jellyfish/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion lib/jellyfish_web/controllers/component_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion lib/jellyfish_web/controllers/peer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit e520ffc

Please sign in to comment.