Skip to content

Commit

Permalink
feat(net4mqtt): conf use alias replace template mqtt_url
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Nov 26, 2024
1 parent 07e3f88 commit cfdfa88
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion conf/live777.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ urls = [

# Default enabled `--features=net4mqtt`
# [net4mqtt]
# mqtt_url = "mqtt://localhost:1883/net4mqtt"
# Global unique alias
# alias = "liveion-0"
# `client_id={alias}` use alias as MQTT `client_id`
# mqtt_url = "mqtt://localhost:1883/net4mqtt?client_id={alias}"

4 changes: 3 additions & 1 deletion conf/liveman.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
# close_other_sub = false

# [net4mqtt]
# mqtt_url = "mqtt://localhost:1883/net4mqtt"
# Global unique alias
# alias = "liveman-0"
# `client_id={alias}` use alias as MQTT `client_id`
# mqtt_url = "mqtt://localhost:1883/net4mqtt?client_id={alias}"
# listen = "127.0.0.1:1077"
# domain = "net4mqtt.local"

Expand Down
7 changes: 7 additions & 0 deletions liveion/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ pub struct Net4mqtt {
pub alias: String,
}

#[cfg(feature = "net4mqtt")]
impl Net4mqtt {
pub fn validate(&mut self) {
self.mqtt_url = self.mqtt_url.replace("{alias}", &self.alias)
}
}

#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct Webhook {
#[serde(default)]
Expand Down
3 changes: 2 additions & 1 deletion liveion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ where

#[cfg(feature = "net4mqtt")]
{
if let Some(c) = cfg.net4mqtt {
if let Some(mut c) = cfg.net4mqtt {
c.validate();
std::thread::spawn(move || {
tokio::runtime::Runtime::new()
.unwrap()
Expand Down
7 changes: 7 additions & 0 deletions liveman/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ pub struct Net4mqtt {
pub domain: String,
}

#[cfg(feature = "net4mqtt")]
impl Net4mqtt {
pub fn validate(&mut self) {
self.mqtt_url = self.mqtt_url.replace("{alias}", &self.alias)
}
}

#[cfg(feature = "net4mqtt")]
impl Default for Net4mqtt {
fn default() -> Self {
Expand Down
3 changes: 2 additions & 1 deletion liveman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ where

#[cfg(feature = "net4mqtt")]
{
if let Some(c) = cfg.net4mqtt.clone() {
if let Some(mut c) = cfg.net4mqtt.clone() {
c.validate();
let (sender, mut receiver) =
tokio::sync::mpsc::channel::<(String, String, Vec<u8>)>(10);

Expand Down

0 comments on commit cfdfa88

Please sign in to comment.