Skip to content

Commit

Permalink
fix: data from the server sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Oct 2, 2023
1 parent ddb608c commit 154f4b8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
target: aarch64-apple-ios-sim
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: buildjet-4vcpu-ubuntu-2204-arm
- os: ubuntu-latest-xl
cross: true
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-linux-android
Expand Down Expand Up @@ -72,10 +73,13 @@ jobs:
toolchain: stable
target: ${{ matrix.target }}

- name: Build (Cargo)
- name: Build (Cargo/Cross)
uses: actions-rs/cargo@v1
if: ${{ !contains(matrix.target, 'android') }}
run: |
cargo build --release --workspace -p livekit --target ${{ matrix.target }}
with:
command: build
args: --release --workspace -p livekit --target ${{ matrix.target }}
use-cross: ${{ matrix.cross }}

- name: Build (Android)
if: ${{ contains(matrix.target, 'android') }}
Expand Down
2 changes: 1 addition & 1 deletion livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ async fn forward_event(
handle: Some(proto::FfiOwnedHandle { id: handle_id }),
data: Some(buffer_info),
}),
participant_sid: Some(participant.sid().to_string()),
participant_sid: participant.map(|p| p.sid().to_string()),
kind: proto::DataPacketKind::from(kind).into(),
},
))
Expand Down
15 changes: 7 additions & 8 deletions livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub enum RoomEvent {
DataReceived {
payload: Arc<Vec<u8>>,
kind: DataPacketKind,
participant: RemoteParticipant,
participant: Option<RemoteParticipant>,
},
E2eeStateChanged {
participant: Participant,
Expand Down Expand Up @@ -555,13 +555,12 @@ impl RoomSession {
kind,
participant_sid,
} => {
if let Some(participant) = self.get_participant_by_sid(&participant_sid) {
self.dispatcher.dispatch(&RoomEvent::DataReceived {
payload: Arc::new(payload),
kind,
participant,
});
}
let participant = participant_sid.map(|sid| self.get_participant_by_sid(&sid));
self.dispatcher.dispatch(&RoomEvent::DataReceived {
payload: Arc::new(payload),
kind,
participant: participant.unwrap_or(None),
});
}
EngineEvent::SpeakersChanged { speakers } => self.handle_speakers_changed(speakers),
EngineEvent::ConnectionQuality { updates } => {
Expand Down
2 changes: 1 addition & 1 deletion livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub enum EngineEvent {
transceiver: RtpTransceiver,
},
Data {
participant_sid: ParticipantSid,
participant_sid: Option<ParticipantSid>,
payload: Vec<u8>,
kind: DataPacketKind,
},
Expand Down
12 changes: 10 additions & 2 deletions livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::convert::TryInto;
use std::fmt::Debug;
use std::ops::Not;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -55,7 +56,8 @@ pub enum SessionEvent {
updates: Vec<proto::ParticipantInfo>,
},
Data {
participant_sid: ParticipantSid,
// None when the data comes from the ServerSDK (So no real participant)
participant_sid: Option<ParticipantSid>,
payload: Vec<u8>,
kind: DataPacketKind,
},
Expand Down Expand Up @@ -561,9 +563,15 @@ impl SessionInner {
let data = proto::DataPacket::decode(&*data).unwrap();
match data.value.as_ref().unwrap() {
proto::data_packet::Value::User(user) => {
let participant_sid = user
.participant_sid
.is_empty()
.not()
.then_some(user.participant_sid.clone());

let _ = self.emitter.send(SessionEvent::Data {
kind: data.kind().into(),
participant_sid: user.participant_sid.clone().try_into().unwrap(),
participant_sid: participant_sid.map(|s| s.try_into().unwrap()),
payload: user.payload.clone(),
});
}
Expand Down

0 comments on commit 154f4b8

Please sign in to comment.