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.
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.
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.
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.
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.
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.
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.
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).
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.