| … | … | @@ -109,6 +109,10 @@ export class Rig extends EventEmitter { |
| 109 | 109 | label: cfg.label || id, |
| 110 | 110 | host: cfg.host || id + '.local', // name to dial when mDNS has no address |
| 111 | 111 | addr: null, // address from mDNS, preferred: no lookup to wait on |
| 112 | // Last address this unit was reached at (mDNS or added by IP). Dialled until |
| 113 | // discovery reports it again: on a phone `<name>.local` cannot be resolved at |
| 114 | // all (Android gives apps no DNS config), so without it a known lamp is unreachable. |
| 115 | lastAddr: cfg.lastAddr || null, |
| 112 | 116 | port: cfg.port || 1337, |
| 113 | 117 | manual: !!cfg.manual, |
| 114 | 118 | online: false, |
| … | … | @@ -125,7 +129,7 @@ export class Rig extends EventEmitter { |
| 125 | 129 | } |
| 126 | 130 | // Slots saved as all-null are "no look yet", same as never set. |
| 127 | 131 | if (entry.slots && entry.slots.every((s) => s === null)) entry.slots = null |
| 128 | | entry.unit = new Unit({ id, host: entry.host, port: entry.port, ...this.unitOpts }) |
| 132 | entry.unit = new Unit({ id, host: entry.lastAddr || entry.host, port: entry.port, ...this.unitOpts }) |
| 129 | 133 | entry.unit.on('status', () => this._changed()) |
| 130 | 134 | entry.unit.on('state', (st) => this._onState(entry, st)) |
| 131 | 135 | entry.unit.on('hello', () => this._changed()) |
| … | … | @@ -154,6 +158,10 @@ export class Rig extends EventEmitter { |
| 154 | 158 | e.online = true |
| 155 | 159 | e.proto = ev.proto |
| 156 | 160 | e.addr = ev.addr |
| 161 | if (e.lastAddr !== ev.addr) { |
| 162 | e.lastAddr = ev.addr |
| 163 | this._save() |
| 164 | } |
| 157 | 165 | e.port = ev.port |
| 158 | 166 | e.unit.host = ev.addr // dial the address: never a .local lookup in the path |
| 159 | 167 | e.unit.port = ev.port |
| … | … | @@ -215,6 +223,7 @@ export class Rig extends EventEmitter { |
| 215 | 223 | if (!e) e = this._addUnit(name, { host, port, manual: true }) |
| 216 | 224 | e.host = host |
| 217 | 225 | e.manual = true |
| 226 | if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) e.lastAddr = host |
| 218 | 227 | if (!e.online) { |
| 219 | 228 | e.unit.host = host |
| 220 | 229 | e.unit.port = port |
| … | … | @@ -452,7 +461,7 @@ export class Rig extends EventEmitter { |
| 452 | 461 | const units = {} |
| 453 | 462 | for (const e of this.units.values()) { |
| 454 | 463 | units[e.id] = { |
| 455 | | label: e.label, host: e.host, port: e.port, manual: e.manual, enabled: e.enabled, |
| 464 | label: e.label, host: e.host, lastAddr: e.lastAddr, port: e.port, manual: e.manual, enabled: e.enabled, |
| 456 | 465 | redMax: e.redMax, fadeMs: e.fadeMs, slots: e.slots, gamma: e.gamma, freq: e.freq |
| 457 | 466 | } |
| 458 | 467 | } |