@@ -57,6 +57,8 @@ defmodule MOQX.MOQLite04.Client do
5757 @ type operation_result ::
5858 { :ok , t ( ) , Stream . t ( ) , [ term ( ) ] } | { :error , t ( ) , term ( ) , [ term ( ) ] }
5959
60+ @ type accept_result :: { :ok , t ( ) , Stream . t ( ) } | { :error , t ( ) , term ( ) }
61+
6062 @ doc """
6163 Connects to a native QUIC MOQ Lite draft-04 endpoint.
6264 """
@@ -136,6 +138,27 @@ defmodule MOQX.MOQLite04.Client do
136138 end
137139 end
138140
141+ @ doc """
142+ Accepts a peer-opened stream and starts active transport delivery.
143+ """
144+ @ spec accept_stream ( t ( ) , timeout ( ) ) :: accept_result ( )
145+ def accept_stream ( % __MODULE__ { } = client , timeout \\ :infinity ) do
146+ with { :ok , stream , context } <-
147+ Transport . accept_stream ( client . context , client . connection , [ ] , timeout ) ,
148+ { :ok , context } <- Transport . set_active ( context , stream , true ) do
149+ { :ok , put_context ( client , context ) , stream }
150+ else
151+ { :error , reason , context } ->
152+ error =
153+ Error . new ( :transport_action_failed ,
154+ action: :accept_stream ,
155+ details: % { transport_reason: reason }
156+ )
157+
158+ { :error , put_context ( client , context ) , error }
159+ end
160+ end
161+
139162 @ doc """
140163 Opens an Announce transaction stream and sends `ANNOUNCE_INTEREST`.
141164 """
@@ -196,6 +219,43 @@ defmodule MOQX.MOQLite04.Client do
196219 open_transaction ( client , :goaway , message )
197220 end
198221
222+ @ doc """
223+ Sends `ANNOUNCE` on an existing Announce transaction stream.
224+ """
225+ @ spec announce ( t ( ) , Stream . t ( ) , MOQLite04.Announce . t ( ) ) :: operation_result ( )
226+ def announce ( % __MODULE__ { } = client , % Stream { } = stream , % MOQLite04.Announce { } = message ) do
227+ send_on_transaction ( client , stream , :announce , message )
228+ end
229+
230+ @ doc """
231+ Sends `SUBSCRIBE_OK` on an existing Subscribe transaction stream.
232+ """
233+ @ spec subscribe_ok ( t ( ) , Stream . t ( ) , MOQLite04.SubscribeOk . t ( ) ) :: operation_result ( )
234+ def subscribe_ok ( % __MODULE__ { } = client , % Stream { } = stream , % MOQLite04.SubscribeOk { } = message ) do
235+ send_on_transaction ( client , stream , :subscribe , message )
236+ end
237+
238+ @ doc """
239+ Sends `SUBSCRIBE_DROP` on an existing Subscribe transaction stream.
240+ """
241+ @ spec subscribe_drop ( t ( ) , Stream . t ( ) , MOQLite04.SubscribeDrop . t ( ) ) :: operation_result ( )
242+ def subscribe_drop (
243+ % __MODULE__ { } = client ,
244+ % Stream { } = stream ,
245+ % MOQLite04.SubscribeDrop { } = message
246+ ) do
247+ send_on_transaction ( client , stream , :subscribe , message )
248+ end
249+
250+ @ doc """
251+ Opens a publisher Group stream and sends `GROUP` followed by `FRAME` messages.
252+ """
253+ @ spec publish_group ( t ( ) , MOQLite04.Group . t ( ) , [ MOQLite04.Frame . t ( ) ] ) :: operation_result ( )
254+ def publish_group ( % __MODULE__ { } = client , % MOQLite04.Group { } = group , frames )
255+ when is_list ( frames ) do
256+ open_group_stream ( client , [ group | frames ] )
257+ end
258+
199259 defp reject_mode ( opts ) do
200260 if Keyword . has_key? ( opts , :mode ) do
201261 { :error , { :unsupported_option , :mode } }
@@ -279,8 +339,30 @@ defmodule MOQX.MOQLite04.Client do
279339 end
280340 end
281341
342+ defp open_group_stream ( % __MODULE__ { } = client , messages ) do
343+ case Transport . open_stream ( client . context , client . connection , direction: :unidirectional ) do
344+ { :ok , stream , context } ->
345+ client
346+ |> put_context ( context )
347+ |> send_on_stream ( stream , :group , messages )
348+
349+ { :error , reason , context } ->
350+ error =
351+ Error . new ( :transport_action_failed ,
352+ action: { :open_stream , :group } ,
353+ details: % { transport_reason: reason }
354+ )
355+
356+ { :error , put_context ( client , context ) , error , [ ] }
357+ end
358+ end
359+
282360 defp send_on_transaction ( % __MODULE__ { } = client , % Stream { } = stream , stream_type , message ) do
283- case command ( client , { :send , stream , stream_type , [ message ] } ) do
361+ send_on_stream ( client , stream , stream_type , [ message ] )
362+ end
363+
364+ defp send_on_stream ( % __MODULE__ { } = client , % Stream { } = stream , stream_type , messages ) do
365+ case command ( client , { :send , stream , stream_type , messages } ) do
284366 { :ok , client , events } -> { :ok , client , stream , events }
285367 { :error , client , reason , events } -> { :error , client , reason , events }
286368 end
0 commit comments