Skip to content

Commit

Permalink
Handle manifest request with not existing future partial (#100)
Browse files Browse the repository at this point in the history
* Handle manifest request with not existing future partial
* fix linter warns
  • Loading branch information
Karolk99 authored Oct 5, 2023
1 parent 0a3d830 commit 9625b3a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/jellyfish/component/hls/request_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,19 @@ defmodule Jellyfish.Component.HLS.RequestHandler do
[]
end

defp update_and_notify_manifest_ready(status, last_partial) do
{waiting_pids, status} =
status
|> Map.put(:last_partial, last_partial)
|> pop_in([:waiting_pids, last_partial])
defp update_and_notify_manifest_ready(%{waiting_pids: waiting_pids} = status, last_partial) do
partials_ready =
waiting_pids
|> Map.keys()
|> Enum.filter(fn partial -> is_partial_ready(partial, last_partial) end)

partials_ready
|> Enum.flat_map(fn partial -> Map.fetch!(waiting_pids, partial) end)
|> then(&send_partial_ready(&1))

send_partial_ready(waiting_pids)
waiting_pids = Map.drop(waiting_pids, partials_ready)

status
%{status | waiting_pids: waiting_pids, last_partial: last_partial}
end

defp handle_is_partial_ready(status, partial, from) do
Expand Down Expand Up @@ -270,8 +274,6 @@ defmodule Jellyfish.Component.HLS.RequestHandler do

defp registry_id(room_id), do: {:via, Registry, {Jellyfish.RequestHandlerRegistry, room_id}}

defp send_partial_ready(nil), do: nil

defp send_partial_ready(waiting_pids) do
Enum.each(waiting_pids, fn pid -> send(pid, :manifest_ready) end)
end
Expand Down

0 comments on commit 9625b3a

Please sign in to comment.