|
1 | 1 | pub mod process_messages; |
2 | 2 | mod websocket_frontend; |
| 3 | +use crate::remote_server::ButtplugRemoteServerEvent; |
3 | 4 | use crate::{error::IntifaceError, options::EngineOptions}; |
4 | 5 | use async_trait::async_trait; |
5 | | -use crate::remote_server::ButtplugRemoteServerEvent; |
6 | 6 | use futures::{pin_mut, Stream, StreamExt}; |
| 7 | +use mdns_sd::{ServiceDaemon, ServiceInfo}; |
7 | 8 | pub use process_messages::{EngineMessage, IntifaceMessage}; |
| 9 | +use rand::distributions::{Alphanumeric, DistString}; |
| 10 | +use std::collections::HashMap; |
8 | 11 | use std::sync::Arc; |
9 | 12 | use tokio::{ |
10 | 13 | select, |
11 | 14 | sync::{broadcast, Notify}, |
12 | 15 | }; |
13 | 16 | use tokio_util::sync::CancellationToken; |
14 | 17 | use websocket_frontend::WebsocketFrontend; |
15 | | -use mdns_sd::{ServiceDaemon, ServiceInfo}; |
16 | | -use std::collections::HashMap; |
17 | | -use rand::distributions::{Alphanumeric, DistString}; |
18 | 18 |
|
19 | 19 | const VERSION: &str = env!("CARGO_PKG_VERSION"); |
20 | 20 |
|
@@ -75,25 +75,37 @@ pub async fn frontend_server_event_loop( |
75 | 75 | let mut mdns = None; |
76 | 76 |
|
77 | 77 | if options.broadcast_server_mdns() { |
78 | | - // Create a daemon |
| 78 | + // Create a daemon |
79 | 79 | let mdns_daemon = ServiceDaemon::new().expect("Failed to create daemon"); |
80 | 80 |
|
81 | 81 | // Create a service info. |
82 | 82 | let service_type = "_intiface_engine._tcp.local."; |
83 | 83 | let random_suffix = Alphanumeric.sample_string(&mut rand::thread_rng(), 6); |
84 | | - let instance_name = format!("intiface_engine_{}_{}", options.mdns_suffix().as_ref().unwrap_or(&"".to_owned()).to_owned(), random_suffix); |
85 | | - info!("Bringing up mDNS Advertisment using instance name {}", instance_name); |
| 84 | + let instance_name = format!( |
| 85 | + "intiface_engine_{}_{}", |
| 86 | + options |
| 87 | + .mdns_suffix() |
| 88 | + .as_ref() |
| 89 | + .unwrap_or(&"".to_owned()) |
| 90 | + .to_owned(), |
| 91 | + random_suffix |
| 92 | + ); |
| 93 | + info!( |
| 94 | + "Bringing up mDNS Advertisment using instance name {}", |
| 95 | + instance_name |
| 96 | + ); |
86 | 97 | let host_name = format!("{}.local.", instance_name); |
87 | 98 | let port = options.websocket_port().unwrap_or(12345); |
88 | | - let properties:HashMap<String, String> = HashMap::new(); |
| 99 | + let properties: HashMap<String, String> = HashMap::new(); |
89 | 100 | let mut my_service = ServiceInfo::new( |
90 | 101 | service_type, |
91 | 102 | &instance_name, |
92 | 103 | &host_name, |
93 | 104 | "", |
94 | 105 | port, |
95 | | - properties |
96 | | - ).unwrap(); |
| 106 | + properties, |
| 107 | + ) |
| 108 | + .unwrap(); |
97 | 109 | my_service = my_service.enable_addr_auto(); |
98 | 110 | mdns_daemon.register(my_service).unwrap(); |
99 | 111 | mdns = Some(mdns_daemon); |
|
0 commit comments