Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Add support for inspecting via websocket #293

Merged
merged 11 commits into from
Apr 5, 2022

Conversation

jacksteamdev
Copy link
Contributor

@jacksteamdev jacksteamdev commented Oct 11, 2021

Based on discussion #191, this PR adds support for inspecting via websocket. Note the new nested states in inspecting called websocket and window.

New queries have been added to the query string that reflect the parameters for createWebSocketReceiver. server is required and protocol is optional (default is "ws").

http://localhost:3000/viz?inspect&server=localhost:8888
http://localhost:3000/viz?inspect&server=localhost:8888&protocol=ws

The event handlers in inspecting in the invoked proxy service are duplicated. Not sure how dry you want this, but we could pull them out into the module scope inside a function. I've moved the inspect receiver into context to avoid duplicating receiver event handlers. Not sure if this is a problem, maybe someone can suggest a better strategy?

This functionality depends on a PR for @xstate/inspect: statelyai/xstate#2728 Without that PR, this doesn't work on the server side (in my use case, at least).

image

@changeset-bot
Copy link

changeset-bot bot commented Oct 11, 2021

🦋 Changeset detected

Latest commit: c4ee436

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate-viz-app Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 11, 2021

@jacksteamdev is attempting to deploy a commit to the Stately Team on Vercel.

A member of the Team first needs to authorize it.

@davidkpiano
Copy link
Member

Since this is an important PR, can you add some it.todo(...) tests to verify the functionality works as expected? I can help fill them in.

src/simulationMachine.tsx Outdated Show resolved Hide resolved
src/simulationMachine.tsx Outdated Show resolved Hide resolved
@jacksteamdev
Copy link
Contributor Author

@Andarist Any chance this could get a quick review?

const [protocol, ...server] = serverUrl.split('://');
receiver = createWebSocketReceiver({
protocol: protocol as 'ws' | 'wss',
server: server.join('://'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks somewhat off and could lead to some invalid URL being passed here (or rather to an invalid URL being constructed here). We might slightly refactor this later but no need to block this PR on this nit-picky comment

@Andarist Andarist merged commit 67e24ae into statelyai:dev Apr 5, 2022
@github-actions github-actions bot mentioned this pull request Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants