From 0958c801160c27cf693a2a56d2f14a9875497229 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 26 Sep 2026 10:03:06 -0700 Subject: [PATCH 1/2] quest: claim kotlin-end From bb9f422fa7cee60be02906fd4a5cbc56e8473fdb Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 26 Sep 2026 10:18:13 -0700 Subject: [PATCH 2/2] feat(kt): end a broadcast with end() Co-Authored-By: Claude Opus 5.5 --- doc/lib/kt/index.md | 5 +++-- kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt | 4 ++-- .../src/jvmAndAndroidMain/kotlin/dev/moq/Server.kt | 7 +++---- .../jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt | 13 +++++++++++++ quest/m1/README.md | 1 - quest/m1/broadcast-remove.md | 1 - quest/m1/kotlin-end.md | 14 -------------- rs/moq-ffi/uniffi.toml | 9 ++++----- 8 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 quest/m1/kotlin-end.md diff --git a/doc/lib/kt/index.md b/doc/lib/kt/index.md index 710cd9ebdd9..3edf1e639ea 100644 --- a/doc/lib/kt/index.md +++ b/doc/lib/kt/index.md @@ -58,8 +58,9 @@ Call `media.discontinuity()` when the source seeks, pauses, or changes its time The three advertising operations: `moq.createBroadcast(path)` (or `origin.createBroadcast`) returns an unannounced producer, invisible to everyone; `broadcast.announce(route)` / `broadcast.unannounce()` own that exact-path -advertisement, and `broadcast.close()` (or `use { }`) releases the producer, -ending the broadcast once no `dynamic()` handle remains; `origin.dynamic(prefix, route)` claims `prefix` and every +advertisement; `broadcast.end()` ends the broadcast for good, while +`broadcast.close()` (or `use { }`) only releases the handle, ending the +broadcast once no `dynamic()` handle remains; `origin.dynamic(prefix, route)` claims `prefix` and every path beneath it (`""` for everything). Hold the returned `OriginDynamic` while the claim should stay advertised, and reject the requests you will not serve. A route is a capability, not an inventory. `announcements(config)` takes diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt index dec946bc2f8..f3966d10def 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt @@ -22,8 +22,8 @@ class Moq internal constructor( /** * Create an unannounced broadcast at [path], invisible to everyone until announced. * - * Advertise it with `announce` after populating tracks. `close()` (or `use`) ends it once no - * `dynamic()` handle remains. + * Advertise it with `announce` after populating tracks. `end()` ends it immediately; + * `close()` (or `use`) ends it once no `dynamic()` handle remains. */ fun createBroadcast(path: String): BroadcastProducer = session.publish().createBroadcast(path) diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Server.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Server.kt index 9257ba51ddf..02e3aba2cd8 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Server.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Server.kt @@ -30,11 +30,10 @@ class Server internal constructor( private val publishOrigin: OriginProducer?, ) : AutoCloseable { /** - * Create a live broadcast at [path], served to incoming sessions. + * Create an unannounced broadcast at [path], served to incoming sessions once announced. * - * The origin announces the path so subscribers can discover it, becoming visible - * Advertise it with `announce` after populating tracks. `close()` (or `use`) - * ends it once no `dynamic()` handle remains. + * Advertise it with `announce` after populating tracks. `end()` ends it immediately; + * `close()` (or `use`) ends it once no `dynamic()` handle remains. */ fun createBroadcast(path: String): BroadcastProducer { val origin = publishOrigin ?: throw IllegalStateException("no publish origin configured") diff --git a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt index 9cd8e325177..987808968f8 100644 --- a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt +++ b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt @@ -142,6 +142,19 @@ class SmokeTest { assertFailsWith { consumer.subscribeTrack("events", null) } } + @Test + fun `end ends a broadcast while a dynamic handle is still held`() = runTest { + BroadcastProducer().use { broadcast -> + broadcast.dynamic().use { + val consumer = broadcast.consume() + broadcast.end() + broadcast.end() + assertFailsWith { consumer.subscribeTrack("events", null) } + assertFailsWith { broadcast.publishTrack("events", null) } + } + } + } + @Test fun `broadcast updates shared video properties`() { BroadcastProducer().use { broadcast -> diff --git a/quest/m1/README.md b/quest/m1/README.md index bf58cf9600c..0b7c71ff13b 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -28,7 +28,6 @@ transport, benchmark tooling); worktrees isolate commits, not semantics. - [Binding audio delay](/quest/m1/binding-surface.md) - moq-ffi, libmoq, and every wrapper configure and observe audio playout delay - [FFI shape](/quest/m1/ffi-shape/README.md) - the bindings mirror Rust's layers: net at the root, then media, json, audio, and video namespaces built from the handle below - [Track demand](/quest/m1/track-demand.md) - Rust and JS watch a track's subscribers through `demand()` alone -- [Kotlin end](/quest/m1/kotlin-end.md) - Kotlin exposes `close()` as `end()`, since `AutoCloseable.close()` takes the name - [Remove finish](/quest/m1/broadcast-remove.md) - on dev, the deprecated broadcast end APIs are gone and `closed()` carries no cause - [CLI inspection](/quest/m1/cli-inspect/README.md) - `moq ls` lists what is live and `moq fetch` reads a group over MoQ, and a guide shows how to inspect a relay - [Session close](/quest/m1/session-close.md) - a graceful session end withdraws announces and waits one second for the ack diff --git a/quest/m1/broadcast-remove.md b/quest/m1/broadcast-remove.md index 6522ebecec6..f95e2b83490 100644 --- a/quest/m1/broadcast-remove.md +++ b/quest/m1/broadcast-remove.md @@ -18,5 +18,4 @@ This is a published API break, so it targets `dev`. ## Required -- [Kotlin end](/quest/m1/kotlin-end.md) - Kotlin keeps a forced end once `finish` is gone - `main` merged into `dev` once #4031 lands, so the deprecations exist there diff --git a/quest/m1/kotlin-end.md b/quest/m1/kotlin-end.md deleted file mode 100644 index 44516dd62cc..00000000000 --- a/quest/m1/kotlin-end.md +++ /dev/null @@ -1,14 +0,0 @@ -# [XS] Kotlin end - -## Goal - -Kotlin can force-end a broadcast after `finish` is removed. Its -`MoqBroadcastProducer` exposes the moq-ffi `close()` as `end()`, because a -generated `close()` would collide with `AutoCloseable.close()`. - -## Plan - -- Rename the method for Kotlin only in `rs/moq-ffi/uniffi.toml`; every other - binding keeps `close()`. Kotlin's `close()` still only releases the handle. -- Test that `end()` ends the broadcast while a `dynamic()` handle is still - held. Document it in `doc/lib/kt`. diff --git a/rs/moq-ffi/uniffi.toml b/rs/moq-ffi/uniffi.toml index ddf0c572fed..9fe25f30f46 100644 --- a/rs/moq-ffi/uniffi.toml +++ b/rs/moq-ffi/uniffi.toml @@ -1,5 +1,4 @@ -# Kotlin objects are AutoCloseable, and `close()` there releases the handle, -# which ends the broadcast like dropping the last Rust producer. A generated -# `close()` would collide with it. -[bindings.kotlin] -exclude = ["MoqBroadcastProducer.close"] +# Kotlin objects are AutoCloseable, and `close()` there only releases the handle. +# A generated `close()` would collide with it, so Kotlin names the method `end()`. +[bindings.kotlin.rename] +"MoqBroadcastProducer.close" = "end"