Class: SimIFrameClient

SimIFrameClient(frame)

new SimIFrameClient(frame)

This SimIFrameClient communicates to one and only one iframe. Dispose it when you are done with it. There is not any support for having two SimIFrameClients connect to the same sim iframe. Available in the main PhET-iO js import.
Parameters:
Name Type Description
frame Object an HTML element representing the iframe with the simulation.

Methods

addOnErrorListener(callback) → {function}

Adds a callback when any invocation causes an error
Parameters:
Name Type Description
callback function
Returns:
wrapped function that can be removed with SimIFrameClient.removeMessageListener()
Type
function

dispose()

Release resources when the SimIFrameClient instance will no longer be used.

invoke(phetioID, method, argsopt, callbackopt)

Primary way to call a method on the simulation frame from the wrapper frame. Given an instance id, method name, and arguments, invoke the method async and return values then errors (in that order) in the callback.
Parameters:
Name Type Attributes Description
phetioID InvocationData.phetioID The id of the instance
method InvocationData.method The name of the phet-io method
args InvocationData.args <optional>
optional args
callback function <optional>
optional callback, parameters depend on method being invoked.

invokeSequence(sequence, callbackopt)

If you need to send multiple messages or if the order of messages matters, then use invokeSequence. callback is called when the entire sequence is complete.
Parameters:
Name Type Attributes Description
sequence Array.<InvocationData> Each "Invocation" entry in the array will be run async.
callback function <optional>
The arguments will depend on the return values of the methods invoked. The args will be all return values followed by all errors. i.e. if there are five invocations in a sequence call, each returning a single value, then there will be ten arguments in the callback. Further more if all are successful but the last, which returns an error, then there are still ten args, but (one indexed) args 5-9 will be null, and the tenth will hold an Error.

launchSim(optionsopt)

Main launch point for the simulation, send a message into the simulation to begin. Some options can be very helpful in customizing the simulation run before the launch command has been sent to the sim, see LaunchSimOptions object for more.
Parameters:
Name Type Attributes Description
options LaunchSimOptions <optional>
optional parameters to pass to the launch sequence

onPhETiOInitialized(callback)

Adds a callback when the sim frame is ready for intercommunication. This happens even before the sim is ready to launch.
Parameters:
Name Type Description
callback function

onSimInitialized(callback)

Adds a callback which is called when the sim has been initialized, when all screens have been constructed and the sim is ready to be displayed.
Parameters:
Name Type Description
callback function

setValues(map, callback)

Convenience function for setting several values. Note the order of application is not guaranteed.
Parameters:
Name Type Description
map Object
callback function