-
Notifications
You must be signed in to change notification settings - Fork 22
/
device.go
64 lines (53 loc) · 1.3 KB
/
device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package airplay
// A Device is an AirPlay Device.
type Device struct {
Name string
Addr string
Port int
Extra DeviceExtra
}
// A DeviceExtra is extra information of AirPlay device.
type DeviceExtra struct {
Model string
Features string
MacAddress string
ServerVersion string
IsPasswordRequired bool
}
// Devices returns all AirPlay devices in LAN.
func Devices() []Device {
devices := []Device{}
for _, entry := range searchEntry(&queryParam{}) {
devices = append(
devices,
entryToDevice(entry),
)
}
return devices
}
// FirstDevice return the first found AirPlay device in LAN.
func FirstDevice() Device {
params := &queryParam{maxCount: 1}
for _, entry := range searchEntry(params) {
return entryToDevice(entry)
}
return Device{}
}
func entryToDevice(entry *entry) Device {
extra := DeviceExtra{
Model: entry.textRecords["model"],
Features: entry.textRecords["features"],
MacAddress: entry.textRecords["deviceid"],
ServerVersion: entry.textRecords["srcvers"],
IsPasswordRequired: false,
}
if pw, ok := entry.textRecords["pw"]; ok && pw == "1" {
extra.IsPasswordRequired = true
}
return Device{
Name: entry.hostName,
Addr: entry.ipv4.String(),
Port: int(entry.port),
Extra: extra,
}
}