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