-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nearbyDevicesList refactor, dmt gui small simplification
- Loading branch information
Showing
10 changed files
with
86 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/node/aspect-nearby/nearby/lib/state/nearbyDevicesListRefresh.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default function nearbyDevicesListRefresh({ nearbyDevices, ourMessage, broadcastInterval }, { removeStaleImmediately = false } = {}) { | ||
const list = []; | ||
|
||
const now = Date.now(); | ||
|
||
for (const device of nearbyDevices.filter(({ thisDevice }) => !thisDevice)) { | ||
if (now - device.lastSeenAt > 2.2 * broadcastInterval) { | ||
if (!device.stale && !removeStaleImmediately) { | ||
list.push({ ...device, ...{ stale: true, staleDetectedAt: now } }); | ||
} else if (device.staleDetectedAt && now - device.staleDetectedAt < 3000) { | ||
list.push({ ...device }); | ||
} | ||
} else { | ||
list.push({ ...device, ...{ stale: false, staleDetectedAt: undefined } }); | ||
} | ||
} | ||
|
||
list.push({ ...ourMessage, ...{ thisDevice: true, stale: false, staleDetectedAt: undefined } }); | ||
|
||
return list; | ||
} |
20 changes: 20 additions & 0 deletions
20
core/node/aspect-nearby/nearby/lib/state/updateDeviceList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default function updateDeviceList({ device, announce, program }) { | ||
const { nearbyDevices } = program.state(); | ||
|
||
let found; | ||
|
||
for (let i = 0; i < nearbyDevices.length; i++) { | ||
if (nearbyDevices[i].deviceKey == device.deviceKey) { | ||
nearbyDevices[i] = device; | ||
found = true; | ||
} | ||
} | ||
|
||
if (!found) { | ||
nearbyDevices.push(device); | ||
} | ||
|
||
if (announce) { | ||
program.store.announceStateChange(); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters