- Handling interaction data
- 6.1 The InteractionInput type
- 6.2 The InteractionOutput interface
- 6.2.1 The
value() function - 6.2.2 The arrayBuffer() function
- 6.2.3 The check data schema algorithm
- 6.2.4 The create interaction request algorithm
- 6.2.5 The parse interaction response algorithm
- 6.4 Error handling
- 2 The InteractionOutput interface
- 6.2.1 The
value() function - 6.2.2 The arrayBuffer() function
- 6.2.3 The check data schema algorithm
- 6.2.4 The create interaction request algorithm
- 6.2.5 The parse interaction response algorithm
- The ConsumedThing interface
- 7.1 Internal slots for ConsumedThing
- 7.2 Constructing ConsumedThing
- 7.3 The getThingDescription() method
- 7.4 The readProperty() method
- 7.5 The readMultipleProperties() method
- 7.6 The readAllProperties() method
- 7.7 The writeProperty() method
- 7.8 The writeMultipleProperties() method
- 7.9 The observeProperty() method
- 7.10 The invokeAction() method
- 7.11 The subscribeEvent() method
- 7.12 The InteractionOptions dictionary
- 7.13 The PropertyMap type
- C. full web idl
Handling interaction data
As specified in the
Web of Things Thing Description specification,
WoT
interactions extend DataSchema and include a number
of possible Forms, out of
which one is selected for the interaction.
The
Form contains a contentType to describe the
data. For certain content types, a DataSchema is defined, based on
JSON Schema, making
possible to represent these contents as JavaScript types and
eventually set range constraints on the data.
6.1 The InteractionInput type
typedefanyDataSchemaValue; typedef (ReadableStream orDataSchemaValue)InteractionInput;
Belongs to the WoT Consumer conformance
class and represents the WoT Interaction data
provided by application scripts to the UA.
DataSchemaValue is an
ECMAScript value that is accepted for DataSchema defined in
[WoT-TD] (i.e.
null, boolean, number, string, array, or object).
ReadableStream
is meant to be used for WoT Interactions that
don’t have a DataSchema in the Thing
Description, only a Form‘s
contentType that can be represented by a
stream.
In practice, any
ECMAScript value may be used for WoT Interactions
that have a DataSchema defined in the
Thing Description, or
which can be mapped by implementations to the
Form‘s
contentType defined in the Thing
Description.
The algorithms in this document specify how exactly input
data is used in WoT Interactions.
6.2 The InteractionOutput interface
Belongs to the WoT Consumer conformance
class. An InteractionOutput
object is always created by the implementations and exposes
the data returned from WoT Interactions to
application scripts.
This interface exposes a convenience function which should
cover the vast majority of IoT use cases: the value() function. Its
implementation will inspect the data, parse it if adheres to
a DataSchema, or otherwise fail
early, leaving the underlying stream undisturbed so that
application scripts could attempt reading the stream
themselves, or handling the data as ArrayBuffer.
[SecureContext, Exposed=(Window,Worker)]
interface InteractionOutput {
readonly attributeReadableStream?data;
readonly attributebooleandataUsed;
readonly attributeForm?form;
readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value();
};The data property
represents the raw payload in WoT Interactions as a
ReadableStream,
initially null.
The dataUsed
property tells whether the data stream has been
disturbed. Initially false.
The form attribute
represents the Form
selected from the Thing Description for
this WoT
Interaction, initially null.
The schema
attribute represents the DataSchema (defined in
[WoT-TD]) of the
payload as a JSON
object, initially null.
The [[value]] internal slot represents the
parsed value of the WoT Interaction,
initially undefined (note that null
is a valid value).
6.2.1 The
value() function
value()
Parses
the data returned by the WoT Interaction and
returns a value with the type described by the interaction
DataSchema if that exists,
or by the contentType of the interaction
Form. The method
MUST run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If the value of the [[value]]
internal slot is notundefined,
resolve promise with
that value and abort these steps. - If the value of the data property is not a
or if dataUsed is
ReadableStream
true, or if form is
nullor if schema or its
type arenullor
undefined, reject promise withand abort these steps.
NotReadableError - If form‘s contentType is not
application/jsonand if a mapping is not
available in the Protocol Bindings
from form‘s contentType to
[JSON-SCHEMA],
reject promise with
and abort these steps.
NotSupportedError - Let reader be the result of getting
a reader from data. If that threw an
exception, reject promise
with that exception and abort these steps. - Let bytes be the result of
reading all bytes from data with
reader. - Set dataUsed to
true. - If form‘s contentType is not
application/jsonand if a mapping is
available in the Protocol Bindings
from form‘s contentType to
[JSON-SCHEMA],
transform bytes with that mapping. - Let json be the result of running
parse
JSON from bytes on bytes. If that throws,
reject promise with that
exception and abort these steps. - Set [[value]] to the result of
running check data schema
on json and schema. If that throws,
reject promise with that
exception and abort these steps. - Resolve promise with
[[value]].
6.2.2 The arrayBuffer() function
When invoked,
MUST run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If data is not
or if dataUsed is
ReadableStream
true, reject promise withand abort these steps.
NotReadableError - Let reader be the result of getting
a reader from data. If that threw an
exception, reject promise
with that exception and abort these steps. - Let bytes be the result of
reading all bytes from data with
reader. - Set dataUsed to
true. - Let arrayBuffer be a new
whose contents are
ArrayBuffer
bytes. If that throws, reject
promise with that
exception and abort these steps. - Resolve promise with
arrayBuffer.
6.2.3 The check data schema
algorithm
To run the
check data schema
steps on payload and schema,
- Let type be schema‘s type.
- If type is
"null"and if
payload is notnull, throw
TypeErrorand abort these steps,
otherwise returnnull. - If type is
"boolean"and
payload is a falsey value or its byte length
is 0, returnfalse, otherwise return
true. - If type is
"integer"or
"number",- If payload is not a number, throw
TypeErrorand abort these steps. - If form‘s minimum is
defined and payload is smaller, or if
form‘s maximum is defined and
payload is bigger, throw
RangeErrorand abort these steps.
- If payload is not a number, throw
- If type is
"string", return
payload. - If type is
"array", run these
sub-steps:- If payload is not an array, throw
TypeErrorand abort these steps. - If form‘s minItems is
defined and payload‘s length is
less than that, or if form‘s
maxItems is defined and
payload‘s length is more than
that, throwRangeErrorand abort these steps. - Let payload be an array of items
obtained by running the check data
schema steps on each element item of
payload and schema‘s items. If this
throws at any stage, re-throw that exception and
abort these steps.
- If payload is not an array, throw
- If type is
"object", run
these sub-steps:- If payload or
schema‘s properties is not an
object, throwTypeErrorand abort these steps. - For each property key in
payload,- Let prop be the value of
key. - Let propSchema be the value of
key in interaction‘s
properties. - Let prop be the result of running
the check data
schema steps on prop and
propSchema. If this throws, re-throw
that exception and abort these steps.
- Let prop be the value of
- Let required be schema‘s required if that
is an array or an empty array otherwise. - For each key in required,
if key is not present in
payload, throwand abort these steps.
SyntaxError
- If payload or
- Return payload.
6.2.4 The create interaction
request algorithm
For a
given ConsumedThing
object thing, in order
to create
interaction request given a source, form and schema,
run these steps:
- Let idata be a new an
InteractionOutput
object whose form is set to
form, whose schema is set to
schema, whose [[value]]
internal slot isundefinedand whose
data isnull. - If source is
aobject, let
ReadableStream
idata‘s data be source, return
idata and abort these steps. - If schema and its
type are defined and notnull, run
these sub-steps:- If type is
"null"and
source is
not, throwTypeErrorand abort these steps. - If type is
"boolean"and
source is a
falsy value, set idata‘s [[value]]
value tofalse, otherwise to
true. - If type is
"integer"or
"number"and source is not a number, or
if form‘s
minimum is defined and source is smaller, or if
form‘s maximum
is defined and source is bigger, throw
RangeErrorand abort these steps. - If type is
"string"and
source is not
a string, let idata‘s [[value]] be the
result of running
serialize JSON to bytes on source. If that is
failure, throwand abort these steps.
SyntaxError - If type is
"array", run
these sub-steps:- If source is not an array,
throw aTypeErrorand abort these
steps. - Let length be the length of
source. - If form‘s
minItems is defined and
length is less than that, or if
form‘s
maxItems is defined and
length is more than that, throw
RangeErrorand abort these
steps. - For each item in source, let
itemschema be
schema‘s items and let
item be the result of running the
create
interaction request steps on
item, form and itemschema. If
this throws, re-throw that exception and abort
these steps. - Set data‘s [[value]] to
source.
- If source is not an array,
- If type is
"object", run
these sub-steps:- If source is not an object,
throwTypeErrorand abort these
steps. - If schema‘s
properties is not an object, throw
TypeErrorand abort these
steps. - For each property key in
source,- Let value be the value of
key. - Let propschema be the value of
key in properties. - Let value be the result of
running the create
interaction request steps on
value, form and propschema.
If this throws, re-throw that exception and
abort these steps.
- Let value be the value of
- If schema‘s
required is an array, for each
item in required check if
item is a property name in
source.
If an item is not found in
source,
throwand abort these steps.
SyntaxError - Set data‘s [[value]] to
source.
- If source is not an object,
- If type is
- Set idata‘s data to a new
created from
ReadableStream
idata‘s [[value]]
internal slot as its underlying
source. - Return idata.
6.2.5 The parse interaction
response algorithm
For a
given ConsumedThing
object thing, in order
to parse
interaction response given response,
form and schema, run these steps:
- Let result be a new
InteractionOutput
object. - Let result‘s schema be schema.
- Let result‘s form be form.
- Let result‘s data be a new
with the payload data of
ReadableStream
response as its underlying
source. - Let result‘s dataUsed be
false. - Return result.
As illustrated in the next pictures, the
InteractionOutput
interface is used every time implementations provide data to
scripts, while InteractionInput
is used when the scripts pass data to the implementation.

