Skip to content

Commit b134663

Browse files
kixelatedclaude
andauthored
feat(moq-native): support websocket-only client (#1235)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 589f662 commit b134663

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

rs/moq-native/src/client.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ pub struct Client {
135135
}
136136

137137
impl Client {
138-
#[cfg(not(any(feature = "noq", feature = "quinn", feature = "quiche")))]
138+
#[cfg(not(any(feature = "noq", feature = "quinn", feature = "quiche", feature = "websocket")))]
139139
pub fn new(_config: ClientConfig) -> anyhow::Result<Self> {
140-
anyhow::bail!("no QUIC backend compiled; enable noq, quinn, or quiche feature");
140+
anyhow::bail!("no QUIC or WebSocket backend compiled; enable noq, quinn, quiche, or websocket feature");
141141
}
142142

143143
/// Create a new client
144-
#[cfg(any(feature = "noq", feature = "quinn", feature = "quiche"))]
144+
#[cfg(any(feature = "noq", feature = "quinn", feature = "quiche", feature = "websocket"))]
145145
pub fn new(config: ClientConfig) -> anyhow::Result<Self> {
146+
#[cfg(any(feature = "noq", feature = "quinn", feature = "quiche"))]
146147
let backend = config.backend.clone().unwrap_or({
147148
#[cfg(feature = "quinn")]
148149
{
@@ -274,19 +275,37 @@ impl Client {
274275
self
275276
}
276277

277-
#[cfg(not(any(feature = "noq", feature = "quinn", feature = "quiche", feature = "iroh")))]
278+
#[cfg(not(any(
279+
feature = "noq",
280+
feature = "quinn",
281+
feature = "quiche",
282+
feature = "iroh",
283+
feature = "websocket"
284+
)))]
278285
pub async fn connect(&self, _url: Url) -> anyhow::Result<moq_lite::Session> {
279-
anyhow::bail!("no QUIC backend compiled; enable noq, quinn, quiche, or iroh feature");
286+
anyhow::bail!("no backend compiled; enable noq, quinn, quiche, iroh, or websocket feature");
280287
}
281288

282-
#[cfg(any(feature = "noq", feature = "quinn", feature = "quiche", feature = "iroh"))]
289+
#[cfg(any(
290+
feature = "noq",
291+
feature = "quinn",
292+
feature = "quiche",
293+
feature = "iroh",
294+
feature = "websocket"
295+
))]
283296
pub async fn connect(&self, url: Url) -> anyhow::Result<moq_lite::Session> {
284297
let session = self.connect_inner(url).await?;
285298
tracing::info!(version = %session.version(), "connected");
286299
Ok(session)
287300
}
288301

289-
#[cfg(any(feature = "noq", feature = "quinn", feature = "quiche", feature = "iroh"))]
302+
#[cfg(any(
303+
feature = "noq",
304+
feature = "quinn",
305+
feature = "quiche",
306+
feature = "iroh",
307+
feature = "websocket"
308+
))]
290309
async fn connect_inner(&self, url: Url) -> anyhow::Result<moq_lite::Session> {
291310
#[cfg(feature = "iroh")]
292311
if url.scheme() == "iroh" {
@@ -388,7 +407,15 @@ impl Client {
388407
}
389408
}
390409

391-
anyhow::bail!("no QUIC backend compiled; enable noq, quinn, or quiche feature");
410+
#[cfg(feature = "websocket")]
411+
{
412+
let alpns = self.versions.alpns();
413+
let session = crate::websocket::connect(&self.websocket, &self.tls, url, &alpns).await?;
414+
return Ok(self.moq.connect(session).await?);
415+
}
416+
417+
#[cfg(not(feature = "websocket"))]
418+
anyhow::bail!("no QUIC backend matched; this should not happen");
392419
}
393420
}
394421

0 commit comments

Comments
 (0)