Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for topic in data transfer protocol (#248) #252

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum RoomEvent {
},
DataReceived {
payload: Arc<Vec<u8>>,
topic: Option<String>,
kind: DataPacketKind,
participant: Option<RemoteParticipant>,
},
Expand Down Expand Up @@ -557,10 +558,11 @@ impl RoomSession {
EngineEvent::Disconnected { reason } => self.handle_disconnected(reason),
EngineEvent::Data {
payload,
topic,
kind,
participant_sid,
} => {
self.handle_data(payload, kind, participant_sid);
self.handle_data(payload, topic, kind, participant_sid);
}
EngineEvent::SpeakersChanged { speakers } => self.handle_speakers_changed(speakers),
EngineEvent::ConnectionQuality { updates } => {
Expand Down Expand Up @@ -970,6 +972,7 @@ impl RoomSession {
fn handle_data(
&self,
payload: Vec<u8>,
topic: Option<String>,
kind: DataPacketKind,
participant_sid: Option<ParticipantSid>,
) {
Expand All @@ -985,6 +988,7 @@ impl RoomSession {

self.dispatcher.dispatch(&RoomEvent::DataReceived {
payload: Arc::new(payload),
topic,
kind,
participant,
});
Expand Down
11 changes: 11 additions & 0 deletions livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,27 @@ impl LocalParticipant {
}
}

pub async fn publish_data_only(
&self,
data: Vec<u8>,
kind: DataPacketKind,
destination_sids: Vec<String>,
) -> RoomResult<()> {
self.publish_data(data, None, kind, destination_sids).await
}

pub async fn publish_data(
&self,
data: Vec<u8>,
topic: Option<String>,
kind: DataPacketKind,
destination_sids: Vec<String>,
) -> RoomResult<()> {
let data = proto::DataPacket {
kind: kind as i32,
value: Some(proto::data_packet::Value::User(proto::UserPacket {
payload: data,
topic: topic,
destination_sids: destination_sids.to_owned(),
..Default::default()
})),
Expand Down
3 changes: 3 additions & 0 deletions livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum EngineEvent {
Data {
participant_sid: Option<ParticipantSid>,
payload: Vec<u8>,
topic: Option<String>,
kind: DataPacketKind,
},
SpeakersChanged {
Expand Down Expand Up @@ -383,11 +384,13 @@ impl EngineInner {
SessionEvent::Data {
participant_sid,
payload,
topic,
kind,
} => {
let _ = self.engine_tx.send(EngineEvent::Data {
participant_sid,
payload,
topic,
kind,
});
}
Expand Down
2 changes: 2 additions & 0 deletions livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub enum SessionEvent {
// None when the data comes from the ServerSDK (So no real participant)
participant_sid: Option<ParticipantSid>,
payload: Vec<u8>,
topic: Option<String>,
kind: DataPacketKind,
},
MediaTrack {
Expand Down Expand Up @@ -573,6 +574,7 @@ impl SessionInner {
kind: data.kind().into(),
participant_sid: participant_sid.map(|s| s.try_into().unwrap()),
payload: user.payload.clone(),
topic: user.topic.clone(),
});
}
proto::data_packet::Value::Speaker(_) => {}
Expand Down
Loading