refactor: 🔥 removed wrong implemented tls in streamer

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-04-16 23:31:17 +03:00
parent 68a280fc80
commit 5713bec4ae
2 changed files with 5 additions and 39 deletions

View file

@ -1,16 +1,10 @@
use std::{
fs::File,
io::{self, BufReader, Write},
sync::Arc,
time::Duration,
};
use std::{io::Write, time::Duration};
use brotli::CompressorWriter;
use futures_util::SinkExt;
use ringbuf::HeapRb;
use tokio::sync::broadcast::{channel, Receiver, Sender};
use tokio_rustls::rustls::{pki_types::CertificateDer, ClientConfig, RootCertStore};
use tokio_tungstenite::{tungstenite::Message, Connector, WebSocketStream};
use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
use crate::BUFFER_LENGTH;
const MAX_TOLERATED_MESSAGE_COUNT: usize = 10;
@ -18,31 +12,8 @@ const MAX_TOLERATED_MESSAGE_COUNT: usize = 10;
pub async fn start(sound_stream_consumer: Receiver<f32>) {
let connect_addr = "wss://192.168.1.2:2525";
let certs: io::Result<Vec<CertificateDer<'static>>> = rustls_pemfile::certs(
&mut BufReader::new(File::open("certificates/cert.pem").unwrap()),
)
.collect();
let certs = certs.unwrap();
let mut root_cert_store = RootCertStore::empty();
for cert in certs {
root_cert_store.add(cert).unwrap();
}
let config = ClientConfig::builder()
.with_root_certificates(root_cert_store)
.with_no_client_auth();
let connector = Connector::Rustls(Arc::new(config));
let ws_stream;
match tokio_tungstenite::connect_async_tls_with_config(
connect_addr,
None,
false,
Some(connector),
)
.await
{
match tokio_tungstenite::connect_async(connect_addr).await {
Ok(ws_stream_connected) => ws_stream = ws_stream_connected.0,
Err(_) => {
return;