When a ConsumedThing
reads data, it receives it from the implementation as an
InteractionOutput
object.
An read handlerExposedThing
provides the read data to the implementation as
.InteractionInput

When a ConsumedThing
writes data, it provides it to the implementation as
.InteractionInput
An writeExposedThing
handler receives data from to implementation as an
InteractionOutput
object.

Action
When a ConsumedThing
invokes an Action
data, it provides the parameters as InteractionInput
and receives the output of the Action as an InteractionOutput
object.
An action handlerExposedThing
receives arguments from the implementation as an
InteractionOutput
object and provides Action output as
InteractionInput
to the implementation.
6.4
Error handling
The algorithms in this API define the errors to be
reported to application scripts.
The errors reported to the other communication end are
mapped and encapsulated by the Protocol
Bindings.

2 The InteractionOutput interface
Belongs to the WoT Consumer conformance
class. An InteractionOutput
object is always created by the implementations and exposes
the data returned from WoT Interactions to
application scripts.
This interface exposes a convenience function which should
cover the vast majority of IoT use cases: the value() function. Its
implementation will inspect the data, parse it if adheres to
a DataSchema, or otherwise fail
early, leaving the underlying stream undisturbed so that
application scripts could attempt reading the stream
themselves, or handling the data as ArrayBuffer.
[SecureContext, Exposed=(Window,Worker)]
interface InteractionOutput {
readonly attributeReadableStream?data;
readonly attributebooleandataUsed;
readonly attributeForm?form;
readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value();
};The data property
represents the raw payload in WoT Interactions as a
ReadableStream,
initially null.
The dataUsed
property tells whether the data stream has been
disturbed. Initially false.
The form attribute
represents the Form
selected from the Thing Description for
this WoT
Interaction, initially null.
The schema
attribute represents the DataSchema (defined in
[WoT-TD]) of the
payload as a JSON
object, initially null.
The [[value]] internal slot represents the
parsed value of the WoT Interaction,
initially undefined (note that null
is a valid value).
6.2.1 The
value() function
value()
Parses
the data returned by the WoT Interaction and
returns a value with the type described by the interaction
DataSchema if that exists,
or by the contentType of the interaction
Form. The method
MUST run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If the value of the [[value]]
internal slot is notundefined,
resolve promise with
that value and abort these steps. - If the value of the data property is not a
or if dataUsed is
ReadableStream
true, or if form is
nullor if schema or its
type arenullor
undefined, reject promise withand abort these steps.
NotReadableError - If form‘s contentType is not
application/jsonand if a mapping is not
available in the Protocol Bindings
from form‘s contentType to
[JSON-SCHEMA],
reject promise with
and abort these steps.
NotSupportedError - Let reader be the result of getting
a reader from data. If that threw an
exception, reject promise
with that exception and abort these steps. - Let bytes be the result of
reading all bytes from data with
reader. - Set dataUsed to
true. - If form‘s contentType is not
application/jsonand if a mapping is
available in the Protocol Bindings
from form‘s contentType to
[JSON-SCHEMA],
transform bytes with that mapping. - Let json be the result of running
parse
JSON from bytes on bytes. If that throws,
reject promise with that
exception and abort these steps. - Set [[value]] to the result of
running check data schema
on json and schema. If that throws,
reject promise with that
exception and abort these steps. - Resolve promise with
[[value]].
6.2.2 The arrayBuffer() function
When invoked,
MUST run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If data is not
or if dataUsed is
ReadableStream
true, reject promise withand abort these steps.
NotReadableError - Let reader be the result of getting
a reader from data. If that threw an
exception, reject promise
with that exception and abort these steps. - Let bytes be the result of
reading all bytes from data with
reader. - Set dataUsed to
true. - Let arrayBuffer be a new
whose contents are
ArrayBuffer
bytes. If that throws, reject
promise with that
exception and abort these steps. - Resolve promise with
arrayBuffer.
6.2.3 The check data schema
algorithm
To run the
check data schema
steps on payload and schema,
- Let type be schema‘s type.
- If type is
"null"and if
payload is notnull, throw
TypeErrorand abort these steps,
otherwise returnnull. - If type is
"boolean"and
payload is a falsey value or its byte length
is 0, returnfalse, otherwise return
true. - If type is
"integer"or
"number",- If payload is not a number, throw
TypeErrorand abort these steps. - If form‘s minimum is
defined and payload is smaller, or if
form‘s maximum is defined and
payload is bigger, throw
RangeErrorand abort these steps.
- If payload is not a number, throw
- If type is
"string", return
payload. - If type is
"array", run these
sub-steps:- If payload is not an array, throw
TypeErrorand abort these steps. - If form‘s minItems is
defined and payload‘s length is
less than that, or if form‘s
maxItems is defined and
payload‘s length is more than
that, throwRangeErrorand abort these steps. - Let payload be an array of items
obtained by running the check data
schema steps on each element item of
payload and schema‘s items. If this
throws at any stage, re-throw that exception and
abort these steps.
- If payload is not an array, throw
- If type is
"object", run
these sub-steps:- If payload or
schema‘s properties is not an
object, throwTypeErrorand abort these steps. - For each property key in
payload,- Let prop be the value of
key. - Let propSchema be the value of
key in interaction‘s
properties. - Let prop be the result of running
the check data
schema steps on prop and
propSchema. If this throws, re-throw
that exception and abort these steps.
- Let prop be the value of
- Let required be schema‘s required if that
is an array or an empty array otherwise. - For each key in required,
if key is not present in
payload, throwand abort these steps.
SyntaxError
- If payload or
- Return payload.
6.2.4 The create interaction
request algorithm
For a
given ConsumedThing
object thing, in order
to create
interaction request given a source, form and schema,
run these steps:
- Let idata be a new an
InteractionOutput
object whose form is set to
form, whose schema is set to
schema, whose [[value]]
internal slot isundefinedand whose
data isnull. - If source is
aobject, let
ReadableStream
idata‘s data be source, return
idata and abort these steps. - If schema and its
type are defined and notnull, run
these sub-steps:- If type is
"null"and
source is
not, throwTypeErrorand abort these steps. - If type is
"boolean"and
source is a
falsy value, set idata‘s [[value]]
value tofalse, otherwise to
true. - If type is
"integer"or
"number"and source is not a number, or
if form‘s
minimum is defined and source is smaller, or if
form‘s maximum
is defined and source is bigger, throw
RangeErrorand abort these steps. - If type is
"string"and
source is not
a string, let idata‘s [[value]] be the
result of running
serialize JSON to bytes on source. If that is
failure, throwand abort these steps.
SyntaxError - If type is
"array", run
these sub-steps:- If source is not an array,
throw aTypeErrorand abort these
steps. - Let length be the length of
source. - If form‘s
minItems is defined and
length is less than that, or if
form‘s
maxItems is defined and
length is more than that, throw
RangeErrorand abort these
steps. - For each item in source, let
itemschema be
schema‘s items and let
item be the result of running the
create
interaction request steps on
item, form and itemschema. If
this throws, re-throw that exception and abort
these steps. - Set data‘s [[value]] to
source.
- If source is not an array,
- If type is
"object", run
these sub-steps:- If source is not an object,
throwTypeErrorand abort these
steps. - If schema‘s
properties is not an object, throw
TypeErrorand abort these
steps. - For each property key in
source,- Let value be the value of
key. - Let propschema be the value of
key in properties. - Let value be the result of
running the create
interaction request steps on
value, form and propschema.
If this throws, re-throw that exception and
abort these steps.
- Let value be the value of
- If schema‘s
required is an array, for each
item in required check if
item is a property name in
source.
If an item is not found in
source,
throwand abort these steps.
SyntaxError - Set data‘s [[value]] to
source.
- If source is not an object,
- If type is
- Set idata‘s data to a new
created from
ReadableStream
idata‘s [[value]]
internal slot as its underlying
source. - Return idata.
6.2.5 The parse interaction
response algorithm
For a
given ConsumedThing
object thing, in order
to parse
interaction response given response,
form and schema, run these steps:
- Let result be a new
InteractionOutput
object. - Let result‘s schema be schema.
- Let result‘s form be form.
- Let result‘s data be a new
with the payload data of
ReadableStream
response as its underlying
source. - Let result‘s dataUsed be
false. - Return result.
The ConsumedThing interface
Represents a client API to operate a Thing. Belongs to the WoT Consumer conformance
class.
[SecureContext, Exposed=(Window,Worker)] interfaceConsumedThing{constructor(ThingDescriptiontd);Promise<InteractionOutput>readProperty(DOMStringpropertyName, optionalInteractionOptionsoptions = null);Promise<PropertyMap>readAllProperties(optionalInteractionOptionsoptions = null);Promise<PropertyMap>readMultipleProperties(sequence<DOMString>propertyNames, optionalInteractionOptionsoptions = null);Promise<undefined>writeProperty(DOMStringpropertyName,InteractionInputvalue, optionalInteractionOptionsoptions = null);Promise<undefined>writeMultipleProperties(PropertyMapvalueMap, optionalInteractionOptionsoptions = null);Promise<InteractionOutput>invokeAction(DOMStringactionName, optionalInteractionInputparams = null, optionalInteractionOptionsoptions = null);Promise<Subscription>observeProperty(DOMStringname,InteractionListenerlistener, optionalErrorListeneronerror, optionalInteractionOptionsoptions = null);Promise<Subscription>subscribeEvent(DOMStringname,InteractionListenerlistener, optionalErrorListeneronerror, optionalInteractionOptionsoptions = null);ThingDescriptiongetThingDescription(); }; dictionaryInteractionOptions{unsigned longformIndex;objecturiVariables;anydata; }; [SecureContext, Exposed=(Window,Worker)] interfaceSubscription{ readonly attributebooleanactive;Promise<undefined>stop(optionalInteractionOptionsoptions = null); }; typedefobjectPropertyMap; callbackInteractionListener=undefined(InteractionOutputdata); callbackErrorListener=undefined(Errorerror);
7.1 Internal slots for ConsumedThing
A ConsumedThing
object has the following
internal slots:
7.2 Constructing
ConsumedThing
After fetching
a Thing Description as
a JSON object, one can create a ConsumedThing
object.
7.3 The getThingDescription() method
Returns the
internal slot [[td]] of the ConsumedThing
object that represents the Thing Description of
the .ConsumedThing
Applications may consult the Thing metadata stored in [[td]]
in order to introspect its capabilities before interacting
with it.
7.4 The readProperty() method
7.5 The readMultipleProperties() method
Reads multiple
Property
values with one
request. Takes as arguments
propertyNames
and optionally
options
. It
returns a
Promise
that resolves with a
PropertyMap
object that maps keys from
propertyNames
to values returned by
this algorithm. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - If option‘s formIndex is
defined, let form be the Form associated with
formIndex in [[td]]’s forms array,
otherwise let form be a Form in [[td]]’s
forms array whose op is
readmultipleproperties, selected by the
implementation. - If form is failure, reject
promise with a
SyntaxError
and abort these steps. - Let result be an object
and for each string name in
propertyNames add
a property with key name
and the valuenull. - Make a request to the underlying platform (via the
Protocol Bindings)
to retrieve the Property values given by
propertyNames with
form and optional URI templates given in
options‘
uriVariables. - If this cannot be done with a single request with the
Protocol Bindings,
reject promise with a
and abort these steps.
NotSupportedError - Process the response and for each key in
result, run the following
sub-steps:- Let value be the value of
result‘s
key. - Let schema be the value of [[td]]’s
properties‘s key. - Let property be the result of running
parse
interaction response on value,
form and schema.
- Let value be the value of
- If the above step throws at any point, reject
promise with that
exception and abort these steps. - Resolve promise with
result.
7.6 The readAllProperties() method
Reads all properties of the
Thing
with one request. Takes
options
as
optional argument. It returns a
Promise
that resolves with a
PropertyMap
object that maps keys from
Property
names to values
returned by this algorithm. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - If option‘s formIndex is
defined, let form be the Form associated with
formIndex in [[td]]’s forms array,
otherwise let form be a Form in [[td]]’s
forms array whose op is
readallproperties, selected by the
implementation. - If form is failure, reject
promise with a
SyntaxError
and abort these steps. - Make a request to the underlying platform (via the
Protocol Bindings)
to retrieve the value of the all the Property
definitions from the TD with form and
optional URI templates given in options‘
uriVariables. - If this cannot be done with a single request with the
Protocol Bindings
of the Thing, then reject
promise with a
and abort these steps.
NotSupportedError - If the request fails, reject promise with the error received from the
Protocol Bindings
and abort these steps. - Process the reply and let result be an object with the keys and
values obtained in the reply. - Process the response and for each key in
result, run the following
sub-steps:- Let value be the value of
result‘s
key. - Let schema be the value of [[td]]’s
properties‘s key. - Let property be the result of running
parse
interaction response on value,
form and schema.
- Let value be the value of
- Resolve promise with
result.
7.7 The writeProperty() method
Writes a single
Property
. Takes as
arguments
propertyName
,
value
and
optionally
options
. It returns a
Promise
that resolves on success and rejects on failure. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - Let interaction be the value of [[td]]’s
properties‘s propertyName. - If option‘s formIndex is
defined, let form be the Form associated with
formIndex in interaction‘s
forms array, otherwise let form be
a Form
in interaction‘s forms whose
op iswriteproperty, selected
by the implementation. - If form is failure, reject
promise with a
SyntaxError
and abort these steps. - Let data be the result of running the
create
interaction request steps on value, form and
interaction. If that throws, reject
promise
with that exception and abort these steps. - Make a request to the underlying platform (via the
Protocol Bindings)
to write the Property given by
propertyName using
data and the
optional URI templates given in options‘
uriVariables. - If the request fails, reject promise with the error received from the
Protocol Bindings
and abort these steps. - Otherwise resolve promise.
7.8 The writeMultipleProperties() method
Writes a multiple
Property
values with one
request. Takes as arguments
properties
— as an object with keys being
Property
names and values
as
Property
values — and
optionally
options
. It returns a
Promise
that resolves on success and rejects on failure. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - If option‘s formIndex is
defined, let form be the Form associated with
formIndex in [[td]]’s forms array,
otherwise let form be a Form in [[td]]’s
forms array whose op is
writemultipleproperties, selected by the
implementation. - If form is failure, reject
promise with a
SyntaxError
and abort these steps. - Let propertyNames be an array of
string with as elements the keys of the
properties object. - For each name in
propertyNames, let property be the
value of [[td]]’s properties‘s name. If property is
nullorundefinedor is not
writeablereject promise withand abort these steps.
NotSupportedError - Let result be an object
and for each string name in
propertyNames add a property with key
name and let its value be
null. - Let schemas be an
object and for each string name in propertyNames add a
property with key name and
let its value be the value of [[td]]’s properties‘s name. - For each key key in
properties, take its value
as value and run the create
interaction request steps on value,
form and the value for schema‘s
key. If that throws for
any name, reject
promise
with that exception and abort these steps. - Make a single request to the underlying platform (via
the Protocol
Bindings) to write each Property provided in
properties with optional
URI templates given in options‘
uriVariables. - If this cannot be done with a single request with the
Protocol Bindings
of the Thing, then reject
promise with a
and abort these steps.
NotSupportedError - If the request fails, return the error received from
the Protocol
Bindings and abort these steps. - Otherwise resolve promise.
7.9 The observeProperty() method
7.10 The invokeAction() method
Makes a request for invoking an
Action
and return the result.
Takes as arguments
actionName
, optionally
params
and optionally
options
. It
returns a
Promise
that resolves with the result of the
Action
represented as an
InteractionOutput
object, or rejects with an error. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - Let interaction be the value of [[td]]’s
actions‘s actionName. - If option‘s formIndex is
defined, let form be the Form associated with
formIndex in interaction‘s
forms array, otherwise let form be
a Form
in interaction‘s forms array
whose op isinvokeaction,
selected by the implementation. - If form is failure, reject
promise with a
SyntaxError
and abort these steps. - Let args be the result of running the
create
interaction request steps on params, form and
interaction. If that throws, reject
promise
with that exception and abort these steps. - Make a request to the underlying platform (via the
Protocol Bindings)
to invoke the Action identified by
actionName with
parameters provided in args and optional URI
templates given in options‘s
uriVariables. - If the request fails locally or returns an error over
the network, reject promise with the error received from the
Protocol Bindings
and abort these steps. - Let value be the reply returned in the
reply. - Let result be the result of running
parse
interaction response with value,
form and interaction. If that
throws, reject promise
with that exception and abort these steps. - Resolve promise with
result.
7.11 The subscribeEvent() method
Makes a request for subscribing to
Event
notifications. Takes as
arguments
eventName
,
listener
and optionally
onerror
and
options
. It
returns a
Promise
to signal success or failure. The method
MUST
run the following steps:
- Return a
Promisepromise and execute the
next steps in
parallel. - If invoking this method is not allowed for the
current scripting context for security reasons, reject
promise with a
SecurityError
and abort these steps. - If listener is not
aFunction,
reject promise with a
TypeErrorand abort these steps. - If onerror is
notnulland is not aFunction,
reject promise with a
TypeErrorand abort these steps. - Let subscription be a new
Subscription
object with its
internal slots set as follows: - Make a request to the underlying platform via the
Protocol Bindings
to subscribe to an Event identified by
eventName with [[form]],
optional URI templates given in options‘
uriVariables and optional subscription data
given in options‘s data. - If the request fails, reject promise with the error received from the
Protocol Bindings
and abort these steps. - Otherwise resolve promise.
- Whenever the underlying platform detects a
notification for this Event subscription, run the
following sub-steps:- Invoke listener with the result of
running parse
interaction response on the data provided with
the Event, [[form]] and
[[interaction]].
- Invoke listener with the result of
- Whenever the underlying platform detects an error for
this subscription, run the following sub-steps:
7.12 The InteractionOptions dictionary
Holds the interaction options that need to be exposed for
application scripts according to the Thing
Description.
The formIndex
property, if defined, represents an application hint for
which Form definition, identified by this index,
of the TD to use
for the given WoT interaction. Implementations SHOULD use the Form with this
index for making the interaction, but MAY override this value if the index is not
found or not valid. If not defined, implementations
SHOULD attempt to use the
Form definitions in order of appearance as
listed in the TD for the
given Wot Interaction.
The uriVariables property
if defined, represents the URI template variables to be used
with the WoT Interaction that are represented as parsed
JSON objects defined in [WOT-TD].
The data property if defined, represents
additional opaque data that needs to be passed to the
interaction.
7.13 The PropertyMap
type
Represents a map of Property names as strings to
a value that the Property can take. It is used
as a property bag for interactions that involve multiple
Properties at
once.
C. full web
idl
typedefobjectThingDescription;[SecureContext, Exposed=(Window,Worker)] namespaceWOT{};partial namespaceWOT{Promise<ConsumedThing>consume(ThingDescriptiontd); };partial namespaceWOT{Promise<ExposedThing>produce(ThingDescriptiontd); };partial namespaceWOT{ThingDiscoverydiscover(optionalThingFilterfilter = null); };typedefanyDataSchemaValue; typedef (ReadableStream orDataSchemaValue)InteractionInput;[SecureContext, Exposed=(Window,Worker)] interfaceInteractionOutput{ readonly attributeReadableStream?data; readonly attributebooleandataUsed; readonly attributeForm?form; readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value(); };[SecureContext, Exposed=(Window,Worker)] interfaceConsumedThing{constructor(ThingDescriptiontd);Promise<InteractionOutput>readProperty(DOMStringpropertyName, optionalInteractionOptionsoptions = null);Promise<PropertyMap>readAllProperties(optionalInteractionOptionsoptions = null);Promise<PropertyMap>readMultipleProperties(sequence<DOMString>propertyNames, optionalInteractionOptionsoptions = null);Promise<undefined>writeProperty(DOMStringpropertyName,InteractionInputvalue, optionalInteractionOptionsoptions = null);Promise<undefined>writeMultipleProperties(PropertyMapvalueMap, optionalInteractionOptionsoptions = null);Promise<InteractionOutput>invokeAction(DOMStringactionName, optionalInteractionInputparams = null, optionalInteractionOptionsoptions = null);Promise<Subscription>observeProperty(DOMStringname,InteractionListenerlistener, optionalErrorListeneronerror, optionalInteractionOptionsoptions = null);Promise<Subscription>subscribeEvent(DOMStringname,InteractionListenerlistener, optionalErrorListeneronerror, optionalInteractionOptionsoptions = null);ThingDescriptiongetThingDescription(); }; dictionaryInteractionOptions{unsigned longformIndex;objecturiVariables;anydata; }; [SecureContext, Exposed=(Window,Worker)] interfaceSubscription{ readonly attributebooleanactive;Promise<undefined>stop(optionalInteractionOptionsoptions = null); }; typedefobjectPropertyMap; callbackInteractionListener=undefined(InteractionOutputdata); callbackErrorListener=undefined(Errorerror);[SecureContext, Exposed=(Window,Worker)] interfaceExposedThing{ExposedThingsetPropertyReadHandler(DOMStringname,PropertyReadHandlerhandler);ExposedThingsetPropertyWriteHandler(DOMStringname,PropertyWriteHandlerhandler);ExposedThingsetPropertyObserveHandler(DOMStringname,PropertyReadHandlerhandler);ExposedThingsetPropertyUnobserveHandler(DOMStringname,PropertyReadHandlerhandler);Promise<undefined>emitPropertyChange(DOMStringname);ExposedThingsetActionHandler(DOMStringname,ActionHandleraction);ExposedThingsetEventSubscribeHandler(DOMStringname,EventSubscriptionHandlerhandler);ExposedThingsetEventUnsubscribeHandler(DOMStringname,EventSubscriptionHandlerhandler);ExposedThingsetEventHandler(DOMStringname,EventListenerHandlereventHandler);Promise<undefined>emitEvent(DOMStringname,InteractionInputdata);Promise<undefined>expose();Promise<undefined>destroy();ThingDescriptiongetThingDescription(); }; callbackPropertyReadHandler=Promise<any>( optionalInteractionOptionsoptions = null); callbackPropertyWriteHandler=Promise<undefined>(InteractionOutputvalue, optionalInteractionOptionsoptions = null); callbackActionHandler=Promise<InteractionInput>(InteractionOutputparams, optionalInteractionOptionsoptions = null); callbackEventSubscriptionHandler=Promise<undefined>( optionalInteractionOptionsoptions = null); callbackEventListenerHandler=Promise<InteractionInput>();[SecureContext, Exposed=(Window,Worker)] interfaceThingDiscovery{constructor(optionalThingFilterfilter = null); readonly attributeThingFilter?filter; readonly attributebooleanactive; readonly attributebooleandone; readonly attributeError?error;undefinedstart();Promise<ThingDescription>next();undefinedstop(); };typedefDOMStringDiscoveryMethod;dictionaryThingFilter{ (DiscoveryMethodor DOMString)method= "any";USVString?url;USVString?query;object?fragment; };

