webrtc: janus: add joined-id property to the signaller

Fix #504

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1480>
This commit is contained in:
Guillaume Desmottes 2024-02-28 14:44:50 +01:00
parent eabf31e6d0
commit 60bb72ddc3

View file

@ -51,6 +51,15 @@ enum JanusId {
Num(u64), Num(u64),
} }
impl std::fmt::Display for JanusId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
JanusId::Str(s) => write!(f, "{s}"),
JanusId::Num(n) => write!(f, "{n}"),
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
struct KeepAliveMsg { struct KeepAliveMsg {
janus: String, janus: String,
@ -155,6 +164,7 @@ struct InnerError {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct RoomJoined { struct RoomJoined {
room: JanusId, room: JanusId,
id: JanusId,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -238,6 +248,9 @@ struct Settings {
display_name: Option<String>, display_name: Option<String>,
secret_key: Option<String>, secret_key: Option<String>,
string_ids: bool, string_ids: bool,
// read-only
joined_id: Option<String>,
} }
impl Default for Settings { impl Default for Settings {
@ -249,6 +262,7 @@ impl Default for Settings {
display_name: None, display_name: None,
secret_key: None, secret_key: None,
string_ids: false, string_ids: false,
joined_id: None,
} }
} }
} }
@ -263,6 +277,8 @@ pub struct Signaller {
#[property(name="display-name", get, set, type = String, member = display_name, blurb = "The name of the publisher in the Janus Video Room")] #[property(name="display-name", get, set, type = String, member = display_name, blurb = "The name of the publisher in the Janus Video Room")]
#[property(name="secret-key", get, set, type = String, member = secret_key, blurb = "The secret API key to communicate with Janus server")] #[property(name="secret-key", get, set, type = String, member = secret_key, blurb = "The secret API key to communicate with Janus server")]
#[property(name="string-ids", get, set, type = bool, member = string_ids, blurb = "Force passing room-id and feed-id as string even if they can be parsed into an integer")] #[property(name="string-ids", get, set, type = bool, member = string_ids, blurb = "Force passing room-id and feed-id as string even if they can be parsed into an integer")]
// read-only
#[property(name="joined-id", get, type = String, member = joined_id, blurb = "Unique ID of the participant")]
settings: Mutex<Settings>, settings: Mutex<Settings>,
} }
@ -427,6 +443,12 @@ impl Signaller {
if let Some(PluginData::VideoRoom { data: plugindata }) = event.plugindata { if let Some(PluginData::VideoRoom { data: plugindata }) = event.plugindata {
match plugindata { match plugindata {
VideoRoomData::Joined(joined) => { VideoRoomData::Joined(joined) => {
{
let mut settings = self.settings.lock().unwrap();
settings.joined_id = Some(joined.id.to_string());
}
self.obj().notify("joined-id");
gst::trace!(CAT, imp: self, "Joined room {:?} successfully", joined.room); gst::trace!(CAT, imp: self, "Joined room {:?} successfully", joined.room);
self.session_requested(); self.session_requested();
} }