added prelude & cleaned imports (#27)

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
Théo Monnom
2023-01-10 22:57:27 +01:00
committed by GitHub
parent 1168e5ae89
commit 4c5828b9c0
31 changed files with 345 additions and 329 deletions
+8 -12
View File
@@ -1,13 +1,9 @@
use std::fmt::Debug;
use std::time::Duration;
use crate::proto::{signal_request, signal_response, JoinResponse};
use crate::proto;
use crate::signal_client::signal_stream::SignalStream;
use livekit_webrtc::peer_connection_factory::{
ContinualGatheringPolicy, ICEServer, IceTransportsType, RTCConfiguration,
};
use livekit_webrtc::prelude::*;
use parking_lot::RwLock;
use std::fmt::Debug;
use std::time::Duration;
use thiserror::Error;
use tokio::sync::mpsc;
use tokio_tungstenite::tungstenite::Error as WsError;
@@ -37,7 +33,7 @@ pub enum SignalError {
#[derive(Debug)]
pub enum SignalEvent {
Open,
Signal(signal_response::Message),
Signal(proto::signal_response::Message),
Close,
}
@@ -98,7 +94,7 @@ impl SignalClient {
}
#[instrument(level = Level::DEBUG)]
pub async fn send(&self, signal: signal_request::Message) {
pub async fn send(&self, signal: proto::signal_request::Message) {
if let Some(stream) = self.stream.read().as_ref() {
if stream.send(signal).await.is_ok() {
return;
@@ -118,8 +114,8 @@ impl SignalClient {
}
}
impl From<JoinResponse> for RTCConfiguration {
fn from(join_response: JoinResponse) -> Self {
impl From<proto::JoinResponse> for RTCConfiguration {
fn from(join_response: proto::JoinResponse) -> Self {
Self {
ice_servers: {
let mut servers = vec![];
+6 -8
View File
@@ -1,19 +1,17 @@
use crate::proto;
use crate::signal_client::{SignalEmitter, SignalEvent, SignalOptions, SignalResult};
use futures_util::stream::{SplitSink, SplitStream};
use futures_util::{SinkExt, StreamExt};
use prost::Message as ProstMessage;
use tokio::net::TcpStream;
use tokio::sync::{mpsc, oneshot};
use tokio::task::JoinHandle;
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
use tokio_tungstenite::tungstenite::protocol::CloseFrame;
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
use tracing::{event, Level};
use crate::proto::{signal_request, SignalRequest, SignalResponse};
use crate::signal_client::{SignalEmitter, SignalEvent, SignalOptions, SignalResult};
pub const PROTOCOL_VERSION: u32 = 8;
type WebSocket = WebSocketStream<MaybeTlsStream<TcpStream>>;
@@ -21,7 +19,7 @@ type WebSocket = WebSocketStream<MaybeTlsStream<TcpStream>>;
#[derive(Debug)]
enum InternalMessage {
Signal {
signal: signal_request::Message,
signal: proto::signal_request::Message,
response_chn: oneshot::Sender<SignalResult<()>>,
},
Pong {
@@ -107,7 +105,7 @@ impl SignalStream {
/// Send a SignalRequest to the websocket
/// It also waits for the message to be sent
pub async fn send(&self, signal: signal_request::Message) -> SignalResult<()> {
pub async fn send(&self, signal: proto::signal_request::Message) -> SignalResult<()> {
let (send, recv) = oneshot::channel();
let msg = InternalMessage::Signal {
signal,
@@ -133,7 +131,7 @@ impl SignalStream {
event!(Level::TRACE, "sending SignalRequest: {:?}", signal);
let data = Message::Binary(
SignalRequest {
proto::SignalRequest {
message: Some(signal),
}
.encode_to_vec(),
@@ -178,7 +176,7 @@ impl SignalStream {
while let Some(msg) = ws_reader.next().await {
match msg {
Ok(Message::Binary(data)) => {
let res = SignalResponse::decode(data.as_slice())
let res = proto::SignalResponse::decode(data.as_slice())
.expect("failed to decode SignalResponse");
let msg = res.message.unwrap();