This document describes a proposed extension to the <invoke>
element. It would enable SCXML running on Web clients to open a virtual connection to a remote system to send and/or receive events. There is no requirement that the connection be symmetrical, and the underlying implementation doesn't have to be a single persistent connection.
The communication protocol and data encoding are defined by the type of invoke; in fact, the type determines whether it is a normal invocation or a connection. JSSC provides the event-stream type by default, and a two-way connection using WebSockets should be available later.
These attributes are added to <invoke>
:
Name | Required | Type | Default value | Valid values | Description |
---|---|---|---|---|---|
target | if using a connection type, but never both of those | URI | none | Any value accepted by the type implementation | The connection will be opened there. |
targetexpr | Vale expression | none | Evaluates when the <invoke> element is executed, used as if there had been a target attribute with the resulting value. |
Moreover, the src
attribute is forbidden when using a connection type.
Specific connection types may use children (for example param
, jssc:header
and content
) to specify initialization and authentication data. By default, the only useful children are:
param
elements with the location
attributefinalize
elementThe connection is opened when an invoked session would be started, i.e. when its source state becomes active after a macrostep. The connection is closed when the source state is exited (it may also be closed from the other side for any reason).
error.communication.id
(where id is the invokeid) is placed into the internal queue and the connection attempt is abandonned. Note that in the case of browser-based implementations, the user may see the exact reason in the JavaScript console, but the interpreter may not have that privilege.done.invoke.id
event in the external queue. It must not reconnect unless the element's source state is re-entered.While the connection is open:
<send>
elements with their type
attribute set to the type of the connection. Moreover, if the autoforward
attribute was present, all events processed by the interpreter must be sent over the connection at the time they are dequeued.invoke
elements, as long as the implementation pretends to have one virtual connection for every connection-like invoke
.error.execution.parsefailed
must be placed in the internal queue and the event's data field must be left empty.finalize
element is present but empty, and the event data can be parsed as key-value pairs, any names (in the namelist) or locations (in params) specified in the connection and present as properties of the event's data must be updated with the values values in the event's data. If instead the finalize
element contains executable content, that content is executed. Either action must occur when the event is dequeued, as usual.When the invoke
element's source state is exited, the connection is closed. When relevant, the other side should be notified according to the actual protocol used. No done
event is generated by the interpreter when the connection is closed in this way.
As soon as a connection is closed for whatever reason, the interpreter must not send anymore events over it and it must ignore any further events that it receives from it.
Invoke types in JSSC are represented by properties of the SCxml.invokeTypes
object. Adding a new type, whether connection-like or normal invokes, simply means adding a new object. In the case of connection-like types, instead of an instantiate
method, the object should have an open
method with the same arguments, except that the first argument passed to it will be the target instead of the source.