-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
219 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod ipc; | ||
pub mod media_data_tracker; | ||
mod mprc; | ||
mod multi_sender; | ||
pub mod stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use jz_action::network::datatransfer::{ | ||
data_stream_client::DataStreamClient, MediaDataBatchResponse, | ||
}; | ||
use tokio::time::Instant; | ||
use std::collections::{hash_map::Entry, HashMap}; | ||
use tonic::transport::Channel; | ||
use tracing::error; | ||
|
||
pub struct MultiSender { | ||
streams: Vec<String>, | ||
|
||
connects: Vec<Option<DataStreamClient<Channel>>>, | ||
} | ||
|
||
impl MultiSender { | ||
pub fn new(streams: Vec<String>) -> Self { | ||
let connects = streams.iter().map(|_| None).collect(); | ||
MultiSender { | ||
streams, | ||
connects: connects, | ||
} | ||
} | ||
} | ||
|
||
impl MultiSender { | ||
pub async fn send(&mut self, val: MediaDataBatchResponse) -> Result<(), Vec<String>> { | ||
let mut sent = vec![]; | ||
for (index, stream) in self.connects.iter_mut().enumerate() { | ||
let url = self.streams[index].clone(); | ||
if stream.is_none() { | ||
match DataStreamClient::connect(url.clone()).await { | ||
Ok(client) => { | ||
*stream = Some(client); | ||
} | ||
Err(err) => { | ||
error!("connect data streams {url} {err}"); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
let client = stream.as_mut().unwrap(); | ||
let now = Instant::now(); | ||
if let Err(err) = client.transfer_media_data(val.clone()).await { | ||
error!("send reqeust will try next time {url} {err}"); | ||
continue; | ||
} | ||
println!("send one success {:?}", now.elapsed()); | ||
sent.push(url); | ||
} | ||
|
||
if sent.len() == self.streams.len() { | ||
Ok(()) | ||
} else { | ||
Err(sent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.