修复局域网连接问题
This commit is contained in:
@@ -109,6 +109,11 @@ func (s *DeviceService) SetOnline(deviceID string, online bool) (model.Device, b
|
||||
|
||||
func (s *DeviceService) ListCandidates(currentDeviceID string) []model.Device {
|
||||
current, _ := s.store.GetDevice(currentDeviceID)
|
||||
currentNetworkGroupKey := strings.TrimSpace(current.NetworkGroupKey)
|
||||
if currentNetworkGroupKey == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devices := s.store.ListDevices()
|
||||
s.applyPresence(devices)
|
||||
candidates := make([]model.Device, 0, len(devices))
|
||||
@@ -117,15 +122,13 @@ func (s *DeviceService) ListCandidates(currentDeviceID string) []model.Device {
|
||||
if device.ID == currentDeviceID || !device.IsOnline {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(device.NetworkGroupKey) != currentNetworkGroupKey {
|
||||
continue
|
||||
}
|
||||
candidates = append(candidates, device)
|
||||
}
|
||||
|
||||
sort.SliceStable(candidates, func(i, j int) bool {
|
||||
leftSameNetwork := current.NetworkGroupKey != "" && candidates[i].NetworkGroupKey == current.NetworkGroupKey
|
||||
rightSameNetwork := current.NetworkGroupKey != "" && candidates[j].NetworkGroupKey == current.NetworkGroupKey
|
||||
if leftSameNetwork != rightSameNetwork {
|
||||
return leftSameNetwork
|
||||
}
|
||||
return candidates[i].LastSeenAt.After(candidates[j].LastSeenAt)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user