mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-02 08:09:35 +02:00
identify client by id instead of MAC
This commit is contained in:
parent
433a2ff252
commit
9ec135e1b8
7 changed files with 61 additions and 50 deletions
|
@ -30,6 +30,7 @@ public class Client implements JsonSerialisable {
|
|||
private ClientConfig config;
|
||||
private Time_t lastSeen;
|
||||
private boolean connected;
|
||||
private string clientId;
|
||||
private boolean deleted = false;
|
||||
|
||||
public Client(JSONObject json) {
|
||||
|
@ -67,6 +68,7 @@ public class Client implements JsonSerialisable {
|
|||
|
||||
lastSeen = new Time_t(json.getJSONObject("lastSeen"));
|
||||
connected = json.getBoolean("connected");
|
||||
clientId = json.getString("id");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -81,6 +83,7 @@ public class Client implements JsonSerialisable {
|
|||
json.put("config", config.toJson());
|
||||
json.put("lastSeen", lastSeen.toJson());
|
||||
json.put("connected", connected);
|
||||
json.put("id", clientId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -118,13 +121,20 @@ public class Client implements JsonSerialisable {
|
|||
public String getVisibleName() {
|
||||
if ((config.getName() != null) && !config.getName().isEmpty())
|
||||
return config.getName();
|
||||
return host.getName();
|
||||
String name = host.getName();
|
||||
if (config.getInstance() > 1)
|
||||
name += " #" + config.getInstance();
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public string getId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
@ -151,6 +161,7 @@ public class Client implements JsonSerialisable {
|
|||
return false;
|
||||
if (config != null ? !config.equals(that.config) : that.config != null) return false;
|
||||
if (connected != that.connected) return false;
|
||||
if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null) return false;
|
||||
return (deleted == that.deleted);
|
||||
}
|
||||
|
||||
|
@ -160,6 +171,7 @@ public class Client implements JsonSerialisable {
|
|||
result = 31 * result + (snapclient != null ? snapclient.hashCode() : 0);
|
||||
result = 31 * result + (config != null ? config.hashCode() : 0);
|
||||
result = 31 * result + (connected ? 1 : 0);
|
||||
result = 31 * result + (clientId != null ? clientId.hashCode() : 0);
|
||||
result = 31 * result + (deleted ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public class ClientConfig implements JsonSerialisable {
|
|||
Volume volume;
|
||||
int latency = 0;
|
||||
String stream = "";
|
||||
int instance = 1;
|
||||
|
||||
public ClientConfig() {
|
||||
volume = new Volume();
|
||||
|
@ -45,6 +46,7 @@ public class ClientConfig implements JsonSerialisable {
|
|||
volume = new Volume(json.getJSONObject("volume"));
|
||||
latency = json.getInt("latency");
|
||||
stream = json.getString("stream");
|
||||
instance = json.getInt("instance");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -58,6 +60,7 @@ public class ClientConfig implements JsonSerialisable {
|
|||
json.put("volume", volume.toJson());
|
||||
json.put("latency", latency);
|
||||
json.put("stream", stream);
|
||||
json.put("instance", instance);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -96,6 +99,10 @@ public class ClientConfig implements JsonSerialisable {
|
|||
this.stream = stream;
|
||||
}
|
||||
|
||||
public int getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
|
@ -111,6 +118,7 @@ public class ClientConfig implements JsonSerialisable {
|
|||
if (latency != that.latency) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (stream != null ? !stream.equals(that.stream) : that.stream != null) return false;
|
||||
if (instance != that.instance) return false;
|
||||
return !(volume != null ? !volume.equals(that.volume) : that.volume != null);
|
||||
|
||||
}
|
||||
|
@ -120,6 +128,7 @@ public class ClientConfig implements JsonSerialisable {
|
|||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (volume != null ? volume.hashCode() : 0);
|
||||
result = 31 * result + latency;
|
||||
result = 31 * result + instance;
|
||||
result = 31 * result + (stream != null ? stream.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue