diff --git a/lib/jellyfish/notification.ex b/lib/jellyfish/notification.ex index 17bb4c4..34b6379 100644 --- a/lib/jellyfish/notification.ex +++ b/lib/jellyfish/notification.ex @@ -96,6 +96,28 @@ defmodule Jellyfish.Notification do } end + defmodule HlsUploaded do + @moduledoc nil + + @enforce_keys [:room_id] + defstruct @enforce_keys + + @type t :: %__MODULE__{ + room_id: Room.id() + } + end + + defmodule HlsUploadCrashed do + @moduledoc nil + + @enforce_keys [:room_id] + defstruct @enforce_keys + + @type t :: %__MODULE__{ + room_id: Room.id() + } + end + @discarded_fields [:__unknown_fields__] @doc false diff --git a/lib/jellyfish/room.ex b/lib/jellyfish/room.ex index f5f3b39..84b6d3e 100644 --- a/lib/jellyfish/room.ex +++ b/lib/jellyfish/room.ex @@ -242,13 +242,19 @@ defmodule Jellyfish.Room do end @doc """ - Adds tracks to hls component + Adds peers and components tracks to hls component + + In order to subscribe to HLS peers/components, the HLS component should be initialized with the subscribe_mode set to :manual. + This mode proves beneficial when you do not wish to record or stream all the available streams within a room via HLS. + It allows for selective addition instead – you can manually select specific streams. + For instance, you could opt to record only the stream of an event's host. """ - @spec hls_subscribe(Client.t(), id(), [track_id()]) :: :ok | {:error, atom() | String.t()} - def hls_subscribe(client, room_id, tracks) do - with :ok <- validate_tracks(tracks), + @spec hls_subscribe(Client.t(), id(), [Peer.id() | Component.id()]) :: + :ok | {:error, atom() | String.t()} + def hls_subscribe(client, room_id, origins) do + with :ok <- validate_origins(origins), {:ok, %Env{status: 201}} <- - Tesla.post(client.http_client, "/hls/#{room_id}/subscribe", %{tracks: tracks}) do + Tesla.post(client.http_client, "/hls/#{room_id}/subscribe", %{origins: origins}) do :ok else error -> Utils.handle_response_error(error) @@ -306,8 +312,8 @@ defmodule Jellyfish.Room do defp validate_subscribe_mode(mode) when mode in @subscribe_modes, do: :ok defp validate_subscribe_mode(_mode), do: :error - defp validate_tracks(tracks) when is_list(tracks), do: :ok - defp validate_tracks(_tracks), do: {:error, :tracks_validation} + defp validate_origins(origins) when is_list(origins), do: :ok + defp validate_origins(_tracks), do: {:error, :origins_validation} defp map_snake_case_to_camel_case(%{} = map), do: diff --git a/lib/protos/jellyfish/server_notifications.pb.ex b/lib/protos/jellyfish/server_notifications.pb.ex index dac7696..2dc99ad 100644 --- a/lib/protos/jellyfish/server_notifications.pb.ex +++ b/lib/protos/jellyfish/server_notifications.pb.ex @@ -121,6 +121,22 @@ defmodule Jellyfish.ServerMessage.HlsPlayable do field :component_id, 2, type: :string, json_name: "componentId" end +defmodule Jellyfish.ServerMessage.HlsUploaded do + @moduledoc false + + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" + + field :room_id, 1, type: :string, json_name: "roomId" +end + +defmodule Jellyfish.ServerMessage.HlsUploadCrashed do + @moduledoc false + + use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0" + + field :room_id, 1, type: :string, json_name: "roomId" +end + defmodule Jellyfish.ServerMessage do @moduledoc false @@ -189,4 +205,14 @@ defmodule Jellyfish.ServerMessage do type: Jellyfish.ServerMessage.HlsPlayable, json_name: "hlsPlayable", oneof: 0 + + field :hls_uploaded, 14, + type: Jellyfish.ServerMessage.HlsUploaded, + json_name: "hlsUploaded", + oneof: 0 + + field :hls_upload_crashed, 15, + type: Jellyfish.ServerMessage.HlsUploadCrashed, + json_name: "hlsUploadCrashed", + oneof: 0 end diff --git a/protos b/protos index a6f6971..3781848 160000 --- a/protos +++ b/protos @@ -1 +1 @@ -Subproject commit a6f69712da283d13ae8b6e828694b48fce92a9e5 +Subproject commit 3781848239f67a88866f861fa798a8c18384e666 diff --git a/test/jellyfish/room_test.exs b/test/jellyfish/room_test.exs index 963b039..6212b53 100644 --- a/test/jellyfish/room_test.exs +++ b/test/jellyfish/room_test.exs @@ -48,8 +48,8 @@ defmodule Jellyfish.RoomTest do @invalid_max_peers "abc" @invalid_video_codec :opus - @tracks ["track-id"] - @invalid_tracks %{id: "track-id"} + @origins ["peer-id", "rtsp-id", "file-id"] + @invalid_origins %{id: "peer-id"} @invalid_peer_id "invalid_peer_id" defmodule InvalidPeerOpts do @@ -308,17 +308,17 @@ defmodule Jellyfish.RoomTest do assert {:ok, %Component{properties: %{subscribe_mode: "manual"}}} = Room.add_component(client, room_id, %Component.HLS{subscribe_mode: :manual}) - assert :ok = Room.hls_subscribe(client, room_id, @tracks) + assert :ok = Room.hls_subscribe(client, room_id, @origins) end test "when room doesn't exist", %{client: client} do assert {:error, "Request failed: Room #{@invalid_room_id} does not exist"} = - Room.hls_subscribe(client, @invalid_room_id, @tracks) + Room.hls_subscribe(client, @invalid_room_id, @origins) end test "when hls component doesn't exist", %{client: client, room_id: room_id} do assert {:error, "Request failed: HLS component does not exist"} = - Room.hls_subscribe(client, room_id, @tracks) + Room.hls_subscribe(client, room_id, @origins) end test "when hls component has subscribe mode :auto", %{client: client, room_id: room_id} do @@ -326,14 +326,14 @@ defmodule Jellyfish.RoomTest do Room.add_component(client, room_id, %Jellyfish.Component.HLS{subscribe_mode: :auto}) assert {:error, "Request failed: HLS component option `subscribe_mode` is set to :auto"} = - Room.hls_subscribe(client, room_id, @tracks) + Room.hls_subscribe(client, room_id, @origins) end test "when request is invalid", %{client: client, room_id: room_id} do assert {:ok, %Component{properties: %{subscribe_mode: "manual"}}} = Room.add_component(client, room_id, %Component.HLS{subscribe_mode: :manual}) - assert {:error, :tracks_validation} = Room.hls_subscribe(client, room_id, @invalid_tracks) + assert {:error, :origins_validation} = Room.hls_subscribe(client, room_id, @invalid_origins) end end