sdroege/async-tungstenite

Can't find `tungstenite::client::IntoClientRequest`

evaporei opened this issue ยท 5 comments

Hello! I'm having issues with the latest 0.24.0 version, the IntoClientRequest is not being found.

2023-12-12_17-52

And I've faced this too in a plugin I'm developing for gst-plugins-rs.

2023-12-12_15-28

I've tried cargo clean, cargo update, rustup update and cloning the repo in a new folder, and nothing fixes the issue.

By looking at the code, I see that in 0.21 of tungstenite, the client module is behind the handshake feature. However this is default here.

Do you know what could be causing this issue and how to fix it?

Thanks, I'll take a look tomorrow. That looks a bit concerning.

I assume this is reproducible directly with the latest version of your branch in https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1362 ?

I assume this is reproducible directly with the latest version of your branch in https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1362 ?

Yup! Thanks ๐Ÿ™‚

That's a problem on your side. You're using http 0.2 with async-tungstenite 0.24 / tungstenite 0.21 but those versions were already ported to http 1.0. As another part (the AWS SDK) requires http 0.2 still, you need to depend on both here and carefully use the correct version.

Something like this works:

diff --git a/net/webrtc/Cargo.toml b/net/webrtc/Cargo.toml
index 25295da80..5cf926a39 100644
--- a/net/webrtc/Cargo.toml
+++ b/net/webrtc/Cargo.toml
@@ -57,6 +57,7 @@ livekit-api = { version = "0.2", default-features = false, features = ["signal-c
 warp = "0.3"
 crossbeam-channel = "0.5"
 rand = "0.8"
+http_1 = { version = "1.0", package = "http" }
 
 [dev-dependencies]
 tracing = { version = "0.1", features = ["log"] }
diff --git a/net/webrtc/src/janusvr_signaller/imp.rs b/net/webrtc/src/janusvr_signaller/imp.rs
index 182f2f41b..613888f8b 100644
--- a/net/webrtc/src/janusvr_signaller/imp.rs
+++ b/net/webrtc/src/janusvr_signaller/imp.rs
@@ -4,7 +4,7 @@ use crate::signaller::{Signallable, SignallableImpl, CAT};
 use crate::RUNTIME;
 
 use anyhow::{anyhow, Error};
-use async_tungstenite::tungstenite;
+use async_tungstenite::tungstenite::{client::IntoClientRequest, Message as WsMessage};
 use futures::channel::mpsc;
 use futures::sink::SinkExt;
 use futures::stream::StreamExt;
@@ -12,14 +12,13 @@ use gst::glib;
 use gst::glib::Properties;
 use gst::prelude::*;
 use gst::subclass::prelude::*;
-use http::Uri;
+use http_1::Uri;
 use rand::prelude::*;
 use serde::{Deserialize, Serialize};
 use std::ops::ControlFlow;
 use std::sync::Mutex;
 use std::time::Duration;
 use tokio::{task, time::timeout};
-use tungstenite::Message as WsMessage;
 
 fn transaction_id() -> String {
     thread_rng()
@@ -203,7 +202,6 @@ impl Signaller {
     }
 
     async fn connect(&self) -> Result<(), Error> {
-        use tungstenite::client::IntoClientRequest;
         let settings = self.settings.lock().unwrap().clone();
         let mut request = settings
             .janus_endpoint
@@ -211,7 +209,7 @@ impl Signaller {
             .into_client_request()?;
         request.headers_mut().append(
             "Sec-WebSocket-Protocol",
-            http::HeaderValue::from_static("janus-protocol"),
+            http_1::HeaderValue::from_static("janus-protocol"),
         );
 
         let (ws, _) = timeout(

Oh nice, thanks!! Sorry for bothering ๐Ÿ˜…

Well, the compiler error was not very helpful at all :)