DataReceived event
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use self::room_session::{ConnectionState, RoomSession, SessionHandle};
|
||||
use crate::proto::data_packet;
|
||||
use crate::room::id::TrackSid;
|
||||
use crate::room::participant::remote_participant::RemoteParticipant;
|
||||
use crate::room::participant::ParticipantHandle;
|
||||
use crate::room::publication::RemoteTrackPublication;
|
||||
use crate::room::publication::TrackPublication;
|
||||
use crate::room::track::remote_track::RemoteTrackHandle;
|
||||
use crate::rtc_engine::EngineError;
|
||||
use std::fmt::Debug;
|
||||
@@ -48,11 +51,36 @@ pub enum RoomEvent {
|
||||
publication: RemoteTrackPublication,
|
||||
participant: Arc<RemoteParticipant>,
|
||||
},
|
||||
TrackUnpublished {
|
||||
publication: RemoteTrackPublication,
|
||||
participant: Arc<RemoteParticipant>,
|
||||
},
|
||||
TrackUnsubscribed {
|
||||
track: RemoteTrackHandle,
|
||||
publication: RemoteTrackPublication,
|
||||
participant: Arc<RemoteParticipant>,
|
||||
},
|
||||
TrackSubscriptionFailed {
|
||||
error: TrackError,
|
||||
sid: TrackSid,
|
||||
participant: Arc<RemoteParticipant>,
|
||||
},
|
||||
TrackMuted {
|
||||
publication: TrackPublication,
|
||||
participant: ParticipantHandle,
|
||||
},
|
||||
TrackUnmuted {
|
||||
publication: TrackPublication,
|
||||
participant: ParticipantHandle,
|
||||
},
|
||||
ActiveSpeakersChanged {
|
||||
speakers: Vec<ParticipantHandle>,
|
||||
},
|
||||
DataReceived {
|
||||
payload: Vec<u8>,
|
||||
kind: data_packet::Kind,
|
||||
participant: Arc<RemoteParticipant>,
|
||||
},
|
||||
ConnectionStateChanged(ConnectionState),
|
||||
Connected,
|
||||
Disconnected,
|
||||
|
||||
@@ -63,7 +63,7 @@ pub trait ParticipantTrait {
|
||||
fn metadata(&self) -> String;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ParticipantHandle {
|
||||
Local(Arc<LocalParticipant>),
|
||||
Remote(Arc<RemoteParticipant>),
|
||||
|
||||
@@ -283,6 +283,21 @@ impl SessionInner {
|
||||
EngineEvent::Restarting => self.handle_restarting(),
|
||||
EngineEvent::Restarted => self.handle_restarted(),
|
||||
EngineEvent::Disconnected => self.handle_disconnected(),
|
||||
EngineEvent::Data {
|
||||
payload,
|
||||
kind,
|
||||
participant_sid,
|
||||
} => {
|
||||
if let Some(participant) = self.get_participant(&participant_sid.into()) {
|
||||
let _ = self
|
||||
.internal_tx
|
||||
.send(SessionEvent::Room(RoomEvent::DataReceived {
|
||||
payload,
|
||||
kind,
|
||||
participant,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -73,6 +73,11 @@ pub enum EngineEvent {
|
||||
stream: MediaStream,
|
||||
receiver: RtpReceiver,
|
||||
},
|
||||
Data {
|
||||
participant_sid: String,
|
||||
payload: Vec<u8>,
|
||||
kind: data_packet::Kind,
|
||||
},
|
||||
Resuming,
|
||||
Resumed,
|
||||
Restarting,
|
||||
@@ -241,7 +246,20 @@ impl EngineInner {
|
||||
self.close().await;
|
||||
}
|
||||
}
|
||||
SessionEvent::Data { data: _ } => {}
|
||||
SessionEvent::Data {
|
||||
participant_sid,
|
||||
payload,
|
||||
kind,
|
||||
} => {
|
||||
let _ = self
|
||||
.engine_emitter
|
||||
.send(EngineEvent::Data {
|
||||
participant_sid,
|
||||
payload,
|
||||
kind,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
SessionEvent::MediaTrack {
|
||||
track,
|
||||
stream,
|
||||
|
||||
@@ -44,7 +44,9 @@ pub type SessionEvents = mpsc::UnboundedReceiver<SessionEvent>;
|
||||
#[derive(Debug)]
|
||||
pub enum SessionEvent {
|
||||
Data {
|
||||
data: Vec<u8>,
|
||||
participant_sid: String,
|
||||
payload: Vec<u8>,
|
||||
kind: proto::data_packet::Kind,
|
||||
},
|
||||
MediaTrack {
|
||||
track: MediaStreamTrackHandle,
|
||||
@@ -501,8 +503,12 @@ impl SessionInner {
|
||||
|
||||
let data = DataPacket::decode(&*data)?;
|
||||
match data.value.unwrap() {
|
||||
Value::User(_user) => {
|
||||
// TODO(theomonnom) Send event
|
||||
Value::User(user) => {
|
||||
let _ = self.emitter.send(SessionEvent::Data {
|
||||
participant_sid: user.participant_sid,
|
||||
payload: user.payload,
|
||||
kind: data_packet::Kind::from_i32(data.kind).unwrap(),
|
||||
});
|
||||
}
|
||||
Value::Speaker(_) => {
|
||||
// TODO(theomonnonm)
|
||||
|
||||
Reference in New Issue
Block a user