This describes the DOM interfaces for scope. The interfaces are divided into three parts, a common interface which can be used at any time and two specific interfaces. Which one to use depends on the STP version which is currently active.
Accessing the DOM interface is done via the opera object and is only available for the special developer tools window.
This is the common interface and is used to create a new client and to query the STP version in use, either STP/0 or STP/1.
interface Scope {
readonly attribute DOMString stpVersion;
boolean scopeAddClient(in ConnectListener onconnect, in ReceiveListener onreceive, in DisconnectListener ondisconnect, [Optional] in unsigned long port);
};
Contains the STP version of the current connection. The string contains either "STP/0" or "STP/1" for an active connection and "STP/0" when no connection has been made.
Registers a new client in scope along with the callbacks onconnect, onreceive and ondisconnect. The call will initiate contact with the builtin scope or a remote host depending on the port parameter. If a remote host debugging is used then scope will await a connection from the remote host, in other words the remote host must connect using opera:debug.
Note : | It will remove any existing client before setting the new one as the current client |
---|---|
Parameters: |
|
Returns: | true if the client was successfully created, false otherwise. |
[Callback=FunctionOnly] interface ConnectedListener {
void onconnected(in DOMString services);
};
Called when the connection with the (remote or builtin) host has been made. For an STP/0 host this means right after the service list is received, for STP/1 it will happen after the handshake and client connect phase is complete.
Parameters: | services – A string containing a comma separated list of services available in the host. e.g. "scope,ecmascript-debugger,exec" |
---|
interface Stp0 : Scope {
boolean scopeEnableService(in DOMString service);
boolean scopeTransmit(in DOMString service, int DOMString payload);
};
Perform a remote call in specific service.
Parameters: |
|
---|---|
Returns: | true if the data was successfully sent, false otherwise. |
Parameters: | service – Name of service to enable. |
---|---|
Returns: | true if the request to enable a service was succesfully sent, false otherwise. |
[Callback=FunctionOnly] interface ReceiveListener {
void onreceived(in DOMString service, in DOMString payload);
};
Called when a new message has been sent to the client, this can either be a response, an event or an error.
Parameters: |
|
---|
interface Stp1 : Scope {
boolean scopeTransmit(in DOMString service, in any payload, in unsigned long command, in unsigned long tag);
};
Perform a remote call in specific service.
Parameters: |
|
---|---|
Returns: | true if the data was successfully sent, false otherwise. |
A callback which is used whenever a new message (response, event or error) is received from the host.
[Callback=FunctionOnly] interface ReceiveListener {
void onreceived(in DOMString service, in any payload, unsigned long command, unsigned long status, unsigned long tag);
};
Called when a new message has been sent to the client, this can either be a response, an event or an error.
Parameters: |
|
---|
Adding a new client is done with the scopeAddClient call but some additional checking is required once the connection has been made. Two things must be checked, first the capability of the DOM interface then the capability of the (remote or builtin) host.
Example code:
var onconnect = function(services)
{
alert("Services " + services);
if ("stpVersion" in opera)
{
// We are using the STP/1 dom interface
// check which version is in use
if (opera.stpVersion == "STP/1")
alert("Connected to STP/1 host");
else
alert("Connected to STP/0 host but using STP/1 dom interface");
}
else
{
// We are using a pre-STP/1 dom interface
// check for stp-1 in the service list
for (service in services.split(","))
{
if (service == "stp-1")
{
alert("Connected to STP/1 host but using STP/0 dom interface");
return;
}
}
alert("Connected to STP/0 host");
}
}
var onreceive = function(service, message, command, status, tag)
{
if (status != 0)
{
alert("Error in command " + command);
return;
}
if (tag != 0)
{
// Handle response to previous command
}
else
{
// Handle event or non-tagged response
}
}
var ondisconnect = function()
{
alert("Host has been disconnected");
}
opera.scopeAddClient(onconnect, onreceive, ondisconnect, 0)
For STP/0 connections the client must use scopeEnableService to enable a service, otherwise it must do a normal call using scopeTransmit using the Scope.Enable command.
Example code to enable WindowManager in an STP/0 host:
scopeEnableService("window-manager");
No response is received for this.
Example code to enable WindowManager in an STP/1 host:
scopeTransmit("scope", ["window-manager"], 5 /*scope.Enable*/, tag);
The client will receive a normal message in the onreceive callback when the service is enabled.
scopeTransmit is used to send data to the host. For the STP/1 DOM interface this is done using native JavaScript objects, where-as the STP/0 DOM interface requires data as a string and must be manually serialized.
Example code for STP/0:
var onreceive = function(service, message)
{
}
opera.scopeTransmit("ecmascript-debugger", "<get-runtimes></get-runtimes>");
Example code for STP/1:
var onreceive = function(service, message, command, status, tag)
{
}
opera.scopeTransmit("ecmascript-debugger", [], 1, 42);