statelyai / xstate-viz

Visualizer for XState machines
https://stately.ai/viz
MIT License
434 stars 102 forks source link

This implements the createWebSocketReceiver receiver... #357

Closed donald-richardson-dxd closed 2 years ago

donald-richardson-dxd commented 2 years ago

...when "server" is present in the url parameters.

You can either provide server without a protocol or with. If you don't provide one it's ws by default (like statecharts.io currently does it). If you provide it, as in wss://localhost:8888 it will provide wss as the protocol to createWebSocketReceiver.

Example urls: http://localhost:3000/viz?inspect&server=localhost:8888 http://localhost:3000/viz?inspect&server=ws://localhost:8888 https://localhost:3000/viz?inspect&server=wss://localhost:8888

changeset-bot[bot] commented 2 years ago

⚠️ No Changeset found

Latest commit: b4fbf0c25976dadeb38e3fa62bed20734fd6e189

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

vercel[bot] commented 2 years ago

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

A member of the Team first needs to authorize it.

donald-richardson-dxd commented 2 years ago

This is a PR for the issue that I poorly described in #356 . I have a headless state machine that I'm visualizing by using the xstate inspect server:

  import { inspect } from '@xstate/inspect/lib/server';
  inspect({
    server: new WebSocket.Server({
      port: 8888
    })
  });

I'm using this locally (actually wrapping it in a native webview) and couldn't use https://statecharts.io/inspect?server=localhost:8888 because of mixed content issues. Also, I preferred not to have to rely on an internet connection. This PR change allows me to use xstate-viz locally with the websocket functionality.

davidkpiano commented 2 years ago

This looks good to me - can you add a changeset by running yarn changeset (this would be a minor change) and run Prettier on the file? Thank you!

Andarist commented 2 years ago

I've just landed an older PR that was implementing exactly this: https://github.com/statelyai/xstate-viz/pull/293 . So I'm going to close this one - I'm sorry that you put some effort into it and it didn't land in the end, the PR itself looks OK, it just turned out to be a duplicate.