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