add video channel

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2021-12-20 15:10:51 +08:00
parent 07ea52d620
commit 3ffd8ac146
4 changed files with 177 additions and 76 deletions

View File

@@ -1,5 +1,6 @@
use super::*;
use std::{
collections::HashSet,
thread::{self, JoinHandle},
time,
};
@@ -15,6 +16,7 @@ pub trait Service: Send + Sync {
pub trait Subscriber: Default + Send + Sync + 'static {
fn id(&self) -> i32;
fn send(&mut self, msg: Arc<Message>);
fn send_video_frame(&mut self, tm: time::Instant, msg: Arc<Message>);
}
#[derive(Default)]
@@ -143,6 +145,20 @@ impl<T: Subscriber + From<ConnInner>> ServiceTmpl<T> {
}
}
pub fn send_video_frame(&self, tm: time::Instant, msg: Message) -> HashSet<i32> {
self.send_video_frame_shared(tm, Arc::new(msg))
}
pub fn send_video_frame_shared(&self, tm: time::Instant, msg: Arc<Message>) -> HashSet<i32> {
let mut conn_ids = HashSet::new();
let mut lock = self.0.write().unwrap();
for s in lock.subscribes.values_mut() {
s.send_video_frame(tm, msg.clone());
conn_ids.insert(s.id());
}
conn_ids
}
pub fn send_without(&self, msg: Message, sub: i32) {
let mut lock = self.0.write().unwrap();
let msg = Arc::new(msg);