fix: emit PERIPHERAL_DISCONNECTED when meshV2 enters error state #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When the Mesh V2 extension enters an
errorstate (e.g., due to heartbeat failure or expired group), the GUI's connection status icon (the dot in the toolbox) was not updating correctly. This is becauseBlocks.jsxin the GUI only refreshes the status buttons upon receivingPERIPHERAL_CONNECTEDorPERIPHERAL_DISCONNECTEDevents.This PR ensures that
PERIPHERAL_DISCONNECTEDis always emitted when transitioning to theerrorstate, forcing the GUI to update its status icon to the 'error' state (typically shown as an exclamation mark).Implementation Details
gui/scratch-vm/src/extensions/scratch3_mesh_v2/index.js:setConnectionState('error')to always emitPERIPHERAL_DISCONNECTED.PERIPHERAL_CONNECTION_LOST_ERRORwhen the previous state wasconnected.test/unit/extension_mesh_v2.jsandtest/unit/extension_mesh_v2_issue66.jsto match the new event emission sequence.PERIPHERAL_CONNECTION_LOST_ERRORto the mock runtime in tests.Test Coverage
test/unit/extension_mesh_v2.js: Added test cases for state transitions and verified event emission.test/unit/extension_mesh_v2_issue66.js: Verified that expired group scenarios correctly emit the expected events.Fixes #82
Co-Authored-By: Gemini noreply@google.com