@@ -29,6 +29,8 @@ import io.livekit.android.room.participant.Participant
2929import io.livekit.android.util.LKLog
3030import livekit.LivekitModels.DataPacket
3131import livekit.LivekitModels.DataStream
32+ import java.io.File
33+ import java.io.InputStream
3234import java.util.Collections
3335import java.util.Date
3436import java.util.concurrent.atomic.AtomicLong
@@ -38,16 +40,53 @@ interface OutgoingDataStreamManager {
3840 /* *
3941 * Start sending a stream of text. Call [TextStreamSender.close] when finished sending.
4042 *
43+ * @see [TextStreamSender.write]
4144 * @throws StreamException if the stream failed to open.
4245 */
4346 suspend fun streamText (options : StreamTextOptions = StreamTextOptions ()): TextStreamSender
4447
4548 /* *
4649 * Start sending a stream of bytes. Call [ByteStreamSender.close] when finished sending.
4750 *
51+ * Extension functions are available for sending bytes from sources such as [InputStream] or [File].
52+ *
53+ * @see [ByteStreamSender.write]
54+ * @see [ByteStreamSender.writeFile]
4855 * @throws StreamException if the stream failed to open.
4956 */
5057 suspend fun streamBytes (options : StreamBytesOptions ): ByteStreamSender
58+
59+ /* *
60+ * Send text through a data stream.
61+ */
62+ @CheckResult
63+ suspend fun sendText (text : String , options : StreamTextOptions = StreamTextOptions ()): Result <Unit > {
64+ val sender = streamText(options)
65+ val result = sender.write(text)
66+
67+ if (result.isFailure) {
68+ sender.close(result.exceptionOrNull()?.message ? : " Unknown error." )
69+ } else {
70+ sender.close()
71+ }
72+ return result
73+ }
74+
75+ /* *
76+ * Send a file through a data stream.
77+ */
78+ @CheckResult
79+ suspend fun sendFile (file : File , options : StreamBytesOptions = StreamBytesOptions ()): Result <Unit > {
80+ val sender = streamBytes(options)
81+ val result = sender.writeFile(file)
82+
83+ if (result.isFailure) {
84+ sender.close(result.exceptionOrNull()?.message ? : " Unknown error." )
85+ } else {
86+ sender.close()
87+ }
88+ return result
89+ }
5190}
5291
5392/* *
0 commit comments