15 Commits

Author SHA1 Message Date
Paul Falstad
609a5e762b rename circuitws.mjs to avoid mime type issues 2022-09-10 23:00:22 -07:00
Johannes Bauer
961292cce8 WebSocket: cleaned up SVG export API
Made the result of the SVG data to be returned asynchronously as a
event. This makes it possible to significantly clean up the whole SVG
initialization code and not expose these internals to the outside. We do
not need any polling anymore after this change.
2022-09-10 13:59:11 +02:00
Johannes Bauer
fe11f2ed1f WebSocket: properly handle initialization events
We need to register two events: one for the iframe to be loaded, which
will then give us a fresh reference to the contentWindow object. On that
contentWindow we can then attach the CircuitJS event which will fire
once the simulator has fully loaded. This way, no racy behavior is
exhibited and we also don't need to poll the simulator periodically.
2022-09-10 09:21:45 +02:00
Johannes Bauer
7857abbdfe WebSocket: implement automatic shutdown after WS close
The default behavior of the WebSocket shim is to continuously retry to
connect to the WS server. If that server is short-lived and goes away
(possibly during development), the simulator continues running in the
browser window. This option can be specified to instruct the WebSocket
code to never reconnect after the server has gone away and instead to
shut down the whole simulation by redirecting the iframe to about:blank.
2022-09-09 17:58:19 +02:00
Johannes Bauer
29c09b6aac WebSocket: Added documentation
Some documentation added that describes the new WebSocket interface.
2022-09-09 17:38:14 +02:00
Johannes Bauer
2cb46d5633 WebSocket: Allow specification of initial iframe source URI
We want to make it possible to load up the target circuit right from the
start without the demo starting; this way, the circuitws.html file can
be used for simulation purposes without any modification and be
instrumented remotely by the query string.
2022-09-09 17:38:14 +02:00
Johannes Bauer
95927f9244 WebSocket: Refactored event handling code
Change the protocol so that we always return a msgid; this way the
client can reliably wait for the correct response to their query, even
if events intervene.
2022-09-09 16:10:47 +02:00
Johannes Bauer
7ec1a2ab47 WebSocket: Introduce command to wait for simulator availability
We want to know when exactly we can start sending messages to the
simulator; for this we need a way to trigger a message without the
simulator being available yet. Hence move processing of events that do
not need the simulator to the beginning.
2022-09-09 16:10:47 +02:00
Johannes Bauer
4389304c17 WebSocket: Implement command to shutdown simulator
We want to tie up loose ends after our instrumentation end, add a
possibility to shutdown the simulator from the remote websocket.
2022-09-09 16:10:47 +02:00
Johannes Bauer
d5459668c2 WebSocket: Fire event on finished reloading of iframe
When reloading the page, listening just for the iframe "load" event is
insufficient, as there is a small window of time during which the iframe
load event has occured, but the simulator is not yet initialized. We
want to be sure that the client can execute anything without having to
double check, therefore we send an event only when we're sure the
simulator is back up and running.
2022-09-09 16:10:47 +02:00
Johannes Bauer
3232e4ff21 WebSocket: Implement reloading iframe command
Reloading the iframe is useful because it allows implicitly to set all
starting parameters from scratch (e.g., initial circuit, background
color, pos/neg color, etc.). It can be used to generically alter the
simulation parameters because the visuals do have an effect (e.g., for
SVG rendering).
2022-09-09 16:10:47 +02:00
Johannes Bauer
2be192015d WebSocket: Exposing read and write access to timestep
Can now also get and set the simulation-internal timestep that is used
from the JavaScript interface.
2022-09-09 16:10:47 +02:00
Johannes Bauer
3bd621b0c4 WebSocket: Exposed circuit import and export
Can now also import and export circuits from the JavaScript interface.
2022-09-09 16:10:47 +02:00
Johannes Bauer
9c09daa53a WebSocket: SVG export implemented
Exposed the SVG export API through JavaScript.
2022-09-09 16:10:47 +02:00
Johannes Bauer
a048675e94 WebSocket: first implementation of shim
We wrap the already present JS interface so that it connects to an
external server via a WebSocket connection. This allows arbitrary contol
of the circuit from any programming language. Added a CLI example to
demonstrate how it can be remote-controlled from Python using an
interactive command line.
2022-09-09 16:10:47 +02:00