@@ -18,8 +18,9 @@ defmodule MOQX do
1818 - request-level failures (`{:moqx_request_error, %MOQX.RequestError{}}`)
1919 - transport/runtime failures (`{:moqx_transport_error, %MOQX.TransportError{}}`)
2020
21- Convenience helpers (`write_frame/2`, `publish_catalog/2`, `fetch_catalog/2`,
22- `await_catalog/2`) are wrappers on top of the core primitives.
21+ Optional convenience flows (`publish_catalog/2`, `update_catalog/2`,
22+ `fetch_catalog/2`, `await_catalog/2`, `await_track_active/2`, etc.) live in
23+ `MOQX.Helpers` on top of this core API.
2324
2425 ## Example
2526
@@ -376,34 +377,6 @@ defmodule MOQX do
376377 end
377378 end
378379
379- @ doc """
380- Creates and publishes the initial catalog object on the `"catalog"` track.
381-
382- This convenience helper composes `create_track/2` and `update_catalog/2`:
383-
384- {:ok, catalog_track} = MOQX.publish_catalog(broadcast, catalog_json)
385-
386- Returns `{:ok, catalog_track}` when both steps succeed.
387- """
388- @ spec publish_catalog ( broadcast ( ) , catalog_payload ( ) ) ::
389- { :ok , track ( ) } | { :error , MOQX.RequestError . t ( ) }
390- def publish_catalog ( broadcast , catalog_payload ) when is_binary ( catalog_payload ) do
391- with { :ok , catalog_track } <- create_track ( broadcast , "catalog" ) ,
392- :ok <- update_catalog ( catalog_track , catalog_payload ) do
393- { :ok , catalog_track }
394- end
395- end
396-
397- @ doc """
398- Writes one catalog object to an existing catalog track.
399-
400- Use this to push catalog updates after the initial `publish_catalog/2` call.
401- """
402- @ spec update_catalog ( track ( ) , catalog_payload ( ) ) :: :ok | { :error , MOQX.RequestError . t ( ) }
403- def update_catalog ( track , catalog_payload ) when is_binary ( catalog_payload ) do
404- write_frame ( track , catalog_payload )
405- end
406-
407380 @ doc """
408381 Writes one frame to a track.
409382
@@ -941,76 +914,6 @@ defmodule MOQX do
941914 end
942915 end
943916
944- @ doc """
945- Fetches the raw catalog track bytes.
946-
947- This is a thin wrapper over `fetch/4` with catalog defaults:
948-
949- - namespace: `"moqtail"`
950- - track name: `"catalog"`
951- - priority: `0`
952- - group order: `:original`
953- - start: `{0, 0}`
954- - end: `{0, 1}`
955- """
956- @ spec fetch_catalog ( session ( ) , Keyword . t ( ) ) ::
957- { :ok , fetch_ref ( ) } | { :error , MOQX.RequestError . t ( ) }
958- def fetch_catalog ( session , opts \\ [ ] ) when is_list ( opts ) do
959- namespace = opts |> Keyword . get ( :namespace , "moqtail" ) |> normalize_fetch_namespace! ( )
960-
961- fetch_opts =
962- opts
963- |> Keyword . delete ( :namespace )
964- |> Keyword . put_new ( :priority , 0 )
965- |> Keyword . put_new ( :group_order , :original )
966- |> Keyword . put_new ( :start , { 0 , 0 } )
967- |> Keyword . put_new ( :end , { 0 , 1 } )
968-
969- fetch ( session , namespace , "catalog" , fetch_opts )
970- end
971-
972- @ doc """
973- Collects fetch messages for `ref` and decodes the payload as a CMSF catalog.
974-
975- Blocks the caller until all objects are received, then concatenates the
976- payloads and passes them to `MOQX.Catalog.decode/1`.
977-
978- Returns `{:ok, catalog}` on success, `{:error, reason}` on fetch failure
979- or decode failure, and `{:error, "timeout"}` if no terminal message arrives
980- within `timeout` milliseconds.
981-
982- ## Example
983-
984- {:ok, ref} = MOQX.fetch_catalog(subscriber, namespace: "moqtail")
985- {:ok, catalog} = MOQX.await_catalog(ref)
986- """
987- @ spec await_catalog ( fetch_ref ( ) , timeout ( ) ) ::
988- { :ok , MOQX.Catalog . t ( ) } | { :error , String . t ( ) }
989- def await_catalog ( ref , timeout \\ 5_000 ) when is_reference ( ref ) do
990- await_catalog_loop ( ref , [ ] , timeout )
991- end
992-
993- defp await_catalog_loop ( ref , acc , timeout ) do
994- receive do
995- { :moqx_fetch_ok , % MOQX.FetchOk { ref: ^ ref } } ->
996- await_catalog_loop ( ref , acc , timeout )
997-
998- { :moqx_fetch_object , % MOQX.FetchObject { ref: ^ ref , payload: payload } } ->
999- await_catalog_loop ( ref , [ acc | [ payload ] ] , timeout )
1000-
1001- { :moqx_fetch_done , % MOQX.FetchDone { ref: ^ ref } } ->
1002- MOQX.Catalog . decode ( IO . iodata_to_binary ( acc ) )
1003-
1004- { :moqx_request_error , % MOQX.RequestError { op: :fetch , ref: ^ ref , message: reason } } ->
1005- { :error , reason }
1006-
1007- { :moqx_transport_error , % MOQX.TransportError { op: :fetch , ref: ^ ref , message: reason } } ->
1008- { :error , reason }
1009- after
1010- timeout -> { :error , "timeout" }
1011- end
1012- end
1013-
1014917 defp validate_fetch_opts_keys! ( opts ) do
1015918 allowed_keys = [ :priority , :group_order , :start , :end ]
1016919
@@ -1020,13 +923,6 @@ defmodule MOQX do
1020923 end
1021924 end
1022925
1023- defp normalize_fetch_namespace! ( namespace ) when is_binary ( namespace ) , do: namespace
1024-
1025- defp normalize_fetch_namespace! ( namespace ) do
1026- raise ArgumentError ,
1027- "expected catalog :namespace to be a string, got: #{ inspect ( namespace ) } "
1028- end
1029-
1030926 defp normalize_fetch_priority! ( priority ) when is_integer ( priority ) and priority in 0 .. 255 ,
1031927 do: priority
1032928
0 commit comments