Allow passing free form metadatas about consumers/producers/listenners

In some applications people might need to be able to pass more metadata
than the only "display-name" this commit allow that by adding a field in
all signalling structure where it is free form json and removing the
"display-name" as the free form `meta` field allows application to pass
this kind of information without any problem.

On the "webrtcsink" side this commit adds a `meta` property as a
gst::Structure which will be passed as a json string to the signalling
server so we enforce data to be structured.
This commit is contained in:
Thibault Saunier 2022-07-07 11:41:10 -04:00 committed by Mathieu Duponchelle
parent ec46b706e9
commit c53e5b8bb2
5 changed files with 211 additions and 135 deletions

View file

@ -4,10 +4,12 @@ use async_std::task;
use async_tungstenite::tungstenite::Message as WsMessage;
use futures::channel::mpsc;
use futures::prelude::*;
use gst::glib;
use gst::glib::prelude::*;
use gst::glib::{self, Type};
use gst::prelude::*;
use gst::subclass::prelude::*;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Mutex;
use webrtcsink_protocol as p;
@ -98,10 +100,14 @@ impl Signaller {
Ok::<(), Error>(())
});
let meta = if let Some(meta) = element.property::<Option<gst::Structure>>("meta") {
serialize_value(&meta.to_value())
} else {
None
};
websocket_sender
.send(p::IncomingMessage::Register(p::RegisterMessage::Producer {
display_name: element.property("display-name"),
}))
.send(p::IncomingMessage::Register(p::RegisterMessage::Producer { meta, }))
.await?;
let element_clone = element.downgrade();
@ -418,3 +424,49 @@ impl ObjectImpl for Signaller {
}
}
}
fn serialize_value(val: &gst::glib::Value) -> Option<serde_json::Value> {
match val.type_() {
Type::STRING => Some(val.get::<String>().unwrap().into()),
Type::BOOL => Some(val.get::<bool>().unwrap().into()),
Type::I32 => Some(val.get::<i32>().unwrap().into()),
Type::U32 => Some(val.get::<u32>().unwrap().into()),
Type::I_LONG | Type::I64 => Some(val.get::<i64>().unwrap().into()),
Type::U_LONG | Type::U64 => Some(val.get::<u64>().unwrap().into()),
Type::F32 => Some(val.get::<f32>().unwrap().into()),
Type::F64 => Some(val.get::<f64>().unwrap().into()),
_ => {
if let Ok(s) = val.get::<gst::Structure>() {
serde_json::to_value(
s.iter()
.filter_map(|(name, value)| {
serialize_value(value).map(|value| (name.to_string(), value))
})
.collect::<HashMap<String, serde_json::Value>>(),
)
.ok()
} else if let Ok(a) = val.get::<gst::Array>() {
serde_json::to_value(
a.iter()
.filter_map(|value| serialize_value(value))
.collect::<Vec<serde_json::Value>>(),
)
.ok()
} else if let Some((_klass, values)) = gst::glib::FlagsValue::from_value(val) {
Some(
values
.iter()
.map(|value| value.nick())
.collect::<Vec<&str>>()
.join("+")
.into(),
)
} else if let Ok(value) = val.serialize() {
Some(value.as_str().into())
} else {
gst::warning!(CAT, "Can't convert {} to json", val.type_().name());
None
}
}
}
}

View file

