mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-11 08:06:41 +02:00
configurable client ID
This commit is contained in:
parent
77bd32247a
commit
81f46ff41f
4 changed files with 22 additions and 11 deletions
|
@ -34,14 +34,15 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
Controller::Controller(size_t instance) : MessageReceiver(),
|
Controller::Controller(const std::string& clientId, size_t instance) : MessageReceiver(),
|
||||||
instance_(instance),
|
clientId_(clientId),
|
||||||
active_(false),
|
instance_(instance),
|
||||||
latency_(0),
|
active_(false),
|
||||||
stream_(nullptr),
|
latency_(0),
|
||||||
decoder_(nullptr),
|
stream_(nullptr),
|
||||||
player_(nullptr),
|
decoder_(nullptr),
|
||||||
serverSettings_(nullptr),
|
player_(nullptr),
|
||||||
|
serverSettings_(nullptr),
|
||||||
asyncException_(false)
|
asyncException_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,9 @@ void Controller::worker()
|
||||||
|
|
||||||
/// Say hello to the server
|
/// Say hello to the server
|
||||||
string macAddress = clientConnection_->getMacAddress();
|
string macAddress = clientConnection_->getMacAddress();
|
||||||
msg::Hello hello(macAddress, ::getHostId(macAddress), instance_);
|
if (clientId_.empty())
|
||||||
|
clientId_ = ::getHostId(macAddress);
|
||||||
|
msg::Hello hello(macAddress, clientId_, instance_);
|
||||||
clientConnection_->send(&hello);
|
clientConnection_->send(&hello);
|
||||||
|
|
||||||
/// Do initial time sync with the server
|
/// Do initial time sync with the server
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
class Controller : public MessageReceiver
|
class Controller : public MessageReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Controller(size_t instance);
|
Controller(const std::string& clientId, size_t instance);
|
||||||
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency);
|
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void worker();
|
void worker();
|
||||||
bool sendTimeSyncMessage(long after = 1000);
|
bool sendTimeSyncMessage(long after = 1000);
|
||||||
|
std::string clientId_;
|
||||||
size_t instance_;
|
size_t instance_;
|
||||||
std::atomic<bool> active_;
|
std::atomic<bool> active_;
|
||||||
std::thread controllerThread_;
|
std::thread controllerThread_;
|
||||||
|
|
|
@ -89,6 +89,7 @@ int main (int argc, char **argv)
|
||||||
Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
|
Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
|
||||||
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
|
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
|
||||||
Value<size_t> instanceValue("i", "instance", "instance id", 1, &instance);
|
Value<size_t> instanceValue("i", "instance", "instance id", 1, &instance);
|
||||||
|
Value<string> clientIdValue("", "clientID", "unique client id", "");
|
||||||
Value<string> userValue("", "user", "the user[:group] to run snapclient as when daemonized");
|
Value<string> userValue("", "user", "the user[:group] to run snapclient as when daemonized");
|
||||||
|
|
||||||
OptionParser op("Allowed options");
|
OptionParser op("Allowed options");
|
||||||
|
@ -105,6 +106,7 @@ int main (int argc, char **argv)
|
||||||
.add(userValue)
|
.add(userValue)
|
||||||
#endif
|
#endif
|
||||||
.add(latencyValue)
|
.add(latencyValue)
|
||||||
|
.add(clientIdValue)
|
||||||
.add(instanceValue);
|
.add(instanceValue);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -222,7 +224,7 @@ int main (int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Controller> controller(new Controller(instance));
|
std::unique_ptr<Controller> controller(new Controller(clientIdValue.getValue(), instance));
|
||||||
if (!g_terminated)
|
if (!g_terminated)
|
||||||
{
|
{
|
||||||
logO << "Latency: " << latency << "\n";
|
logO << "Latency: " << latency << "\n";
|
||||||
|
|
|
@ -325,7 +325,12 @@ static std::string getHostId(const std::string defaultId = "")
|
||||||
CFRelease(uuidCf);
|
CFRelease(uuidCf);
|
||||||
#elif ANDROID
|
#elif ANDROID
|
||||||
result = getProp("ro.serialno");
|
result = getProp("ro.serialno");
|
||||||
|
#else
|
||||||
|
std::ifstream infile("/var/lib/dbus/machine-id");
|
||||||
|
if (infile.good())
|
||||||
|
std::getline(infile, result);
|
||||||
#endif
|
#endif
|
||||||
|
strutils::trim(result);
|
||||||
if (!result.empty())
|
if (!result.empty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue