fix participant updates (#23)
This commit is contained in:
@@ -14,7 +14,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::task::JoinHandle;
|
||||
use tracing::{error, instrument, Level};
|
||||
use tracing::{error, info, instrument, Level};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum ConnectionState {
|
||||
@@ -253,7 +253,7 @@ impl SessionInner {
|
||||
#[instrument(level = Level::DEBUG)]
|
||||
async fn on_engine_event(self: &Arc<Self>, event: EngineEvent) -> RoomResult<()> {
|
||||
match event {
|
||||
EngineEvent::ParticipantUpdate(update) => self.handle_participant_update(update),
|
||||
EngineEvent::ParticipantUpdate { updates } => self.handle_participant_update(updates),
|
||||
EngineEvent::MediaTrack {
|
||||
track,
|
||||
stream,
|
||||
@@ -352,8 +352,9 @@ impl SessionInner {
|
||||
/// It'll create, update or remove a participant
|
||||
/// It also update the participant tracks.
|
||||
#[instrument(level = Level::DEBUG)]
|
||||
fn handle_participant_update(self: &Arc<Self>, update: proto::ParticipantUpdate) {
|
||||
for pi in update.participants {
|
||||
fn handle_participant_update(self: &Arc<Self>, updates: Vec<proto::ParticipantInfo>) {
|
||||
for pi in updates {
|
||||
info!("test");
|
||||
if pi.sid == self.local_participant.sid()
|
||||
|| pi.identity == self.local_participant.identity()
|
||||
{
|
||||
@@ -366,6 +367,7 @@ impl SessionInner {
|
||||
if let Some(remote_participant) = remote_participant {
|
||||
if pi.state == participant_info::State::Disconnected as i32 {
|
||||
// Participant disconnected
|
||||
info!("Participant disconnected: {}", pi.sid);
|
||||
self.clone()
|
||||
.handle_participant_disconnect(remote_participant)
|
||||
} else {
|
||||
@@ -374,6 +376,7 @@ impl SessionInner {
|
||||
}
|
||||
} else {
|
||||
// Create a new participant
|
||||
info!("Participant connected: {}", pi.sid);
|
||||
let remote_participant = {
|
||||
let pi = pi.clone();
|
||||
self.create_participant(pi.sid.into(), pi.identity.into(), pi.name, pi.metadata)
|
||||
@@ -478,9 +481,7 @@ impl SessionInner {
|
||||
self.local_participant.update_info(pi, true); // The sid may have changed
|
||||
}
|
||||
|
||||
self.handle_participant_update(proto::ParticipantUpdate {
|
||||
participants: join_response.other_participants,
|
||||
});
|
||||
self.handle_participant_update(join_response.other_participants);
|
||||
|
||||
// TODO(theomonnom): unpublish & republish tracks
|
||||
}
|
||||
|
||||
@@ -69,7 +69,9 @@ pub enum EngineError {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EngineEvent {
|
||||
ParticipantUpdate(ParticipantUpdate),
|
||||
ParticipantUpdate {
|
||||
updates: Vec<proto::ParticipantInfo>,
|
||||
},
|
||||
MediaTrack {
|
||||
track: MediaStreamTrackHandle,
|
||||
stream: MediaStream,
|
||||
@@ -282,6 +284,12 @@ impl EngineInner {
|
||||
})
|
||||
.await;
|
||||
}
|
||||
SessionEvent::ParticipantUpdate { updates } => {
|
||||
let _ = self
|
||||
.engine_emitter
|
||||
.send(EngineEvent::ParticipantUpdate { updates })
|
||||
.await;
|
||||
}
|
||||
SessionEvent::SpeakersChanged { speakers } => {
|
||||
let _ = self
|
||||
.engine_emitter
|
||||
|
||||
@@ -43,6 +43,9 @@ pub type SessionEvents = mpsc::UnboundedReceiver<SessionEvent>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SessionEvent {
|
||||
ParticipantUpdate {
|
||||
updates: Vec<proto::ParticipantInfo>,
|
||||
},
|
||||
Data {
|
||||
participant_sid: String,
|
||||
payload: Vec<u8>,
|
||||
@@ -421,6 +424,11 @@ impl SessionInner {
|
||||
true,
|
||||
);
|
||||
}
|
||||
signal_response::Message::Update(update) => {
|
||||
let _ = self.emitter.send(SessionEvent::ParticipantUpdate {
|
||||
updates: update.participants,
|
||||
});
|
||||
}
|
||||
signal_response::Message::SpeakersChanged(speaker) => {
|
||||
let _ = self.emitter.send(SessionEvent::SpeakersChanged {
|
||||
speakers: speaker.speakers,
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
-Ilibwebrtc/src
|
||||
-Ilibwebrtc/src/third_party/abseil-cpp
|
||||
-Ilibwebrtc/src/third_party/libc++
|
||||
-I../../../target/cxxbridge
|
||||
-DWEBRTC_WIN
|
||||
-I../target/cxxbridge
|
||||
-DWEBRTC_MAC
|
||||
-DWEBRTC_POSIX
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "api/task_queue/default_task_queue_factory.h"
|
||||
#include "api/video_codecs/builtin_video_decoder_factory.h"
|
||||
#include "api/video_codecs/builtin_video_encoder_factory.h"
|
||||
#include "webrtc-sys/src/peer_connection_factory.rs.h"
|
||||
#include "livekit/rtc_error.h"
|
||||
#include "media/engine/webrtc_media_engine.h"
|
||||
#include "webrtc-sys/src/peer_connection_factory.rs.h"
|
||||
|
||||
namespace livekit {
|
||||
|
||||
@@ -81,23 +81,26 @@ std::unique_ptr<NativeRTCConfiguration> create_rtc_configuration(
|
||||
RTCConfiguration conf) {
|
||||
auto rtc =
|
||||
std::make_unique<webrtc::PeerConnectionInterface::RTCConfiguration>();
|
||||
for (auto& item : conf.ice_servers) {
|
||||
|
||||
for (auto item : conf.ice_servers) {
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
ice_server.username = item.username.c_str();
|
||||
ice_server.password = item.password.c_str();
|
||||
|
||||
for (auto& url : item.urls) {
|
||||
for (auto url : item.urls) {
|
||||
ice_server.urls.emplace_back(url.c_str());
|
||||
}
|
||||
rtc->servers.push_back(ice_server);
|
||||
rtc->continual_gathering_policy =
|
||||
static_cast<webrtc::PeerConnectionInterface::ContinualGatheringPolicy>(
|
||||
conf.continual_gathering_policy);
|
||||
|
||||
rtc->type = static_cast<webrtc::PeerConnectionInterface::IceTransportsType>(
|
||||
conf.ice_transport_type);
|
||||
rtc->servers.push_back(ice_server);
|
||||
}
|
||||
|
||||
rtc->continual_gathering_policy =
|
||||
static_cast<webrtc::PeerConnectionInterface::ContinualGatheringPolicy>(
|
||||
conf.continual_gathering_policy);
|
||||
|
||||
rtc->type = static_cast<webrtc::PeerConnectionInterface::IceTransportsType>(
|
||||
conf.ice_transport_type);
|
||||
|
||||
return rtc;
|
||||
}
|
||||
} // namespace livekit
|
||||
|
||||
Reference in New Issue
Block a user