@ -36,7 +36,6 @@ const RTP_TWCC_URI: &str =
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
const DEFAULT_STUN_SERVER: Option<&str> = Some("stun://stun.l.google.com:19302");
const DEFAULT_DISPLAY_NAME: Option<&str> = None;
const DEFAULT_MIN_BITRATE: u32 = 1000;
/* I have found higher values to cause packet loss *somewhere* in
@ -64,7 +63,7 @@ struct Settings {
do_fec: bool,
do_retransmission: bool,
enable_data_channel_navigation: bool,
display_name: Option<String>,
meta: Option<gst::Structure>,
}
/// Represents a codec we can offer
@ -318,7 +317,7 @@ impl Default for Settings {
do_fec: DEFAULT_DO_FEC,
do_retransmission: DEFAULT_DO_RETRANSMISSION,
enable_data_channel_navigation: DEFAULT_ENABLE_DATA_CHANNEL_NAVIGATION,
display_name: DEFAULT_DISPLAY_NAME.map(String::from),
meta: None,
}
}
}
@ -2605,11 +2604,11 @@ impl ObjectImpl for WebRTCSink {
DEFAULT_ENABLE_DATA_CHANNEL_NAVIGATION,
glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_READY
),
glib::ParamSpecString::new(
"display-name",
"Display name",
"The display name of the producer",
DEFAULT_DISPLAY_NAME,
glib::ParamSpecBoxed::new(
"meta",
"Meta",
"Free form metadata about the producer",
gst::Structure::static_type(),
glib::ParamFlags::READWRITE,
),
]
@ -2710,10 +2709,10 @@ impl ObjectImpl for WebRTCSink {
settings.enable_data_channel_navigation =
value.get::<bool>().expect("type checked upstream");
}
"display-name" => {
"meta" => {
let mut settings = self.settings.lock().unwrap();
settings.display_name = value
.get::<Option<String>>()
settings.meta = value
.get::<Option<gst::Structure>>()
.expect("type checked upstream")
}
_ => unimplemented!(),
@ -2767,9 +2766,9 @@ impl ObjectImpl for WebRTCSink {
settings.enable_data_channel_navigation.to_value()
}
"stats" => self.gather_stats().to_value(),
"display-name" => {
"meta" => {
let settings = self.settings.lock().unwrap();
settings.display_name.to_value()
settings.meta.to_value()
}
_ => unimplemented!(),
}

View file

@ -10,27 +10,30 @@ pub enum RegisteredMessage {
#[serde(rename_all = "camelCase")]
Producer {
peer_id: String,
display_name: Option<String>,
#[serde(default)]
meta: Option<serde_json::Value>,
},
/// Registered as a consumer
#[serde(rename_all = "camelCase")]
Consumer {
peer_id: String,
display_name: Option<String>,
#[serde(default)]
meta: Option<serde_json::Value>,
},
/// Registered as a listener
#[serde(rename_all = "camelCase")]
Listener {
peer_id: String,
display_name: Option<String>,
#[serde(default)]
meta: Option<serde_json::Value>,
},
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Peer {
pub id: String,
pub display_name: Option<String>,
#[serde(default)]
pub meta: Option<serde_json::Value>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
@ -44,13 +47,15 @@ pub enum OutgoingMessage {
#[serde(rename_all = "camelCase")]
ProducerAdded {
peer_id: String,
display_name: Option<String>,
#[serde(default)]
meta: Option<serde_json::Value>,
},
/// Notifies listeners that a producer was removed
#[serde(rename_all = "camelCase")]
ProducerRemoved {
peer_id: String,
display_name: Option<String>,
#[serde(default)]
meta: Option<serde_json::Value>,
},
/// Instructs a peer to generate an offer
#[serde(rename_all = "camelCase")]
@ -75,19 +80,19 @@ pub enum RegisterMessage {
#[serde(rename_all = "camelCase")]
Producer {
#[serde(default)]
display_name: Option<String>,
meta: Option<serde_json::Value>,
},
/// Register as a consumer
#[serde(rename_all = "camelCase")]
Consumer {
#[serde(default)]
display_name: Option<String>,
meta: Option<serde_json::Value>,
},
/// Register as a listener
#[serde(rename_all = "camelCase")]
Listener {
#[serde(default)]
display_name: Option<String>,
meta: Option<serde_json::Value>,
},
}

View file

@ -19,7 +19,7 @@ pin_project! {
producers: HashMap<PeerId, HashSet<PeerId>>,
consumers: HashMap<PeerId, Option<PeerId>>,
listeners: HashSet<PeerId>,
display_names: HashMap<PeerId, Option<String>>,
meta: HashMap<PeerId, Option<serde_json::Value>>,
}
}
@ -35,7 +35,7 @@ impl Handler {
producers: HashMap::new(),
consumers: HashMap::new(),
listeners: HashSet::new(),
display_names: HashMap::new(),
meta: HashMap::new(),
}
}
@ -47,15 +47,9 @@ impl Handler {
) -> Result<(), Error> {
match msg {
p::IncomingMessage::Register(message) => match message {
p::RegisterMessage::Producer { display_name } => {
self.register_producer(peer_id, display_name)
}
p::RegisterMessage::Consumer { display_name } => {
self.register_consumer(peer_id, display_name)
}
p::RegisterMessage::Listener { display_name } => {
self.register_listener(peer_id, display_name)
}
p::RegisterMessage::Producer { meta } => self.register_producer(peer_id, meta),
p::RegisterMessage::Consumer { meta } => self.register_consumer(peer_id, meta),
p::RegisterMessage::Listener { meta } => self.register_listener(peer_id, meta),
},
p::IncomingMessage::StartSession(message) => {
self.start_session(&message.peer_id, peer_id)
@ -108,9 +102,9 @@ impl Handler {
listener.to_string(),
p::OutgoingMessage::ProducerRemoved {
peer_id: peer_id.to_string(),
display_name: match self.display_names.get(peer_id) {
Some(name) => name.clone(),
None => None,
meta: match self.meta.get(peer_id) {
Some(meta) => meta.clone(),
None => Default::default(),
},
},
));
@ -133,7 +127,7 @@ impl Handler {
));
}
let _ = self.display_names.remove(peer_id);
let _ = self.meta.remove(peer_id);
}
#[instrument(level = "debug", skip(self))]
@ -206,10 +200,10 @@ impl Handler {
.cloned()
.map(|peer_id| p::Peer {
id: peer_id.clone(),
display_name: match self.display_names.get(&peer_id) {
Some(name) => name.clone(),
None => None,
},
meta: self
.meta
.get(&peer_id)
.map_or_else(|| Default::default(), |m| m.clone()),
})
.collect(),
},
@ -348,11 +342,7 @@ impl Handler {
/// Register peer as a producer
#[instrument(level = "debug", skip(self))]
fn register_producer(
&mut self,
peer_id: &str,
display_name: Option<String>,
) -> Result<(), Error> {
fn register_producer(&mut self, peer_id: &str, meta: Option<serde_json::Value>) -> Result<(), Error> {
if self.producers.contains_key(peer_id) {
Err(anyhow!("{} is already registered as a producer", peer_id))
} else {
@ -363,7 +353,7 @@ impl Handler {
listener.to_string(),
p::OutgoingMessage::ProducerAdded {
peer_id: peer_id.to_string(),
display_name: display_name.clone(),
meta: meta.clone(),
},
));
}
@ -372,11 +362,11 @@ impl Handler {
peer_id.to_string(),
p::OutgoingMessage::Registered(p::RegisteredMessage::Producer {
peer_id: peer_id.to_string(),
display_name: display_name.clone(),
meta: meta.clone(),
}),
));
self.display_names.insert(peer_id.to_string(), display_name);
self.meta.insert(peer_id.to_string(), meta);
info!(peer_id = %peer_id, "registered as a producer");
@ -386,11 +376,7 @@ impl Handler {
/// Register peer as a consumer
#[instrument(level = "debug", skip(self))]
fn register_consumer(
&mut self,
peer_id: &str,
display_name: Option<String>,
) -> Result<(), Error> {
fn register_consumer(&mut self, peer_id: &str, meta: Option<serde_json::Value>) -> Result<(), Error> {
if self.consumers.contains_key(peer_id) {
Err(anyhow!("{} is already registered as a consumer", peer_id))
} else {
@ -400,11 +386,11 @@ impl Handler {
peer_id.to_string(),
p::OutgoingMessage::Registered(p::RegisteredMessage::Consumer {
peer_id: peer_id.to_string(),
display_name: display_name.clone(),
meta: meta.clone(),
}),
));
self.display_names.insert(peer_id.to_string(), display_name);
self.meta.insert(peer_id.to_string(), meta);
info!(peer_id = %peer_id, "registered as a consumer");
@ -414,11 +400,7 @@ impl Handler {
/// Register peer as a listener
#[instrument(level = "debug", skip(self))]
fn register_listener(
&mut self,
peer_id: &str,
display_name: Option<String>,
) -> Result<(), Error> {
fn register_listener(&mut self, peer_id: &str, meta: Option<serde_json::Value>) -> Result<(), Error> {
if !self.listeners.insert(peer_id.to_string()) {
Err(anyhow!("{} is already registered as a listener", peer_id))
} else {
@ -426,11 +408,11 @@ impl Handler {
peer_id.to_string(),
p::OutgoingMessage::Registered(p::RegisteredMessage::Listener {
peer_id: peer_id.to_string(),
display_name: display_name.clone(),
meta: meta.clone(),
}),
));
self.display_names.insert(peer_id.to_string(), display_name);
self.meta.insert(peer_id.to_string(), meta);
info!(peer_id = %peer_id, "registered as a listener");
@ -521,14 +503,16 @@ impl Stream for Handler {
mod tests {
use super::*;
use futures::channel::mpsc;
use serde_json::json;
#[async_std::test]
async fn test_register_producer() {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
@ -541,7 +525,7 @@ mod tests {
sent_message,
p::OutgoingMessage::Registered(p::RegisteredMessage::Producer {
peer_id: "producer".to_string(),
display_name: None,
meta: Default::default(),
})
);
}
@ -552,7 +536,7 @@ mod tests {
let mut handler = Handler::new(Box::pin(rx));
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
display_name: Some("foobar".to_string()),
meta: Some(json!( {"display-name": "foobar".to_string() }))
});
tx.send(("producer".to_string(), Some(message)))
@ -575,7 +559,9 @@ mod tests {
p::OutgoingMessage::List {
producers: vec![p::Peer {
id: "producer".to_string(),
display_name: Some("foobar".to_string())
meta: Some(json!(
{"display-name": "foobar".to_string()
})),
}]
}
);
@ -586,8 +572,9 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
@ -600,7 +587,7 @@ mod tests {
sent_message,
p::OutgoingMessage::Registered(p::RegisteredMessage::Consumer {
peer_id: "consumer".to_string(),
display_name: None,
meta: Default::default()
})
);
}
@ -610,15 +597,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
@ -638,15 +627,18 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Listener { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Listener {
meta: Default::default(),
});
tx.send(("listener".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
display_name: Some("foobar".to_string()),
meta: Some(json!({
"display-name": "foobar".to_string(),
})),
});
tx.send(("producer".to_string(), Some(message)))
.await
@ -658,7 +650,9 @@ mod tests {
sent_message,
p::OutgoingMessage::ProducerAdded {
peer_id: "producer".to_string(),
display_name: Some("foobar".to_string()),
meta: Some(json!({
"display-name": Some("foobar".to_string()),
}))
}
);
}
@ -668,15 +662,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -705,15 +701,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -727,8 +725,9 @@ mod tests {
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Listener { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Listener {
meta: Default::default(),
});
tx.send(("listener".to_string(), Some(message)))
.await
.unwrap();
@ -752,7 +751,7 @@ mod tests {
sent_message,
p::OutgoingMessage::ProducerRemoved {
peer_id: "producer".to_string(),
display_name: None
meta: Default::default()
}
);
}
@ -762,15 +761,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -806,15 +807,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -850,15 +853,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -902,15 +907,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -952,15 +959,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -1028,15 +1037,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -1074,8 +1085,9 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();
@ -1103,8 +1115,9 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
@ -1132,15 +1145,17 @@ mod tests {
let (mut tx, rx) = mpsc::unbounded();
let mut handler = Handler::new(Box::pin(rx));
let message =
p::IncomingMessage::Register(p::RegisterMessage::Producer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Producer {
meta: Default::default(),
});
tx.send(("producer".to_string(), Some(message)))
.await
.unwrap();
let _ = handler.next().await.unwrap();
let message =
p::IncomingMessage::Register(p::RegisterMessage::Consumer { display_name: None });
let message = p::IncomingMessage::Register(p::RegisterMessage::Consumer {
meta: Default::default(),
});
tx.send(("consumer".to_string(), Some(message)))
.await
.unwrap();

View file

@ -342,16 +342,21 @@ function session_closed(peer_id) {
sessions[peer_id] = null;
}
function addPeer(peer_id, display_name) {
console.log("Display name: ", display_name);
function addPeer(peer_id, meta) {
console.log("Meta: ", JSON.stringify(meta));
var nav_ul = document.getElementById("camera-list");
if (display_name == null) {
var li_str = '<li id="peer-' + peer_id + '"><button class="button button1">' + peer_id + '</button></li>';
} else {
var li_str = '<li id="peer-' + peer_id + '"><button class="button button1">' + display_name + '</button></li>';
meta = meta ? meta : {"display-name": peer_id};
let display_html = `${meta["display-name"] ? meta["display-name"] : peer_id}<ul>`;
for (const key in meta) {
if (key != "display-name") {
display_html += `<li>- ${key}: ${meta[key]}</li>`;
}
}
display_html += "</ul>"
var li_str = '<li id="peer-' + peer_id + '"><button class="button button1">' + display_html + '</button></li>';
nav_ul.insertAdjacentHTML('beforeend', li_str);
var li = document.getElementById("peer-" + peer_id);
@ -393,10 +398,10 @@ function onServerMessage(event) {
} else if (msg.type == "list") {
clearPeers();
for (i = 0; i < msg.producers.length; i++) {
addPeer(msg.producers[i].id, msg.producers[i].displayName);
addPeer(msg.producers[i].id, msg.producers[i].meta);
}
} else if (msg.type == "producerAdded") {
addPeer(msg.peerId, msg.displayName);
addPeer(msg.peerId, msg.meta);
} else if (msg.type == "producerRemoved") {
var li = document.getElementById("peer-" + msg.peerId);
li.parentNode.removeChild(li);