Document new TypeScript SDK MachineConnectionEvent values (RECONNECTING, RECONNECTION_FAILED)#4937
Document new TypeScript SDK MachineConnectionEvent values (RECONNECTING, RECONNECTION_FAILED)#4937shannonbradshaw wants to merge 3 commits intonew-docs-sitefrom
Conversation
viamrobotics/viam-typescript-sdk#864 added two new MachineConnectionEvent values: RECONNECTING (emitted as soon as the SDK starts retrying after an unintentional drop) and RECONNECTION_FAILED (emitted when retries are exhausted, with error and attempts on the payload). DISCONNECTED is now only emitted on intentional close or when noReconnect is set. Update the connection-state how-to, the dashboard tutorial, and the how-apps-connect concept page to add the two new states, switch the rebuild-after-reconnect trigger from DISCONNECTED to RECONNECTING, and note the new payload fields.
✅ Deploy Preview for viam-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Updates the Build Apps documentation to reflect newly added MachineConnectionEvent values in the TypeScript SDK (RECONNECTING, RECONNECTION_FAILED) and the updated semantics for when DISCONNECTED is emitted.
Changes:
- Expanded
MachineConnectionEventdocumentation to include the two new events and clarified emission semantics in the main connection-state handling guide. - Updated the dashboard tutorial’s
watchConnectionexample and testing narrative to reflect the new reconnection event flow. - Added a reconnection narrative note in the connection model concept doc describing the new events and payload fields.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/build-apps/tasks/handle-connection-state.md | Adds the two new connection events, replaces outdated “five values” prose with a 7-row table, and updates the rebuild-after-reconnect guidance. |
| docs/build-apps/app-tutorials/tutorial-dashboard.md | Updates the connection-state switch example and test instructions to include RECONNECTING / RECONNECTION_FAILED. |
| docs/build-apps/concepts/how-apps-connect.md | Extends reconnection narrative to mention RECONNECTING and RECONNECTION_FAILED plus payload fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (eventType === VIAM.MachineConnectionEvent.RECONNECTING) { | ||
| wasReconnecting = true; | ||
| } | ||
| if (eventType === VIAM.MachineConnectionEvent.CONNECTED && wasDisconnected) { | ||
| wasDisconnected = false; | ||
| if (eventType === VIAM.MachineConnectionEvent.CONNECTED && wasReconnecting) { | ||
| wasReconnecting = false; | ||
| await rebuildAfterReconnect(); |
There was a problem hiding this comment.
In the rebuild-after-reconnect example, wasReconnecting is set to true on RECONNECTING but is only cleared when a subsequent CONNECTED arrives. If reconnection ultimately fails (or the client is intentionally closed), the flag stays true, so a later fresh connect could incorrectly be treated as a “reconnect” and trigger rebuildAfterReconnect(). Consider clearing the flag on RECONNECTION_FAILED/DISCONNECTED (and/or tracking a reconnect attempt ID) so the example doesn’t misfire after a failed reconnect.
There was a problem hiding this comment.
Good catch — the flag would misfire on a subsequent fresh connect. Rewrote the example as a switch that clears wasReconnecting on RECONNECTION_FAILED and DISCONNECTED as well, and added a sentence in the surrounding prose explaining why. Fixed in 5e5989d.
Generated by Claude Code
…CTION_FAILED The previous rebuild-after-reconnect example set wasReconnecting = true on RECONNECTING but only cleared it on CONNECTED. If reconnection failed (or the client was intentionally closed) and the user later started a fresh connect, its first CONNECTED event would be incorrectly treated as a reconnect and trigger rebuildAfterReconnect. Rewrite the example as a switch that clears the flag on both RECONNECTION_FAILED and DISCONNECTED, and document that rule in the surrounding prose.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Source change
4a3bfca): TheMachineConnectionEventenum gained two values:RECONNECTING(emitted as soon as the SDK starts retrying after an unintentional drop) andRECONNECTION_FAILED(emitted when retries are exhausted, witherrorandattemptsfields on the payload).DISCONNECTEDis now only emitted on intentional close or whennoReconnectis set.Docs changes
docs/build-apps/tasks/handle-connection-state.md: added the two new states to the main switch example and the in-browser status example; replaced the "five values" prose with a seven-row table that explains when each value is emitted; rewrote the rebuild-after-reconnect example to trigger onRECONNECTINGinstead ofDISCONNECTEDand noted the new event semantics.docs/build-apps/app-tutorials/tutorial-dashboard.md: addedRECONNECTING(orange) andRECONNECTION_FAILED(red) cases to the dashboard'swatchConnectionswitch; updated the test description to mention the new "Reconnecting..." indicator.docs/build-apps/concepts/how-apps-connect.md: added a sentence describing the newRECONNECTINGandRECONNECTION_FAILEDevents in the reconnection-narrative section.How I found these
MachineConnectionEvent,RECONNECTING,RECONNECTION_FAILED,DIALING,DISCONNECTINGacross the docs repo.viam-typescript-sdk/src/robot/client.ts'sonDisconnectand reconnect handlers and insrc/events.ts.Generated by daily docs change agent