diff --git a/.pr-preview.json b/.pr-preview.json new file mode 100644 index 00000000..010969ea --- /dev/null +++ b/.pr-preview.json @@ -0,0 +1,4 @@ +{ + "src_file": "index.html", + "type": "respec" + } diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..04f41dc4 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +All documentation, code and communication under this repository are covered by the [W3C Code of Ethics and Professional Conduct](https://www.w3.org/Consortium/cepc/). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..706c373d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# Web of Things Working Group + +Contributions to this repository are intended to become part of Recommendation-track documents governed by the +[W3C Patent Policy](http://www.w3.org/Consortium/Patent-Policy-20040205/) and +[Software and Document License](http://www.w3.org/Consortium/Legal/copyright-software). To make substantive contributions to specifications, you must either participate +in the relevant W3C Working Group or make a non-member patent licensing commitment. + +If you are not the sole contributor to a contribution (pull request), please identify all +contributors in the pull request comment. + +To add a contributor (other than yourself, that's automatic), mark them one per line as follows: + +``` ++@github_username +``` + +If you added a contributor by mistake, you can remove them in a comment with: + +``` +-@github_username +``` + +If you are making a pull request on behalf of someone else but you had no part in designing the +feature, you can remove yourself with the above syntax. + +For further guidelines, refer to [https://github.com/w3c/wotwg#contributing](https://github.com/w3c/wotwg#contributing). diff --git a/Overview.html b/Overview.html new file mode 100644 index 00000000..60d57b03 --- /dev/null +++ b/Overview.html @@ -0,0 +1,5747 @@ + + +
+ + + + + + + +Copyright + © 2017-2018 W3C® + (MIT, + ERCIM, + Keio, Beihang). W3C + liability, + trademark and + permissive document license rules apply.
+The overall Web of Things (WoT) concepts are + described in the WoT Architecture + document. The Web of Things is made of entities (Things) that can describe their capabilities in a + machine-interpretable format, the Thing Description (TD) and expose these capabilities + through the WoT Interface, that is, network + interactions modeled as Properties for reading + and writing values, Actions to execute remote procedures + with or without return values and Events for signaling + notifications.
+This specification describes a programming interface + representing the WoT Interface that + allows scripts run on a Thing to discover and + consume (retrieve) other Thing Descriptions + and to expose Things characterized by WoT Interactions specified by a script.
+Scripting is an optional "convenience" building block in WoT + and it is typically used in gateways that are able to run a + WoT Runtime and + script management, providing a convenient way to extend WoT + support to new types of endpoints and implement WoT + applications like + Thing Directory.
+This section describes the status of this document at + the time of its publication. Other documents may supersede this + document. A list of current W3C publications and the + latest revision of this technical report can be found in the + W3C technical reports + index at https://www.w3.org/TR/.
+Implementers need to be aware that this specification is + considered unstable. Vendors interested in implementing this + specification before it eventually reaches the Candidate + Recommendation phase should subscribe to the repository and + take part in the discussions.
+Please contribute to this draft using the + GitHub + Issue feature of the WoT Scripting + API repository. For feedback on security and privacy + considerations, please use the WoT Security and + Privacy Issues.
+This document was published by the Web of Things Working Group as + a Working Draft. This document is intended to become a W3C + Recommendation.
+Comments regarding this document are welcome. Please send + them to public-wot-wg@w3.org + (subscribe, + archives).
+Changes from the previous publication can be found in + Appendix A. A diff-marked version of this document is also + available for comparison purposes.
+Publication as a Working Draft does not imply endorsement by + the W3C + Membership. This is a draft document and may be updated, + replaced or obsoleted by other documents at any time. It is + inappropriate to cite this document as other than work in + progress.
+This document was produced by a group operating under the + W3C Patent Policy. + W3C maintains a + public list + of any patent disclosures made in connection with the + deliverables of the group; that page also includes instructions + for disclosing a patent. An individual who has actual knowledge + of a patent which the individual believes contains Essential + Claim(s) must disclose the information in accordance with + section + 6 of the W3C + Patent Policy.
+This document is governed by the 1 February 2018 + W3C Process + Document.
+WoT provides layered interoperability based on how Things are modeled: as being "consumed" and + "exposed".
+By consuming a TD, a client Thing creates a runtime resource model that allows + accessing the Properties, Actions and + Events exposed by the server Thing exposed on a + remote device.
+Exposing a Thing requires defining a Thing Description (TD) and instantiating a software + stack to serve requests for accessing the exposed Properties, Actions and Events. This specification describes how to expose + and consume Things by a script.
+Typically scripts are meant to be used on devices + able to provide resources (with a WoT Interface) for managing (installing, updating, + running) scripts, such as bridges or gateways that expose and + control simpler devices as WoT Things.
+This specification does not make assumptions on + how the WoT Runtime handles and runs + scripts, including single or multiple tenancy, script + deployment and lifecycle management. The API already supports + the generic mechanisms that make it possible to implement + script management, for instance by exposing a manager + Thing whose Actions (action + handlers) implement script lifecycle management + operations.
+For an introduction on how scripts could be used in Web of Things, check the Primer + document. For some background on API design decisions check the + Rationale + document.
+This section is non-normative.
+The following scripting use cases are supported in this + specification:
+ExposedThing
to be exposed, based on
+ a Thing Description provided in
+ string serialized format, or out of a template or an
+ existing ConsumedThing
object.
+ WoT
+ objectThe WoT object is the API entry point and it is exposed by + an implementation of the WoT Runtime. The + WoT object + does not expose properties, only methods for discovering, + consuming and exposing a Thing.
+Browser implementations SHOULD use a namespace object such as
+ navigator.wot
. Node.js-like runtimes MAY provide the API object through
+ the require() or
+
+ import mechanism.
// [SecureContext] +// [NamespaceObject] +interface+WoT
{ +Observable
discover
(optionalThingFilter
filter); + Promise<ThingDescription
>fetch
(USVString url); +ConsumedThing
consume
(ThingDescription
td); +ExposedThing
produce
(ThingModel
model); + Promise<void>register
(USVString directory,ExposedThing
thing); + Promise<void>unregister
(USVString directory,ExposedThing
thing); +}; +typedef objectThingFragment
; +typedef objectPropertyFragment
; +typedef objectActionFragment
; +typedef objectEventFragment
; +typedef objectDataSchema
; +typedef objectSecurityScheme
; +typedef objectLink
; +typedef objectForm
; +typedef USVStringThingDescription
; +typedef (ThingFragment
orThingDescription
)ThingModel
;
The algorithms for the WoT methods will be + specified later, including error handling and security + considerations.
+The ThingModel
type represents
+ either a ThingFragment
, or a
+ ThingDescription
.
discover()
+ methodStarts the discovery process that will provide ThingDescription
s that match the
+ optional argument filter of type
. Returns an
+ [ThingFilter
Observable
](https://github.com/tc39/proposal-observable)
+ object that can be subscribed to and unsubscribed from. The
+ handler function provided to the Observable during
+ subscription will receive an argument of type
+ USVString
representing a ThingDescription
.
DiscoveryMethod
+ enumerationtypedef DOMString DiscoveryMethod
;
+ DiscoveryMethod
+ represents the discovery type to be used:
ThingFilter
+ dictionaryThe ThingFilter
+ dictionary that represents the constraints for discovering
+ Things as key-value pairs.
dictionary ThingFilter
{
+ (DiscoveryMethod
or DOMString) method
= "any";
+ USVString? url
;
+ USVString? query
;
+ ThingFragment
? fragment
;
+};
+ The method
+ property represents the discovery type that should be used
+ in the discovery process. The possible values are defined
+ by the
enumeration
+ that MAY be extended
+ by string values defined by solutions (with no guarantee of
+ interoperability).DiscoveryMethod
The url
property
+ represents additional information for the discovery method,
+ such as the URL of the target entity serving the discovery
+ request, for instance a Thing
+ Directory (if method
is
+ "directory"
) or a Thing (otherwise).
The query
+ property represents a query string accepted by the
+ implementation, for instance a SPARQL or JSON query.
+ Support may be implemented locally in the WoT Runtime or remotely as a service in a
+ Thing Directory.
The fragment
property
+ represents a ThingFragment
dictionary used for
+ matching property by property against discovered Things.
The discover(filter)
method MUST run the following steps:
discover()
is not allowed for
+ the current scripting context for security reasons, throw
+ SecurityError
and terminate these steps.Observable
obs and
+ execute the next steps in parallel.
+ obs.subscribe(handler, errorHandler,
+ complete)
is called, execute the following
+ sub-steps:
+ TypeError
and terminate the algorithm.
+ Otherwise configure handler to be invoked
+ when a discovery hit happens.TypeError
and terminate these steps.
+ Otherwise if defined, save it to be invoked in error
+ conditions.TypeError
and terminate these steps.
+ Otherwise if defined, save it to be invoked when the
+ discovery process finished for other reasons than
+ having been canceled.NotSupported
error and terminate these
+ steps.
+ ThingFragment
,
+ throw TypeError
and terminate these steps.
+ Otherwise save the object for matching the discovered
+ items against it.
+ "any"
, use the widest
+ discovery method supported by the underlying
+ platform.
+ "local"
, use the local Thing Directory for
+ discovery. Usually that defines Things deployed in the same device, or
+ connected to the device in slave mode (e.g.
+ sensors connected via Bluetooth or a serial
+ connection).
+
+ "directory"
, use the remote Thing Directory
+ specified in filter.url.
+ "multicast"
, use all the multicast
+ discovery protocols supported by the underlying
+ platform.false
, discard td and
+ continue the discovery process.false
in any checks, discard td
+ and continue the discovery process.Error
whose
+ message
property is set to
+ UnknownError
unless there was an error code
+ provided by the Protocol Bindings,
+ in which case set it to that value.
+ obs.unsubscribe()
method is
+ called, run the following cancel discovery steps:
+ false
.fetch()
+ methodAccepts an url
argument of type
+ USVString
that represents a URL (e.g.
+ "file://..."
or "https://..."
) and
+ returns a Promise
that resolves with a
+ ThingDescription
(a
+ serialized JSON-LD document of type
+ USVString
).
The fetch(url)
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ fetch()
is not allowed for the
+ current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.TypeError
and
+ terminate these steps.application/td+json
), as far
+ as a valid Thing Description
+ can be obtained as defined in [WOT-TD]. Let td
+ be the Thing Description
+ string-serialized from the returned content, as specified
+ in the
+ Thing Description serialization.
+ Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ consume()
+ methodAccepts an td
argument of type
and returns a
+ ThingDescription
ConsumedThing
object
+ instantiated based on parsing that description.
The consume(td)
method must run the following
+ steps:
TypeError
and terminate these steps.ThingFragment
with a default value,
+ add that property and value to stub.
+ ConsumedThing
object
+ thing initialized from stub that
+ implements Observable
.
+ read()
and write()
+ methods to the ThingProperty
elements so that they
+ make requests to access the remote Things and
+ wait for the reply, as defined by the Protocol Bindings. Also, all
+ ThingProperty
+ elements SHOULD
+ implement Observable
, i.e.
+ define a subscribe()
method that should make
+ request to observe the given Properties
+ as defined by the Protocol Bindings.
+ invoke()
methods to the ThingAction
elements so that they
+ make requests to the remote Thing to invoke its
+ actions, as defined by the Protocol
+ Bindings.
+ subscribe()
method to all
+ ThingEvent
elements
+ so that they make requests to subscribe to the events
+ defined by the remote Thing, as defined
+ by the Protocol Bindings.
+ produce()
+ methodAccepts a model
argument of type
+
and
+ returns an ThingModel
ExposedThing
+ object.
The produce(model)
method MUST run the following steps:
produce()
is not allowed for
+ the current scripting context for security reasons, throw
+ SecurityError
and terminate these steps.TypeError
and terminate these steps.ThingFragment
with a default value,
+ add that property and value to model.
+ ExposedThing
object thing
+ initialized from model.
+ ExposedThing
defined in ThingFragment
, initialize the
+ property based on the provided initial or default values
+ provided to the local WoT Runtime
+ implementation, for instance initialize:
+ id
property to be the final unique
+ identifier of the Thing,
+ security
object of type SecurityScheme
to
+ represent the actual security scheme and its properties
+ as set up by the implementation,
+ properties
property to be an
+ object with all properties being ThingProperty
+ objects in which the read()
and
+ write()
methods are provided to define
+ local methods to get and set the Property values,
+ actions
property to be an object
+ with all properties being ThingAction
objects in which the
+ invoke()
method is provided to define a
+ local method to run the defined Actions,
+ events
property to be an object
+ with all properties being ExposedEvent
objects in which
+ the emit()
method is provided to define a
+ local way to trigger sending notifications to all
+ subscribed clients,
+ The TD parsing algorithm + takes a string td as argument and runs the + following steps:
+register()
+ methodTakes two mandatory arguments:
+directory
denoting a Thing Directory, and
+ thing
denoting an ExposedThing
object.
+ Generate the Thing Description as
+ td, given the Properties, Actions and Events defined for
+ this ExposedThing
object.
+ Then make a request to register td to the given
+ WoT Thing Directory.
+ unregister()
methodTakes two mandatory arguments:
+directory
denoting a Thing Directory, and
+ thing
denoting an ExposedThing
object.
+ Makes a request to unregister the thing
from
+ the given WoT Thing Directory.
let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let subscription = wot.discover(discoveryFilter).subscribe(
+ td => {
+ console.log("Found Thing " + td.name);
+ // fetch the TD and create a ConsumedThing
+ let thing = wot.consume(td);
+ },
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log("Discovery timeout");
+ },
+ 5000);
+ let subscription = wot.discover({ method: "local" }).subscribe(
+ td => { console.log("Found local Thing " + td.name); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({ method: "local" }).subscribe({
+ td => { console.log("Found local Thing " + td.name); },
+ error: err => { console.log("Discovery error: " + err.message); },
+ complete: () => { console.log("Discovery finished successfully");}
+});
+ ConsumedThing
+ interfaceRepresents an object that extends a ThingFragment
with methods for client
+ interactions (send request for reading and writing Properties), invoke Actions, subscribe and
+ unsubscribe for Property changes and Events.
interface+ConsumedThing
:ThingFragment
{ + readonly attribute DOMStringid
; + readonly attribute DOMStringname
; + readonly attribute DOMString?base
; + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeEventMap
events
; + // getter for ThingFragment properties + getter any (DOMString name); +}; +[NoInterfaceObject] +interfacePropertyMap
{ + readonly maplike<DOMString,ThingProperty
>; +}; +[NoInterfaceObject] +interfaceActionMap
{ + readonly maplike<DOMString,ThingAction
>; +}; +[NoInterfaceObject] +interfaceEventMap
{ + readonly maplike<DOMString,ThingEvent
>; +}; +ConsumedThing
includesObservable
; // for TD changes
The id
attribute
+ represents the unique identifier of the Thing instance,
+ typically a URI, IRI, or URN as USVString
.
The name
attribute
+ represents the name of the Thing as
+ DOMString
.
The base
attribute
+ represents the base URI that is valid for all defined local
+ interaction resources.
The properties
+ attribute represents a dictionary of ThingProperty
items. The
+ PropertyMap
interface
+ represents a maplike dictionary where all values are ThingProperty
objects. The
+ read()
and write()
methods make a
+ request to access the Properties on the remote
+ Thing represented by this ConsumedThing
proxy object.
The actions
+ attribute represents a dictionary of ThingAction
items. The
+ ActionMap
interface represents a
+ maplike dictionary where all values are ThingAction
objects. The
+ invoke()
method represents a request to invoke the
+ Action on the remote Thing.
The events
+ attribute represents a dictionary of ThingEvent
items. The EventMap
interface
+ represents a maplike dictionary where all values are ThingEvent
objects. Subscribing to the
+ events involves setting up an observation (subscription)
+ mechanism on the remote object.
Below a
interface example
+ is given.ConsumedThing
try {
+ let subscription = wot.discover({ method: "local" }).subscribe(
+ td => {
+ let thing = wot.consume(td);
+ console.log("Thing " + thing.name + " has been consumed.");
+ let subscription = thing["temperature"].subscribe(function(value) {
+ console.log("Temperature: " + value);
+ });
+ thing.actions["startMeasurement"].invoke({ units: "Celsius" })
+ .then(() => { console.log("Temperature measurement started."); })
+ .catch(e => {
+ console.log("Error starting measurement.");
+ subscription.unsubscribe();
+ })
+ },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+ );
+} catch(error) {
+ console.log("Error: " + error.message);
+};
+ ExposedThing
+ interfaceThe ExposedThing
interface is
+ the server API that allows defining request handlers,
+ properties, Actions, and Events to a
+ Thing. It also implements the Observable
interface. An ExposedThing
is created by the produce() method.
interface+ExposedThing
:ThingFragment
{ + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeExposedEvents
events
; + // getter for ThingFragment properties + getter any (DOMString name); + // setter for ThingFragment properties + setter void (DOMString name, any value); + // methods to expose and destroy the Thing + Promise<void>expose
(); + Promise<void>destroy
(); + // define Properties +ExposedThing
addProperty
(DOMString name,PropertyFragment
property, optional any initValue); +ExposedThing
setPropertyReadHandler
(DOMString name,PropertyReadHandler
readHandler); +ExposedThing
setPropertyWriteHandler
(DOMString name,PropertyWriteHandler
writeHandler); +ExposedThing
removeProperty
(DOMString name); + // define Actions +ExposedThing
addAction
(DOMString name,ActionFragment
init,ActionHandler
action); +ExposedThing
removeAction
(DOMString name); +ExposedThing
setActionHandler
(DOMString name,ActionHandler
action); + // define Events +ExposedThing
addEvent
(DOMString name,EventFragment
event); +ExposedThing
removeEvent
(DOMString name); +}; +[NoInterfaceObject] +interfaceExposedEvents
{ + maplike<DOMString,ExposedEvent
>; +}; +callbackPropertyReadHandler
= Promise<any> (); +callbackPropertyWriteHandler
= Promise<void> (any value); +callbackActionHandler
= Promise<any> (any parameters);
The properties
+ attribute represents a dictionary of ThingProperty
items in which the
+ read()
and write()
methods define
+ local methods that access the physical representations of the
+ Properties.
The actions
+ attribute represents a dictionary of ThingAction
items in which the
+ invoke()
method represents a local method to
+ invoke the Action.
The events
+ attribute represents a dictionary of ExposedEvent
items that add the
+ emit()
method to the ThingEvent
definition. The
+ ExposedEvents
interface
+ represents a maplike dictionary where all values are ExposedEvent
objects.
expose()
methodStart serving external requests for the Thing, so that WoT Interactions + using Properties, Actions and + Events will be possible.
+The expose()
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ expose()
is not allowed for
+ the current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ destroy()
methodStop serving external requests for the Thing and destroy the object. Note that eventual + unregistering should be done before invoking this method.
+The destroy()
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ destroy()
is not allowed for
+ the current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ addProperty()
methodAdds a Property with name defined by the
+ name argument, the data schema provided by the
+ property argument of type PropertyFragment
, and optionally an
+ initial value provided in the argument initValue
+ whose type should match the one defined in the
+ type
property according to the value-matching algorithm. If
+ initValue is not provided, it SHOULD be initialized as
+ undefined
. Implementations SHOULD update the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
removeProperty()
methodRemoves the Property specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addAction()
methodAdds to the actions
property of a Thing object an Action with name
+ defined by the name argument, defines input and
+ output data format by the init argument of type
+ ActionFragment
, and
+ adds the function provided in the action argument
+ as a handler, then updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
The provided action callback function will
+ implement invoking an Action and SHOULD be called by
+ implementations when a request for invoking the Action is received from the underlying platform.
+ The callback will receive a parameters
+ dictionary argument according to the definition in the
+ init.input argument and will return a value of
+ type defined by the init.output argument according
+ to the value-matching
+ algorithm.
There SHOULD be
+ exactly one handler for any given Action. If no
+ handler is initialized for any given Action,
+ implementations SHOULD throw a TypeError
.
removeAction()
methodRemoves the Action specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addEvent()
methodAdds an event with name defined by the name
+ argument and qualifiers and initialization value provided by
+ the event argument of type EventFragment
to the Thing object and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
removeEvent()
methodRemoves the event specified by the name
+ argument and updates the Thing
+ Description. Returns a reference to the same object for
+ supporting chaining.
PropertyReadHandler
+ callbackA function that is called when an external request for
+ reading a Property is received. It should
+ return a Promise and resolves it with the value of the
+ Property matching the name
argument to
+ the setPropertyReadHandler
function, or rejects
+ with an error if the property is not found or the value
+ cannot be retrieved.
PropertyWriteHandler
+ callbackA function that is called when an external request for
+ writing a Property is received. It is given
+ the requested new value
as argument and should
+ return a Promise which is resolved when the value of the
+ Property that matches the name
+ argument has been updated with value
, or rejects
+ with an error if the property is not found or the value
+ cannot be updated.
Note that this function is invoked by
+ implementations before the property is updated and it
+ actually defines what to do when a write request is
+ received. The code in this callback function can invoke the
+ read()
method to find out the old value of the
+ property, if needed. Therefore the old value is not
+ provided to this function.
ActionHandler
+ callbackA function called with a parameters
+ dictionary argument assembled by the WoT runtime based on the Thing Description and the external client request.
+ It returns a Promise that rejects with an error or resolves
+ if the action is successful or ongoing (may also resolve with
+ a control object such as an Observable
for actions that need
+ progress notifications or that can be canceled).
setPropertyReadHandler()
methodTakes name
as string argument and
+ readHandler
as argument of type PropertyReadHandler
.
+ Sets the handler function for reading the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
The readHandler
callback function will
+ implement reading a Property and
+ SHOULD be called by
+ implementations when a request for reading a Property is received from the underlying
+ platform.
There SHOULD be at + most one handler for any given Property and + newly added handlers replace the old handlers. If no handler + is initialized for any given Property, + implementations SHOULD implement a default property read + handler.
+When an external request for reading Property propertyName is received, the + runtime SHOULD + execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ setPropertyWriteHandler()
methodTakes name
as string argument and
+ writeHandler
as argument of type PropertyWriteHandler
.
+ Sets the handler function for writing the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
There SHOULD be at + most one write handler for any given Property and newly added handlers replace the old + handlers. If no write handler is initialized for any given + Property, implementations SHOULD implement default property update + and notifying observers on change.
+When an external request for writing a Property propertyName with a new value + value is received, the runtime SHOULD execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ setActionHandler()
methodTakes name
as string argument and
+ action
as argument of type ActionHandler
. Sets the handler
+ function for the specified Action matched by
+ name
. Throws on error. Returns a reference to
+ the same object for supporting chaining.
The action
callback function will implement
+ an Action and SHOULD be called by implementations when a
+ request for invoking the Action is received
+ from the underlying platform.
There SHOULD be at + most one handler for any given Action and newly added + handlers replace the old handlers.
+When an external request for invoking the Action identified by name is received, + the runtime SHOULD + execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ ReferenceError
and terminate these steps.
+ Below some
interface examples
+ are given.ExposedThing
+ try {
+ var temperatureValueDefinition = {
+ type: "number",
+ minimum: -50,
+ maximum: 10000
+ };
+ var temperaturePropertyDefinition = temperatureValueDefinition;
+ // add the 'forms' property
+ temperaturePropertyDefinition.forms = [ ... ];
+ var thing = WoT.produce({
+ name: "tempSensor",
+ properties: {
+ temperature: temperaturePropertyDefinition
+ },
+ actions: {
+ reset: {
+ description: "Reset the temperature sensor",
+ input: {
+ temperature: temperatureValueDefinition
+ },
+ output: null,
+ forms: []
+ },
+ },
+ events: {
+ onchange: temperatureValueDefinition
+ },
+ links: []
+ });
+ await thing.expose();
+ await wot.register("https://mydirectory.org", thing);
+ // define Thing business logic
+ setInterval( async () => {
+ let mock = Math.random()*100;
+ let old = await thing["temperature"].read();
+ if (old < mock) {
+ await thing["temperature"].write(mock);
+ thing.emitEvent("onchange", mock);
+ }
+ }, 1000);
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ try {
+ var statusValueDefinition = {
+ type: "object",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true
+ },
+ rgb: {
+ type: "array",
+ "minItems": 3,
+ "maxItems": 3,
+ items : {
+ "type" : "number",
+ "minimum": 0,
+ "maximum": 255
+ }
+ }
+ };
+ var statusPropertyDefinition = statusValueDefinition;
+ // add the 'forms' property
+ statusPropertyDefinition["forms"] = [];
+ var thing = WoT.produce({
+ name: "mySensor",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true,
+ },
+ status: statusPropertyDefinition
+ },
+ actions: {
+ status: {
+ description: "Get status object",
+ input: null,
+ output: {
+ status : statusValueDefinition;
+ },
+ forms: []
+ },
+ },
+ events: {
+ onstatuschange: statusValueDefinition;
+ },
+ links: []
+ });
+ thing.expose().then(() => {
+ thing.register();
+ });
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ let thingDescription = '{ \
+ "name": "mySensor", \
+ "@context": [ "http://www.w3.org/ns/td",\
+ "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ],\
+ "@type": [ "Thing", "Sensor" ], \
+ "geo:location": "testspace", \
+ "properties": { \
+ "prop1": { \
+ "type": "number",\
+ "@type": [ "Property", "Temperature" ], \
+ "saref:TemperatureUnit": "degree_Celsius" \
+ } } }';
+try {
+ // note that produce() fails if thingDescription contains error
+ let thing = WoT.produce(thingDescription);
+ // Interactions were added from TD
+ // WoT adds generic handler for reading any property
+ // define a specific handler for one property
+ let name = "examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log("Handling read request for " + name);
+ return new Promise((resolve, reject) => {
+ let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log("Error");
+ });
+ });
+ thing.expose();
+} catch(err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ // fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+ // WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+ // Interactions were added from TD
+ // add server functionality
+ // ...
+});
+ The [WOT-TD] specification defines the + + WoT information model, i.e. the data types and data + structures used in WoT Interactions. In + this API these definitions translate to dictionary objects that + are extended with methods by the interfaces defined in this + specification.
+In order to avoid duplication of definitions, references to + these data types and structures is defined in this section, but + for their full description please refer to the Thing + Description specification.
+DataSchema
+ dictionary and its subclassesValue types basically represent types that may be used in
+ JSON object definitions and are used in ThingFragment
to define Properties, Events and Action parameters. Value types are represented as
+ dictionary objects whose properties and possible sub-classes
+ are defined in the
+ DataSchema section of [WOT-TD].
One property of all DataSchema
dictionary is the
+ type
property whose value is from a set of
+ enumerated strings defined in the DataSchema
+ section of [WOT-TD] and is referred as
+ DataType in
+ this specification.
Based on type
, the following sub-classes of
+ DataSchema
are defined in
+ [WOT-TD]: BooleanSchema, NumberSchema, IntegerSchema, StringSchema, ObjectSchema, ArraySchema.
SecurityScheme
dictionary
+ and its subclassesSecurity metadata is represented as dictionary objects + whose properties and sub-classes are defined in the + SecurityScheme section of [WOT-TD].
+One property of the SecurityScheme
dictionary is the
+ scheme
property whose value is from a set of
+ enumerated strings defined in the
+ SecurityScheme section of [WOT-TD]. Based on type
,
+ multiple subclasses of SecurityScheme
are defined.
Link
dictionaryRepresents a Web Link with + properties defined in the Link + section of [WOT-TD].
+Form
dictionaryRepresents metadata describing service details, with + properties defined in the Form + section of [WOT-TD].
+InteractionFragment
+ dictionaryRepresents the common properties of WoT Interactions, one of Property,
+ Action or Event, as defined in the
+ InteractionPattern section of [WOT-TD]. Its subclasses are
+ referred as PropertyFragment
, ActionFragment
and EventFragment
.
PropertyFragment
+ dictionaryRepresents the Property interaction
+ data that initializes a ThingProperty
object. Its properties
+ are defined in the Property
+ and
+ InteractionPattern sections of [WOT-TD].
ActionFragment
+ dictionaryRepresents the Action interaction data that
+ initializes a ThingAction
object. Its
+ properties are defined in the Action
+ and
+ InteractionPattern sections of [WOT-TD].
EventFragment
+ dictionaryRepresents the Event interaction data that
+ initializes a ThingEvent
object. Its
+ properties are defined in the Event
+ section of [WOT-TD].
ThingFragment
+ dictionaryThe ThingFragment
+ dictionary is defined as Thing
+ in [WOT-TD]. It is a dictionary that
+ contains properties representing semantic metadata and
+ interactions (Properties, Actions and
+ Events). It is used for initializing an internal
+ representation of a Thing Description and
+ its properties may be used in ThingFilter
.
ThingDescription
+ typeSerialized representation of the Thing Description (a JSON-LD document).
+In this version of the API, Thing Descriptions are represented
+ as an opaque USVString
that can be transmitted
+ between devices.
The data types and structures imported from [WOT-TD] are extended by + this specification in order to provide the interfaces for + WoT Interactions.
+Every Thing describes its metadata as
+ defined in ThingFragment
, and basic
+ interactions defined as Properties, Actions and Events. The following interfaces are
+ used for representing these interactions.
Interaction
+ interfaceThe Interaction
interface
+ is an abstract class to represent Thing
+ interactions: Properties, Actions and
+ Events.
The InteractionFragment
+ dictionary holds the common properties of PropertyFragment
, ActionFragment
and EventFragment
dictionaries used for
+ initializing ThingProperty
, ThingAction
and ThingEvent
objects in a ThingFragment
dictionary used for
+ creating an ExposedThing
+ object.
interface+Interaction
{ + readonly attribute (Form
or FrozenArray<Form
>)forms
; +}; +Interaction
includesInteractionFragment
;
The forms
read-only
+ property represents the protocol bindings initialization data
+ and is initialized by the WoT Runtime.
ThingProperty
+ interfaceThe ThingProperty
interface
+ is used in ConsumedThing
and
+ ExposedThing
objects to
+ represent Thing Property
+ interactions.
The PropertyFragment
+ dictionary is used for initializing Property objects
+ in a ThingFragment
+ dictionary used for creating an ExposedThing
object. It MUST implement one of the
+ DataSchema
dictionaries.
interface+ThingProperty
:Interaction
{ + // getter for PropertyFragment properties + getter any (DOMString name); + // get and set interface for the Property + Promise<any>read
(); + Promise<void>write
(any value); +}; +ThingProperty
includesPropertyFragment
; +ThingProperty
includesObservable
;
The ThingProperty
interface
+ contains all the properties defined on PropertyFragment
as read-only
+ properties.
The type
+ read-only property represents the type definition for the
+ Property as a DataSchema
dictionary object.
The writable read-only property tells
+ whether the Property value can be updated. If it
+ is false
, then the set(value)
+ method SHOULD always
+ reject.
The observable read-only
+ property tells whether the Property supports
+ subscribing to value change notifications. If it is
+ false
, then the subscribe()
method
+ SHOULD always
+ fail.
The constant read-only property
+ - defined in DataSchema
- tells
+ whether the Property value is a constant. If
+ true
, the set()
and
+ subscribe()
methods SHOULD always fail.
The required read-only property
+ - defined in DataSchema
- tells
+ whether the Property should be always present on
+ the ExposedThing
+ object.
The read()
+ method will fetch the value of the Property.
+ Returns a Promise that resolves with the
+ value, or rejects with an error.
The
+ write()
method will attempt to set the value of
+ the Propertyspecified in the
+ value
argument whose type SHOULD match the one specified by the
+ type
property. Returns a Promise that
+ resolves on success, or rejects on an error.
ThingAction
+ interfaceinterface+ThingAction
:Interaction
{ + Promise<any>invoke
(optional any inputValue); +}; +ThingAction
includesActionFragment
;
The
+ invoke()
method when invoked, starts the
+ Action interaction with the input value provided by
+ the inputValue argument. If inputValue
+ is null
, the action does not take any arguments
+ and rejects if any arguments are provided. If the value is
+ undefined
, the action will ignore any arguments
+ provided. Otherwise the type of inputValue
+ SHOULD match the
+ DataSchema
definition in the
+ input
property. Returns a Promise that
+ will reject with an error or will resolve with a value of
+ type defined by the output
property.
ThingEvent
interfaceinterface+ThingEvent
:Interaction
{ +}; +ThingEvent
includesEventFragment
; +ThingEvent
includesThingProperty
;
Since ThingEvent
implements
+ Observable
through the ThingProperty
interface, event
+ subscription is done by invoking the subscribe()
+ method on the event object that returns a cancelable Subscription
.
ExposedEvent
+ interfaceinterface ExposedEvent
: ThingEvent
{
+ void emit
(any payload);
+};
+ emit()
+ methodEmits an event that carries data specified by the
+ payload
argument.
The value-matching algorithm is applied to a
+ value input in relation to a valueType
+ property of type DataSchema
, for instance the
+ value
and type
properties of a
+ PropertyFragment
+ object, or the inputValue parameter to the
+ invoke()
method of a ThingAction
object in relation to the
+ same object. It executes the following steps:
false
.
+ "null"
: if value is
+ null
, return true
, otherwise
+ return false
."boolean"
: if value is either
+ true
or false
, then return
+ true
, otherwise return
+ false
."integer"
: if value is not an
+ integer type defined by the underlying platform (such as
+ long
or long long
), then return
+ false
, otherwise execute the following
+ sub-steps:
+ true
."number"
, if value is not an
+ integer or floating point type defined by the underlying
+ platform (such as long
or long
+ long
or double
), then return
+ false
, otherwise otherwise execute the
+ following sub-steps:
+ true
."string"
: if value is not a string
+ type defined by the underlying platform, then return
+ false
, otherwise return true
. In this
+ case the algorithm expects a third parameter
+ valueType.enum and runs the following
+ sub-steps:
+ "array"
, execute the following sub-steps:
+ false
.undefined
, return false
.null
, return true
(i.e. any
+ type is accepted as array element, including
+ heterogenous arrays).false
, then return
+ false
.
+ true
."object"
,
+ execute the following sub-steps:
+ Object
,
+ return false
.false
.null
, return true
(i.e.
+ accept any object value).false
.true
.This section is non-normative.
+Observables are proposed to + be included in ECMAScript and are used for handling pushed data + associated with various possible sources, for instance events, + timers, streams, etc. A minimal required implementation is + described here.
+This section is informal and contains rather + laconic information for implementations on what to support + for interoperability.
+interface+Observable
{ +Subscription
subscribe
(EventHandler handler, + optionalErrorHandler
errorHandler, + optionalOnComplete
onComplete); +}; +interfaceSubscription
{ + voidunsubscribe
(); + readonly attribute booleanclosed
; +}; +callbackEventHandler
= void (any value); +callbackErrorHandler
= void (Error error); +callbackOnComplete
= void ();
The following callbacks can be provided when subscribing to
+ an Observable
:
EventHandler
callback takes
+ the next sample for the data in the value
+ argument.ErrorHandler
callback takes
+ an error in the value
argument. It is called
+ when an error occurred in producing the data the client should
+ know about.OnComplete
callback is called
+ when the data source has finished sending values.Subscription
+ interfaceContains the closed
+ property of type boolean
that tells if the
+ subscription is closed or active.
Also, contains the unsubscribe
()
+ method that cancels the subscription, i.e. makes a request to
+ the underlying platform to stop receiving data from the
+ source, and sets the closed
property to
+ false
.
Observable
interfaceThe Observable
interface
+ enabled subscribing to pushed data notifications by the
+ subscribe
()
+ method:
In general the security measures taken to protect a WoT + system will depend on the threats and attackers that system may + face and the value of the assets needs to protect. A detailed + discussion of security and privacy considerations for the Web + of Things, including a threat model that can be adapted to + various circumstances, is presented in the informative document + [WOT-SECURITY-CONSIDERATIONS]. + This section includes only normative recommendations relevant + to the WoT Thing Description.
+When designing new devices and services + for use with the WoT, we have documented a set of best + practices in [WOT-SECURITY-BEST-PRACTICES] + that SHOULD be + followed. This best-practices document may be updated as + security measures evolve. Following these practices does not + guarantee security, but it at least will help to avoid common + known vulnerabilities and pitfalls.
+Below are specific recommendations related to WoT runtime + implementations:
+Some additional specific recommendations relevant for WoT + script developers:
+The generic WoT terminology is defined in [WOT-ARCHITECTURE]: + Thing, Thing Description (in short + TD), + Web of + Things (in short WoT), WoT Interface, + Protocol + Bindings, WoT Runtime, Consuming a Thing + Description, Thing Directory, + WoT + Interactions, Property, + Action, Event etc.
+JSON-LD is + defined in [JSON-LD] as a JSON document that is + augmented with support for Linked Data.
+The terms URL and URL path are defined in + [URL].
+The following terms are defined in [HTML52] and are used in the context + of browser implementations: + + + browsing + context, + + + top-level browsing + context, + + + global + object, + + + incumbent settings + object, + + + Document, + + + document base URL, + + + Window, + + + WindowProxy, + + + origin, + + + ASCII + serialized origin, + + executing algorithms + + + in parallel, + + + queue a task, + + + task source, + + + iframe, + + + valid MIME type.
+ +A browsing context refers to the
+ environment in which Document objects are
+ presented to the user. A given browsing context
+ has a single WindowProxy
+ object, but it can have many Document
+ objects, with their associated Window
+ objects. The script execution context
+ associated with the browsing context identifies the
+ entity which invokes this API, which can be a web app, a
+ web page, or an iframe.
The term + secure + context is defined in [WEBAPPSEC].
+Error, EvalError, RangeError, ReferenceError, SyntaxError, + TypeError, + URIError , + script execution + context, + Promise, + + JSON, + JSON.stringify and + JSON.parse are defined in + [ECMASCRIPT].
+DOMString, USVString, ArrayBuffer, BufferSource and any are defined in + [WEBIDL].
+The algorithms utf-8 encode, and utf-8 decode are defined in + [ENCODING].
+IANA media + types (formerly known as MIME types) are defined in + RFC2046.
+The terms hyperlink reference and + relation + type are defined in [HTML52] and RFC8288.
+As well as sections marked as non-normative, all authoring + guidelines, diagrams, examples, and notes in this specification + are non-normative. Everything else in this specification is + normative.
+The key words MAY, MUST, SHOULD, and SHOULD NOT + are to be interpreted as described in [RFC2119].
+This document defines conformance criteria that apply to a + single product: the UA (user agent) that implements the interfaces + it contains.
+This specification can be used for implementing the WoT + Scripting API in multiple programming languages. The interface + definitions are specified in [WEBIDL].
+The user agent (UA) may be implemented in the browser, or in + a separate runtime environment, such as Node.js or small embedded + runtimes.
+Implementations that use ECMAScript executed in a browser to + implement the APIs defined in this document MUST implement them in a manner consistent + with the ECMAScript Bindings defined in the Web IDL + specification [WEBIDL].
+Implementations that use TypeScript or ECMAScript in a + runtime to implement the APIs defined in this document + MUST implement them in a + manner consistent with the TypeScript Bindings defined in the + TypeScript specification [TYPESCRIPT].
+This document serves a general description of the WoT + Scripting API. Language and runtime specific issues are + discussed in separate extensions of this document.
+The following is a list of major changes to the document. + For a complete list of changes, see the github + change log. You can also view the + recently closed issues.
+The following problems are being discussed and need most + attention:
+ExposedThing
+ (https://github.com/w3c/wot-scripting-api/issues/45).
+ Special thanks to former editor Johannes Hund (until August + 2017, when at Siemens AG) for developing this specification. + Also, the editors would like to thank Dave Raggett, Matthias + Kovatsch, Michael Koster and Michael McCool for their comments + and guidance.
++ +Copyright + +© +2017-2018 + + +W3C + + + +® + +( + + +MIT + +, + + +ERCIM + +, + +Keio +, + +Beihang + +). + +W3C + + +liability +, + +trademark + +and + +permissive +document +license + +rules +apply. +
+
+The
+overall
+
+
+Web
+of
+Things
+
+(WoT)
+provides
+layered
+interoperability
+between
+
+concepts
+are
+described
+in
+the
+
+WoT
+Architecture
+
+document.
+The
+Web
+of
+
+Things
+is
+made
+of
+entities
+(
+
+Thing
+
+
+by
+using
+
+s)
+that
+can
+describe
+their
+capabilities
+in
+a
+machine-interpretable
+format,
+the
+
+Thing
+Description
+
+(TD)
+and
+expose
+these
+capabilities
+through
+
+the
+
+WoT
+Interface
+,
+that
+is,
+network
+interactions
+modeled
+as
+
+Properties
+
+
+s.
+
+for
+reading
+and
+writing
+values,
+
+Action
+
+s
+to
+execute
+remote
+procedures
+with
+or
+without
+return
+values
+and
+
+Event
+
+s
+for
+signaling
+notifications.
+
+
+This
+specification
+describes
+a
+programming
+interface
+representing
+the
+
+WoT
+Interface
+
+that
+allows
+scripts
+run
+on
+a
+
+Thing
+
+to
+discover
+and
+consume
+(retrieve)
+other
+
+Thing
+Description
+
+
+s
+and
+to
+expose
+
+Things
+
+characterized
+by
+
+WoT
+Interactions
+,
+i.e.
+Properties
+,
+Actions
+
+
+and
+Events
+.
+
+specified
+by
+a
+script.
+
+
+Scripting +is +an +optional +"convenience" +building +block +in +WoT +and +it +is +typically +used +in +gateways +that +are +able +to +run +a + +WoT +Runtime + +and + +script +management +, +providing +a +convenient +way +to +extend +WoT +support +to +new +types +of +endpoints +and +implement +WoT +applications +like + +Thing +Directory +. +
++ +This +section +describes +the +status +of +this +document +at +the +time +of +its +publication. +Other +documents +may +supersede +this +document. +A +list +of +current + +W3C + +publications +and +the +latest +revision +of +this +technical +report +can +be +found +in +the + + +W3C + +technical +reports +index + +at +https://www.w3.org/TR/. + +
++Implementers +need +to +be +aware +that +this +specification +is +considered +unstable. +Vendors +interested +in +implementing +this +specification +before +it +eventually +reaches +the +Candidate +Recommendation +phase +should +subscribe +to +the + +repository + +and +take +part +in +the +discussions. +
++Please +contribute +to +this +draft +using +the + +GitHub +Issue + +feature +of +the + +WoT +Scripting +API + +repository. +For +feedback +on +security +and +privacy +considerations, +please +use +the + +WoT +Security +and +Privacy + +Issues. +
++This +document +was +published +by +the + +Web +of +Things +Working +Group + +as +a +Working +Draft. +This +document +is +intended +to +become +a +W3C +Recommendation. +
++Comments +regarding +this +document +are +welcome. +Please +send +them +to + +public-wot-wg@w3.org + +( + +subscribe +, + +archives + +). +
++Changes +from +the +previous +publication +can +be +found +in + +Appendix +A +. +A + +diff-marked +version + +of +this +document +is +also +available +for +comparison +purposes. +
++Publication +as +a +Working +Draft +does +not +imply +endorsement +by +the + +W3C + +Membership. +This +is +a +draft +document +and +may +be +updated, +replaced +or +obsoleted +by +other +documents +at +any +time. +It +is +inappropriate +to +cite +this +document +as +other +than +work +in +progress. +
++This +document +was +produced +by +a +group +operating +under +the + + +W3C + +Patent +Policy +. + +W3C + +maintains +a + +public +list +of +any +patent +disclosures + +made +in +connection +with +the +deliverables +of +the +group; +that +page +also +includes +instructions +for +disclosing +a +patent. +An +individual +who +has +actual +knowledge +of +a +patent +which +the +individual +believes +contains + +Essential +Claim(s) + +must +disclose +the +information +in +accordance +with + +section +6 +of +the + +W3C + +Patent +Policy +. +
++This +document +is +governed +by +the + +1 +February +2018 + +W3C + +Process +Document +. +
+
+The
+overall
+
+WoT
+concepts
+are
+described
+in
+the
+WoT
+Architecture
+document.
+The
+Web
+of
+Things
+is
+made
+of
+entities
+(
+Thing
+s)
+that
+can
+describe
+their
+capabilities
+in
+a
+machine-interpretable
+format,
+the
+
+provides
+layered
+interoperability
+based
+on
+how
+
+Thing
+Description
+
+
+(TD)
+
+s
+are
+modeled:
+as
+being
+"consumed"
+
+and
+expose
+these
+capabilities
+through
+the
+WoT
+Interface
+.
+Support
+for
+scripting
+is
+optional
+for
+WoT
+devices.
+
+"exposed".
+
+
+By
+
+consuming
+a
+TD
+,
+a
+client
+
+Thing
+
+creates
+a
+runtime
+resource
+model
+that
+allows
+accessing
+the
+
+Properties
+,
+
+Actions
+
+and
+
+Events
+
+exposed
+by
+the
+server
+
+Thing
+.
+
+
+exposed
+on
+a
+remote
+device.
+
+
+Exposing
+a
+
+Thing
+
+requires
+defining
+a
+
+Thing
+Description
+
+(TD)
+and
+instantiating
+a
+software
+stack
+needed
+
+to
+serve
+requests
+for
+accessing
+the
+exposed
+
+Properties
+,
+
+Actions
+
+and
+
+Events
+.
+This
+specification
+describes
+how
+to
+expose
+and
+consume
+
+Thing
+
+s
+by
+a
+script.
+
+Typically
+scripts
+are
+meant
+to
+be
+used
+on
+devices
+able
+to
+provide
+resources
+(with
+a
+
+WoT
+interface
+
+Interface
+
+
+)
+for
+managing
+(installing,
+updating,
+running)
+scripts,
+such
+as
+bridges
+or
+gateways
+that
+expose
+and
+control
+simpler
+devices
+as
+WoT
+
+Thing
+
+s.
+
+This +specification +does +not +make +assumptions +on +how +the + +WoT +Runtime + +handles +and +runs +scripts, +including +single +or +multiple +tenancy, +script +deployment +and +lifecycle +management. +The +API +already +supports +the +generic +mechanisms +that +make +it +possible +to +implement +script +management, +for +instance +by +exposing +a +manager + +Thing + +whose + +Actions + +(action +handlers) +implement +script +lifecycle +management +operations. +
++For +an +introduction +on +how +scripts +could +be +used +in + +Web +of +Things +, +check +the + +Primer + +document. +For +some +background +on +API +design +decisions +check +the + +Rationale + +document. +
++ +This +section +is +non-normative. + +
++The +following +scripting +use +cases +are +supported +in +this +specification: +
+
+ExposedThing
+
+
+to
+be
+exposed,
+based
+on
+a
+
+Thing
+Description
+
+provided
+in
+string
+serialized
+format,
+or
+out
+of
+a
+template
+or
+an
+existing
+
+
+ConsumedThing
+
+
+object.
+
+WoT
+
+
+object
+
+
++The +WoT +object +is +the +API +entry +point +and +it +is +exposed +by +an +implementation +of +the + +WoT +Runtime +. +The + +WoT +object + +does +not +expose +properties, +only +methods +for +discovering, +consuming +and +exposing +a + +Thing +. +
+
+Browser
+implementations
+
+SHOULD
+
+use
+a
+namespace
+object
+such
+as
+
+
.
+
+Node.js
+
+-like
+runtimes
+
+MAY
+
+provide
+the
+API
+object
+through
+the
+
+require()
+
+or
+
+import
+
+mechanism.
+wot
+,
+and
+
+navigator.wot
+
data-idl="" data-title="WoT">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-wot" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-wot-discover-filter" data-idl= +"" data-title="discover" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-observable" class="internalDFN" +data-link-type="dfn"><<a href= +"#dom-consumedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="wot" data-lt= +"discover()|discover" href="#dom-wot-discover" class="internalDFN" +data-link-type="dfn">discover(<span class= +"idlParam">optional <a href= +"#dom-thingfilter" class="internalDFN" data-link-type= + +data-idl="" data-title="WoT">// [SecureContext] +// [NamespaceObject] +interface +data-link-for="" data-lt="" href="#dom-wot" class="internalDFN" +data-link-type="dfn">+WoT
{ + +data-link-type= +"dfn">Observable
discover
(optional +"dfn">ThingFilter
"idlParamName">filter +<span class="idlMethod" id="idl-def-wot-fetch-url" data-idl="" +data-title="fetch" data-dfn-for="wot"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<<a href="#dom-thingdescription" +class="internalDFN" data-link-type= + +"idlParamName">filter); + +"https://heycam.github.io/webidl/#idl-promise">Promise< +"dfn">ThingDescription
> "fetch()|fetch" href="#dom-wot-fetch" class="internalDFN" +data-link-type="dfn">fetch(<span class= + +"wot.fetch()|wot.fetch|fetch()|fetch" href="#dom-wot-fetch" class= +"internalDFN" data-link-type= +"dfn">fetch
( +"idlParam">"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id="idl-def-wot-consume-td" data-idl="" +data-title="consume" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-consumedthing" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-USVString">USVString url); + "dfn"><a data-no-default="" +data-link-for="wot" data-lt="consume()|consume" href= + +"dfn">ConsumedThing
+"#dom-wot-consume" class="internalDFN" data-link-type= +"dfn">consume<span class= +"idlParamType"><a href="#dom-thingdescription" class="internalDFN" +data-link-type= ++"dfn">consume
( +"dfn">ThingDescription
"idlParamName">td +<span class="idlMethod" id="idl-def-wot-produce-model" data-idl="" +data-title="produce" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" + +"idlParamName">td); + "dfn"><a data-no-default="" +data-link-for="wot" data-lt="produce()|produce" href= +"#dom-wot-produce" class="internalDFN" data-link-type= +"dfn">produce<span class= +"idlParamType"><a href="#dom-thingmodel" class="internalDFN" + +"dfn">ExposedThing
produce
(ThingModel
model); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>register
(USVString directory,ExposedThing
thing); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unregister
(USVString directory,ExposedThing
thing); +}; +typedef objectThingFragment
; +typedef objectPropertyFragment
; +typedef objectActionFragment
; +typedef objectEventFragment
; +typedef objectDataSchema
; +typedef objectSecurityScheme
; +typedef object +data-link-type= +"dfn"> +}; +<span class="idlTypedef" id="idl-def-thingdescription" data-idl="" +data-title="ThingDescription">typedef <span class= +"idlTypedefType"><a href= ++"dfn">Link
; +typedef objectForm
; +typedef +"https://heycam.github.io/webidl/#idl-USVString">USVString "dfn"> +<span class="idlTypedef" id="idl-def-thingmodel" data-idl="" +data-title="ThingModel">typedef <span class= +"idlTypedefType">(<a href="#dom-thingtemplate" class="internalDFN" +data-link-type="dfn"> or <a href= + +"dfn">ThingDescription
; +typedef (ThingFragment
or +"#dom-thingdescription" class="internalDFN" data-link-type= +"dfn">ThingDescription
) ++ThingModel +
+ + +; + +
+The +algorithms +for +the +WoT +methods +will +be +specified +later, +including +error +handling +and +security +considerations. +
+
+The
+
+ThingModel
+
+type
+represents
+either
+a
+
+ThingFragment
+
,
+or
+a
+
+ThingDescription
+
.
+discover()
+
+
+method
+
+
+
+Starts
+the
+discovery
+process
+that
+will
+provide
+
+
+
+
+ConsumedThing
+
+ThingDescription
+
+objects
+
+s
+
+that
+match
+the
+optional
+argument
+
+filter
+
+of
+type
+
+
+
+
.
+
+ThingFilter
+
+
+When
+the
+argument
+is
+not
+provided,
+starts
+the
+widest
+discovery
+the
+Thing
+Description
+and
+Protocol
+Bindings
+allow
+and
+support.
+
+Returns
+an
+[
+
+
+Observable
+
+](https://github.com/tc39/proposal-observable)
+
+object
+that
+can
+be
+subscribed
+to
+and
+unsubscribed
+from.
+The
+handler
+function
+provided
+to
+the
+Observable
+during
+subscription
+will
+receive
+an
+argument
+of
+type
+
+USVString
+
+representing
+a
+
+ThingDescription
+
.
+
+DiscoveryMethod
+
+
+enumeration
+
+
+"DiscoveryMethod">typedef <a href=
+
+"DiscoveryMethod">typedef
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+
+DiscoveryMethod
+
+
+
+;
+
+
+
+
+
+DiscoveryMethod
+
+
+represents
+the
+discovery
+type
+to
+be
+used:
+
+ThingFilter
+
+
+dictionary
+
+
+
+The
+
+
+ThingFilter
+
+
+dictionary
+that
+represents
+the
+constraints
+for
+discovering
+
+Thing
+
+s
+as
+key-value
+pairs.
+
dictionary "dfn"> {
+<span class="idlMember" id="idl-def-thingfilter-method" data-idl=""
+data-title="method" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href="#dom-discoverymethod" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-no-default="" data-link-for="thingfilter"
+data-lt="" href="#dom-thingfilter-method" class="internalDFN"
+data-link-type="dfn"> = <span class=
+"idlMemberValue">"any"
+<span class="idlMember" id="idl-def-thingfilter-url" data-idl=""
+data-title="url" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+
+"dfn">ThingFilter
{
+ (DiscoveryMethod
or DOMString) method
= "any";
+
+"https://heycam.github.io/webidl/#idl-USVString">USVString?
+data-link-for="thingfilter" data-lt="" href="#dom-thingfilter-url"
+class="internalDFN" data-link-type=
+"dfn">
+<span class="idlMember" id="idl-def-thingfilter-query" data-idl=""
+data-title="query" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+
+"dfn">url
;
+
+"https://heycam.github.io/webidl/#idl-USVString">USVString?
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-query" class="internalDFN" data-link-type=
+"dfn">
+<span class="idlMember" id="idl-def-thingfilter-constraints"
+data-idl="" data-title="constraints" data-dfn-for=
+"thingfilter"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<a data-no-default=""
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-constraints" class="internalDFN" data-link-type=
+"dfn">
+
+"dfn">query
;
+
+data-link-type=
+"dfn">ThingFragment
? fragment
;
+
+};
+
+
+
+The
+
+
+method
+
+
+property
+represents
+the
+discovery
+type
+that
+should
+be
+used
+in
+the
+discovery
+process.
+The
+possible
+values
+are
+defined
+by
+the
+
+
+
+enumeration
+that
+
+DiscoveryMethod
+
+
+can
+
+
+MAY
+
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+
+The
+
+
+url
+
+
+property
+represents
+additional
+information
+for
+the
+discovery
+method,
+such
+as
+the
+URL
+of
+the
+target
+entity
+serving
+the
+discovery
+request,
+such
+as
+
+for
+instance
+
+a
+
+Thing
+Directory
+
+(if
+
+method
+
+is
+
+"directory"
+
+)
+
+or
+a
+Thing.
+
+Thing
+(otherwise).
+
+
+The
+
+
+query
+
+
+property
+represents
+a
+query
+string
+accepted
+by
+the
+implementation,
+for
+instance
+a
+SPARQL
+or
+JSON
+
+query.
+Support
+may
+be
+implemented
+locally
+in
+the
+
+WoT
+Runtime
+
+or
+remotely
+as
+a
+service
+in
+a
+
+Thing
+Directory
+.
+
+The
+
+
+
+
+property
+represents
+constraints
+
+fragment
+
+additional
+information
+
+a
+
+ThingFragment
+
+dictionary
+used
+
+for
+the
+discovery
+
+matching
+property
+by
+property
+against
+discovered
+
+Thing
+
+s.
+
+The
+
+discover(filter)
+
+method
+in
+
+
+MUST
+
+run
+
+the
+form
+of
+a
+list
+of
+sets
+of
+property-value
+pairs
+(dictionaries).
+The
+list
+elements
+(dictionaries)
+are
+in
+OR
+relationship,
+
+following
+steps:
+
+discover()
+
+is
+not
+allowed
+for
+the
+current
+scripting
+context
+for
+security
+reasons,
+throw
+
+SecurityError
+
+and
+
+Observable
+
+obs
+
+and
+execute
+
+the
+
+obs.subscribe(handler,
+errorHandler,
+complete)
+
+is
+called,
+execute
+
+the
+following
+
+TypeError
+
+and
+terminate
+the
+algorithm.
+Otherwise
+configure
+
+handler
+
+to
+be
+invoked
+when
+a
+discovery
+hit
+happens.
+
+SemanticAnnotations
+
+TypeError
+
+
+
+TypeError
+
+and
+terminate
+these
+steps.
+Otherwise
+if
+defined,
+save
+it
+to
+be
+invoked
+when
+the
+discovery
+process
+finished
+for
+other
+reasons
+than
+having
+been
+canceled.
+
+name
+
+NotSupported
+
+
+
+SemanticType
+
+ThingFragment
+
+
+
+TypeError
+
+and
+terminate
+these
+steps.
+Otherwise
+save
+
+the
+
+"any"
+
,
+use
+the
+widest
+discovery
+method
+supported
+by
+the
+underlying
+platform.
+
+"local"
+
,
+use
+the
+local
+
+Thing
+Directory
+
+
+
+"directory"
+
,
+use
+
+the
+
+"multicast"
+
,
+use
+all
+
+the
+
+false
+
,
+discard
+
+td
+
+and
+continue
+
+the
+
+false
+
+in
+any
+checks,
+discard
+
+td
+
+and
+continue
+the
+discovery
+process.
+
+
+@type
+
+Error
+
+
+
+@context
+,
+
+message
+
+property
+is
+set
+to
+
+
+@type
+
+UnknownError
+
+
+unless
+there
+was
+an
+error
+code
+provided
+by
+the
+
+Protocol
+Bindings
+,
+in
+which
+case
+set
+it
+to
+that
+value.
+
+@id
+
+obs.unsubscribe()
+
+
+
+false
+
.
+fetch()
+
+
+method
+
+
+
+Accepts
+an
+
+url
+
+argument
+of
+type
+
+USVString
+
+that
+represents
+a
+URL
+(e.g.
+
+"file://..."
+
+or
+
+"https://..."
+
+)
+
+and
+returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+a
+
+
+ThingDescription
+
+.
+
+
+(a
+serialized
+
+JSON-LD
+
+document
+of
+type
+
+USVString
+
+).
+
+
+The
+
+
+ThingDescription
+
+fetch(url)
+
+type
+Representation
+of
+
+method
+
+MUST
+
+run
+
+the
+Thing
+Description
+,
+standardized
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+fetch()
+
+is
+not
+allowed
+for
+
+the
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+application/td+json
+
+),
+as
+far
+as
+a
+valid
+
+Thing
+
+Description
+
+
+Error
+
+object
+
+error
+
+with
+
+error.message
+
+set
+to
+the
+error
+code
+seen
+by
+the
+
+Protocol
+Bindings
+
+
+and
+
+consume()
+
+
+method
+
+
+
+Accepts
+an
+
+td
+
+argument
+of
+type
+
+
+
+and
+returns
+a
+
+
+ThingDescription
+
+
+
+ConsumedThing
+
+
+object
+instantiated
+based
+on
+parsing
+
+that
+description.
+
+The
+
+consume(td)
+
+method
+must
+run
+the
+following
+steps:
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+ThingFragment
+
+with
+a
+default
+value,
+add
+that
+property
+and
+value
+to
+
+stub
+.
+ConsumedThing
+
+object
+
+thing
+
+initialized
+from
+
+stub
+
+that
+implements
+
+Observable
+
.
+read()
+
+and
+
+write()
+
+methods
+to
+the
+
+ThingProperty
+
+elements
+so
+that
+they
+make
+requests
+to
+access
+the
+remote
+
+Thing
+
+s
+and
+wait
+for
+the
+reply,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+Also,
+all
+
+ThingProperty
+
+elements
+
+SHOULD
+
+implement
+
+Observable
+
,
+i.e.
+define
+a
+
+subscribe()
+
+method
+that
+should
+make
+request
+to
+observe
+the
+given
+
+Properties
+
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+invoke()
+
+methods
+to
+the
+
+ThingAction
+
+elements
+so
+that
+they
+make
+requests
+to
+the
+remote
+
+Thing
+
+to
+invoke
+its
+actions,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+subscribe()
+
+method
+to
+all
+
+ThingEvent
+
+elements
+so
+that
+they
+make
+requests
+to
+subscribe
+to
+the
+events
+defined
+by
+the
+remote
+
+Thing
+,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+produce()
+
+
+method
+
+
+
+Accepts
+a
+
+model
+
+argument
+of
+type
+
+
+
+and
+returns
+an
+
+
+ThingModel
+
+
+
+ExposedThing
+
+
+object,
+locally
+created
+based
+on
+the
+provided
+initialization
+parameters.
+An
+
+object.
+
+The
+
+
+
+ExposedThing
+
+produce(model)
+
+can
+be
+created
+in
+
+method
+
+MUST
+
+run
+
+the
+following
+ways:
+
+steps:
+
+
+produce()
+
+is
+not
+allowed
+for
+the
+current
+scripting
+context
+for
+security
+reasons,
+throw
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+ConsumedThing
+
+ThingFragment
+
+
+
+
+ThingModel
+
+ExposedThing
+
+
+
+ExposedThing
+
+
+
+ThingTemplate
+
+ThingFragment
+
+
+,
+initialize
+the
+property
+based
+on
+the
+provided
+initial
+
+or
+
+ThingDescription
+
+id
+
+
+
+security
+
+object
+of
+type
+
+
+SemanticAnnotations
+
+SecurityScheme
+
+
+
+semanticType
+
+properties
+
+
+property
+
+SemanticType
+
+ThingProperty
+
+
+
+objects
+
+read()
+
+and
+
+write()
+
+methods
+are
+provided
+to
+
+define
+local
+methods
+to
+get
+and
+set
+the
+
+Property
+
+values,
+
+metadata
+
+actions
+
+
+property
+
+SemanticMetadata
+
+ThingAction
+
+
+
+objects
+
+SemanticType
+
+invoke()
+
+
+
+events
+
+property
+to
+be
+an
+object
+with
+all
+properties
+being
+
+
+name
+
+ExposedEvent
+
+
+
+context
+
+emit()
+
+
+
+The
+prefix
+
+
+TD
+parsing
+algorithm
+
+
+attribute
+represents
+
+takes
+
+a
+short
+prefix
+associated
+with
+
+string
+
+td
+
+as
+argument
+and
+runs
+the
+following
+steps:
+
+SemanticMetadata
+
+register()
+
+
+
+
+The
+
+Takes
+two
+mandatory
+arguments:
+
+SemanticMetadata
+
+directory
+
+
+
+type
+
+thing
+
+
+
+SemanticType
+
+ExposedThing
+
+
+
+object.
+
+A
+
+Generate
+the
+
+Thing
+Template
+is
+a
+dictionary
+that
+provides
+a
+user
+
+Description
+
+as
+
+td
+,
+given
+name,
+and
+
+the
+semantic
+types
+
+
+Properties
+,
+Action
+
+s
+
+and
+semantic
+metadata
+attached
+to
+the
+
+
+Event
+
+s
+defined
+for
+this
+
+
+
+ExposedThing
+
+
+object.
+Then
+make
+a
+request
+to
+register
+
+td
+
+to
+the
+given
+WoT
+
+Thing
+Description
+'s
+root
+level.
+
+Directory
+.
+
+ThingTemplate
+
+unregister()
+
+
+
+method
+
+
++Takes +two +mandatory +arguments: +
+SemanticAnnotations
+
+directory
+
+
+
+name
+
+thing
+
+
+denoting
+an
+
+
+ExposedThing
+
+object.
+
+Makes
+a
+request
+to
+unregister
+
+the
+user
+given
+name
+of
+
+
+thing
+
+from
+
+the
+given
+WoT
+
+Thing
+Directory
+
+.
+Editor's
+note
+Support
+for
+configuration
+and
+security
+data
+might
+be
+added
+later.
+
+
let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let subscription = wot.discover(discoveryFilter).subscribe(
+ "hljs-params">thing { <span class=
+"hljs-built_in">console.log(<span class=
+"hljs-string">"Found Thing " + thing.name); },
+
+"hljs-params">td => {
+ console.log(
+"hljs-string">"Found Thing " + td.name);
+
+"hljs-comment">// fetch the TD and create a ConsumedThing
+ let thing = wot.consume(td);
+ },
+
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log("Discovery timeout");
+ },
+
+5000
+
+);
+
+let subscription = wot.discover({ method: "local" }).subscribe(
+ "hljs-params">thing { <span class=
+
+"hljs-params">td => {
+"hljs-built_in">console.log("hljs-string">"Found local Thing " + thing.name); },
+
+"hljs-string">"Found local Thing " + td.name); },
+
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+let subscription = wot.discover({ method: "local" }).subscribe({
+ thing => { <span class=
+
+ td => {
+"hljs-built_in">console.log("hljs-string">"Found local Thing " + thing.name); },
+
+"hljs-string">"Found local Thing " + td.name); },
+
+ error: err => { console.log("Discovery error: " + err.message); },
+ complete: () => { console.log("Discovery finished successfully");}
+});
+
+
+ConsumedThing
+
+
+interface
+
+
+
+The
+
+Represents
+an
+object
+that
+extends
+a
+
+
+
+
+ConsumedThing
+
+ThingFragment
+
+interface
+is
+a
+
+with
+methods
+for
+
+client
+API
+
+interactions
+(send
+request
+
+for
+sending
+requests
+to
+servers
+in
+order
+to
+retrieve
+or
+update
+
+reading
+and
+writing
+
+Properties
+,
+
+
+),
+
+invoke
+Actions
+,
+
+
+Action
+
+s,
+subscribe
+
+and
+observe
+Properties
+
+unsubscribe
+for
+
+Property
+
+
+changes
+
+and
+
+Events
+.
+
+Event
+
+s.
+
+
interface "dfn"> { +<span class="idlAttribute" id="idl-def-consumedthing-name" +data-idl="" data-title="name" data-dfn-for= +"consumedthing"> readonly attribute <span class= +"idlAttrType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-no-default="" +data-link-for="consumedthing" data-lt="" href= +"#dom-consumedthing-name" class="internalDFN" data-link-type= +"dfn"> +<span class="idlMethod" id= +"idl-def-consumedthing-getthingdescription" data-idl="" data-title= +"getThingDescription" data-dfn-for="consumedthing"> <span class= +"idlMethType"><a href="#dom-thingdescription" class="internalDFN" + +"dfn">+ConsumedThing
: +data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="getthingdescription()|getThingDescription" href= +"#dom-consumedthing-getthingdescription" class="internalDFN" +data-link-type="dfn">getThingDescription +<span class="idlMethod" id= +"idl-def-consumedthing-readproperty-name" data-idl="" data-title= +"readProperty" data-dfn-for="consumedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt="readproperty()|readProperty" +href="#dom-consumedthing-readproperty" class="internalDFN" +data-link-type="dfn">readProperty(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-writeproperty-name-value" data-idl="" +data-title="writeProperty" data-dfn-for= +"consumedthing"> <a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt= +"writeproperty()|writeProperty" href= +"#dom-consumedthing-writeproperty" class="internalDFN" +data-link-type="dfn">writeProperty(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-invokeaction-name-parameters" data-idl="" +data-title="invokeAction" data-dfn-for= +"consumedthing"> <a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt="invokeaction()|invokeAction" +href="#dom-consumedthing-invokeaction" class="internalDFN" +data-link-type="dfn">invokeAction(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-onpropertychange-name" data-idl="" +data-title="onPropertyChange" data-dfn-for= +"consumedthing"> <a href= +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="onpropertychange()|onPropertyChange" href= +"#dom-consumedthing-onpropertychange" class="internalDFN" +data-link-type="dfn">onPropertyChange(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-consumedthing-onevent-name" +data-idl="" data-title="onEvent" data-dfn-for= +"consumedthing"> <a href= +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="onevent()|onEvent" href="#dom-consumedthing-onevent" +class="internalDFN" data-link-type= +"dfn">onEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-consumedthing-ontdchange" +data-idl="" data-title="onTDChange" data-dfn-for= +"consumedthing"> <a href= ++"dfn">ThingFragment
{ + readonly attribute DOMStringid
; + readonly attribute DOMStringname
; + readonly attribute DOMString?base
; + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeEventMap
events
; + // getter for ThingFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); +}; +[NoInterfaceObject] +interfacePropertyMap
{ + readonly maplike<DOMString,ThingProperty
>; +}; +[NoInterfaceObject] +interfaceActionMap
{ + readonly maplike<DOMString,ThingAction
>; +}; +[NoInterfaceObject] +interfaceEventMap
{ + readonly maplike<DOMString,ThingEvent
>; +}; + +"dfn">ConsumedThing
includes +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="ontdchange()|onTDChange" href= +"#dom-consumedthing-ontdchange" class="internalDFN" data-link-type= +"dfn">onTDChange +}; ++"dfn">Observable
; +// +for +TD +changes + + +
+The
+
+
+
+
+attribute
+
+represents
+ConsumedThing
+
+id
+
+a
+local
+proxy
+object
+
+the
+unique
+identifier
+
+of
+the
+remote
+
+
+Thing
+.
+
+
+instance,
+typically
+a
+URI,
+IRI,
+or
+URN
+as
+
+USVString
+
.
+
+The
+
+
+name
+
+
+property
+The
+name
+property
+
+attribute
+
+represents
+the
+name
+of
+the
+
+Thing
+
+as
+specified
+in
+the
+TD
+.
+In
+this
+version
+it
+is
+read
+only.
+
+
+DOMString
+
.
+
+The
+
+
+
+
+getThingDescription()
+
+base
+
+method
+Returns
+the
+Thing
+Description
+of
+
+attribute
+represents
+
+the
+Thing
+.
+Editor's
+note
+In
+this
+version,
+introspection
+based
+on
+TD
+is
+out
+of
+scope.
+Parsing
+and
+exposing
+Thing
+Description
+s
+
+base
+URI
+that
+
+is
+discussed
+in
+Issue
+38
+.
+
+valid
+for
+all
+defined
+local
+interaction
+resources.
+
+
+The
+
+
+
+
+readProperty()
+
+properties
+
+method
+Takes
+the
+Property
+name
+as
+the
+name
+argument,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+Protocol
+Bindings
+to
+retrieve
+the
+Property
+on
+the
+remote
+Thing
+and
+return
+the
+result.
+Returns
+
+attribute
+represents
+
+a
+dictionary
+of
+
+
+ThingProperty
+
+Promise
+
+
+items.
+The
+
+
+PropertyMap
+
+
+that
+resolves
+with
+the
+Property
+value
+or
+rejects
+with
+an
+Error
+.
+
+4.4
+The
+
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+writeProperty()
+
+ThingProperty
+
+method
+Takes
+the
+Property
+
+
+name
+as
+the
+name
+argument
+and
+the
+new
+value
+as
+the
+value
+argument,
+then
+requests
+from
+the
+underlying
+platform
+
+objects.
+The
+
+read()
+
+and
+the
+Protocol
+Bindings
+
+
+write()
+
+methods
+make
+a
+request
+
+to
+update
+
+access
+
+the
+
+Property
+
+Properties
+
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+represented
+by
+this
+
+
+ConsumedThing
+
+Promise
+
+
+that
+resolves
+on
+success
+or
+rejects
+with
+an
+Error
+.
+
+proxy
+object.
+
+
+The
+
+
+
+
+invokeAction()
+
+actions
+
+method
+Takes
+the
+Action
+name
+from
+the
+name
+argument
+and
+the
+list
+of
+parameters,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+Protocol
+Bindings
+to
+invoke
+the
+Action
+on
+the
+remote
+Thing
+and
+return
+the
+result.
+Returns
+
+attribute
+represents
+
+a
+Promise
+
+dictionary
+of
+
+
+ThingAction
+
+
+that
+resolves
+with
+the
+return
+value
+or
+rejects
+with
+an
+Error
+.
+
+4.6
+
+
+items.
+
+The
+
+
+
+
+onPropertyChange()
+
+ActionMap
+
+method
+Returns
+an
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+
+Observable
+
+ThingAction
+
+for
+the
+Property
+specified
+in
+the
+name
+argument,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications.
+
+objects.
+
+The
+callback
+function
+passed
+to
+the
+
+
+
+method
+subscribe()
+
+invoke()
+
+when
+invoked
+on
+
+represents
+a
+request
+to
+invoke
+
+the
+returned
+observer
+will
+receive
+
+
+Action
+
+on
+
+the
+new
+property
+value
+each
+time
+it
+is
+changed.
+
+remote
+
+Thing
+.
+
+The
+
+
+
+
+onEvent()
+
+events
+
+method
+Returns
+an
+
+attribute
+represents
+a
+dictionary
+of
+
+
+
+
+Observable
+
+ThingEvent
+
+for
+the
+Event
+specified
+in
+the
+name
+argument,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications.
+The
+callback
+function
+passed
+to
+the
+subscribe()
+method
+when
+invoked
+on
+the
+returned
+observer
+will
+receive
+the
+event
+data
+each
+time
+the
+event
+is
+fired.
+4.8
+
+items.
+
+The
+
+
+
+
+onTDChange()
+
+EventMap
+
+method
+Returns
+an
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+Observable
+
+ThingEvent
+
+,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications
+to
+the
+Thing
+Description
+.
+The
+callback
+function
+passed
+
+
+objects.
+Subscribing
+
+to
+the
+subscribe()
+method
+when
+invoked
+
+events
+involves
+setting
+up
+an
+observation
+(subscription)
+mechanism
+
+on
+the
+returned
+observer
+will
+receive
+the
+new
+Thing
+Description
+each
+time
+it
+is
+changed.
+
+remote
+object.
+
+
+Below
+a
+
+
+
+interface
+example
+is
+given.
+
+ConsumedThing
+
+
+
"hljs-keyword">try {
+
+"hljs-keyword">let subscription = wot.discover({ method: "local" }).subscribe(
+
+"hljs-params">td => {
+
+"hljs-keyword">let thing = wot.consume(td);
+ console.log(
+"hljs-string">"Thing " + thing.name + " has been consumed.");
+
+"hljs-keyword">let subscription = thing["temperature"].subscribe(function(value) {
+
+"hljs-built_in">console.log("Temperature: " + value);
+ });
+ thing.actions["startMeasurement"].invoke({ units: "Celsius" })
+ .then(() => { console.log("Temperature measurement started."); })
+ .catch(e => {
+
+"hljs-built_in">console.log("Error starting measurement.");
+ subscription.unsubscribe();
+ })
+ },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+ );
+} catch(error) {
+ console.log(
+"hljs-string">"Error: " + error.message);
+
+};
+
+
+ExposedThing
+
+
+interface
+
+
+
+The
+
+
+ExposedThing
+
+
+interface
+is
+the
+server
+API
+that
+allows
+defining
+request
+handlers,
+properties,
+
+Actions
+,
+and
+
+Events
+
+to
+a
+
+Thing
+.
+It
+also
+implements
+the
+
+
+
+
+interface.
+An
+
+ConsumedThing
+
+Observable
+
+
+ExposedThing
+
+
+is
+created
+by
+the
+
+produce()
+
+method.
+
"idl-def-exposedthing" data-idl="" data-title= +"ExposedThing">interface +"idlInterfaceID">"dfn"> { +<span class= +"idlSectionComment"> // define how to expose and run the Thing +<span class="idlMethod" id="idl-def-exposedthing-start" data-idl="" +data-title="start" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="start()|start" href= +"#dom-exposedthing-start" class="internalDFN" data-link-type= +"dfn">start +<span class="idlMethod" id="idl-def-exposedthing-stop" data-idl="" +data-title="stop" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="stop()|stop" href= +"#dom-exposedthing-stop" class="internalDFN" data-link-type= +"dfn">stop +<span class="idlMethod" id= +"idl-def-exposedthing-register-directory" data-idl="" data-title= +"register" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="register()|register" href= +"#dom-exposedthing-register" class="internalDFN" data-link-type= +"dfn">register(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id= +"idl-def-exposedthing-unregister-directory" data-idl="" data-title= +"unregister" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= + +"dfn">+ExposedThing
:ThingFragment
{ + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeExposedEvents
events
; + // getter for ThingFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); + // setter for ThingFragment properties + setter void ( +"idlParam">DOMString name, any value); + // methods to expose and destroy the Thing + Promise<void> data-link-for="exposedthing" data-lt="unregister()|unregister" +href="#dom-exposedthing-unregister" class="internalDFN" +data-link-type="dfn">unregister(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id= +"idl-def-exposedthing-emitevent-eventname-payload" data-idl="" +data-title="emitEvent" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= + +data-link-for="exposedthing" data-lt= +"exposedthing.expose()|exposedthing.expose|expose()|expose" href= +"#dom-exposedthing-expose" class="internalDFN" data-link-type= +"dfn">expose
(); + Promise<void> data-link-for="exposedthing" data-lt="emitevent()|emitEvent" href= +"#dom-exposedthing-emitevent" class="internalDFN" data-link-type= +"dfn">emitEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class= +"idlSectionComment"> // define Thing Description modifiers +<span class="idlMethod" id= +"idl-def-exposedthing-addproperty-property" data-idl="" data-title= +"addProperty" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" +data-link-type= +"dfn"> <span class= + +data-link-for="exposedthing" data-lt= +"exposedthing.destroy()|exposedthing.destroy|destroy()|destroy" +href="#dom-exposedthing-destroy" class="internalDFN" +data-link-type="dfn">destroy
(); + // define Properties + +"internalDFN" data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="addproperty()|addProperty" href= +"#dom-exposedthing-addproperty" class="internalDFN" data-link-type= +"dfn">addProperty<span class= +"idlParamType"><a href="#dom-thingproperty" class="internalDFN" + +data-lt= +"exposedthing.addproperty()|exposedthing.addproperty|addproperty()|addproperty" +href="#dom-exposedthing-addproperty" class="internalDFN" + +data-link-type= +"dfn"> <span class= +"idlParamName">property +<span class="idlMethod" id= +"idl-def-exposedthing-removeproperty-name" data-idl="" data-title= +"removeProperty" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" ++"dfn">addProperty
(DOMString name,PropertyFragment
property, optional any initValue); + "dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="removeproperty()|removeProperty" href= +"#dom-exposedthing-removeproperty" class="internalDFN" +data-link-type="dfn">removeProperty(<span class= + +data-lt= +"exposedthing.setpropertyreadhandler()|exposedthing.setpropertyreadhandler|setpropertyreadhandler()|setpropertyreadhandler" +href="#dom-exposedthing-setpropertyreadhandler" class="internalDFN" +data-link-type= +"dfn">setPropertyReadHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-exposedthing-addaction-action" +data-idl="" data-title="addAction" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="addaction()|addAction" href="#dom-exposedthing-addaction" +class="internalDFN" data-link-type= +"dfn">addAction<span class= +"idlParamType"><a href="#dom-thingaction" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,PropertyReadHandler
readHandler); + "dfn"> <span class= +"idlParamName">action +<span class="idlMethod" id="idl-def-exposedthing-removeaction-name" +data-idl="" data-title="removeAction" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="removeaction()|removeAction" href= +"#dom-exposedthing-removeaction" class="internalDFN" +data-link-type="dfn">removeAction(<span class= + +data-lt= +"exposedthing.setpropertywritehandler()|exposedthing.setpropertywritehandler|setpropertywritehandler()|setpropertywritehandler" +href="#dom-exposedthing-setpropertywritehandler" class= +"internalDFN" data-link-type= +"dfn">setPropertyWriteHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-exposedthing-addevent-event" +data-idl="" data-title="addEvent" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="addevent()|addEvent" href="#dom-exposedthing-addevent" +class="internalDFN" data-link-type= +"dfn">addEvent<span class= +"idlParamType"><a href="#dom-thingevent" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,PropertyWriteHandler
writeHandler); + "dfn"> +<span class="idlMethod" id="idl-def-exposedthing-removeevent-name" +data-idl="" data-title="removeEvent" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="removeevent()|removeEvent" href= +"#dom-exposedthing-removeevent" class="internalDFN" data-link-type= +"dfn">removeEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class= +"idlSectionComment"> // define request handlers +<span class="idlMethod" id= +"idl-def-exposedthing-setpropertyreadhandler-name-readhandler" +data-idl="" data-title="setPropertyReadHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="setpropertyreadhandler()|setPropertyReadHandler" href= +"#dom-exposedthing-setpropertyreadhandler" class="internalDFN" +data-link-type="dfn">setPropertyReadHandler(<span class= + +data-lt= +"exposedthing.removeproperty()|exposedthing.removeproperty|removeproperty()|removeproperty" +href="#dom-exposedthing-removeproperty" class="internalDFN" +data-link-type= +"dfn">removeProperty
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString, + <span class= + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name); + // define Actions + +"internalDFN" data-link-type= +"dfn">ExposedThing
addAction
( +"idlParam">"#dom-propertyreadhandler" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">readHandler +<span class="idlMethod" id= +"idl-def-exposedthing-setpropertywritehandler-name-writehandler" +data-idl="" data-title="setPropertyWriteHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,ActionFragment
init,ActionHandler
action); + +data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="setpropertywritehandler()|setPropertyWriteHandler" href= +"#dom-exposedthing-setpropertywritehandler" class="internalDFN" + +data-lt= +"exposedthing.removeaction()|exposedthing.removeaction|removeaction()|removeaction" +href="#dom-exposedthing-removeaction" class="internalDFN" + +data-link-type= +"dfn">setPropertyWriteHandler, + <span class= ++"dfn">removeAction
( +"idlParam">"#dom-propertywritehandler" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">writeHandler +<span class="idlMethod" id= +"idl-def-exposedthing-setactionhandler-name-action" data-idl="" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name); +data-title="setActionHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= ++"exposedthing"> + +data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="setactionhandler()|setActionHandler" href= +"#dom-exposedthing-setactionhandler" class="internalDFN" +data-link-type="dfn">setActionHandler(<span class= + +data-lt= +"exposedthing.setactionhandler()|exposedthing.setactionhandler|setactionhandler()|setactionhandler" +href="#dom-exposedthing-setactionhandler" class="internalDFN" +data-link-type= +"dfn">setActionHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a href="#dom-actionhandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">action +}; +<span class="idlCallback" id="idl-def-propertyreadhandler" +data-idl="" data-title="PropertyReadHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-propertyreadhandler" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise +<span class="idlCallback" id="idl-def-propertywritehandler" +data-idl="" data-title="PropertyWriteHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-propertywritehandler" class="internalDFN" +data-link-type="dfn"> +<span class="idlCallback" id="idl-def-actionhandler" data-idl="" +data-title="ActionHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name, +href="#dom-actionhandler" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType"><a href= ++"dfn">ActionHandler
action); + // define Events + +"internalDFN" data-link-type= +"dfn">ExposedThing
addEvent
(DOMString name,EventFragment
event); + +data-link-type= +"dfn">ExposedThing
removeEvent
(DOMString name); +}; +[NoInterfaceObject] +interfaceExposedEvents
{ + maplike<DOMString,ExposedEvent
>; +}; +callbackPropertyReadHandler
= Promise<any> (); +callbackPropertyWriteHandler
= Promise<void> (any value); +callbackActionHandler
= +"https://heycam.github.io/webidl/#idl-promise"> +Promise + +< + +any + +> + +( + + + +any + + + +parameters + + +); + +
+Start
+serving
+external
+requests
+for
+the
+Thing
+.
+5.2
+
+The
+
+
+
+
+stop()
+
+properties
+
+method
+Stop
+serving
+external
+requests
+for
+the
+Thing
+.
+5.3
+The
+
+attribute
+represents
+a
+dictionary
+of
+
+
+
+register()
+
+ThingProperty
+
+method
+Generates
+the
+Thing
+Description
+
+
+given
+
+items
+in
+which
+
+the
+properties,
+Actions
+
+
+read()
+
+and
+Event
+defined
+for
+this
+object.
+If
+a
+
+
+
+directory
+
+write()
+
+argument
+is
+given,
+make
+a
+request
+to
+register
+
+methods
+define
+local
+methods
+that
+access
+
+the
+Thing
+Description
+with
+
+physical
+representations
+of
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+register
+Action
+
+
+Properties
+
+.
+
+The
+
+
+
+
+unregister()
+
+actions
+
+method
+If
+
+attribute
+represents
+
+a
+dictionary
+of
+
+
+
+directory
+
+ThingAction
+
+argument
+is
+given,
+make
+a
+request
+to
+unregister
+the
+Thing
+Description
+
+
+with
+
+items
+in
+which
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+
+
+
+unregister
+
+invoke()
+
+Action
+.
+Then,
+and
+in
+the
+case
+no
+arguments
+were
+provided
+
+method
+represents
+a
+local
+method
+
+to
+this
+function,
+stop
+the
+Thing
+and
+remove
+
+invoke
+
+the
+Thing
+Description
+
+
+Action
+
+.
+
+The
+
+
+
+
+emitEvent()
+
+events
+
+method
+Emits
+an
+the
+event
+initialized
+with
+the
+event
+name
+specified
+by
+
+attribute
+represents
+a
+dictionary
+of
+
+ExposedEvent
+
+items
+that
+add
+
+the
+
+
+eventName
+
+emit()
+
+argument
+and
+data
+specified
+by
+
+method
+to
+
+the
+
+
+
+payload
+
+ThingEvent
+
+argument.
+
+5.6
+
+
+definition.
+
+The
+
+
+
+
+DataSchema
+
+ExposedEvents
+
+type
+<span class="idlTypedef" id=
+"idl-def-dataschema" data-idl="" data-title=
+"DataSchema">typedef <a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+data-link-for="" data-lt="" href="#dom-dataschema" class=
+"internalDFN" data-link-type=
+"dfn">
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+
+objects.
+DataSchema
+
+ExposedEvent
+
+
+DataSchema
+
+expose()
+
+
+
+method
+
+
+
+Start
+serving
+external
+requests
+for
+
+the
+
+Thing
+Description
+
+,
+so
+that
+
+WoT
+Interactions
+
+
+in
+a
+serialized
+form.
+
+using
+
+Properties
+,
+Action
+
+s
+and
+
+Event
+
+s
+will
+be
+possible.
+
+
+The
+
+
+
+DataSchema
+
+expose()
+
+is
+under
+development,
+currently
+it
+can
+denote
+any
+type
+supported
+by
+
+method
+
+MUST
+
+run
+
+the
+Thing
+Description
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+
+the
+
+addProperty()
+
+expose()
+
+
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+Error
+
+object
+
+error.message
+
+set
+to
+the
+error
+code
+seen
+by
+the
+
+Protocol
+Bindings
+
+and
+terminate
+these
+steps.
+
+ThingProperty
+
+destroy()
+
+
+
+
+Represents
+
+Stop
+serving
+external
+requests
+for
+
+the
+
+Thing
+
+Property
+description.
+
+and
+destroy
+the
+object.
+Note
+that
+eventual
+unregistering
+should
+be
+done
+before
+invoking
+this
+method.
+
+
+The
+
+
+name
+
+destroy()
+
+attribute
+represents
+
+method
+
+MUST
+
+run
+
+the
+name
+of
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+
+the
+
+schema
+
+destroy()
+
+
+
+DataSchema
+
+SecurityError
+
+
+
+writable
+
+Error
+
+
+
+error.message
+
+set
+to
+
+the
+
+observable
+
+addProperty()
+
+
+
+
+Adds
+a
+
+
+Property
+
+changes
+can
+be
+observed
+
+with
+name
+defined
+by
+the
+
+name
+
+argument,
+the
+data
+schema
+provided
+
+by
+the
+
+property
+
+argument
+of
+type
+
+PropertyFragment
+
,
+and
+optionally
+
+an
+external
+client.
+The
+default
+
+initial
+
+value
+provided
+in
+the
+argument
+
+initValue
+
+whose
+type
+should
+match
+the
+one
+defined
+in
+the
+
+type
+
+property
+according
+to
+the
+
+value-matching
+algorithm
+.
+If
+
+initValue
+
+is
+not
+provided,
+it
+
+SHOULD
+
+be
+initialized
+as
+
+
+
.
+Implementations
+
+SHOULD
+
+update
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+false
+
+undefined
+
+
+removeProperty()
+
+
+method
+
+
+
+Removes
+the
+
+Property
+
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+addAction()
+
+
+method
+
+
+
+Adds
+an
+Action
+
+to
+the
+
+actions
+
+property
+of
+a
+
+Thing
+
+object
+as
+
+an
+
+Action
+
+with
+name
+
+defined
+by
+the
+action
+
+
+name
+
+argument,
+defines
+input
+and
+output
+data
+format
+by
+the
+
+init
+
+argument
+of
+type
+
+
+
+,
+and
+adds
+the
+function
+provided
+in
+the
+
+action
+
+argument
+as
+a
+handler,
+then
+
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+ThingAction
+
+ActionFragment
+
+
+The
+ThingAction
+
+provided
+
+action
+
+callback
+function
+will
+implement
+invoking
+an
+
+Action
+
+
+dictionary
+describes
+the
+arguments
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+invoking
+
+the
+return
+value.
+The
+name
+attribute
+provides
+the
+
+
+Action
+
+name.
+The
+inputSchema
+attribute
+provides
+the
+description
+of
+the
+input
+arguments
+(argument
+list
+
+is
+represented
+by
+an
+object).
+If
+missing,
+it
+means
+
+received
+from
+
+the
+action
+does
+not
+accept
+arguments.
+
+underlying
+platform.
+
+The
+callback
+will
+receive
+a
+
+
+
+outputSchema
+
+parameters
+
+attribute
+provides
+
+dictionary
+argument
+according
+to
+
+the
+description
+
+definition
+in
+the
+
+init.input
+
+argument
+and
+will
+return
+a
+value
+
+of
+type
+defined
+by
+
+the
+returned
+data.
+If
+missing,
+it
+means
+
+
+init.output
+
+argument
+according
+to
+
+the
+action
+does
+not
+return
+data.
+
+
+value-matching
+algorithm
+.
+There
+
+SHOULD
+
+be
+exactly
+one
+handler
+for
+any
+given
+
+Action
+.
+If
+no
+handler
+is
+initialized
+for
+any
+given
+
+Action
+,
+implementations
+
+SHOULD
+
+throw
+a
+
+TypeError
+
.
+removeAction()
+
+
+method
+
+
+
+Removes
+the
+
+Action
+
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+addEvent()
+
+
+method
+
+
+
+Adds
+an
+event
+to
+the
+Thing
+object
+as
+
+with
+name
+
+defined
+by
+the
+
+name
+
+argument
+and
+qualifiers
+and
+initialization
+value
+provided
+by
+the
+
+event
+
+argument
+of
+type
+
+
+
+
+to
+the
+
+Thing
+
+object
+
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+ThingEvent
+
+EventFragment
+
+
+removeEvent()
+
+
+method
+
+
+
+Removes
+the
+event
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+PropertyReadHandler
+
+
+callback
+
+
+
+A
+function
+that
+returns
+
+is
+called
+when
+an
+external
+request
+for
+reading
+a
+
+Property
+
+is
+received.
+It
+should
+return
+
+a
+Promise
+and
+resolves
+it
+with
+the
+value
+of
+the
+
+Property
+
+matching
+the
+
+name
+
+argument
+to
+the
+
+setPropertyReadHandler
+
+function,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+retrieved.
+
+PropertyWriteHandler
+
+
+callback
+
+
+
+A
+function
+that
+is
+
+called
+with
+
+when
+an
+external
+request
+for
+writing
+a
+
+Property
+
+is
+received.
+It
+is
+given
+the
+requested
+new
+
+
+value
+
+as
+argument
+that
+returns
+
+and
+should
+return
+
+a
+Promise
+which
+is
+resolved
+when
+the
+value
+of
+the
+
+Property
+
+matching
+
+that
+matches
+
+the
+
+name
+
+argument
+to
+the
+setPropertyReadHandler
+function
+is
+
+has
+been
+
+updated
+with
+
+value
+
,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+updated.
+
+Note
+that
+this
+function
+is
+invoked
+by
+implementations
+before
+the
+property
+is
+updated,
+so
+the
+
+updated
+and
+it
+actually
+defines
+what
+to
+do
+when
+a
+write
+request
+is
+received.
+The
+
+code
+in
+this
+callback
+function
+can
+invoke
+the
+
+
+method
+to
+find
+out
+the
+old
+value
+of
+the
+property,
+if
+needed.
+Therefore
+the
+old
+value
+is
+not
+provided
+to
+this
+readProperty()
+
+read()
+
+method.
+
+function.
+
+
+ActionHandler
+
+
+callback
+
+
+
+A
+function
+called
+with
+a
+
+parameters
+
+dictionary
+argument
+assembled
+by
+the
+
+WoT
+runtime
+
+based
+on
+the
+
+Thing
+Description
+
+and
+the
+external
+client
+request.
+It
+returns
+a
+Promise
+that
+rejects
+with
+an
+error
+or
+resolves
+if
+the
+action
+is
+successful
+or
+ongoing
+(may
+also
+resolve
+with
+a
+control
+object
+such
+as
+an
+
+
+Observable
+
+
+for
+actions
+that
+need
+progress
+notifications
+or
+that
+can
+be
+canceled).
+
+setPropertyReadHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+readHandler
+
+as
+argument
+of
+type
+
+
+PropertyReadHandler
+
+.
+Sets
+the
+handler
+function
+for
+reading
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+The
+
+readHandler
+
+callback
+function
+will
+implement
+reading
+a
+
+Property
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+reading
+a
+
+Property
+
+is
+received
+from
+the
+underlying
+platform.
+
+There + +SHOULD + +be +at +most +one +handler +for +any +given + +Property + +and +newly +added +handlers +replace +the +old +handlers. +If +no +handler +is +initialized +for +any +given + +Property +, +implementations + +SHOULD + +implement +a +default +property +read +handler. +
++When +an +external +request +for +reading + +Property + +propertyName + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+setPropertyWriteHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+writeHandler
+
+as
+argument
+of
+type
+
+
+PropertyWriteHandler
+
+.
+Sets
+the
+handler
+function
+for
+writing
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+There + +SHOULD + +be +at +most +one +write +handler +for +any +given + +Property + +and +newly +added +handlers +replace +the +old +handlers. +If +no +write +handler +is +initialized +for +any +given + +Property +, +implementations + +SHOULD + +implement +default +property +update +and +notifying +observers +on +change. +
++When +an +external +request +for +writing +a + +Property + +propertyName + +with +a +new +value + +value + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+setActionHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+action
+
+as
+argument
+of
+type
+
+
+ActionHandler
+
+.
+Sets
+the
+handler
+function
+for
+the
+specified
+
+Action
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+If
+provided,
+this
+
+The
+
+action
+
+callback
+function
+will
+implement
+invoking
+
+an
+
+Action
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+invoking
+a
+
+the
+
+Action
+
+is
+received
+from
+the
+underlying
+platform.
+The
+callback
+will
+receive
+a
+parameters
+dictionary
+argument.
+
+
+There
+
+SHOULD
+
+be
+exactly
+
+at
+most
+
+one
+handler
+for
+any
+given
+
+Action
+
+and
+newly
+added
+handlers
+replace
+the
+old
+handlers.
+
+When +an +external +request +for +invoking +the + +Action + +identified +by + +name + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+
+.
+
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+Below
+some
+
+
+
+interface
+examples
+are
+given.
+
+ExposedThing
+
+
+
+ try {
+ "hljs-keyword">var thing = WoT.produce({ <span class=
+"hljs-attr">name: <span class=
+"hljs-string">"tempSensor" });
+
+ thing.addProperty({
+ : <span class=
+"hljs-string">"temperature",
+ : <span class=
+"hljs-number">0.0,
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ <span class=
+"hljs-comment">// use default values for the rest
+ }).addProperty({
+ : <span class=
+"hljs-string">"max",
+ : <span class=
+"hljs-number">0.0,
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ <span class=
+"hljs-comment">// use default values for the rest
+ }).addAction({
+ : <span class=
+"hljs-string">"reset",
+
+ }).addEvent({
+
+"hljs-keyword">var temperatureValueDefinition = {
+ type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">-50,
+ maximum:
+"hljs-number">10000
+ };
+
+"hljs-keyword">var temperaturePropertyDefinition = temperatureValueDefinition;
+ // add the 'forms' property
+ temperaturePropertyDefinition.forms = [ ... ];
+ var thing = WoT.produce({
+ name: "hljs-string">"onchange",
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ });
+
+ thing.setActionHandler(<span class=
+"hljs-string">"reset", () => {
+ .log(<span class=
+"hljs-string">"Resetting maximum");
+ thing.writeProperty(<span class=
+"hljs-string">"max");
+ });
+ thing.start().then(<span class=
+"hljs-params">() {
+ thing.register();
+
+"hljs-string">"tempSensor",
+ properties: {
+"hljs-attr">temperature: temperaturePropertyDefinition
+ },
+ actions: { reset: { description:
+"hljs-string">"Reset the temperature sensor",
+ input: {
+"hljs-attr">temperature: temperatureValueDefinition
+ },
+ output:
+"hljs-literal">null,
+ forms: []
+ },
+ },
+ events: {
+"hljs-attr">onchange: temperatureValueDefinition
+ },
+ links: []
+ });
+ await thing.expose();
+ await wot.register("hljs-string">"https://mydirectory.org", thing);
+
+ // define Thing business logic
+ setInterval( async () => {
+ let mock = Math.random()*100;
+ thing.writeProperty(<span class=
+"hljs-string">"temperature", mock);
+
+ let old = "hljs-keyword">await thing.readProperty(<span class=
+"hljs-string">"max");
+
+"hljs-keyword">await thing["temperature"].read();
+
+ if (old < mock) {
+ thing.writeProperty(<span class=
+"hljs-string">"max", mock);
+ thing.emitEvent();
+
+ await thing["hljs-string">"temperature"].write(mock);
+ thing.emitEvent("onchange", mock);
+
+ }
+ }, 1000);
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+
+ try {
+ var statusValueDefinition = {
+ type: "hljs-string">"object",
+ properties: { brightness: { type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">0.0,
+ maximum:
+"hljs-number">100.0,
+ required:
+"hljs-literal">true
+ },
+ rgb: { type:
+"hljs-string">"array",
+ "minItems":
+"hljs-number">3,
+ "maxItems":
+"hljs-number">3,
+ items : { "type" :
+"hljs-string">"number",
+
+"hljs-string">"minimum": 0,
+
+"hljs-string">"maximum": 255
+ }
+ }
+ };
+
+"hljs-keyword">var statusPropertyDefinition = statusValueDefinition;
+ // add the 'forms' property
+ statusPropertyDefinition["forms"] = [];
+ var thing = WoT.produce({ name:
+"hljs-string">"mySensor",
+ properties: { brightness: { type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">0.0,
+ maximum:
+"hljs-number">100.0,
+ required:
+"hljs-literal">true,
+ },
+
+"hljs-attr">status: statusPropertyDefinition
+ },
+ actions: { status: { description:
+"hljs-string">"Get status object",
+ input:
+"hljs-literal">null,
+ output: {
+"hljs-attr">status : statusValueDefinition;
+ },
+ forms: []
+ },
+ },
+ events: {
+"hljs-attr">onstatuschange: statusValueDefinition;
+ },
+ links: []
+ });
+ thing.expose().then(() => {
+ thing.register();
+ });
+} catch (err) {
+ console.log(
+"hljs-string">"Error creating ExposedThing: " + err);
+}
+
+ let thingDescription = "hljs-string">'{ "@context": [ "https://w3c.github.io/wot/w3c-wot-td-context.jsonld", "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ], "@type": [ "Thing", "Sensor" ], "name": "mySensor", "geo:location": "testspace", "interaction": [ { "@type": [ "Property", "Temperature" ], "name": "prop1", "schema": { "type": "number" }, "saref:TemperatureUnit": "degree_Celsius" } ] }';
+
+"hljs-string">'{ \
+ "name": "mySensor", \
+ "@context": [ "http://www.w3.org/ns/td",\
+ "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ],\
+ "@type": [ "Thing", "Sensor" ], \
+ "geo:location": "testspace", \
+ "properties": { \
+ "prop1": { \
+ "type": "number",\
+ "@type": [ "Property", "Temperature" ], \
+ "saref:TemperatureUnit": "degree_Celsius" \
+ } } }';
+
+try {
+ // note that produce() fails if thingDescription contains error
+ let thing = WoT.produce(thingDescription);
+ // Interactions were added from TD
+ // WoT adds generic handler for reading any property
+ // define a specific handler for one property
+ let name = "examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log("Handling read request for " + name);
+ return new Promise((resolve, reject) => {
+ let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log("Error");
+ });
+ });
+ thing.start();
+
+ thing.expose();
+
+} catch(err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+
+ // fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+ // WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+ // Interactions were added from TD
+ // add server functionality
+ // ...
+});
+
+
+The
+[
+
+This
+section
+is
+non-normative.
+
+
+WOT-TD
+
+
+]
+specification
+defines
+the
+
+WoT
+information
+model
+,
+i.e.
+the
+data
+types
+and
+data
+structures
+used
+in
+
+WoT
+Interactions
+.
+In
+this
+API
+these
+definitions
+translate
+to
+dictionary
+objects
+that
+are
+extended
+with
+methods
+by
+the
+interfaces
+defined
+in
+this
+specification.
+
+
+In +order +to +avoid +duplication +of +definitions, +references +to +these +data +types +and +structures +is +defined +in +this +section, +but +for +their +full +description +please +refer +to +the + +Thing +Description +specification +.
+ThingDescription
+
+DataSchema
+
+
+
+dictionary
+and
+its
+subclasses
+
+
+
+Value
+types
+basically
+represent
+types
+that
+may
+be
+used
+in
+
+JSON
+
+object
+definitions
+and
+are
+used
+in
+
+ThingFragment
+
+to
+define
+
+Properties
+,
+Action
+s,
+
+
+Event
+
+s
+and
+links
+(introspection)
+
+
+Action
+
+parameters.
+Value
+types
+are
+represented
+as
+dictionary
+objects
+whose
+properties
+and
+possible
+sub-classes
+are
+defined
+in
+the
+
+DataSchema
+
+section
+of
+[
+
+WOT-TD
+
+].
+
+One
+property
+of
+all
+
+DataSchema
+
+dictionary
+
+is
+an
+API
+extension
+that
+
+the
+
+type
+
+property
+whose
+value
+
+is
+out
+
+from
+a
+set
+
+of
+scope
+for
+
+enumerated
+strings
+defined
+in
+the
+
+DataSchema
+
+section
+of
+[
+
+WOT-TD
+
+]
+and
+is
+referred
+as
+
+DataType
+
+in
+
+this
+specification.
+However,
+
+
+Based
+on
+
+type
+
,
+the
+draft
+interfaces
+
+following
+sub-classes
+of
+
+DataSchema
+
+are
+defined
+here
+for
+informative
+purposes.
+<span class="idlInterface" id=
+"idl-def-consumedthing-partial-1" data-idl="" data-title=
+"ConsumedThing">partial interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-consumedthing" class="internalDFN" data-link-type=
+"dfn"> {
+<span class="idlMethod" id="idl-def-consumedthing-getproperties"
+data-idl="" data-title="getProperties" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingproperty"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getproperties()|getProperties" href=
+"#dom-consumedthing-getproperties" class="internalDFN"
+data-link-type="dfn">getProperties
+<span class="idlMethod" id="idl-def-consumedthing-getactions"
+data-idl="" data-title="getActions" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingaction"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getactions()|getActions" href=
+"#dom-consumedthing-getactions" class="internalDFN" data-link-type=
+"dfn">getActions
+<span class="idlMethod" id="idl-def-consumedthing-getevents"
+data-idl="" data-title="getEvents" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingevent"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getevents()|getEvents" href="#dom-consumedthing-getevents"
+class="internalDFN" data-link-type=
+"dfn">getEvents
+<span class="idlMethod" id="idl-def-consumedthing-getlinks"
+data-idl="" data-title="getLinks" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-tdlink"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getlinks()|getLinks" href="#dom-consumedthing-getlinks"
+class="internalDFN" data-link-type=
+"dfn">getLinks
+};
+
+in
+[
+
+
+WOT-TD
+
+
+]:
+
+BooleanSchema
+
+6.1
+
+,
+
+
+NumberSchema
+,
+IntegerSchema
+,
+StringSchema
+,
+ObjectSchema
+,
+ArraySchema
+.
+getProperties()
+
+SecurityScheme
+
+
+
+
+Returns
+the
+list
+of
+Properties
+
+Security
+metadata
+is
+represented
+as
+dictionary
+objects
+whose
+properties
+and
+sub-classes
+are
+
+defined
+in
+the
+Thing
+Description
+
+
+SecurityScheme
+
+
+section
+of
+[
+
+WOT-TD
+
+].
+
+One
+property
+
+of
+the
+Thing
+
+
+
+SecurityScheme
+
+
+dictionary
+is
+the
+
+scheme
+
+property
+whose
+value
+is
+from
+a
+set
+of
+enumerated
+strings
+defined
+
+in
+the
+form
+
+
+SecurityScheme
+
+section
+
+of
+a
+list
+
+[
+
+WOT-TD
+
+].
+Based
+on
+
+type
+
,
+multiple
+subclasses
+
+of
+
+
+
+
+ThingProperty
+
+SecurityScheme
+
+objects.
+
+are
+defined.
+
+
+getActions()
+
+Link
+
+
+
+
+Returns
+
+Represents
+a
+
+Web
+Link
+
+with
+properties
+defined
+in
+
+the
+list
+
+
+Link
+
+section
+
+of
+Action
+
+[
+
+WOT-TD
+
+
+s
+
+
+].
+
+Form
+
+dictionary
+
+Represents
+metadata
+describing
+service
+details,
+with
+properties
+
+defined
+in
+the
+Thing
+Description
+
+
+Form
+
+
+section
+
+of
+[
+
+WOT-TD
+
+].
+
+InteractionFragment
+
+dictionary
+
+Represents
+
+the
+Thing
+
+common
+properties
+of
+
+WoT
+Interactions
+,
+one
+of
+
+Property
+,
+Action
+
+
+or
+
+Event
+,
+as
+defined
+
+in
+the
+form
+
+
+InteractionPattern
+
+section
+
+of
+[
+
+WOT-TD
+
+].
+Its
+subclasses
+are
+referred
+as
+
+PropertyFragment
+
,
+ActionFragment
+
+and
+
+EventFragment
+
.
+PropertyFragment
+
+dictionary
+
+Represents
+the
+
+Property
+
+interaction
+data
+that
+initializes
+
+a
+list
+
+
+
+ThingProperty
+
+object.
+Its
+properties
+are
+defined
+in
+the
+
+Property
+
+and
+
+InteractionPattern
+
+sections
+
+of
+[
+
+WOT-TD
+
+].
+
+ActionFragment
+
+dictionary
+
+Represents
+the
+
+Action
+
+interaction
+data
+that
+initializes
+a
+
+
+
+ThingAction
+
+
+objects.
+
+object.
+Its
+properties
+are
+defined
+in
+the
+
+Action
+
+and
+
+InteractionPattern
+
+sections
+of
+[
+
+WOT-TD
+
+].
+
+
+getEvents()
+
+EventFragment
+
+
+
+
+Returns
+
+Represents
+
+the
+list
+of
+
+
+Event
+
+s
+
+interaction
+data
+that
+initializes
+a
+
+ThingEvent
+
+object.
+Its
+properties
+are
+
+defined
+in
+the
+Thing
+Description
+
+
+Event
+
+
+section
+
+of
+the
+
+[
+
+WOT-TD
+
+].
+
+ThingFragment
+
+dictionary
+
+The
+
+ThingFragment
+
+dictionary
+is
+defined
+as
+
+Thing
+
+
+in
+the
+form
+of
+
+[
+
+WOT-TD
+
+].
+It
+is
+
+a
+list
+
+dictionary
+that
+contains
+properties
+representing
+semantic
+metadata
+and
+interactions
+(
+
+Properties
+,
+Action
+
+s
+and
+
+Event
+
+s).
+It
+is
+used
+for
+initializing
+an
+internal
+representation
+
+of
+a
+
+Thing
+Description
+
+and
+its
+properties
+may
+be
+used
+in
+
+
+
+ThingEvent
+
+ThingFilter
+
+objects.
+
+.
+
+getLinks()
+
+ThingDescription
+
+
+
+
+Returns
+the
+list
+
+Serialized
+representation
+
+of
+linked
+resources
+in
+
+the
+
+
+Thing
+Description
+
+(a
+
+JSON-LD
+
+document).
+
+In
+this
+version
+
+of
+the
+API,
+
+Thing
+Description
+
+s
+are
+represented
+as
+an
+opaque
+
+USVString
+
+that
+can
+be
+transmitted
+between
+devices.
+
+The
+data
+types
+and
+structures
+imported
+from
+[
+
+WOT-TD
+
+]
+are
+extended
+by
+this
+specification
+
+in
+order
+to
+provide
+
+the
+form
+of
+a
+list
+of
+
+interfaces
+for
+
+WoT
+Interactions
+.
+Every
+
+Thing
+
+describes
+its
+metadata
+as
+defined
+in
+
+
+
+,
+and
+basic
+interactions
+defined
+as
+
+Properties
+,
+Action
+
+
+TDLink
+
+ThingFragment
+
+objects.
+
+s
+and
+
+Event
+
+s.
+The
+following
+interfaces
+are
+used
+for
+representing
+these
+interactions.
+
+
+TDLink
+
+Interaction
+
+
+
+
+Contains
+a
+hyperlink
+reference,
+a
+relation
+type
+
+The
+
+Interaction
+
+interface
+is
+an
+abstract
+class
+to
+represent
+
+Thing
+
+interactions:
+
+Properties
+,
+Actions
+
+and
+
+Events
+.
+The
+
+InteractionFragment
+
+dictionary
+holds
+the
+common
+properties
+of
+
+PropertyFragment
+
,
+ActionFragment
+
+and
+
+EventFragment
+
+dictionaries
+used
+for
+initializing
+
+ThingProperty
+
,
+ThingAction
+
+and
+
+ThingEvent
+
+objects
+in
+
+a
+media
+type.
+
+
+
+ThingFragment
+
+dictionary
+used
+for
+creating
+an
+
+ExposedThing
+
+object.
+
+
"idl-def-interaction" data-idl="" data-title= +"Interaction">interface+Interaction
{ + readonly attribute (Form
or FrozenArray<Form
>) +class="internalDFN" data-link-type= +"dfn"> +<span class="idlMember" id="idl-def-tdlink-rel" data-idl="" +data-title="rel" data-dfn-for="tdlink"> <span class= +"idlMemberType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-no-default="" +data-link-for="tdlink" data-lt="" href="#dom-tdlink-rel" class= +"internalDFN" data-link-type= +"dfn"> +}; ++"dfn">forms
; +}; + +"dfn">Interaction
includes ++InteractionFragment +
+; + + +
+The
+
+
+
+read-only
+property
+represents
+the
+protocol
+bindings
+initialization
+data
+and
+is
+initialized
+by
+the
+
+WoT
+Runtime
+.TDLink
+
+forms
+
+ThingProperty
+
+interface
+
+The
+
+ThingProperty
+
+interface
+is
+used
+in
+
+ConsumedThing
+
+and
+
+ExposedThing
+
+objects
+to
+represent
+
+Thing
+
+Property
+
+interactions.
+
+The
+
+PropertyFragment
+
+
+
+dictionary
+contains
+
+is
+used
+for
+initializing
+
+Property
+
+objects
+in
+a
+
+ThingFragment
+
+dictionary
+used
+for
+creating
+an
+
+ExposedThing
+
+object.
+It
+
+MUST
+
+implement
+one
+of
+
+the
+following
+properties:
+
+
+
+DataSchema
+
+dictionaries.
+
+
"idl-def-thingproperty" data-idl="" data-title= +"ThingProperty">interfaceThingProperty
:Interaction
{ + // getter for PropertyFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); + // get and set interface for the Property + +"https://heycam.github.io/webidl/#idl-promise">Promise<any>read
(); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>write
(any value); +}; + +"dfn">ThingProperty
includesPropertyFragment
; + +"dfn">ThingProperty
includes ++Observable +
+; +
+The
+
+
+
+
+interface
+contains
+all
+the
+properties
+defined
+on
+href
+
+ThingProperty
+
+
+PropertyFragment
+
+as
+read-only
+properties.
+
+The
+
+type
+
+
+attribute
+
+read-only
+property
+
+represents
+the
+type
+definition
+for
+the
+
+Property
+
+as
+
+a
+hyperlink
+reference
+
+
+
+DataSchema
+
+dictionary
+object.
+
+The
+
+writable
+
+read-only
+property
+tells
+whether
+the
+
+Property
+
+value
+can
+be
+updated.
+If
+it
+is
+
+false
+
,
+then
+the
+
+set(value)
+
+method
+
+SHOULD
+
+always
+reject.
+
+The
+
+observable
+
+read-only
+property
+tells
+whether
+the
+
+Property
+
+supports
+subscribing
+to
+value
+change
+notifications.
+If
+it
+is
+
+false
+
,
+then
+the
+
+subscribe()
+
+method
+
+SHOULD
+
+always
+fail.
+
+The
+
+constant
+
+read-only
+property
+-
+defined
+in
+
+DataSchema
+
+-
+tells
+whether
+the
+
+Property
+
+value
+is
+a
+constant.
+If
+
+true
+
,
+the
+
+set()
+
+and
+
+subscribe()
+
+methods
+
+SHOULD
+
+always
+fail.
+
+The
+
+required
+
+read-only
+property
+-
+defined
+in
+
+DataSchema
+
+-
+tells
+whether
+the
+
+Property
+
+should
+be
+always
+present
+on
+the
+
+ExposedThing
+
+object.
+
+The
+
+read()
+
+method
+will
+fetch
+the
+value
+of
+the
+
+Property
+
+.
+Returns
+a
+
+Promise
+
+that
+resolves
+with
+the
+value,
+or
+rejects
+with
+an
+error.
+
+The
+
+
+
+
+rel
+
+write()
+
+attribute
+represents
+
+method
+will
+attempt
+to
+set
+the
+value
+of
+the
+
+Property
+
+specified
+in
+the
+
+value
+
+argument
+whose
+type
+
+SHOULD
+
+match
+the
+one
+specified
+by
+the
+
+type
+
+property.
+Returns
+
+a
+relation
+
+
+Promise
+
+that
+resolves
+on
+success,
+or
+rejects
+on
+an
+error.
+
+ThingAction
+
+interface
++"idl-def-thingaction" data-idl="" data-title= +"ThingAction">interfaceThingAction
:Interaction
{ + +"https://heycam.github.io/webidl/#idl-promise">Promise<any>invoke
(optional any inputValue); +}; + +"dfn">ThingAction
includes ++ActionFragment +
+; +
+The
+
+invoke()
+
+method
+when
+invoked,
+starts
+the
+
+Action
+
+interaction
+with
+the
+input
+value
+provided
+by
+the
+
+inputValue
+
+argument.
+If
+
+inputValue
+
+is
+
+null
+
,
+the
+action
+does
+not
+take
+any
+arguments
+and
+rejects
+if
+any
+arguments
+are
+provided.
+If
+the
+value
+is
+
+undefined
+
,
+the
+action
+will
+ignore
+any
+arguments
+provided.
+Otherwise
+the
+
+type
+of
+
+inputValue
+
+SHOULD
+
+match
+the
+
+DataSchema
+
+definition
+in
+the
+
+input
+
+property.
+Returns
+a
+
+Promise
+
+that
+will
+reject
+with
+an
+error
+or
+will
+resolve
+with
+a
+value
+of
+type
+defined
+by
+the
+
+output
+
+property.
+
+ThingEvent
+
+interface
++"idl-def-thingevent" data-idl="" data-title= +"ThingEvent">interfaceThingEvent
:Interaction
{ +}; + +"dfn">ThingEvent
includesEventFragment
; + +"dfn">ThingEvent
includes ++ThingProperty +
+; +
+Since
+
+ThingEvent
+
+implements
+
+Observable
+
+through
+the
+
+ThingProperty
+
+interface,
+event
+subscription
+is
+done
+by
+invoking
+the
+
+subscribe()
+
+method
+on
+the
+event
+object
+that
+returns
+a
+cancelable
+
+Subscription
+
+.
+
+mediaType
+
+ExposedEvent
+
+
+
+
+"idl-def-exposedevent" data-idl="" data-title=
+"ExposedEvent">interface ExposedEvent
: ThingEvent
{
+ void emit
(any payload);
+};
+
+emit()
+
+method
+
+Emits
+an
+event
+that
+carries
+data
+specified
+by
+the
+
+payload
+
+argument.
+
+The
+value-matching
+algorithm
+is
+applied
+to
+
+a
+IANA
+media
+
+
+value
+
+input
+in
+relation
+to
+a
+
+valueType
+
+property
+of
+
+type
+.
+For
+TD
+
+
+
+DataSchema
+
,
+for
+instance
+the
+
+value
+
+and
+
+type
+
+properties
+of
+a
+
+PropertyFragment
+
+
+s
+there
+will
+be
+registered
+media
+types,
+so
+applications
+will
+be
+able
+
+object,
+or
+the
+
+inputValue
+
+parameter
+
+to
+check
+whether
+an
+
+the
+
+
+
+href
+
+invoke()
+
+link
+points
+
+method
+of
+a
+
+ThingAction
+
+object
+in
+relation
+
+to
+the
+same
+object.
+It
+executes
+the
+following
+steps:
+
+false
+
.
+"null"
+
:
+if
+
+value
+
+is
+
+null
+
,
+return
+
+true
+
,
+otherwise
+return
+
+false
+
.
+"boolean"
+
:
+if
+
+value
+
+is
+either
+
+true
+
+or
+
+false
+
,
+then
+return
+
+true
+
,
+otherwise
+return
+
+false
+
.
+"integer"
+
:
+if
+
+value
+
+is
+not
+an
+integer
+type
+defined
+by
+
+the
+
+long
+
+or
+
+long
+long
+
+),
+then
+return
+
+false
+
,
+otherwise
+execute
+the
+following
+sub-steps:
+
+true
+
.
+"number"
+
,
+if
+
+value
+
+is
+not
+an
+integer
+or
+floating
+point
+type
+defined
+by
+the
+underlying
+platform
+(such
+as
+
+long
+
+or
+
+long
+long
+
+or
+
+double
+
+),
+then
+return
+
+false
+
,
+otherwise
+otherwise
+execute
+the
+following
+sub-steps:
+
+true
+
.
+"string"
+
:
+if
+
+value
+
+is
+not
+a
+string
+type
+defined
+by
+the
+underlying
+platform,
+then
+return
+
+false
+
,
+otherwise
+return
+
+true
+
.
+In
+
+this
+
+"array"
+
,
+execute
+the
+following
+sub-steps:
+
+false
+
.
+undefined
+
,
+return
+
+false
+
.
+null
+
,
+return
+
+true
+
+(i.e.
+any
+type
+is
+accepted
+as
+array
+element,
+including
+heterogenous
+arrays).
+
+false
+
,
+then
+return
+
+false
+
.
+true
+
.
+"object"
+
,
+execute
+the
+following
+sub-steps:
+
+Object
+
,
+return
+
+false
+
.
+false
+
.
+null
+
,
+return
+
+true
+
+(i.e.
+accept
+any
+object
+value).
+
+false
+
.
+true
+
.+ +This +section +is +non-normative. + +
++ +Observables + +are + +proposed + +to +be +included +in +ECMAScript +and +are +used +for +handling +pushed +data +associated +with +various +possible +sources, +for +instance +events, +timers, +streams, +etc. +A +minimal +required +implementation +is +described +here. +
++This +section +is +informal +and +contains +rather +laconic +information +for +implementations +on +what +to +support +for +interoperability. +
+interface "dfn"> { +<span class="idlMethod" id= +"idl-def-observable-subscribe-next-error-complete" data-idl="" +data-title="subscribe" data-dfn-for="observable"> <span class= +"idlMethType"><a href="#dom-subscription" class="internalDFN" + +"dfn">+Observable
{ +Subscription
subscribe
("idlParam">(<a href="#dom-observer" +class="internalDFN" data-link-type= +"dfn"> or <a href="#dom-onnext" class= + +"idlParam">EventHandler handler, + optionalErrorHandler
errorHandler, + optional +"internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">next, + <span class= +"idlParam">optional <a href= +"#dom-onerror" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">error, + <span class= +"idlParam">optional <a href= +"#dom-oncomplete" class="internalDFN" data-link-type= ++"dfn">OnComplete
"idlParamName">complete +}; +<span class="idlInterface" id="idl-def-subscription" data-idl="" +data-title="Subscription">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-subscription" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-subscription-unsubscribe" +data-idl="" data-title="unsubscribe" data-dfn-for= +"subscription"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="subscription" +data-lt="unsubscribe|unsubscribe()" href= +"#dom-subscription-unsubscribe" class="internalDFN" data-link-type= +"dfn"> +<span class="idlAttribute" id="idl-def-subscription-closed" +data-idl="" data-title="closed" data-dfn-for= +"subscription"> readonly attribute <span class= +"idlAttrType"><a href= + +"idlParamName">onComplete); +}; +interfaceSubscription
{ + voidunsubscribe
(); + readonly attribute +"https://heycam.github.io/webidl/#idl-boolean">boolean data-link-for="subscription" data-lt="" href= +"#dom-subscription-closed" class="internalDFN" data-link-type= + +data-link-for="subscription" data-lt="subscription.closed|closed" +href="#dom-subscription-closed" class="internalDFN" data-link-type= + +"dfn">closed
; +}; +<span class="idlInterface" id="idl-def-observer" data-idl="" +data-title="Observer">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-observer" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-observer-next-value" data-idl= +"" data-title="next" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="next()|next" href="#dom-observer-next" class="internalDFN" +data-link-type="dfn">next(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-any">any +<span class="idlMethod" id="idl-def-observer-error-error" data-idl= +"" data-title="error" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="error()|error" href="#dom-observer-error" class= +"internalDFN" data-link-type="dfn">error(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-Error">Error +<span class="idlMethod" id="idl-def-observer-complete" data-idl="" +data-title="complete" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="complete()|complete" href="#dom-observer-complete" class= +"internalDFN" data-link-type="dfn">complete +}; +<span class="idlCallback" id="idl-def-onnext" data-idl="" +data-title="OnNext">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-onnext" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType">void<span class= ++}; +callbackEventHandler
= void ( +"idlParamType">"https://heycam.github.io/webidl/#idl-any">any +<span class="idlCallback" id="idl-def-onerror" data-idl="" +data-title="OnError">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-onerror" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType">void<span class= + +"https://heycam.github.io/webidl/#idl-any">any value); +callbackErrorHandler
= void ( +"idlParamType">"https://heycam.github.io/webidl/#idl-Error">Error +<span class="idlCallback" id="idl-def-oncomplete" data-idl="" +data-title="OnComplete">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-oncomplete" class="internalDFN" data-link-type= +"dfn"> = <span class= + +"https://heycam.github.io/webidl/#idl-Error">Error error); +callbackOnComplete
= +"idlCallbackType"> +void + +(); + +
+The
+Observer
+interface
+defines
+the
+
+following
+
+callbacks
+needed
+
+can
+be
+provided
+when
+subscribing
+
+to
+handle
+
+an
+
+
+Observable
+
+:
+
+OnNext
+
+EventHandler
+
+
+
+callback
+takes
+the
+next
+sample
+for
+the
+data
+in
+the
+
+value
+
+argument.
+
+OnError
+
+ErrorHandler
+
+
+
+callback
+takes
+an
+error
+in
+the
+
+value
+
+argument.
+It
+is
+called
+when
+an
+error
+
+OnComplete
+
+
+callback
+is
+called
+when
+the
+data
+source
+has
+finished
+sending
+values.
+
+Subscription
+
+
+interface
+
+
+
+Contains
+the
+
+
+closed
+
+
+property
+of
+type
+
+boolean
+
+that
+tells
+if
+the
+subscription
+is
+closed
+or
+active.
+
+Also,
+contains
+the
+
+
+unsubscribe
+
+
+()
+method
+that
+cancels
+the
+subscription,
+i.e.
+makes
+a
+request
+to
+the
+underlying
+platform
+to
+stop
+receiving
+data
+from
+the
+source,
+and
+sets
+the
+
+closed
+
+property
+to
+
+false
+
.
+
+Observable
+
+
+interface
+
+
+
+The
+
+
+Observable
+
+
+interface
+enabled
+subscribing
+to
+pushed
+data
+notifications
+by
+the
+
+
+subscribe
+
+
+()
+method:
+
+In
+general
+
+the
+security
+measures
+taken
+to
+protect
+a
+
+WoT
+Security
+
+system
+will
+depend
+on
+the
+threats
+
+and
+Privacy
+repository
+
+attackers
+that
+system
+may
+face
+and
+the
+value
+of
+the
+assets
+needs
+to
+protect.
+A
+detailed
+discussion
+of
+security
+and
+privacy
+considerations
+
+for
+work
+in
+progress
+regarding
+
+the
+Web
+of
+Things,
+including
+a
+
+threat
+models,
+assets,
+risks,
+recommended
+mitigations,
+
+model
+that
+can
+be
+adapted
+to
+various
+circumstances,
+is
+presented
+in
+the
+informative
+document
+[
+
+WOT-SECURITY-CONSIDERATIONS
+
+].
+This
+section
+includes
+only
+normative
+recommendations
+relevant
+to
+the
+WoT
+Thing
+Description.
+
+When
+designing
+new
+devices
+
+and
+services
+for
+use
+with
+the
+WoT,
+we
+have
+documented
+a
+set
+of
+
+best
+practices
+for
+
+in
+[
+
+WOT-SECURITY-BEST-PRACTICES
+
+]
+that
+
+SHOULD
+
+be
+followed.
+
+This
+best-practices
+document
+may
+be
+updated
+as
+
+security
+measures
+evolve.
+Following
+these
+practices
+does
+not
+guarantee
+security,
+but
+it
+at
+least
+will
+help
+to
+avoid
+common
+known
+vulnerabilities
+
+and
+privacy
+for
+systems
+
+pitfalls.
+
+Below +are +specific +recommendations +related +to +WoT +runtime +implementations: +
+Some +additional +specific +recommendations +relevant +for +WoT +script +developers: + +
++The +generic +WoT +terminology +is +defined +in +[ + + +WOT-ARCHITECTURE + + +]: + +Thing +, + +Thing +Description + +(in +short + +TD + +), + +Web +of +Things + +(in +short + + +WoT + + +), + +WoT +Interface +, + +Protocol +Bindings +, + +WoT +Runtime +, + +Consuming +a +Thing +Description +, + +Thing +Directory +, + +WoT +Interactions +, + +Property +, + +Action +, + +Event + +etc. +
+
+
+JSON-LD
+
+is
+defined
+in
+[
+
+
+JSON-LD
+
+
+]
+as
+a
+JSON
+document
+that
+is
+augmented
+with
+support
+for
+Linked
+Data
+by
+providing
+a
+@context
+property
+with
+a
+defining
+URI
+.
+
+Data.
+
+
+The +terms + + +URL + + +and + + +URL +path + + +are +defined +in +[ + + +URL + + +]. +
++The +following +terms +are +defined +in +[ + + +HTML52 + + +] +and +are +used +in +the +context +of +browser +implementations: + + +browsing +context + +, + + +top-level +browsing +context + +, + + +global +object + +, + + +incumbent +settings +object + +, + + +Document + +, + + +document +base +URL + +, + + +Window + +, + + +WindowProxy + +, + + +origin + +, + + +ASCII +serialized +origin + +, +executing +algorithms + + +in +parallel + +, + + +queue +a +task + +, + + +task +source + +, + + +iframe + +, + + +valid +MIME +type + +. +
+
+A
+
+browsing
+context
+
+refers
+to
+the
+environment
+in
+which
+
+Document
+
+objects
+are
+presented
+to
+the
+user.
+A
+given
+
+browsing
+context
+
+has
+a
+single
+
+
+WindowProxy
+
+
+object,
+but
+it
+can
+have
+many
+
+
+Document
+
+
+objects,
+with
+their
+associated
+
+
+Window
+
+
+objects.
+The
+
+script
+execution
+context
+
+associated
+with
+the
+
+browsing
+context
+
+identifies
+the
+entity
+which
+invokes
+this
+API,
+which
+can
+be
+a
+
+web
+app
+,
+a
+
+web
+page
+,
+or
+an
+
+iframe
+.
+
+The +term + + +secure +context + + +is +defined +in +[ + + +WEBAPPSEC + + +]. +
++ + +Error +, + +EvalError +, + +RangeError +, + +ReferenceError +, + +SyntaxError +, + +TypeError +, + +URIError + + +, + + +script +execution +context + +, + + +Promise + +, + + +JSON + +, + + +JSON.stringify + + +and + + +JSON.parse + + +are +defined +in +[ + + +ECMASCRIPT + + +]. +
++ + +DOMString + +, + + +USVString + +, + + +ArrayBuffer + +, + + +BufferSource + + +and + + +any + + +are +defined +in +[ + + +WEBIDL + + +]. +
++The +algorithms + + +utf-8 +encode + +, +and + + +utf-8 +decode + + +are +defined +in +[ + + +ENCODING + + +]. +
++ +IANA +media +type + +s +(formerly +known +as +MIME +types) +are +defined +in + +RFC2046 +. +
++The +terms + +hyperlink +reference + +and + +relation +type + +are +defined +in +[ + + +HTML52 + + +] +and + +RFC8288 +. +
++As +well +as +sections +marked +as +non-normative, +all +authoring +guidelines, +diagrams, +examples, +and +notes +in +this +specification +are +non-normative. +Everything +else +in +this +specification +is +normative. +
++The +key +words + +MAY +, + +MUST +, + +SHOULD +, +and + +SHOULD +NOT + + +are +to +be +interpreted +as +described +in +[ + + +RFC2119 + + +]. +
++This +document +defines +conformance +criteria +that +apply +to +a +single +product: +the + +UA + +(user +agent) +that +implements +the +interfaces +it +contains. +
++This +specification +can +be +used +for +implementing +the +WoT +Scripting +API +in +multiple +programming +languages. +The +interface +definitions +are +specified +in +[ + + +WEBIDL + + +]. +
++The +user +agent +(UA) +may +be +implemented +in +the +browser, +or +in +a +separate +runtime +environment, +such +as + +Node.js + +or +small +embedded +runtimes. +
++Implementations +that +use +ECMAScript +executed +in +a +browser +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +ECMAScript +Bindings +defined +in +the +Web +IDL +specification +[ + + +WEBIDL + + +]. +
++Implementations +that +use +TypeScript +or +ECMAScript +in +a +runtime +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +TypeScript +Bindings +defined +in +the +TypeScript +specification +[ + + +TYPESCRIPT + + +]. +
++This +document +serves +a +general +description +of +the +WoT +Scripting +API. +Language +and +runtime +specific +issues +are +discussed +in +separate +extensions +of +this +document. +
+
+The
+following
+is
+a
+list
+of
+major
+changes
+to
+the
+document.
+For
+a
+complete
+list
+of
+changes,
+see
+the
+
+github
+change
+log
+.
+You
+can
+also
+view
+the
+
+recently
+closed
+bugs
+
+issues
+
+.
+
+The +following +problems +are +being +discussed +and +need +most +attention: +
+
+ExposedThing
+
+
++Special +thanks +to +former +editor +Johannes +Hund +(until +August +2017, +when +at +Siemens +AG) +for +developing +this +specification. +Also, +the +editors +would +like +to +thank +Dave +Raggett, +Matthias +Kovatsch, +Michael +Koster +and +Michael +McCool +for +their +comments +and +guidance. +
++ The Web of Things is made of entities (Things) that can describe their capabilities in a machine-interpretable Thing Description (TD) and expose these capabilities through the WoT Interface, that is, network interactions modeled as Properties (for reading and writing values), Actions (to execute remote procedures with or without return values) and Events (for signaling notifications). +
++ The main Web of Things (WoT) concepts are described in the [[[WOT-ARCHITECTURE]]] specification. +
++ Scripting is an optional building block in WoT and it is typically used in gateways or browsers that are able to run a WoT Runtime and + script management, providing a convenient way to extend WoT support to new types of endpoints and implement WoT applications such as Thing Directory. +
++ This specification describes an application programming interface (API) representing the WoT Interface that allows scripts to discover, operate Things and to expose locally defined Things characterized by WoT Interactions specified by a script. +
++ The APIs defined in this document deliberately follow the [[[WOT-TD]]] specification closely. It is possible to implement more abstract APIs on top of them, or implementing directly the WoT network facing interface (i.e. the WoT Interface). +
++ This specification is implemented at least by the Eclipse Thingweb + project also known as node-wot, which is considered the reference open source implementation at the moment. Check its source code, including examples. +
++ Implementers need to be aware that this specification is considered unstable. Vendors interested in implementing this specification before it eventually reaches the Candidate Recommendation phase should subscribe to the repository and take part in the discussions. +
++ Please contribute to this draft using the GitHub Issues page of the WoT Scripting API repository. + For feedback on security and privacy considerations, please use the WoT Security and Privacy Issues. +
++ WoT provides layered interoperability based on how Things are used: + "consumed" and "exposed", as defined in the [[[WOT-ARCHITECTURE]]] terminology. +
++ By consuming a TD, a client Thing creates a local runtime resource model that allows accessing the Properties, Actions and Events exposed by the server Thing on a remote device. +
++ Typically scripts are meant to be used on bridges or gateways that expose and control simpler devices as WoT Things and have means to handle (e.g. install, uninstall, update etc.) and run scripts. +
++ This specification does not make assumptions on how the WoT Runtime handles and runs scripts, including single or multiple tenancy, script deployment and lifecycle management. The API already supports the generic mechanisms that make it possible to implement script management, for instance by exposing a manager Thing whose Actions (action handlers) implement script lifecycle management operations. +
+ ++ The following scripting use cases are supported in this specification: +
++ After evaluating dynamic modifications to Thing Descriptions + through several versions of this API, the editors concluded that the + simplest way to represent these use cases is to take an existing + TD, modify it (i.e. add or remove definitions) and then create + a new Thing based on the modified TD. +
++ This specification describes the conformance criteria for the following classes of user agent (UA). +
+
+ Due to requirements of small embedded implementations, splitting WoT client and server interfaces was needed. Then, discovery is a distributed application, but typical scenarios have been covered by a generic discovery API in this specification. This resulted in using 3 conformance classes for a UA that implements this API, one for client, one for server, and one for discovery. An application that uses this API can introspect for the presence of the consume()
, produce()
and discover()
methods on the WoT API object in order to determine which conformance class the UA implements.
+
+ Implementations of this conformance class MUST implement the {{ConsumedThing}}
interface and the consume()
method on the WoT API object.
+
+ Implementations of this conformance class MUST implement {{ExposedThing}}
interface and the produce()
method on the WoT API object.
+
+ Implementations of this conformance class MUST implement the ThingDiscovery
interface and the discover()
method on the WoT API object.
+
+ These conformance classes MAY be implemented in a single UA. +
++ This specification can be used for implementing the WoT Scripting API in multiple programming languages. The interface definitions are specified in [[!WEBIDL]]. +
++ The UA may be implemented in the browser, or in a separate runtime environment, such as Node.js or in small embedded runtimes. +
++ Implementations that use ECMAScript executed in a browser to implement the APIs defined in this document MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]]. +
++ Implementations that use TypeScript or ECMAScript in a runtime to implement the APIs defined in this document MUST implement them in a manner consistent with the TypeScript Bindings defined in the TypeScript specification [[!TYPESCRIPT]]. +
++ typedef object ThingDescription; ++ +
+ Represents a Thing Description (TD) as + defined in + [[!WOT-TD]]. It is expected to be + a parsed JSON object that is validated using JSON Schema validation. +
++ Fetching a TD given a URL should be done with an external method, such as the Fetch API or a HTTP client library, which offer already standardized options on specifying fetch details. +
++ try { + let res = await fetch('https://tds.mythings.biz/sensor11'); + // ... additional checks possible on res.headers + let td = await res.json(); + let thing = await WOT.consume(td); + console.log("Thing name: " + thing.getThingDescription().title); + } catch (err) { + console.log("Fetching TD failed", err.message); + } ++
+ Note that the [[[WOT-TD]]] specification allows using a shortened Thing Description + by the means of defaults and requiring clients to expand them with default values specified in the + [[[WOT-TD]]] specification for the properties that are not explicitly defined in a given + TD. +
++ The [[!WOT-TD]] specification defines how a TD should be validated. + Therefore, this API expects the {{ThingDescription}} objects be validated before used as parameters. This specification defines a basic TD validation as follows. +
++ Additional steps may be added to fill the default values of mandatory fields. +
++ Defines the WoT API object as a singleton and contains the API + methods, grouped by conformance classes. +
++ [SecureContext, Exposed=(Window,Worker)] + namespace WOT { + // methods defined in UA conformance classes + }; ++
+ partial namespace WOT { + Promise<ConsumedThing> consume(ThingDescription td); + }; ++
+ Implementations encapsulate the complexity of how to use the + Protocol Bindings for implementing WoT interactions. + In the future elements of that could be standardized. +
+
+ Note the difference between constructing ConsumedThing and using
+ the consume()
method: the latter also initializes the protocol
+ bindings, whereas a simple constructed object will not have WoT Interactions
+ initialized until they are invoked.
+
+ partial namespace WOT { + Promise<ExposedThing> produce(ThingDescription td); + }; ++
+ partial namespace WOT { + ThingDiscovery discover(optional ThingFilter filter = null); + }; ++
+ As specified in the [[[WOT-TD]]] 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. +
+ ++ typedef any DataSchemaValue; + typedef (ReadableStream or DataSchemaValue) 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. +
++ 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 attribute ReadableStream? data; + readonly attribute boolean dataUsed; + readonly attribute Form? form; + readonly attribute DataSchema? 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). +
++ 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 {{ExposedThing}} + read handler provides the read data to the implementation as + {{InteractionInput}}. +
+ ++ When a {{ConsumedThing}} writes data, it provides it to the implementation + as {{InteractionInput}}. +
++ An {{ExposedThing}} + write handler receives data from to implementation as + an {{InteractionOutput}} object. +
+ ++ 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 {{ExposedThing}} + action handler receives arguments from the implementation as + an {{InteractionOutput}} object and provides Action output as + {{InteractionInput}} to the implementation. +
++ 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. +
++ This topic is still being discussed in + Issue #200. + A standardized error mapping would be needed in order to ensure consistency + in mapping script errors to protocol errors and vice versa. In particular, + when algorithms say "error received from the Protocol Bindings", + that will be factored out as an explicit error mapping algorithm. Currently, + that is encapsulated by implementations. +
++ Represents a client API to operate a Thing. Belongs to the + WoT Consumer conformance class. +
++ [SecureContext, Exposed=(Window,Worker)] + interface ConsumedThing { + constructor(ThingDescription td); + Promise<InteractionOutput> readProperty(DOMString propertyName, + optional InteractionOptions options = null); + Promise<PropertyMap> readAllProperties(optional InteractionOptions options = null); + Promise<PropertyMap> readMultipleProperties( + sequence<DOMString> propertyNames, + optional InteractionOptions options = null); + Promise<undefined> writeProperty(DOMString propertyName, + InteractionInput value, + optional InteractionOptions options = null); + Promise<undefined> writeMultipleProperties(PropertyMap valueMap, + optional InteractionOptions options = null); + /*Promise<undefined> writeAllProperties(PropertyMap valueMap, + optional InteractionOptions options = null);*/ + Promise<InteractionOutput> invokeAction(DOMString actionName, + optional InteractionInput params = null, + optional InteractionOptions options = null); + Promise<Subscription> observeProperty(DOMString name, + InteractionListener listener, + optional ErrorListener onerror, + optional InteractionOptions options = null); + Promise<Subscription> subscribeEvent(DOMString name, + InteractionListener listener, + optional ErrorListener onerror, + optional InteractionOptions options = null); + ThingDescription getThingDescription(); + }; + + dictionary InteractionOptions { + unsigned long formIndex; + object uriVariables; + any data; + }; + + [SecureContext, Exposed=(Window,Worker)] + interface Subscription { + readonly attribute boolean active; + Promise<undefined> stop(optional InteractionOptions options = null); + }; + + typedef object PropertyMap; + + callback InteractionListener = undefined(InteractionOutput data); + callback ErrorListener = undefined(Error error); ++
+ The writeAllProperties()
method is still under discussion.
+ Meanwhile, use the writeMultipleProperties()
method instead.
+
+ A {{ConsumedThing}} object has the following internal slots: +
+Internal Slot | +Initial value | +Description (non-normative) | +
---|---|---|
[[\td]] | +`null` | +The Thing Description of the {{ConsumedThing}}. | +
ConsumedThing
+ After fetching a + Thing Description as a JSON object, one can create a + {{ConsumedThing}} object. +
++ 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. +
++ As discussed in + Issue #193, the design decision is that write interactions only + return success or error, not the written value (optionally). + TDs should capture the schema of the Property + values, including precision and alternative formats. When a return + value is expected from the interaction, an Action should be used + instead of a Property. +
++ 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 support for URI variables comes from the need, exposed by the [[[WOT-TD]]] specification, to be able to describe + existing REST-ful endpoints that use them. However, it should be possible to write a Thing Description that would use + Actions for representing this kind of interactions and model the URI variables as action parameters. In that case, + implementations can serialize the parameters as URI variables, and therefore, the |options| parameter could be + dismissed. +
++ The data property if defined, represents additional opaque + data that needs to be passed to the interaction. +
++ 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. +
++ It could be defined in Web IDL (as well as {{ThingDescription}}) as a maplike interface from string to any. +
++ User provided callback that is given an argument of type + {{InteractionOutput}} and is used for observing Property changes + and handling Event notifications. + Since subscribing to Events are WoT interactions and might take + options or even data, they are not modelled with software events. +
++ User provided callback that is given an argument of type + {{Error}} and is used for conveying critical and non-critical errors + from the Protocol Bindings to applications. +
++ Represents a subscription to Property change and Event + interactions. +
+
+ The active boolean property denotes if the subscription is
+ active, i.e. it is not stopped because of an error or because of invocation
+ of the stop()
method.
+
Internal Slot | +Initial value | +Description (non-normative) | +
---|---|---|
[[\type]] | +`null` | ++ Indicates what WoT Interaction the {{Subscription}} refers to. + The value can be either `"property"` or `"event"` or `null`. + | +
[[\name]] | +`null` | +The Property or Event name. | +
[[\interaction]] | +`null` | ++ The Thing Description fragment that describes the + WoT interaction. + | +
[[\form]] | +`null` | +The Form associated with the subscription. | +
+ Stops delivering notifications for the subscription. It takes an + optional parameter |options:InteractionOptions| and returns a {{Promise}}. + When invoked, the method MUST execute the following steps: +
+ This algorithm is under development and is non-normative. + Implementations MAY choose another algorithm to find a matching + `unsubscribe` Form to a given `subscribe` Form. +
++ The next example illustrates how to fetch a TD by URL, create a {{ConsumedThing}}, read metadata (title), read property value, subscribe to property change, subscribe to a WoT event, unsubscribe. +
++ try { + let res = await fetch("https://tds.mythings.org/sensor11"); + let td = res.json(); + let thing = new ConsumedThing(td); + console.log("Thing " + thing.getThingDescription().title + " consumed."); + } catch (e) { + console.log("TD fetch error: " + e.message); + }; + + try { + // subscribe to property change for “temperature” + await thing.observeProperty("temperature", async (data) => { + try { + console.log("Temperature changed to: " + await data.value()); + } catch (error) { + console.error("Cannot read the observed property temperature"); + console.error(error); + } + }); + // subscribe to the “ready” event defined in the TD + await thing.subscribeEvent("ready", async (eventData) => { + try { + console.log("Ready; index: " + await eventData.value()); + // run the “startMeasurement” action defined by TD + await thing.invokeAction("startMeasurement", { units: "Celsius" }); + console.log("Measurement started."); + } catch (error) { + console.error("Cannot read the ready event or startMeasurement failed"); + console.error(error) + } + }); + } catch (e) { + console.log("Error starting measurement."); + } + + setTimeout(async () => { + try { + const temperatureData = await thing.readProperty("temperature") + const temperature = await temperatureData.value(); + console.log("Temperature: " + temperature); + + await thing.unsubscribe("ready"); + console.log("Unsubscribed from the ‘ready’ event."); + } catch (error) { + console.log("Error in the cleanup function"); + } + }, 10000); ++
+ The following shows an advance usage of {{InteractionOutput}} to read a property without a {{DataSchema}}. +
++ /* + * takePicture affordance form: + * "form": { + * "op": "invokeaction", + * "href" : "http://camera.example.com:5683/takePicture", + * "response": { + * "contentType": "image/jpeg", + * "contentCoding": "gzip" + * } + *} + * See https://www.w3.org/TR/wot-thing-description/#example-23 + */ + let response; + let image; + try { + response = await thing.invokeAction(“takePicture”)); + image = await response.value() // throws NotReadableError --> schema not defined + } catch(ex) { + image = await response.arrayBuffer(); + // image: ArrayBuffer [0x1 0x2 0x3 0x5 0x15 0x23 ...] + } ++
+ Finally, the next two examples shows the usage of a {{ReadableStream}} from an {{InteractionOutput}}. +
++ /*{ + "video": { + "description" : "the video stream of this camera", + "forms": [ + { + "op": "readproperty", + "href": "http://camera.example.com/live", + "subprotocol": "hls" + "contentType": "video/mp4" + } + ] + }}*/ + + const video = await thing.readProperty("video") + const reader = video.data.getReader() + reader.read().then(function processVideo({ done, value }) { + if (done) { + console.log("live video stoped"); + return; + } + const decoded = decode(value) + UI.show(decoded) + // Read some more, and call this function again + return reader.read().then(processText); + }); ++
Here consider that the JSON object is too big to be read wholly in the memory. Therefore, + we use streaming processing to get the total number of the events recorded by the remote Web Thing. +
++ /* + * "eventHistory": + * { + * "description" : "A long list of the events recorderd by this thing", + * "type": "array", + * "forms": [ + * { + * "op": "readproperty", + * "href": "http://recorder.example.com/eventHistory", + * } + * ] + * } + */ + + // Example of streaming processing: counting json objects + let objectCounter = 0 + const parser = new Parser() //User library for json streaming parsing (i.e. https://github.com/uhop/stream-json/wiki/Parser) + + parser.on('data', data => data.name === 'startObject' && ++objectCounter); + parser.on('end', () => console.log(`Found ${objectCounter} objects.`)); + + const response = await thing.readProperty(“eventHistory”) + await response.data.pipeTo(parser); + + // Found N objects ++
+ The {{ExposedThing}} interface is the server API to operate the Thing that allows defining request handlers, Property, Action, and Event interactions. +
++ [SecureContext, Exposed=(Window,Worker)] + interface ExposedThing: ConsumedThing { + ExposedThing setPropertyReadHandler(DOMString name, + PropertyReadHandler handler); + ExposedThing setPropertyWriteHandler(DOMString name, + PropertyWriteHandler handler); + ExposedThing setPropertyObserveHandler(DOMString name, + PropertyReadHandler handler); + ExposedThing setPropertyUnobserveHandler(DOMString name, + PropertyReadHandler handler); + + ExposedThing setActionHandler(DOMString name, ActionHandler action); + + ExposedThing setEventSubscribeHandler(DOMString name, + EventSubscriptionHandler handler); + ExposedThing setEventUnsubscribeHandler(DOMString name, + EventSubscriptionHandler handler); + ExposedThing setEventHandler(DOMString name, + EventListenerHandler eventHandler); + undefined emitEvent(DOMString name, InteractionInput data); + + Promise<undefined> expose(); + Promise<undefined> destroy(); + }; + + callback PropertyReadHandler = Promise<any>( + optional InteractionOptions options = null); + + callback PropertyWriteHandler = Promise<undefined>( + InteractionOutput value, + optional InteractionOptions options = null); + + callback ActionHandler = Promise<InteractionInput>( + InteractionOutput params, + optional InteractionOptions options = null); + + callback EventSubscriptionHandler = Promise<undefined>( + optional InteractionOptions options = null); + + callback EventListenerHandler = Promise<InteractionInput>(); ++
+ The {{ExposedThing}} interface extends {{ConsumedThing}}. It + is constructed from a full or partial {{ThingDescription}} object. +
++ Note that an existing {{ThingDescription}} object can be optionally modified (for instance by adding or removing elements on its |properties|, |actions| and |events| internal properties) and the resulting object can used for constructing an + {{ExposedThing}} object. This is the current way of adding and + removing Property, Action and Event definitions, as illustrated in the examples. +
++ Before invoking expose(), the {{ExposedThing}} object does not serve any requests. This allows first constructing {{ExposedThing}} and then initialize its Properties and service handlers before starting serving requests. +
+
+ The readProperty()
, readMultipleProperties()
, readAllProperties()
, writeProperty()
, writeMultipleProperties()
, writeAllProperties()
methods have the same algorithmic steps as described in ConsumedThing
, with the difference that making a request to the underlying platform MAY be implemented with local methods or libraries and don't necessarily need to involve network operations.
+
+ The implementation of {{ConsumedThing}} interface in an {{ExposedThing}} provide the default methods to interact with the {{ExposedThing}}. +
+
+ After constructing an {{ExposedThing}}, a script can initialize its Properties and can set up the optional read, write and action request handlers (the default ones are provided by the implementation). The script provided handlers MAY use the default handlers, thereby extending the default behavior, but they can also bypass them, overriding the default behavior. Finally, the script would call expose()
on the {{ExposedThing}} in order to start serving external requests.
+
+ The request handlers actually implement the behavior and it is the + responsibility of the developers to keep the Thing Description + defined in {{ExposedThing}} synchronized with the implementation of the + request handlers. +
++ A function that is called when an external request for reading a + Property is received and defines what to do with such requests. + It returns a {{Promise}} and resolves with an {{ReadableStream}} object or an + + ECMAScript value conforming to DataSchema, or rejects with an + error. +
++ Takes as arguments |name:string| and |handler:PropertyReadHandler|. + Sets the service handler that defines what to do when a request is + received for reading the specified Property matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ Note that there is no need to register handlers for handling requests + for reading multiple or all Properties. The request and reply + are transmitted in a single network request, but the ExposedThing + may implement them using multiple calls to the single read handler. +
++ The |handler| callback function should implement reading a Property and SHOULD be called by implementations when a request for reading a Property is received from the underlying platform. +
++ There MUST be at most one handler for any given Property, so newly added handlers MUST replace the previous handlers. If no handler is initialized for any given Property, implementations SHOULD implement a default property read handler based on the Thing Description provided in the [[\td]] internal slot. +
++ The |value| returned here SHOULD either conform to DataSchema + or it SHOULD be an {{ReadableStream}} object created by the + |handler|. +
++ Takes as arguments |name:string| and |handler:PropertyReadHandler|. + Sets the service handler that defines what to do when a request is received + for observing the specified Property matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |handler| callback function should implement reading a + Property and resolve with an {{InteractionOutput}} object or + reject with an error. +
++ There MUST be at most one handler for any given Property, so newly added handlers MUST replace the previous handlers. If no handler is initialized for any given Property, implementations SHOULD implement a default property read handler based on the Thing Description. +
++ Takes as arguments |name:string| and |handler:PropertyReadHandler|. + Sets the service handler that defines what to do when a request is + received for unobserving the specified Property matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |handler| callback function should implement what to do when an + unobserve request is received by the implementation. +
++ There MUST be at most one handler for any given Property, so newly added handlers MUST replace the previous handlers. If no handler is initialized for any given Property, implementations SHOULD implement a default handler based on the Thing Description. +
++ A function that is called when an external request for writing a + Property is received and defines what to do with such requests. + Takes as argument |value:InteractionOutput| and returns a {{Promise}}, + resolved when the value of the Property - identified by the name + provided when setting the handler has been updated -, or rejects + with an error if the property is not found or the value cannot be updated. +
++ Note that the code in this callback function can read the property before updating it in order to find out the old value, if needed. Therefore the old value is not provided to this function. +
++ The value is provided by implementations as an {{InteractionOutput}} object + in order to be able to represent values that are not described by a + DataSchema, such as streams. +
++ Takes as arguments |name:string| and |handler:PropertyWriteHandler|. + Sets the service handler that defines what to do when a request is + received for writing the Property matched by |name| given when + setting the handler. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ Note that even for readonly Properties it is possible to specify + a write handler, as explained in Issue 199. In this case, the write + handler may define in an application-specific way to fail the request. +
++ There MUST be at most one write handler for any given Property, so newly added handlers MUST replace the previous handlers. If no write handler is initialized for any given Property, implementations SHOULD implement default property update if the Property is + writeable and notifying observers on change if the Property is + observable, based on the Thing Description. +
++ A function that is called when an external request for invoking an + Action is received and defines what to do with such requests. + It is invoked with |params:InteractionOutput| and optionally + with an |options:InteractionOptions| object. + It returns a {{Promise}} that rejects with an error or resolves with + the value returned by the Action as {{InteractionInput}}. +
++ Application scripts MAY return a {{ReadableStream}} object from an + {{ActionHandler}}. Implementations will then use the stream for + constructing the Action's response. +
++ Takes as arguments |name:string| and |action:ActionHandler|. + Sets the handler function that defines what to do when a request is + received to invoke the Action matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |action| callback function will implement an Action and SHOULD be called by implementations when a request for invoking the Action is received from the underlying platform. +
++ There MUST be at most one handler for any given Action, so newly added handlers MUST replace the previous handlers. +
++ A function that is called when an associated Event is triggered + and provides the data to be sent with the Event to subscribers. + Returns a {{Promise}} that resolves with {{InteractionInput}} value + that represents the Event data, or rejects with an error. +
++ Applications MAY return {{ReadableStream}} from an {{EventListenerHandler}} + Implementations will then use the stream provided in + {{InteractionOutput}} when constructing the event notification. +
++ A function that is called when an external request for subscribing to an + Event is received and defines what to do with such requests. + It is invoked with an |options:InteractionOptions| object provided by the implementation and coming from subscribers. + It returns a {{Promise}} that rejects with an error or resolves when + the subscription is accepted. +
++ Takes as arguments |name:string| and |handler:EventSubscriptionHandler|. + Sets the handler function that defines what to do when a subscription + request is received for the specified Event matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |handler| callback function SHOULD implement what to do when an + subscribe request is received, for instance necessary initializations. + Note that the handler for emitting Events is set separately. +
++ There MUST be at most one event subscribe handler for any given + Event, so newly added handlers MUST replace the previous handlers. +
++ Takes as arguments |name:string| and |handler:EventSubscriptionHandler|. + Sets the handler function that defines what to do when the specified + Event matched by |name| is unsubscribed from. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |handler| callback function SHOULD implement what to do when an + unsubscribe request is received. +
++ There MUST be at most one handler for any given Event, so newly added handlers MUST replace the previous handlers. +
++ Takes as arguments |name:string| and |eventHandler:EventListenerHandler|. + Sets the event handler function for the specified Event + matched by |name|. + Throws on error. + Returns a reference to |this| object for supporting chaining. +
++ The |eventHandler| callback function will implement what to do when the + event is emitted. It SHOULD resolve with a value that represents the + Event data, or reject with an error. +
++ There MUST be at most one handler for any given Event, so newly added handlers MUST replace the previous handlers. +
++ This will trigger the handling events + steps. +
++ The next example illustrates how to create an {{ExposedThing}} based on a partial TD object constructed beforehands. +
++ try { + let temperaturePropertyDefinition = { + type: "number", + minimum: -50, + maximum: 10000 + }; + let tdFragment = { + properties: { + temperature: temperaturePropertyDefinition + }, + actions: { + reset: { + description: "Reset the temperature sensor", + input: { + temperature: temperatureValueDefinition + }, + output: null, + forms: [] + }, + }, + events: { + onchange: temperatureValueDefinition + } + }; + let thing1 = await WOT.produce(tdFragment); + // initialize Properties + await thing1.writeProperty("temperature", 0); + // add service handlers + thing1.setPropertyReadHandler("temperature", () => { + return readLocalTemperatureSensor(); // Promise + }); + // start serving requests + await thing1.expose(); + } catch (err) { + console.log("Error creating ExposedThing: " + err); + } ++ +
+ The next example illustrates how to add or modify a Property definition on an existing {{ExposedThing}}: take its |td| property, add or modify it, then create another {{ExposedThing}} with that. +
++ try { + // create a deep copy of thing1's TD + let instance = JSON.parse(JSON.stringify(thing1.td)); + const statusValueDefinition = { + type: "object", + properties: { + brightness: { + type: "number", + minimum: 0.0, + maximum: 100.0, + required: true + }, + rgb: { + type: "array", + "minItems": 3, + "maxItems": 3, + items : { + "type" : "number", + "minimum": 0, + "maximum": 255 + } + } + }; + instance["name"] = "mySensor"; + instance.properties["brightness"] = { + type: "number", + minimum: 0.0, + maximum: 100.0, + required: true, + }; + instance.properties["status"] = statusValueDefinition; + instance.actions["getStatus"] = { + description: "Get status object", + input: null, + output: { + status : statusValueDefinition; + }, + forms: [...] + }; + instance.events["onstatuschange"] = statusValueDefinition; + instance.forms = [...]; // update + var thing2 = new ExposedThing(instance); + // TODO: add service handlers + await thing2.expose(); + }); + } catch (err) { + console.log("Error creating ExposedThing: " + err); + } ++
+ Discovery is a distributed application that requires provisioning and support from participating network nodes (clients, servers, directory services). This API models the client side of typical discovery schemes supported by various IoT deployments. +
++ The {{ThingDiscovery}} object is constructed given a filter and provides the properties and methods controlling the discovery process. +
++ [SecureContext, Exposed=(Window,Worker)] + interface ThingDiscovery { + constructor(optional ThingFilter filter = null); + readonly attribute ThingFilter? filter; + readonly attribute boolean active; + readonly attribute boolean done; + readonly attribute Error? error; + undefined start(); + Promise<ThingDescription> next(); + undefined stop(); + }; ++
+ The {{ThingDiscovery}} interface has a next()
method and a done
property, but it is not an Iterable. Look into Issue 177 for rationale.
+
+ The discovery results internal slot is an internal queue for temporarily storing the found {{ThingDescription}} objects until they are consumed by the application using the next() method. Implementations MAY optimize the size of this queue based on e.g. the available resources and the frequency of invoking the next() method. +
++ The filter property represents the discovery filter of type ThingFilter specified for the discovery. +
++ The active property is `true` when the discovery is actively ongoing on protocol level (i.e. new TDs may still arrive) and `false` otherwise. +
++ The done property is `true` if the discovery has been completed with no more results to report and discovery results is also empty. +
++ The error property represents the last error that occurred during the discovery process. Typically used for critical errors that stop discovery. +
+ ++ The start() method sets active to `true`. The stop() method sets the active property to |false|, but done may be still `false` if there are {{ThingDescription}} objects in the discovery results not yet consumed with next(). +
++ During successive calls of next(), the active property may be `true` or `false`, but the done property is set to `false` by next() only when both the active property is `false` and discovery results is empty. +
++ typedef DOMString DiscoveryMethod; ++
+ Represents the discovery type to be used: +
++ Represents an object containing the constraints for discovering Things as key-value pairs. +
++ dictionary ThingFilter { + (DiscoveryMethod or DOMString) method = "any"; + USVString? url; + USVString? query; + object? fragment; + }; ++
+ The method property represents the discovery type that should be used in the discovery process. The possible values are defined by the DiscoveryMethod enumeration that MAY be extended by string values defined by solutions (with no guarantee of interoperability). +
++ The url property represents additional information for the discovery method, such as the URL of the target entity serving the discovery request, for instance the URL of a Thing Directory (if method is `"directory"`), or otherwise the URL of a directly targeted Thing. +
++ The query property represents a query string accepted by the implementation, for instance a SPARQL or JSON query. Support may be implemented locally in the WoT Runtime or remotely as a service in a Thing Directory. +
++ The fragment property represents a template object used for matching property by property against discovered Things. +
++ The following example finds {{ThingDescription}} objects of Things that are exposed by local hardware, regardless how many instances of WoT Runtime it is running. Note that the discovery can end (become inactive) before the internal discovery results queue is emptied, so we need to continue reading {{ThingDescription}} objects until done. This is typical with local and directory type discoveries. +
++ let discovery = new ThingDiscovery({ method: "local" }); + do { + let td = await discovery.next(); + console.log("Found Thing Description for " + td.title); + let thing = new ConsumedThing(td); + console.log("Thing name: " + thing.getThingDescription().title); + } while (!discovery.done); ++
+ The next example finds {{ThingDescription}} objects of Things listed in a Thing Directory service. We set a timeout for safety. +
++ let discoveryFilter = { + method: "directory", + url: "http://directory.wotservice.org" + }; + let discovery = new ThingDiscovery(discoveryFilter); + setTimeout( () => { + discovery.stop(); + console.log("Discovery stopped after timeout."); + }, + 3000); + do { + let td = await discovery.next(); + console.log("Found Thing Description for " + td.title); + let thing = new ConsumedThing(td); + console.log("Thing name: " + thing.getThingDescription().title); + } while (!discovery.done); + if (discovery.error) { + console.log("Discovery stopped because of an error: " + error.message); + } ++
+ The next example is for an open-ended multicast discovery, which likely won't complete soon (depending on the underlying protocol), so stopping it with a timeout is a good idea. It will likely deliver results one by one. +
++ let discovery = new ThingDiscovery({ method: "multicast" }); + setTimeout( () => { + discovery.stop(); + console.log("Stopped open-ended discovery"); + }, + 10000); + do { + let td = await discovery.next(); + let thing = new ConsumedThing(td); + console.log("Thing name: " + thing.getThingDescription().title); + } while (!discovery.done); ++
+ A detailed discussion of security and privacy considerations for the Web of Things, including a threat model that can be adapted to various circumstances, is + presented in the informative document [[!WOT-SECURITY-GUIDELINES]]. + This section discusses only security and privacy risks and possible mitigations + directly relevant to the scripts and WoT Scripting API. +
++ A suggested set of best practices to improve security for WoT devices and + services has been documented in [[!WOT-SECURITY-BEST-PRACTICES]]. + That document may be updated as security measures evolve. + Following these practices does not guarantee security, + but it might help avoid common known vulnerabilities. +
++ This section is normative and contains specific risks relevant for the WoT Scripting Runtime. +
+ ++ A typical way to compromise any process is to send it a corrupted input + via one of the exposed interfaces. This can be done to a script instance + using WoT interface it exposes. +
++ In case a script is compromised or misbehaving, the underlying physical device (and potentially surrounded environment) can be damaged if a script can use directly exposed native device interfaces. If such interfaces lack safety checks on their inputs, they might bring the underlying physical device (or environment) to an unsafe state (i.e. device overheats and explodes). +
++ If the WoT Scripting Runtime supports post-manufacturing provisioning + or updates of scripts, WoT Scripting Runtime or any related data + (including security credentials), it can be a major attack vector. + An attacker can try to modify any above described element + during the update or provisioning process or simply + provision attacker's code and data directly. +
++ Typically the WoT Scripting Runtime needs to store the security credentials that are provisioned to a WoT device to operate in WoT network. If an attacker can compromise the confidentiality or integrity of these credentials, then it can obtain access to the WoT assets, impersonate WoT things or devices or create Denial-Of-Service (DoS) attacks. +
++ This section describes specific risks relevant for script developers. +
+ ++ A script instance may receive data formats defined by the TD, or data formats defined by the applications. While the WoT Scripting Runtime SHOULD perform validation on all input fields defined by the TD, scripts may be still exploited by input data. +
++ If a script performs a heavy functional processing on received requests before the request is authenticated, it presents a great risk for Denial-Of-Service (DOS) attacks. +
++ During the lifetime of a WoT network, a content of a TD can change. + This includes its identifier, which might not be an immutable one and might be updated periodically. +
++ While stale TDs can present a potential problem for WoT network operation, + it might not be a security risk. +
++ The generic WoT terminology is defined in [[!WOT-ARCHITECTURE]]: Thing, Thing Description (in short TD), Web of Things (in short WoT), WoT Interface (same as WoT network interface), Protocol Bindings, WoT Runtime, Consuming a Thing Description, Thing Directory, WoT Interactions, Property, Action, Event, + + DataSchema, Form etc. +
++ JSON-LD is defined in [[!JSON-LD]] as a JSON document that is augmented with support for Linked Data. +
++ JSON Schema is defined in these specifications. +
++ The terms + URL, + URL scheme, + URL host, + URL path, + URL record, + parse a URL, + absolute-URL string, + path-absolute-URL string, + basic URL parser + are defined in [[!URL]]. +
++ The terms + MIME type, + Parsing a MIME type, + Serializing a MIME type, + valid MIME type string, + JSON MIME type + are defined in [[!MIMESNIFF]]. +
++ The terms + UTF-8 encoding, + UTF-8 decode, + encode, + decode + are defined in [[!ENCODING]]. +
++ string, + parse JSON from bytes and + serialize JSON to bytes, + are defined in [[!INFRA]]. +
++ {{Promise}}, + Error, + JSON, + JSON.stringify, + JSON.parse, + internal method and + internal slot are defined in [[!ECMASCRIPT]]. +
++ The terms + browsing context, + top-level browsing context, + global object, + current settings object, + executing algorithms in parallel + are defined in [[!HTML5]] and are used in the context of browser implementations. +
++ The term + + secure context is defined in [[!WEBAPPSEC]]. +
++ IANA media types (formerly known as MIME types) are defined in + RFC2046. +
++ The terms hyperlink reference and relation type are defined in [[!HTML5]] and RFC8288. +
++ API rationale usually belongs to a separate document, but in the WoT case + the complexity of the context justifies including basic rationale here. +
++ The WoT Interest Group and Working Group have explored different + approaches to application development for WoT that have been all + implemented and tested. +
++ It is possible to develop WoT applications that only use the + WoT network interface, typically exposed by a WoT gateway that + presents a REST-ful API towards clients and implements IoT protocol + plugins that communicate with supported IoT deployments. One such + implementation is the + Mozilla WebThings platform. +
++ WoT Things show good synergy with software objects, so a + Thing can be represented as a software object, with Properties represented as object properties, Actions as methods, and + Events as events. In addition, metadata is stored in special + properties. Consuming and exposing is done with factory methods that + produce a software object that directly represents a remote Thing + and its interactions. One such implementation is the + Arena Web Hub + project. +
+
+ In the next example, a Thing that represents interactions with
+ a lock would look like the following: the |status| property
+ and the open()
method are directly exposed on the object.
+
+ let lock = await WoT.consume(‘https://td.my.com/lock-00123’); + console.log(lock.status); + lock.open('withThisKey'); ++
+ Since the direct mapping of Things to software objects have had + some challenges, this specification takes another approach that + exposes software objects to represent the Thing metadata as + data property and the WoT interactions as methods. One implementation + is node-wot + in the the Eclipse ThingWeb project, + which is the current reference implementation of the API specified in + this document. +
+
+ The same example now would look like the following: the
+ |status| property and the open()
method are
+ represented indirectly.
+
+ let res = await fetch(‘https://td.my.com/lock-00123’); + let td = await res.json(); + let lock = new ConsumedThing(td); + console.log(lock.readProperty(‘status’)); + lock.invokeAction(‘open’, 'withThisKey'); ++
+ In conclusion, the WoT WG decided to explore the third option that + closely follows the [[[WOT-TD]]] specification. Based on this, a simple + API can also be implemented. + Since Scripting is an optional module in WoT, this leaves room for + applications that only use the WoT network interface. + Therefore all three approaches above are supported by the [[[WOT-TD]]] specification. +
++ Moreover, the WoT network interface can be implemented in many languages + and runtimes. Consider this API an example for what needs to be taken + into consideration when designing a Scripting API for WoT. +
+
+ The fetch(url)
method has been part of this API in earlier versions. However, now fetching a TD given a URL should be done with an external method, such as the Fetch API or a HTTP client library, which offer already standardized options on specifying fetch details. The reason is that while simple fetch operations (covering most use cases) could be done in this API, when various fetch options were needed, there was no point in duplicating existing work to re-expose those options in this API.
+
+ Since fetching a TD has been scoped out, and TD validation + is defined externally in the [[[WOT-TD]]] specification, that is scoped out, too. + This specification expects a TD as + parsed JSON object that has been validated according to the [[[WOT-TD]]] specification. +
++ The factory methods for consuming and exposing Things are asynchronous and fully validate the input TD. In addition, one can also construct {{ConsumedThing}} and {{ExposedThing}} by providing a parsed and validated TD. Platform initialization is then done when needed during the WoT interactions. So applications that prefer validating a TD themselves, may use the constructors, whereas applications that leave validation to implementations and prefer interactions initialized up front SHOULD use the factory methods on the WoT API object. +
++ Earlier drafts used the + Observer + construct, but since it has not become standard, a new design was needed + that was light enough for embedded implementations. Therefore observing + Property changes and handling WoT Events is done with + callback registrations. +
+
+ The reason to use function names like readProperty()
, readMultipleProperties()
etc. instead of a generic polymorphic read()
function is that the current names map exactly to the "op"
vocabulary from the Form definition in the [[[WOT-TD]]] specification.
+
fetch()
for fetching a TD (delegated to external API).
+ Observer
and use W3C TAG recommended design patterns.
+ + For a complete list of changes, see the github change log. You can also view the recently closed issues. +
++ Special thanks to former editor Johannes Hund (until August 2017, when at Siemens AG) and Kazuaki Nimura (until December 2018) for developing this specification. Also, the editors would like to thank Dave Raggett, Matthias Kovatsch, Michael Koster, Elena Reshetova, Michael McCool as well as the other WoT WG members for their comments, contributions and guidance. +
++ Copyright © 2017 + + W3C® (MIT, + ERCIM, + Keio, Beihang). + W3C liability, + trademark and + permissive document license rules apply. +
++ The Web of Things (WoT) provides layered interoperability between Things by using the WoT Interfaces. +
++ This specification describes a programming interface representing the WoT Interface that allows scripts run on a Thing to discover and consume (retrieve) other Things and to expose Things characterized by properties, Actions and Events. +
++ Scripting is an optional "convenience" building block in WoT and it is typically used in gateways that are able to run a WoT Runtime and script management, + providing a convenient way to extend WoT support to new types of endpoints and implement WoT applications like Thing Directory. +
++ This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/. +
++ Implementers need to be aware that this specification is considered unstable. Vendors interested in implementing this specification before it eventually reaches the Candidate Recommendation phase should subscribe to the repository and take part in the discussions. +
++ Please contribute to this draft using the GitHub Issue feature of the WoT Scripting API repository. For feedback on security + and privacy considerations, please use the WoT Security and Privacy Issues. +
++ This document was published by the Web of Things Working Group as a First Public Working Draft. + This document is intended to become a W3C Recommendation. +
++ Comments regarding this document are welcome. Please send them to + public-wot-wg@w3.org (subscribe, + archives). +
++ Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate + to cite this document as other than work in progress. +
++ This document was produced by a group operating under the + 5 February 2004 W3C Patent + Policy. + W3C maintains a public list of any patent + disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains + Essential + Claim(s) must disclose the information in accordance with + section + 6 of the W3C Patent Policy. +
+This document is governed by the 1 March 2017 W3C Process Document. +
+ + ++ The overall WoT concepts are described in the WoT Architecture document. The Web of Things is made of entities (Things) + that can describe their capabilities in a machine-interpretable format, the Thing Description (TD) and expose these capabilities through the WoT Interface. Support for scripting is optional for WoT devices. +
++ By consuming a TD, a client Thing creates a runtime resource model that allows accessing + the properties, Actions and Events exposed by the server Thing. +
++ Exposing a Thing requires defining a Thing Description and instantiating a software stack needed + to serve requests for accessing the exposed properties, Actions and Events. This specification describes how + to expose and consume Things by a script. +
++ Typically scripts are meant to be used on devices able to provide resources (with a WoT interface) for managing (installing, updating, running) scripts, such as + bridges or gateways that expose and control simpler devices as WoT Things. +
++ For an introduction on how scripts could be used in Web of Things, check the Primer document. For some background + on API design decisions check the Rationale document. +
+This section is non-normative.
++ The following scripting use cases are covered in this specification: +
++ The following use cases are being considered for next versions: +
+WoT
objectThe WoT object is the main API entry point and it is exposed by an implementation of the WoT Runtime. The WoT object has + no internal state and provides methods for discovering, consuming and exposing a Thing. +
+
+ Browser implementations SHOULD use a namespace object such as wot
, and Node.js-like runtimes MAY provide the
+ API object through the require()
or import
mechanism.
+
interface WoT
{
+ Observable<ConsumedThing
> discover(optional ThingFilter
filter);
+ Promise<ConsumedThing
> consume(USVString url);
+ Promise<ExposedThing
> expose(ThingInit
init);
+};
+ + The algorithms for the WoT methods will be specified later. +
+discover()
method
+ Starts the discovery process that will provide
objects that match the optional argument ConsumedThing
+
. When the argument is not provided, starts the widest discovery the Thing Description and Protocol Bindings allow. Returns an ThingFilter
+ Observable
object that can be subscribed and unsubscribed to.
+
ThingFilter
dictionary
+ The ThingFilter
dictionary that represents the constraints for discovering Things
+ as key-value pairs.
+
dictionary ThingFilter
{
+ (DiscoveryType or DOMString) method
= "any";
+ USVString url
;
+ Dictionary description
;
+};
+
+ The method
property represents the discovery type that should be used in the discovery process. The
+ possible values are defined by the
enumeration that can be extended by string values defined by solutions (with no guarantee of interoperability).
+ DiscoveryMethod
+
+ The url
property represents additional information for the discovery method, such as the URL of the Thing Directory server to be used.
+
+ The description
property represents additional information for the discovery method in the
+ form of a set of key-value pairs, as defined in the Thing Description.
+
+ The DiscoveryMethod
enumeration can be extended by the Thing Description with values that are not specified here. This extensibility of DiscoveryMethod
by proprietary or private methods is a working assumption until
+ consensus is formed and may be removed later.
+
+ The ThingFilter
dictionary may be extended later with further attributes.
DiscoveryMethod
enumerationenum DiscoveryMethod
{
+ "any",
+ "local",
+ "nearby",
+ "directory",
+ "broadcast",
+ "other"
+};
+
+ The DiscoveryMethod
enumeration represents the discovery type to be used:
+
any
" does not provide any restrictionlocal
" for discovering Things
+ defined in the same devicenearby
" for discovering Things
+ nearby the device, e.g. by Bluetooth or NFC
+ directory
" for discovery based on a service provided by a directory or repository
+ of Things
+ broadcast
" for an open ended discovery based on sending a request to a broadcast
+ address
+ other
" for a proprietary method defined by the solution.
+ consume()
method
+ Accepts an url
argument and returns a Promise
of a ConsumedThing
.
+
expose()
method
+ Returns a Promise
of a locally created ExposedThing
based on the provided
+ initialization parameters.
+
+ The reason ExposedThing
s are created by a factory method instead of a constructor is that an ExposedThing
may be created in the local WoT Runtime or in a remote runtime. Even though currently only local creation is supported, the method is designed with this possible
+ future compatibility in mind.
+
ThingInit
dictionaryThe ThingInit
dictionary contains properties to initialize a Thing:
+
name
attribute represents the user given name of the Thing.url
attribute represents the address of the Thing.description
attribute represents the Thing Description of the Thing.let discoveryType = { method: "directory", url: "http://directory.wotservice.org" };
+let subscription = wot.discover(discoveryType).subscribe(
+ thing => { console.log("Found Thing " + thing.url); },
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout(
+ () => { subscription.unsubscribe(); console.log("Discovery timeout"); },
+ 5000);
+
+ Note that canceling a discovery (through unsubscribe) may not be successful in all cases, for instance when discovery is based on open ended broadcast requests. However, once unsubscribe()
has been called, implementations
+ MUST suppress further event handling ( i.e. further discoveries and errors) on the Observable. Also, a discovery error may not mean the end of the discovery process. However, in order to respect
+ Observable semantics (error always terminates processing), implementations MUST close or suppress further event handling on the Observable.
+
let subscription = wot.discover({ method: "local" }).subscribe(
+ thing => { console.log("Found local Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({ method: "nearby", description: {protocol: "BLE4.2"} }).subscribe(
+ thing => { console.log("Found nearby Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({ method: "other", description: { solution: "XYZ123", key: "..."} }).subscribe(
+ thing => { console.log("Found Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ ConsumedThing
interface
+ The ConsumedThing
interface is a client API for sending requests to servers in order to retrieve or update properties, invoke Actions, and observe properties, Actions and Events.
+
interface+ConsumedThing
{ + readonly attribute DOMStringname
; + readonly attribute USVStringurl
; + readonly attributeThingDescription
description
; + Promise<any> invokeAction(DOMString name, any parameters); + Promise<void> setProperty(DOMString name, any value); + Promise<any> getProperty(DOMString name); +ConsumedThing
addListener(DOMString eventName,ThingEventListener
listener); +ConsumedThing
removeListener(DOMString eventName, +ThingEventListener
listener); +ConsumedThing
removeAllListeners(optional DOMString eventName); + Observable observe(DOMString name,RequestType
requestType); +}; + +callbackThingEventListener
= void (Event event);
+ Represents a local proxy object of the remote Thing. +
+name
read-only attribute represents the name of the Thing.url
read-only attribute represents the URL of the Thing.description
attribute read-only attribute represents the description of the Thing.
+ + Parsing and exposing Thing Descriptions is discussed in Issue 38.
+invokeAction()
method
+ Takes the Action name from the name argument and the list of parameters, then requests from the underlying platform and the Protocol Bindings to invoke the Action on the remote Thing and return the result. Returns a Promise
that resolves with the return value or rejects with an Error.
+
setProperty()
method
+ Takes the Property name as the name argument and the new value as the value argument, then requests from the underlying platform and the Protocol Bindings to update the Property on the remote Thing and return the result. Returns a Promise
that resolves on success or rejects with an Error.
+
getProperty()
method
+ Takes the Property name as the name argument, then requests from the underlying platform and the Protocol Bindings to retrieve the Property on the remote Thing and return the result. Returns a Promise
that resolves with the Property value or rejects with an Error.
+
addListener()
method+ Adds the listener provided in the argument listener to the Event name provided in the argument eventName. +
+removeListener()
method+ Removes a listener from the Event identified by the provided eventName and listener argument. +
+removeAllListeners()
method+ Removes all listeners for the Event provided by the eventName optional argument, or if that was not provided, then removes all listeners from all Events. +
+observe()
method+ Returns an Observable for the Property, Event or Action specified in the name argument, allowing subscribing and unsubscribing to notifications. The requestType specifies whether a Property, an Event or an Action is observed. +
+
+ The observe()
method could replace addListener()
and removeListener()
, though they could be kept for convenience.
+
ThingEventListener
callback+ A function called with an Event object when an event is emitted. +
++ Clients can subscribe to the Events defined in ExposedThing events. The event types are described in this section. +
+PropertyChangeEvent
interface[Constructor(PropertyChangeEventInit
init)]
+interface PropertyChangeEvent
: Event {
+ readonly attribute PropertyChangeEventInit
data
;
+};
+
+ The data
attribute represents the changed Property.
+
PropertyChangeEventInit
dictionarydictionary PropertyChangeEventInit
{
+ DOMString name
;
+ any value
;
+};
+ The name
> attribute represents the Property name.
The value
attribute represents the new value of the Property.
ActionInvocationEvent
interface[Constructor(ActionInvocationEventInit
init)]
+interface ActionInvocationEvent
: Event {
+ readonly attribute ActionInvocationEventInit
data
;
+};
+
+ The data
attribute represents the notification data from the Action invocation.
+
ActionInvocationEventInit
dictionarydictionary ActionInvocationEventInit
{
+ DOMString actionName
;
+ any returnValue
;
+};
+ + Action parameters could be also included, but it's debatable because privacy reasons. +
+
+ The actionName
attribute represents the name of the Action that has been invoked.
+
+ The returnValue
attribute represents the return value of the
+ Action.
+
ThingDescriptionChangeEvent
interface[Constructor(ThingDescriptionChangeEventInit
init)]
+interface ThingDescriptionChangeEvent
: Event {
+ readonly attribute ThingDescriptionChangeEventInit
data
;
+};
+
+ The data
attribute represents the changes that occurred to the Thing Description.
+
ThingDescriptionChangeEventInit
dictionarydictionary ThingDescriptionChangeEventInit
{
+ TDChangeType
type
;
+ TDChangeMethod
method
;
+ DOMString name
;
+ TDChangeData
data
;
+ ThingDescription
description
;
+};
+ type
attribute represents the change type, whether has
+ it been applied on properties, Actions or Events.
+ method
attribute tells what operation has been applied,
+ addition, removal or change.
+ name
attribute represents the name of the Property, Action or event that has changed.
+ description
attribute is defined for the
+ addition and change methods, and represents the new description.
+ data
attribute provides the initialization data for
+ the added or changed elements.
+ TDChangeMethod
enumerationenum TDChangeMethod
{
+ "add",
+ "remove",
+ "change"
+};
+ TDChangeType
enumerationenum+TDChangeType
{ + "property", + "action", + "event" +}; + +typedef (ThingPropertyInit
orThingActionInit
orThingEventInit
)TDChangeData
;
property
value tells the operation was applied on a Property definition.action
value tells the operation was applied on a action definition.event
value tells the operation was applied on an event definition.TDChangeData
type
+ Represents the new description of the changed element. Depending on the change type, it can be either a ThingPropertyInit
, ThingActionInit
, or ThingEventInit
.
+
+ Below a
interface example is given.
+ ConsumedThing
+
wot.consume("http://mmyservice.org/mySensor").then( thing => {
+ console.log("Thing " + thing.name + " has been consumed.");
+ console.log("{ " + JSON.serialize(thing) + " }");
+ thing.addListener("onchange", function(event) {
+ if (event instanceof PropertyChangeEvent) {
+ console.log("Property " + event.name + " value has changed to " + event.value);
+ }
+ }).invokeAction("startMeasurement", ["Celsius"]);
+ },
+).catch(error => {
+ console.log("Discovery finished because an error: " + error.message);
+});
+ ExposedThing
interface
+ The ExposedThing
interface is the server API that allows defining request handlers, properties, Actions,
+ and Events to a Thing.
+
typedef USVString+ThingDescription
; + +callbackRequestHandler
= any (Request
request); + +interfaceExposedThing
{ + // define Thing Description modifiers +ExposedThing
addProperty(ThingPropertyInit
property); +ExposedThing
removeProperty(DOMString name); +ExposedThing
addAction(ThingActionInit
action); +ExposedThing
removeAction(DOMString name); +ExposedThing
addEvent(ThingEventInit
event); +ExposedThing
removeEvent(DOMString name); + // define request handlers +ExposedThing
onRetrieveProperty(RequestHandler
handler); +ExposedThing
onUpdateProperty(RequestHandler
handler); +ExposedThing
onInvokeAction(RequestHandler
handler); +ExposedThing
onObserve(RequestHandler
handler); + // define how to expose and run the Thing + Promise<void> register(optional USVString directory); + Promise<void> unregister(optional USVString directory); + Promise<void> start(); + Promise<void> stop(); + Promise<void> emitEvent(DOMString eventName, any payload); +}; + +ExposedThing
implementsConsumedThing
;
ThingDescription
type+ WoT provides a unified representation for data exchange between Things, standardized in the Wot Things Description specification. +
++ In this version of the API, Thing Descriptions are represented as opaque strings, denoting a serialized form, for instance JSON or JSON-LD. See Issue 38 and Issue 45. Parsing and composing Thing Descriptions is left for external libraries until + standardized here. +
+Request
interfaceinterface Request
{
+ readonly attribute RequestType
type
;
+ readonly attribute USVString from
;
+ readonly attribute DOMString name
;
+ readonly attribute Dictionary options
;
+ readonly attribute any data
;
+ Promise respond(any response);
+ void respondWithError(Error error);
+};
+
+ Represents an incoming request the ExposedThing
is supposed to handle, for instance retrieving and updating properties, invoking Actions and observing Events (WoT interactions).
+
type
attribute represents the type of the request as defined in RequestType
.
+ from
attribute represents the address of the client device issuing the request. The type of the address (URL,
+ UUID or other) is defined by the Thing Description.
+ name
attribute represents the name of the Property to be retrieved or updated, or the name of the invoked Action, or the event name to be observed.
+ options
attribute represents the options relevant to the request (e.g. the format or measurement units
+ for the returned value) as key-value pairs. The exact format is specified by the Thing Description.
+ data
attribute represents the value of the Property,
+ or the input data (arguments) of an Action. It is not used for retrieve requests and event requests, only for Property update and Action invocation requests.
+ RequestType
enumerationenum RequestType
{
+ "property",
+ "action",
+ "event",
+ "td"
+};
+ property
" represents requests to retrieve or update a Property.action
" represents requests to invoke an Action.event
" represents requests to emit an event.td
" represents requests to change the Thing Description,
+ i.e. to add, remove or modify properties, Actions or Events.
+
+ This functionality is here for the sake of completeness for future versions of the API. Currently there is no corresponding functionality at the ConsumedThing
level and it is not guaranteed that a Thing Description could be remotely changed by scripting.
+
respond()
method
+ Sends a positive response to the Request
based on the Protocol Bindings and includes the data specified by the data argument.
+
respondWithError()
method
+ Sends a negative response to the Request
based on the Protocol Bindings and includes the error specified by the error argument.
+
RequestHandler
callback
+ Callback function for handling interaction requests. Receives an argument request of type
and should return an object or value that is used by Protocol Bindings to reply to the request. The returned type is defined by the Thing Description.
+ Request
+
addProperty()
method+ Adds a Property defined by the argument and updates the Thing Description. +
+ThingPropertyInit
dictionarydictionary ThingPropertyInit
{
+ DOMString name
;
+ boolean configurable
= true;
+ boolean enumerable
= true;
+ boolean writable
= true;
+ sequence<SemanticType
> semanticTypes
;
+ ThingDescription
description
;
+ any value
;
+};
+ + Represents the Thing + Property description. +
+name
attribute represents the name of the Property.value
attribute represents the value of the Property.configurable
attribute defines whether the Property can be deleted from the object and whether its properties can be changed. The default value is false
.
+ enumerable
attribute defines whether the Property can be listed and iterated. The default value is true
.
+ writable
attribute defines whether the Property can be updated. The default value is true
.
+ semanticTypes
attribute represents a list of semantic type annotations
+ (e.g. labels, classifications etc) relevant to the Property, represented as SemanticType
dictionaries.
+ description
attribute represents the Property description to be added to the Thing Description.
+ SemanticType
dictionarydictionary SemanticType
{
+ DOMString name
;
+ USVString context
;
+};
+ + Represents a semantic type annotation, containing a name and a context. +
+name
attribute represents the name of the semantic type in the given context.context
attribute represents an URL link to the context of the semantic classification.+ Semantic type examples to be added. +
+removeProperty()
method
+ Removes the Property specified by the name
argument, updates the Thing Description and returns the object.
+
addAction()
method
+ Adds an Action to the Thing object as defined by the action
argument of type ThingActionInit
and updates the Thing Description.
+
ThingActionInit
dictionarydictionary ThingActionInit
{
+ DOMString name
;
+ ThingDescription
inputDataDescription
;
+ ThingDescription
outputDataDescription
;
+ sequence<SemanticType
> semanticTypes
;
+ Function action
;
+};
+
+ The ThingActionInit
dictionary describes the arguments and the return value.
+
name
attribute provides the Action name.action
attribute provides a function that defines the Action.inputDataDescription
attribute provides the description of the
+ input arguments.outputDataDescription
attribute provides the description of
+ the returned data.semanticTypes
attribute provides a list of semantic type annotations (e.g.
+ labels, classifications etc) relevant to the Action, represented as SemanticType
dictionaries.
+ removeAction()
method
+ Removes the Action specified by the name
argument, updates the Thing Description and returns the object.
+
addEvent()
method
+ Adds an event to the Thing object as defined by the event
argument of type ThingEventInit
and updates the Thing Description.
+
ThingEventInit
dictionarydictionary ThingEventInit
{
+ DOMString name
;
+ sequence<SemanticType
> semanticTypes
;
+ ThingDescription
dataDescription
;
+};
+ name
attribute represents the event name.semanticTypes
attribute represent a list of semantic type annotations attached
+ to the event.dataDescription
attribute represents the description of the data that is
+ attached to the event.removeEvent()
method
+ Removes the event specified by the name
argument, updates the Thing Description and returns the object.
+
onRetrieveProperty()
method
+ Registers the handler function for Property retrieve requests received for the Thing, as defined by
+ the handler
property of type
. The handler will receive an argument request of type RequestHandler
+
where at least request.name is defined and represents the name of the Property to be retrieved.
+ Request
+
onUpdateProperty()
method
+ Defines the handler function for Property update requests received for the Thing, as defined by the
+ handler
property of type
. The handler will receive an argument request of type RequestHandler
+
where request.name defines the name of the Property to be retrieved and request.data defines the new value of the Property.
+ Request
+
onInvokeAction()
method
+ Defines the handler function for Action invocation requests received for the Thing, as defined by the
+ handler
property of type
. The handler will receive an argument request of type RequestHandler
+
where request.name defines the name of the Action to be invoked and request.data defines the input arguments for the Action as defined by the Thing Description.
+ Request
+
onObserve()
method
+ Defines the handler function for observe requests received for the Thing, as defined by the handler
property of type
. The handler will receive an argument request of type RequestHandler
+
where
+ Request
+
RequestType
and defines whether a Property change or Action invocation or event emitting is observed, or the changes to the Thing Description are observed.
+ true
if subscription is turned or kept being turned on, and it is false
when subscription is turned off.
+ register()
method
+ Generates the Thing Description given the properties, Actions and Event defined for this object. If a directory
argument is given, make a request to register the Thing Description with
+ the given WoT repository by invoking its register
+ Action.
+
unregister()
method
+ If a directory
argument is given, make a request to unregister the Thing Description with the given WoT repository by invoking its unregister
+ Action. Then, and in the case no arguments were provided to this function, stop the Thing and remove the
+ Thing Description.
+
start()
method+ Start serving external requests for the Thing. +
+stop()
method+ Stop serving external requests for the Thing. +
+emitEvent()
method
+ Emits an the event initialized with the event name specified by the eventName
argument and data specified by the payload
argument.
+
+ The following default events SHOULD be supported by ExposedThing
implementations:
+
PropertyChangeEvent
ActionInvocationEvent
ThingDescriptionChangeEvent
.+ In addition, user defined events are specified by the Thing Description. +
+
+ Below some
interface examples are given.
+ ExposedThing
+
WoT.createExposedThing(thingDescription)
+ .then(function(thing) {
+ // manually add properties, actions, and events
+ thing.addProperty({
+ name: "temperature",
+ value: "0",
+ writable: false
+ // use default values for the rest
+ }).addEvent({
+ name: "onchange",
+ outputDataDescription: {
+ type: "float32"
+ }
+ }).addAction({
+ name: "reset",
+ action: () => { this.temperature = 0; }
+ })
+ // add server functionality
+ .onRetrieveProperty( request => {
+ console.log("Handling read request");
+ return this.temperature;
+ }).onObserve( request => {
+ console.log("Handling observe request");
+ // add listener identified by request.from
+ }).onInvokeAction( request => {
+ console.log("Handling action request");
+ }).start();
+ });
+ let thingDescription = '{ + "name": "mySensor", + "url": "http://myservice.org/mySensor/description" +}'; +WoT.createExposedThing(thingDescription) + .then(function(thing) { + // properties, actions and events are added based on the TD + console.log("created " + thing.name }); + // now add the requests handlers + thing.onRetrieveProperty(function(request) { + console.log("Sending property '" + request.property + "' to " + request.from); + }).onUpdateProperty(function(request) { + console.log("Updating property '" + request.property + "' by " + request.from); + }).onObserve(function(request) { + console.log("Adding listener " + request.from); + console.log("Observing " + request.type + " " + request.name + + (request.subscribe? " recursively" : "")); + }).start().then(function() { + console.log("Thing started serving requests"); + }); + })+
let thingDescription = '{ + "name": "mySensor", + "description": { + "@context": [ + "http://w3c.github.io/wot/w3c-wot-td-context.jsonld", + "http://w3c.github.io/wot/w3c-wot-common-context.jsonld", + ], + "@type": [ "Thing" ], + "interaction": [ + // ... + ] + // ... + }' +}; +WoT.createExposedThing(thingDescription) + .then(function(thing) { + // properties, actions and events are added based on the TD + // ... + });+
+ Please see the WoT Security and Privacy repository for work in progress regarding threat models, assets, risks, recommended mitigations, and best practices for security and privacy for + systems using the Web of Things. Once complete, security and privacy considerations relevant to the Scripting API will be summarized in this section. +
++ The generic WoT terminology is defined in [WOT-ARCHITECTURE]: Thing, Thing Description (in short TD), Web of Things (in short WoT), WoT Interface, Protocol Bindings, WoT Runtime, Consuming a Thing Description, Thing Directory, Property, Action, Event etc. +
++ In this version of the specification, a WoT Runtime is assumed to run scripts that uses this API to define one or more Things + that share a common event loop. Script deployment methods are out of scope of this version. In future versions, running multiple scripts (as modules) may be possible, and script deployment MAY be implemented + using a manager Thing whose Actions permit script lifecycle management operations. +
+
+ JSON-LD is defined in [JSON-LD] as a JSON document that is augmented with support for Linked Data by providing a @context
property
+ with a defining URI .
+
+ The terms URL and + + URL path are defined in [URL]. +
++ The following terms are defined in [HTML5] and are used in the context of browser implementations: + + browsing context, + + + top-level browsing context, + + + global object, + + + incumbent settings object, + + + Document, + + + document base URL, + + + Window, + + + WindowProxy, + + + origin, + + + ASCII serialized origin, executing algorithms + in parallel, + + + queue a task, + + + task source, + + + iframe, + + + valid MIME type. +
+
+ A browsing context refers to the environment in which
+ Document objects are presented to the user. A given
+ browsing context has a single WindowProxy
object, but it can have many Document
objects, with their associated
+ Window
objects. The script execution context associated with the browsing context identifies the entity which invokes this API, which can be a web app, a web page, or an
+ iframe.
+
+ The term + + secure context is defined in [WEBAPPSEC]. +
++ + Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError + , + + script execution context, + + Promise, + + JSON, + + JSON.stringify and + + JSON.parse are defined in [ECMASCRIPT]. +
++ DOMString, + USVString, + ArrayBuffer, + BufferSource and + any are defined in [WEBIDL]. +
++ The term event and the Event object are defined in DOM and Node.js. +
++ This specification uses the convention that an event listener will receive an Event object. This should work both in a browser environment and in a Node.js + like environment. +
++ Observables are proposed to be included in ECMAScript. +
++ The algorithms + utf-8 encode, and + + utf-8 decode are defined in [ENCODING]. +
++ IANA media types (formerly known as MIME types) are defined in + RFC2046. +
++ As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative. +
+The key words MAY, MUST, and SHOULD are to be interpreted as described in [RFC2119]. +
++ This document defines conformance criteria that apply to a single product: the UA (user agent) that implements the interfaces it contains. +
++ This specification can be used for implementing the WoT Scripting API in multiple programming languages. The interface definitions are specified in [WEBIDL]. +
++ The user agent (UA) may be implemented in the browser, or in a separate runtime environment, such as Node.js or small embedded runtimes. +
++ Implementations that use ECMAScript executed in a browser to implement the APIs defined in this document MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification + [WEBIDL]. +
++ Implementations that use TypeScript or ECMAScript in a runtime to implement the APIs defined in this document MUST implement them in a manner consistent with the TypeScript Bindings defined in the TypeScript + specification [TYPESCRIPT]. +
++ This document serves a general description of the WoT Scripting API. Language and runtime specific issues are discussed in separate extensions of this document. +
++ The following is a list of major changes to the document. For a complete list of changes, see the github change log. You can also view the recently closed bugs. +
++ The following problems are being discussed and need most attention: +
++ Special thanks to former editor Johannes Hund for developing this specification. Also, the editors would like to thank Dave Raggett, Matthias Kovatsch, Michael Koster and Michael McCool for their comments and guidance. +
+
+
+
+
+
+
++ +Copyright + +© +2017 + + +W3C + + + +® + +( + + +MIT + +, + + +ERCIM + +, + +Keio +, + +Beihang + +). + +W3C + + +liability +, + +trademark + +and + +permissive +document +license + +rules +apply. +
++The + +Web +of +Things + +(WoT) +provides +layered +interoperability +between + +Things + +by +using +the + +WoT +Interface + +s. +
++This +specification +describes +a +programming +interface +representing +the + +WoT +Interface + +that +allows +scripts +run +on +a + +Thing + +to +discover +and +consume +(retrieve) +other + +Thing + +s +and +to +expose + +Things + +characterized +by +properties, + +Actions + +and + +Events +. +
++Scripting +is +an +optional +"convenience" +building +block +in +WoT +and +it +is +typically +used +in +gateways +that +are +able +to +run +a + +WoT +Runtime + +and + +script +management +, +providing +a +convenient +way +to +extend +WoT +support +to +new +types +of +endpoints +and +implement +WoT +applications +like + +Thing +Directory +. +
++ +This +section +describes +the +status +of +this +document +at +the +time +of +its +publication. +Other +documents +may +supersede +this +document. +A +list +of +current + +W3C + +publications +and +the +latest +revision +of +this +technical +report +can +be +found +in +the + + +W3C + +technical +reports +index + +at +https://www.w3.org/TR/. + +
++Implementers +need +to +be +aware +that +this +specification +is +considered +unstable. +Vendors +interested +in +implementing +this +specification +before +it +eventually +reaches +the +Candidate +Recommendation +phase +should +subscribe +to +the + +repository + +and +take +part +in +the +discussions. +
++Please +contribute +to +this +draft +using +the + +GitHub +Issue + +feature +of +the + +WoT +Scripting +API + +repository. +For +feedback +on +security +and +privacy +considerations, +please +use +the + +WoT +Security +and +Privacy + +Issues. +
+
+This
+document
+was
+published
+by
+the
+
+Web
+of
+Things
+Working
+Group
+
+as
+an
+Editor's
+
+a
+First
+Public
+Working
+
+Draft.
+This
+document
+is
+intended
+to
+become
+a
+
+W3C
+
+Recommendation.
+
+Comments +regarding +this +document +are +welcome. +Please +send +them +to + +public-wot-wg@w3.org + +( + +subscribe +, + +archives + +). +
+
+Publication
+as
+an
+Editor's
+
+a
+First
+Public
+Working
+
+Draft
+does
+not
+imply
+endorsement
+by
+the
+
+W3C
+
+Membership.
+This
+is
+a
+draft
+document
+and
+may
+be
+updated,
+replaced
+or
+obsoleted
+by
+other
+documents
+at
+any
+time.
+It
+is
+inappropriate
+to
+cite
+this
+document
+as
+other
+than
+work
+in
+progress.
+
+This +document +was +produced +by +a +group +operating +under +the + +5 +February +2004 + +W3C + +Patent +Policy +. + +W3C + +maintains +a + +public +list +of +any +patent +disclosures + +made +in +connection +with +the +deliverables +of +the +group; +that +page +also +includes +instructions +for +disclosing +a +patent. +An +individual +who +has +actual +knowledge +of +a +patent +which +the +individual +believes +contains + +Essential +Claim(s) + +must +disclose +the +information +in +accordance +with + +section +6 +of +the + +W3C + +Patent +Policy +. +
++This +document +is +governed +by +the + +1 +March +2017 + +W3C + +Process +Document +. +
++The +overall +WoT +concepts +are +described +in +the + +WoT +Architecture + +document. +The +Web +of +Things +is +made +of +entities +( + +Thing + +s) +that +can +describe +their +capabilities +in +a +machine-interpretable +format, +the + +Thing +Description + +(TD) +and +expose +these +capabilities +through +the + +WoT +Interface +. +Support +for +scripting +is +optional +for +WoT +devices. +
++By + +consuming +a +TD +, +a +client + +Thing + +creates +a +runtime +resource +model +that +allows +accessing +the +properties, + +Actions + +and + +Events + +exposed +by +the +server + +Thing +. +
++Exposing +a + +Thing + +requires +defining +a + +Thing +Description + +and +instantiating +a +software +stack +needed +to +serve +requests +for +accessing +the +exposed +properties, + +Actions + +and + +Events +. +This +specification +describes +how +to +expose +and +consume + +Thing + +s +by +a +script. +
++Typically +scripts +are +meant +to +be +used +on +devices +able +to +provide +resources +(with +a + +WoT +interface + +) +for +managing +(installing, +updating, +running) +scripts, +such +as +bridges +or +gateways +that +expose +and +control +simpler +devices +as +WoT + +Thing + +s. +
++For +an +introduction +on +how +scripts +could +be +used +in + +Web +of +Things +, +check +the + +Primer + +document. +For +some +background +on +API +design +decisions +check +the + +Rationale + +document. +
++ +This +section +is +non-normative. + +
++The +following +scripting +use +cases +are +covered +in +this +specification: +
++The +following +use +cases +are +being +considered +for +next +versions: +
+
+WoT
+
+
+object
++The +WoT +object +is +the +main +API +entry +point +and +it +is +exposed +by +an +implementation +of +the + +WoT +Runtime +. +The + +WoT +object + +has +no +internal +state +and +provides +methods +for +discovering, +consuming +and +exposing +a + +Thing +. +
+
+Browser
+implementations
+
+SHOULD
+
+use
+a
+namespace
+object
+such
+as
+
+wot
+
,
+and
+
+Node.js
+
+-like
+runtimes
+
+MAY
+
+provide
+the
+API
+object
+through
+the
+
+
+require()
+
+
+or
+
+
+import
+
+
+mechanism.
+
interface WoT
{
+ Observable<ConsumedThing
> discover(optional ThingFilter
filter);
+ Promise<ConsumedThing
> consume(USVString url);
+ Promise<ExposedThing
> expose(ThingInit
init);
+};
+
+
++The +algorithms +for +the +WoT +methods +will +be +specified +later. +
+
+discover()
+
+
+method
+
+Starts
+the
+discovery
+process
+that
+will
+provide
+
+
+
+objects
+that
+match
+the
+optional
+argument
+
+ConsumedThing
+
+
+
+
+
.
+When
+the
+argument
+is
+not
+provided,
+starts
+the
+widest
+discovery
+the
+
+Thing
+Description
+
+and
+
+Protocol
+Bindings
+
+allow.
+Returns
+an
+
+
+ThingFilter
+
+
+
+Observable
+
+
+object
+that
+can
+be
+subscribed
+and
+unsubscribed
+to.
+
+ThingFilter
+
+
+dictionary
+
+The
+
+
+ThingFilter
+
+
+dictionary
+that
+represents
+the
+constraints
+for
+discovering
+
+Thing
+
+s
+as
+key-value
+pairs.
+
dictionary ThingFilter
{
+ (DiscoveryType or DOMString) method
= "any";
+ USVString url
;
+ Dictionary description
;
+};
+
+
+
+The
+
+
+method
+
+
+property
+represents
+the
+discovery
+type
+that
+should
+be
+used
+in
+the
+discovery
+process.
+The
+possible
+values
+are
+defined
+by
+the
+
+
+
+enumeration
+that
+can
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+
+DiscoveryMethod
+
+
+
+The
+
+
+url
+
+
+property
+represents
+additional
+information
+for
+the
+discovery
+method,
+such
+as
+the
+URL
+of
+the
+
+Thing
+Directory
+
+server
+to
+be
+used.
+
+The
+
+
+description
+
+
+property
+represents
+additional
+information
+for
+the
+discovery
+method
+in
+the
+form
+of
+a
+set
+of
+key-value
+pairs,
+as
+defined
+in
+the
+
+Thing
+Description
+.
+
+The
+
+
+DiscoveryMethod
+
+
+enumeration
+can
+be
+extended
+by
+the
+
+Thing
+Description
+
+with
+values
+that
+are
+not
+specified
+here.
+This
+extensibility
+of
+
+
+DiscoveryMethod
+
+
+by
+proprietary
+or
+private
+methods
+is
+a
+working
+assumption
+until
+consensus
+is
+formed
+and
+may
+be
+removed
+later.
+
+The
+
+
+ThingFilter
+
+
+dictionary
+may
+be
+extended
+later
+with
+further
+attributes.
+
+DiscoveryMethod
+
+
+enumeration
+enum DiscoveryMethod
{
+ "any",
+ "local",
+ "nearby",
+ "directory",
+ "broadcast",
+ "other"
+};
+
+
+
+The
+
+
+DiscoveryMethod
+
+
+enumeration
+represents
+the
+discovery
+type
+to
+be
+used:
+
+any
+
+
+"
+does
+not
+provide
+any
+restriction
+
+local
+
+
+"
+for
+discovering
+
+Thing
+
+s
+defined
+in
+the
+same
+device
+
+nearby
+
+
+"
+for
+discovering
+
+Thing
+
+s
+nearby
+the
+device,
+e.g.
+by
+Bluetooth
+or
+NFC
+
+directory
+
+
+"
+for
+discovery
+based
+on
+a
+service
+provided
+by
+a
+directory
+or
+repository
+of
+
+Thing
+
+s
+
+broadcast
+
+
+"
+for
+an
+open
+ended
+discovery
+based
+on
+sending
+a
+request
+to
+a
+broadcast
+address
+
+other
+
+
+"
+for
+a
+proprietary
+method
+defined
+by
+the
+solution.
+
+consume()
+
+
+method
+
+Accepts
+an
+
+url
+
+argument
+and
+returns
+a
+
+
+Promise
+
+
+of
+a
+
+
+ConsumedThing
+
+.
+
+expose()
+
+
+method
+
+Returns
+a
+
+
+Promise
+
+
+of
+a
+locally
+created
+
+
+ExposedThing
+
+
+based
+on
+the
+provided
+initialization
+parameters.
+
+The
+reason
+
+
+ExposedThing
+
+
+s
+are
+created
+by
+a
+factory
+method
+instead
+of
+a
+constructor
+is
+that
+an
+
+
+ExposedThing
+
+
+may
+be
+created
+in
+the
+local
+
+WoT
+Runtime
+
+or
+in
+a
+remote
+runtime.
+Even
+though
+currently
+only
+local
+creation
+is
+supported,
+the
+method
+is
+designed
+with
+this
+possible
+future
+compatibility
+in
+mind.
+
+ThingInit
+
+
+dictionary
+
+The
+
+
+ThingInit
+
+
+dictionary
+contains
+properties
+to
+initialize
+a
+
+Thing
+:
+
+name
+
+
+attribute
+represents
+the
+user
+given
+name
+of
+the
+
+Thing
+.
+
+url
+
+
+attribute
+represents
+the
+address
+of
+the
+
+Thing
+.
+
+description
+
+
+attribute
+represents
+the
+
+Thing
+Description
+
+of
+the
+
+Thing
+.
+let discoveryType = { method: "directory", url: "http://directory.wotservice.org" };
+let subscription = wot.discover(discoveryType).subscribe(
+ thing => { console.log("Found Thing " + thing.url); },
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout(
+ () => { subscription.unsubscribe(); console.log("Discovery timeout"); },
+
+5000
+
+);
+
+
+Note
+that
+canceling
+a
+discovery
+(through
+unsubscribe)
+may
+not
+be
+successful
+in
+all
+cases,
+for
+instance
+when
+discovery
+is
+based
+on
+open
+ended
+broadcast
+requests.
+However,
+once
+
+unsubscribe()
+
+has
+been
+called,
+implementations
+
+MUST
+
+suppress
+further
+event
+handling
+(
+i.e.
+further
+discoveries
+and
+errors)
+on
+the
+Observable.
+Also,
+a
+discovery
+error
+may
+not
+mean
+the
+end
+of
+the
+discovery
+process.
+However,
+in
+order
+to
+respect
+Observable
+semantics
+(error
+always
+terminates
+processing),
+implementations
+
+MUST
+
+close
+or
+suppress
+further
+event
+handling
+on
+the
+Observable.
+
let subscription = wot.discover({ method: "local" }).subscribe(
+ thing => { console.log("Found local Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+let subscription = wot.discover({ method: "nearby", description: {protocol: "BLE4.2"} }).subscribe(
+ thing => { console.log("Found nearby Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+let subscription = wot.discover({ method: "other", description: { solution: "XYZ123", key: "..."} }).subscribe(
+ thing => { console.log("Found Thing " + thing.url); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+
+ConsumedThing
+
+
+interface
+
+The
+
+
+ConsumedThing
+
+
+interface
+is
+a
+client
+API
+for
+sending
+requests
+to
+servers
+in
+order
+to
+retrieve
+or
+update
+properties,
+invoke
+
+Actions
+,
+and
+observe
+properties,
+
+Actions
+
+and
+
+Events
+.
+
interface+ConsumedThing
{ + readonly attribute DOMStringname
; + readonly attribute USVStringurl
; + readonly attributeThingDescription
description
; + Promise<any> invokeAction(DOMString name, any parameters); + Promise<void> setProperty(DOMString name, any value); + Promise<any> getProperty(DOMString name); +ConsumedThing
addListener(DOMString eventName,ThingEventListener
listener); +ConsumedThing
removeListener(DOMString eventName, +ThingEventListener
listener); +ConsumedThing
removeAllListeners(optional DOMString eventName); + Observable observe(DOMString name,RequestType
requestType); +}; + +callback + + ++ThingEventListener +
+ + += + +void + +( + + + +Event + + + +event + + +); + +
+Represents +a +local +proxy +object +of +the +remote + +Thing +. +
+
+name
+
+
+read-only
+attribute
+represents
+the
+name
+of
+the
+
+Thing
+.
+
+url
+
+
+read-only
+attribute
+represents
+the
+URL
+of
+the
+
+Thing
+.
+
+description
+
+
+attribute
+read-only
+attribute
+represents
+the
+description
+of
+the
+
+Thing
+.
++Parsing +and +exposing + +Thing +Description + +s +is +discussed +in + +Issue +38 +. +
+
+invokeAction()
+
+
+method
+
+Takes
+the
+
+Action
+
+name
+from
+the
+
+name
+
+argument
+and
+the
+list
+of
+parameters,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+invoke
+the
+
+Action
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+the
+return
+value
+or
+rejects
+with
+an
+
+Error
+.
+
+setProperty()
+
+
+method
+
+Takes
+the
+
+Property
+
+name
+as
+the
+
+name
+
+argument
+and
+the
+new
+value
+as
+the
+
+value
+
+argument,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+update
+the
+
+Property
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+on
+success
+or
+rejects
+with
+an
+
+Error
+.
+
+getProperty()
+
+
+method
+
+Takes
+the
+
+Property
+
+name
+as
+the
+
+name
+
+argument,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+retrieve
+the
+
+Property
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+the
+
+Property
+
+value
+or
+rejects
+with
+an
+
+Error
+.
+
+addListener()
+
+
+method
++Adds +the +listener +provided +in +the +argument + +listener + +to +the + +Event + +name +provided +in +the +argument + +eventName +. +
+
+removeListener()
+
+
+method
++Removes +a +listener +from +the + +Event + +identified +by +the +provided + +eventName + +and + +listener + +argument. +
+
+removeAllListeners()
+
+
+method
++Removes +all +listeners +for +the + +Event + +provided +by +the + +eventName + +optional +argument, +or +if +that +was +not +provided, +then +removes +all +listeners +from +all + +Events +. +
+
+observe()
+
+
+method
++Returns +an + +Observable + +for +the + +Property +, + +Event + +or + +Action + +specified +in +the + +name + +argument, +allowing +subscribing +and +unsubscribing +to +notifications. +The + +requestType + +specifies +whether +a + +Property +, +an + +Event + +or +an + +Action + +is +observed. +
+
+The
+
+observe()
+
+method
+could
+replace
+
+addListener()
+
+and
+
+removeListener()
+
,
+though
+they
+could
+be
+kept
+for
+convenience.
+
+ThingEventListener
+
+
+callback
++A +function +called +with +an + +Event + +object +when +an +event +is +emitted. +
++Clients +can +subscribe +to +the + +Events + +defined +in + +ExposedThing +events +. +The +event +types +are +described +in +this +section. +
+
+PropertyChangeEvent
+
+
+interface
+[Constructor(PropertyChangeEventInit
init)]
+interface PropertyChangeEvent
: Event {
+ readonly attribute PropertyChangeEventInit
data
;
+};
+
+
+
+The
+
+
+data
+
+
+attribute
+represents
+the
+changed
+
+Property
+.
+
+PropertyChangeEventInit
+
+
+dictionary
+dictionary PropertyChangeEventInit
{
+ DOMString name
;
+ any value
;
+};
+
+
+
+The
+
+
+name
+
+
+>
+attribute
+represents
+the
+
+Property
+
+name.
+
+The
+
+
+value
+
+
+attribute
+represents
+the
+new
+value
+of
+the
+
+Property
+.
+
+ActionInvocationEvent
+
+
+interface
+[Constructor(ActionInvocationEventInit
init)]
+interface ActionInvocationEvent
: Event {
+ readonly attribute ActionInvocationEventInit
data
;
+};
+
+
+
+The
+
+
+data
+
+
+attribute
+represents
+the
+notification
+data
+from
+the
+
+Action
+
+invocation.
+
+ActionInvocationEventInit
+
+
+dictionary
+dictionary ActionInvocationEventInit
{
+ DOMString actionName
;
+ any returnValue
;
+};
+
+
++Action +parameters +could +be +also +included, +but +it's +debatable +because +privacy +reasons. +
+
+The
+
+
+actionName
+
+
+attribute
+represents
+the
+name
+of
+the
+
+Action
+
+that
+has
+been
+invoked.
+
+The
+
+
+returnValue
+
+
+attribute
+represents
+the
+return
+value
+of
+the
+
+Action
+.
+
+ThingDescriptionChangeEvent
+
+
+interface
+[Constructor(ThingDescriptionChangeEventInit
init)]
+interface ThingDescriptionChangeEvent
: Event {
+ readonly attribute ThingDescriptionChangeEventInit
data
;
+};
+
+
+
+The
+
+
+data
+
+
+attribute
+represents
+the
+changes
+that
+occurred
+to
+the
+
+Thing
+Description
+.
+
+ThingDescriptionChangeEventInit
+
+
+dictionary
+dictionary ThingDescriptionChangeEventInit
{
+ TDChangeType
type
;
+ TDChangeMethod
method
;
+ DOMString name
;
+ TDChangeData
data
;
+ ThingDescription
description
;
+};
+
+
+
+type
+
+
+attribute
+represents
+the
+change
+type,
+whether
+has
+it
+been
+applied
+on
+properties,
+
+Actions
+
+or
+
+Events
+.
+
+method
+
+
+attribute
+tells
+what
+operation
+has
+been
+applied,
+addition,
+removal
+or
+change.
+
+name
+
+
+attribute
+represents
+the
+name
+of
+the
+
+Property
+,
+
+Action
+
+or
+event
+that
+has
+changed.
+
+description
+
+
+attribute
+is
+defined
+for
+the
+addition
+and
+change
+methods,
+and
+represents
+the
+new
+description.
+
+data
+
+
+attribute
+provides
+the
+initialization
+data
+for
+the
+added
+or
+changed
+elements.
+
+TDChangeMethod
+
+
+enumeration
+enum TDChangeMethod
{
+ "add",
+ "remove",
+ "change"
+};
+
+
+
+add
+
+
+value
+denotes
+addition
+of
+a
+
+Property
+,
+
+Action
+
+or
+event.
+
+remove
+
+
+value
+denotes
+removal
+of
+a
+
+Property
+,
+
+Action
+
+or
+event.
+
+change
+
+
+value
+denotes
+a
+change
+applied
+on
+a
+
+Property
+,
+
+Action
+
+or
+event.
+
+TDChangeType
+
+
+enumeration
+enum+TDChangeType
{ + "property", + "action", + "event" +}; + +typedef + +( + ++ThingPropertyInit +
+ +or + ++ThingActionInit +
+ +or + ++ThingEventInit +
+ +) + + + ++TDChangeData +
+ + +; + +
+property
+
+
+value
+tells
+the
+operation
+was
+applied
+on
+a
+
+Property
+
+definition.
+
+action
+
+
+value
+tells
+the
+operation
+was
+applied
+on
+a
+action
+definition.
+
+event
+
+
+value
+tells
+the
+operation
+was
+applied
+on
+an
+event
+definition.
+
+TDChangeData
+
+
+type
+
+Represents
+the
+new
+description
+of
+the
+changed
+element.
+Depending
+on
+the
+change
+type,
+it
+can
+be
+either
+a
+
+
+ThingPropertyInit
+
+,
+
+
+ThingActionInit
+
+,
+or
+
+
+ThingEventInit
+
+.
+
+Below
+a
+
+
+
+interface
+example
+is
+given.
+
+ConsumedThing
+
+
+
wot.consume("http://mmyservice.org/mySensor").then( thing => {
+ console.log("Thing " + thing.name + " has been consumed.");
+ console.log("{ " + JSON.serialize(thing) + " }");
+ thing.addListener("onchange", function(event) {
+ if (event instanceof PropertyChangeEvent) {
+ console.log("Property " + event.name + " value has changed to " + event.value);
+ }
+ }).invokeAction("startMeasurement", ["Celsius"]);
+ },
+).catch(error => {
+ console.log("Discovery finished because an error: " + error.message);
+});
+
+
+ExposedThing
+
+
+interface
+
+The
+
+
+ExposedThing
+
+
+interface
+is
+the
+server
+API
+that
+allows
+defining
+request
+handlers,
+properties,
+
+Actions
+,
+and
+
+Events
+
+to
+a
+
+Thing
+.
+
typedef USVString+ThingDescription
; +callbackRequestHandler
= any (Request
request); +interfaceExposedThing
{ + // define Thing Description modifiers +ExposedThing
addProperty(ThingPropertyInit
property); +ExposedThing
removeProperty(DOMString name); +ExposedThing
addAction(ThingActionInit
action); +ExposedThing
removeAction(DOMString name); +ExposedThing
addEvent(ThingEventInit
event); +ExposedThing
removeEvent(DOMString name); + // define request handlers +ExposedThing
onRetrieveProperty(RequestHandler
handler); +ExposedThing
onUpdateProperty(RequestHandler
handler); +ExposedThing
onInvokeAction(RequestHandler
handler); +ExposedThing
onObserve(RequestHandler
handler); + // define how to expose and run the Thing + Promise<void> register(optional USVString directory); + Promise<void> unregister(optional USVString directory); + Promise<void> start(); + Promise<void> stop(); + Promise<void> emitEvent(DOMString eventName, any payload); +}; + + ++ExposedThing +
+ +implements + ++ConsumedThing +
+ +; + +
+ThingDescription
+
+
+type
++WoT +provides +a +unified +representation +for +data +exchange +between + +Thing + +s, +standardized +in +the + +Wot +Things +Description + +specification. +
++In +this +version +of +the +API, + +Thing +Description + +s +are +represented +as +opaque +strings, +denoting +a +serialized +form, +for +instance +JSON +or +JSON-LD. +See + +Issue +38 + +and + +Issue +45 +. +Parsing +and +composing + +Thing +Description + +s +is +left +for +external +libraries +until +standardized +here. +
+
+Request
+
+
+interface
+interface Request
{
+ readonly attribute RequestType
type
;
+ readonly attribute USVString from
;
+ readonly attribute DOMString name
;
+ readonly attribute Dictionary options
;
+ readonly attribute any data
;
+ Promise respond(any response);
+ void respondWithError(Error error);
+};
+
+
+
+Represents
+an
+incoming
+request
+the
+
+
+ExposedThing
+
+
+is
+supposed
+to
+handle,
+for
+instance
+retrieving
+and
+updating
+properties,
+invoking
+
+Actions
+
+and
+observing
+
+Events
+
+(WoT
+interactions).
+
+type
+
+
+attribute
+represents
+the
+type
+of
+the
+request
+as
+defined
+in
+
+
+RequestType
+
+.
+
+from
+
+
+attribute
+represents
+the
+address
+of
+the
+client
+device
+issuing
+the
+request.
+The
+type
+of
+the
+address
+(URL,
+UUID
+or
+other)
+is
+defined
+by
+the
+
+Thing
+Description
+.
+
+name
+
+
+attribute
+represents
+the
+name
+of
+the
+
+Property
+
+to
+be
+retrieved
+or
+updated,
+or
+the
+name
+of
+the
+invoked
+
+Action
+,
+or
+the
+event
+name
+to
+be
+observed.
+
+options
+
+
+attribute
+represents
+the
+options
+relevant
+to
+the
+request
+(e.g.
+the
+format
+or
+measurement
+units
+for
+the
+returned
+value)
+as
+key-value
+pairs.
+The
+exact
+format
+is
+specified
+by
+the
+
+Thing
+Description
+.
+
+data
+
+
+attribute
+represents
+the
+value
+of
+the
+
+Property
+,
+or
+the
+input
+data
+(arguments)
+of
+an
+
+Action
+.
+It
+is
+not
+used
+for
+retrieve
+requests
+and
+event
+requests,
+only
+for
+
+Property
+
+update
+and
+
+Action
+
+invocation
+requests.
+
+RequestType
+
+
+enumeration
+enum RequestType
{
+ "property",
+ "action",
+ "event",
+ "td"
+};
+
+
+
+property
+
+
+"
+represents
+requests
+to
+retrieve
+or
+update
+a
+
+Property
+.
+
+action
+
+
+"
+represents
+requests
+to
+invoke
+an
+
+Action
+.
+
+event
+
+
+"
+represents
+requests
+to
+emit
+an
+event.
+
+td
+
+
+"
+represents
+requests
+to
+change
+the
+
+Thing
+Description
+,
+i.e.
+to
+add,
+remove
+or
+modify
+properties,
+
+Actions
+
+or
+
+Events
+.
+
+This
+functionality
+is
+here
+for
+the
+sake
+of
+completeness
+for
+future
+versions
+of
+the
+API.
+Currently
+there
+is
+no
+corresponding
+functionality
+at
+the
+
+
+ConsumedThing
+
+
+level
+and
+it
+is
+not
+guaranteed
+that
+a
+Thing
+Description
+could
+be
+remotely
+changed
+by
+scripting.
+
+respond()
+
+
+method
+
+Sends
+a
+positive
+response
+to
+the
+
+
+Request
+
+
+based
+on
+the
+
+Protocol
+Bindings
+
+and
+includes
+the
+data
+specified
+by
+the
+
+data
+
+argument.
+
+respondWithError()
+
+
+method
+
+Sends
+a
+negative
+response
+to
+the
+
+
+Request
+
+
+based
+on
+the
+
+Protocol
+Bindings
+
+and
+includes
+the
+error
+specified
+by
+the
+
+error
+
+argument.
+
+RequestHandler
+
+
+callback
+
+Callback
+function
+for
+handling
+interaction
+requests.
+Receives
+an
+argument
+
+request
+
+of
+type
+
+
+
+and
+should
+return
+an
+object
+or
+value
+that
+is
+used
+by
+
+Protocol
+Bindings
+
+to
+reply
+to
+the
+request.
+The
+returned
+type
+is
+defined
+by
+the
+
+Thing
+Description
+.
+
+Request
+
+
+
+addProperty()
+
+
+method
++Adds +a + +Property + +defined +by +the +argument +and +updates +the + +Thing +Description +. +
+
+ThingPropertyInit
+
+
+dictionary
+dictionary ThingPropertyInit
{
+ DOMString name
;
+ boolean configurable
= true;
+ boolean enumerable
= true;
+ boolean writable
= true;
+ sequence<SemanticType
> semanticTypes
;
+ ThingDescription
description
;
+ any value
;
+};
+
+
++Represents +the + +Thing + + +Property + +description. +
+
+name
+
+
+attribute
+represents
+the
+name
+of
+the
+
+Property
+.
+
+value
+
+
+attribute
+represents
+the
+value
+of
+the
+
+Property
+.
+
+configurable
+
+
+attribute
+defines
+whether
+the
+
+Property
+
+can
+be
+deleted
+from
+the
+object
+and
+whether
+its
+properties
+can
+be
+changed.
+The
+default
+value
+is
+
+false
+
.
+
+enumerable
+
+
+attribute
+defines
+whether
+the
+
+Property
+
+can
+be
+listed
+and
+iterated.
+The
+default
+value
+is
+
+true
+
.
+
+writable
+
+
+attribute
+defines
+whether
+the
+
+Property
+
+can
+be
+updated.
+The
+default
+value
+is
+
+true
+
.
+
+semanticTypes
+
+
+attribute
+represents
+a
+list
+of
+semantic
+type
+annotations
+(e.g.
+labels,
+classifications
+etc)
+relevant
+to
+the
+
+Property
+,
+represented
+as
+
+
+SemanticType
+
+
+dictionaries.
+
+description
+
+
+attribute
+represents
+the
+
+Property
+
+description
+to
+be
+added
+to
+the
+
+Thing
+Description
+.
+
+SemanticType
+
+
+dictionary
+dictionary SemanticType
{
+ DOMString name
;
+ USVString context
;
+};
+
+
++Represents +a +semantic +type +annotation, +containing +a +name +and +a +context. +
+
+name
+
+
+attribute
+represents
+the
+name
+of
+the
+semantic
+type
+in
+the
+given
+context.
+
+context
+
+
+attribute
+represents
+an
+URL
+link
+to
+the
+context
+of
+the
+semantic
+classification.
++Semantic +type +examples +to +be +added. +
+
+removeProperty()
+
+
+method
+
+Removes
+the
+
+Property
+
+specified
+by
+the
+
+name
+
+argument,
+updates
+the
+
+Thing
+Description
+
+and
+returns
+the
+object.
+
+addAction()
+
+
+method
+
+Adds
+an
+
+Action
+
+to
+the
+
+Thing
+
+object
+as
+defined
+by
+the
+
+action
+
+argument
+of
+type
+
+
+ThingActionInit
+
+
+and
+updates
+the
+
+Thing
+Description
+.
+
+ThingActionInit
+
+
+dictionary
+dictionary ThingActionInit
{
+ DOMString name
;
+ ThingDescription
inputDataDescription
;
+ ThingDescription
outputDataDescription
;
+ sequence<SemanticType
> semanticTypes
;
+ Function action
;
+};
+
+
+
+The
+
+
+ThingActionInit
+
+
+dictionary
+describes
+the
+arguments
+and
+the
+return
+value.
+
+name
+
+
+attribute
+provides
+the
+
+Action
+
+name.
+
+action
+
+
+attribute
+provides
+a
+function
+that
+defines
+the
+
+Action
+.
+
+inputDataDescription
+
+
+attribute
+provides
+the
+description
+of
+the
+input
+arguments.
+
+outputDataDescription
+
+
+attribute
+provides
+the
+description
+of
+the
+returned
+data.
+
+semanticTypes
+
+
+attribute
+provides
+a
+list
+of
+semantic
+type
+annotations
+(e.g.
+labels,
+classifications
+etc)
+relevant
+to
+the
+
+Action
+,
+represented
+as
+
+
+SemanticType
+
+
+dictionaries.
+
+removeAction()
+
+
+method
+
+Removes
+the
+
+Action
+
+specified
+by
+the
+
+name
+
+argument,
+updates
+the
+
+Thing
+Description
+
+and
+returns
+the
+object.
+
+addEvent()
+
+
+method
+
+Adds
+an
+event
+to
+the
+
+Thing
+
+object
+as
+defined
+by
+the
+
+event
+
+argument
+of
+type
+
+
+ThingEventInit
+
+
+and
+updates
+the
+
+Thing
+Description
+.
+
+ThingEventInit
+
+
+dictionary
+dictionary ThingEventInit
{
+ DOMString name
;
+ sequence<SemanticType
> semanticTypes
;
+ ThingDescription
dataDescription
;
+};
+
+
+
+name
+
+
+attribute
+represents
+the
+event
+name.
+
+semanticTypes
+
+
+attribute
+represent
+a
+list
+of
+semantic
+type
+annotations
+attached
+to
+the
+event.
+
+dataDescription
+
+
+attribute
+represents
+the
+description
+of
+the
+data
+that
+is
+attached
+to
+the
+event.
+
+removeEvent()
+
+
+method
+
+Removes
+the
+event
+specified
+by
+the
+
+name
+
+argument,
+updates
+the
+
+Thing
+Description
+
+and
+returns
+the
+object.
+
+onRetrieveProperty()
+
+
+method
+
+Registers
+the
+handler
+function
+for
+
+Property
+
+retrieve
+requests
+received
+for
+the
+
+Thing
+,
+as
+defined
+by
+the
+
+handler
+
+property
+of
+type
+
+
+
.
+The
+handler
+will
+receive
+an
+argument
+
+request
+
+of
+type
+
+RequestHandler
+
+
+
+
+
+where
+at
+least
+
+request.name
+
+is
+defined
+and
+represents
+the
+name
+of
+the
+
+Property
+
+to
+be
+retrieved.
+
+Request
+
+
+
+onUpdateProperty()
+
+
+method
+
+Defines
+the
+handler
+function
+for
+
+Property
+
+update
+requests
+received
+for
+the
+
+Thing
+,
+as
+defined
+by
+the
+
+handler
+
+property
+of
+type
+
+
+
.
+The
+handler
+will
+receive
+an
+argument
+
+request
+
+of
+type
+
+RequestHandler
+
+
+
+
+
+where
+
+request.name
+
+defines
+the
+name
+of
+the
+
+Property
+
+to
+be
+retrieved
+and
+
+request.data
+
+defines
+the
+new
+value
+of
+the
+
+Property
+.
+
+Request
+
+
+
+onInvokeAction()
+
+
+method
+
+Defines
+the
+handler
+function
+for
+
+Action
+
+invocation
+requests
+received
+for
+the
+
+Thing
+,
+as
+defined
+by
+the
+
+handler
+
+property
+of
+type
+
+
+
.
+The
+handler
+will
+receive
+an
+argument
+
+request
+
+of
+type
+
+RequestHandler
+
+
+
+
+
+where
+
+request.name
+
+defines
+the
+name
+of
+the
+
+Action
+
+to
+be
+invoked
+and
+
+request.data
+
+defines
+the
+input
+arguments
+for
+the
+
+Action
+
+as
+defined
+by
+the
+
+Thing
+Description
+.
+
+Request
+
+
+
+onObserve()
+
+
+method
+
+Defines
+the
+handler
+function
+for
+observe
+requests
+received
+for
+the
+
+Thing
+,
+as
+defined
+by
+the
+
+handler
+
+property
+of
+type
+
+
+
.
+The
+handler
+will
+receive
+an
+argument
+
+request
+
+of
+type
+
+RequestHandler
+
+
+
+
+
+where
+
+Request
+
+
+
+RequestType
+
+
+and
+defines
+whether
+a
+
+Property
+
+change
+or
+
+Action
+
+invocation
+or
+event
+emitting
+is
+observed,
+or
+the
+changes
+to
+the
+
+Thing
+Description
+
+are
+observed.
+
+true
+
+if
+subscription
+is
+turned
+or
+kept
+being
+turned
+on,
+and
+it
+is
+
+false
+
+when
+subscription
+is
+turned
+off.
+
+register()
+
+
+method
+
+Generates
+the
+
+Thing
+Description
+
+given
+the
+properties,
+
+Actions
+
+and
+
+Event
+
+defined
+for
+this
+object.
+If
+a
+
+directory
+
+argument
+is
+given,
+make
+a
+request
+to
+register
+the
+
+Thing
+Description
+
+with
+the
+given
+WoT
+repository
+by
+invoking
+its
+
+register
+
+
+Action
+.
+
+unregister()
+
+
+method
+
+If
+a
+
+directory
+
+argument
+is
+given,
+make
+a
+request
+to
+unregister
+the
+
+Thing
+Description
+
+with
+the
+given
+WoT
+repository
+by
+invoking
+its
+
+unregister
+
+
+Action
+.
+Then,
+and
+in
+the
+case
+no
+arguments
+were
+provided
+to
+this
+function,
+stop
+the
+
+Thing
+
+and
+remove
+the
+
+Thing
+Description
+.
+
+start()
+
+
+method
++Start +serving +external +requests +for +the + +Thing +. +
+
+stop()
+
+
+method
++Stop +serving +external +requests +for +the + +Thing +. +
+
+emitEvent()
+
+
+method
+
+Emits
+an
+the
+event
+initialized
+with
+the
+event
+name
+specified
+by
+the
+
+eventName
+
+argument
+and
+data
+specified
+by
+the
+
+payload
+
+argument.
+
+The
+following
+default
+events
+
+SHOULD
+
+be
+supported
+by
+
+
+ExposedThing
+
+
+implementations:
+
+PropertyChangeEvent
+
+
+
+ActionInvocationEvent
+
+
+
+ThingDescriptionChangeEvent
+
+.
++In +addition, +user +defined +events +are +specified +by +the + +Thing +Description +. +
+
+Below
+some
+
+
+
+interface
+examples
+are
+given.
+
+ExposedThing
+
+
+
WoT.createExposedThing(thingDescription)
+ .then(function(thing) {
+ // manually add properties, actions, and events
+ thing.addProperty({
+ name: "temperature",
+ value: "0",
+ writable: false
+ // use default values for the rest
+ }).addEvent({
+ name: "onchange",
+ outputDataDescription: {
+ type: "float32"
+ }
+ }).addAction({
+ name: "reset",
+ action: () => { this.temperature = 0; }
+ })
+ // add server functionality
+ .onRetrieveProperty( request => {
+ console.log("Handling read request");
+ return this.temperature;
+ }).onObserve( request => {
+ console.log("Handling observe request");
+ // add listener identified by request.from
+ }).onInvokeAction( request => {
+ console.log("Handling action request");
+ }).start();
+});
+
+let thingDescription = '{ + "name": "mySensor", + "url": "http://myservice.org/mySensor/description" +}'; +WoT.createExposedThing(thingDescription) + .then(function(thing) { + // properties, actions and events are added based on the TD + console.log("created " + thing.name }); + // now add the requests handlers + thing.onRetrieveProperty(function(request) { + console.log("Sending property '" + request.property + "' to " + request.from); + }).onUpdateProperty(function(request) { + console.log("Updating property '" + request.property + "' by " + request.from); + }).onObserve(function(request) { + console.log("Adding listener " + request.from); + console.log("Observing " + request.type + " " + request.name + + (request.subscribe? " recursively" : "")); + }).start().then(function() { + console.log("Thing started serving requests"); + }); +}) ++
let thingDescription = '{ + "name": "mySensor", + "description": { + "@context": [ + "http://w3c.github.io/wot/w3c-wot-td-context.jsonld", + "http://w3c.github.io/wot/w3c-wot-common-context.jsonld", + ], + "@type": [ "Thing" ], + "interaction": [ + // ... + ] + // ... + }' +}; +WoT.createExposedThing(thingDescription) + .then(function(thing) { + // properties, actions and events are added based on the TD + // ... +}); ++
+Please +see +the + +WoT +Security +and +Privacy + +repository +for +work +in +progress +regarding +threat +models, +assets, +risks, +recommended +mitigations, +and +best +practices +for +security +and +privacy +for +systems +using +the +Web +of +Things. +Once +complete, +security +and +privacy +considerations +relevant +to +the +Scripting +API +will +be +summarized +in +this +section. +
++The +generic +WoT +terminology +is +defined +in +[ + + +WOT-ARCHITECTURE + + +]: + +Thing +, + +Thing +Description + +(in +short + +TD + +), + +Web +of +Things + +(in +short + + +WoT + + +), + +WoT +Interface +, + +Protocol +Bindings +, + +WoT +Runtime +, + +Consuming +a +Thing +Description +, + +Thing +Directory +, + +Property +, + +Action +, + +Event + +etc. +
++In +this +version +of +the +specification, +a + +WoT +Runtime + +is +assumed +to +run +scripts +that +uses +this +API +to +define +one +or +more + +Thing + +s +that +share +a +common +event +loop. +Script +deployment +methods +are +out +of +scope +of +this +version. +In +future +versions, +running +multiple +scripts +(as +modules) +may +be +possible, +and +script +deployment + +MAY + +be +implemented +using +a +manager + +Thing + +whose + +Actions + +permit +script +lifecycle +management +operations. +
+
+
+JSON-LD
+
+is
+defined
+in
+[
+
+
+JSON-LD
+
+
+]
+as
+a
+JSON
+document
+that
+is
+augmented
+with
+support
+for
+Linked
+Data
+by
+providing
+a
+
+@context
+
+property
+with
+a
+defining
+URI
+.
+
+The +terms + + +URL + + +and + + +URL +path + + +are +defined +in +[ + + +URL + + +]. +
++The +following +terms +are +defined +in +[ + + +HTML5 + + +] +and +are +used +in +the +context +of +browser +implementations: + + +browsing +context + +, + + +top-level +browsing +context + +, + + +global +object + +, + + +incumbent +settings +object + +, + + +Document + +, + + +document +base +URL + +, + + +Window + +, + + +WindowProxy + +, + + +origin + +, + + +ASCII +serialized +origin + +, +executing +algorithms + + +in +parallel + +, + + +queue +a +task + +, + + +task +source + +, + + +iframe + +, + + +valid +MIME +type + +. +
+
+A
+
+browsing
+context
+
+refers
+to
+the
+environment
+in
+which
+
+Document
+
+objects
+are
+presented
+to
+the
+user.
+A
+given
+
+browsing
+context
+
+has
+a
+single
+
+
+WindowProxy
+
+
+object,
+but
+it
+can
+have
+many
+
+
+Document
+
+
+objects,
+with
+their
+associated
+
+
+Window
+
+
+objects.
+The
+
+script
+execution
+context
+
+associated
+with
+the
+
+browsing
+context
+
+identifies
+the
+entity
+which
+invokes
+this
+API,
+which
+can
+be
+a
+
+web
+app
+,
+a
+
+web
+page
+,
+or
+an
+
+iframe
+.
+
+The +term + + +secure +context + + +is +defined +in +[ + + +WEBAPPSEC + + +]. +
++ + +Error +, + +EvalError +, + +RangeError +, + +ReferenceError +, + +SyntaxError +, + +TypeError +, + +URIError + +, + + +script +execution +context + +, + + +Promise + +, + + +JSON + +, + + +JSON.stringify + + +and + + +JSON.parse + + +are +defined +in +[ + + +ECMASCRIPT + + +]. +
++ + +DOMString + +, + + +USVString + +, + + +ArrayBuffer + +, + + +BufferSource + + +and + + +any + + +are +defined +in +[ + + +WEBIDL + + +]. +
++The +term + + +event + + +and +the + + +Event + + +object +are +defined +in + +DOM + +and + +Node.js +. +
++This +specification +uses +the +convention +that +an +event +listener +will +receive +an + +Event + +object. +This +should +work +both +in +a +browser +environment +and +in +a +Node.js +like +environment. +
++ + +Observable + +s + +are +proposed +to +be +included +in +ECMAScript. +
++The +algorithms + + +utf-8 +encode + +, +and + + +utf-8 +decode + + +are +defined +in +[ + + +ENCODING + + +]. +
++ +IANA +media +type + +s +(formerly +known +as +MIME +types) +are +defined +in + +RFC2046 +. +
++As +well +as +sections +marked +as +non-normative, +all +authoring +guidelines, +diagrams, +examples, +and +notes +in +this +specification +are +non-normative. +Everything +else +in +this +specification +is +normative. +
++The +key +words + +MAY +, + +MUST +, +and + +SHOULD + +are +to +be +interpreted +as +described +in +[ + + +RFC2119 + + +]. +
++This +document +defines +conformance +criteria +that +apply +to +a +single +product: +the + +UA + +(user +agent) +that +implements +the +interfaces +it +contains. +
++This +specification +can +be +used +for +implementing +the +WoT +Scripting +API +in +multiple +programming +languages. +The +interface +definitions +are +specified +in +[ + + +WEBIDL + + +]. +
++The +user +agent +(UA) +may +be +implemented +in +the +browser, +or +in +a +separate +runtime +environment, +such +as + +Node.js + +or +small +embedded +runtimes. +
++Implementations +that +use +ECMAScript +executed +in +a +browser +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +ECMAScript +Bindings +defined +in +the +Web +IDL +specification +[ + + +WEBIDL + + +]. +
++Implementations +that +use +TypeScript +or +ECMAScript +in +a +runtime +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +TypeScript +Bindings +defined +in +the +TypeScript +specification +[ + + +TYPESCRIPT + + +]. +
++This +document +serves +a +general +description +of +the +WoT +Scripting +API. +Language +and +runtime +specific +issues +are +discussed +in +separate +extensions +of +this +document. +
++The +following +is +a +list +of +major +changes +to +the +document. +For +a +complete +list +of +changes, +see +the + +github +change +log +. +You +can +also +view +the + +recently +closed +bugs +. +
++The +following +problems +are +being +discussed +and +need +most +attention: +
+
+Special
+thanks
+to
+former
+editor
+Johannes
+Hund
+(until
+August
+2017,
+when
+at
+Siemens
+AG)
+
+for
+developing
+this
+specification.
+Also,
+the
+editors
+would
+like
+to
+thank
+Dave
+Raggett,
+Matthias
+Kovatsch,
+Michael
+Koster
+and
+Michael
+McCool
+for
+their
+comments
+and
+guidance.
+
Copyright + © 2017-2018 W3C® + (MIT, + ERCIM, + Keio, Beihang). W3C + liability, + trademark and + permissive document license rules apply.
+The Web of Things (WoT) provides layered + interoperability between Things by using the + WoT Interfaces.
+This specification describes a programming interface + representing the WoT Interface that + allows scripts run on a Thing to discover and + consume (retrieve) other Things and to expose + Things characterized by WoT Interactions, i.e. Properties, + Actions and Events.
+Scripting is an optional "convenience" building block in WoT + and it is typically used in gateways that are able to run a + WoT Runtime and + script management, providing a convenient way to extend WoT + support to new types of endpoints and implement WoT + applications like + Thing Directory.
+This section describes the status of this document at + the time of its publication. Other documents may supersede this + document. A list of current W3C publications and the + latest revision of this technical report can be found in the + W3C technical reports + index at https://www.w3.org/TR/.
+Implementers need to be aware that this specification is + considered unstable. Vendors interested in implementing this + specification before it eventually reaches the Candidate + Recommendation phase should subscribe to the repository and + take part in the discussions.
+Please contribute to this draft using the + GitHub + Issue feature of the WoT Scripting + API repository. For feedback on security and privacy + considerations, please use the WoT Security and + Privacy Issues.
+This document was published by the Web of Things Working Group as + a Working Draft. + This document is intended to become a W3C Recommendation. + Comments regarding this document are + welcome. Please send them to public-wot-wg@w3.org + (subscribe, + archives).
+Changes from the previous publication can be found in + Appendix A. A diff-marked version of this document is also + available for comparison purposes.
+Publication as a Working Draft does not imply endorsement by + the W3C + Membership. This is a draft document and may be updated, + replaced or obsoleted by other documents at any time. It is + inappropriate to cite this document as other than work in + progress.
+This document was produced by a group operating under the + W3C Patent Policy. + W3C maintains a + public list + of any patent disclosures made in connection with the + deliverables of the group; that page also includes instructions + for disclosing a patent. An individual who has actual knowledge + of a patent which the individual believes contains Essential + Claim(s) must disclose the information in accordance with + section + 6 of the W3C + Patent Policy.
+This document is governed by the 1 February 2018 + W3C Process + Document.
+The overall WoT concepts are described in the + + WoT Architecture document. The Web of Things is made of entities (Things) that can describe their capabilities in a + machine-interpretable format, the Thing Description (TD) and expose these capabilities + through the WoT Interface. Support for scripting + is optional for WoT devices.
+By consuming a TD, a client Thing creates a runtime resource model that allows + accessing the Properties, Actions and + Events exposed by the server Thing.
+Exposing a Thing requires defining a Thing Description (TD) and instantiating a software + stack needed to serve requests for accessing the exposed + Properties, Actions and Events. This specification describes how to expose + and consume Things by a script.
+Typically scripts are meant to be used on devices + able to provide resources (with a WoT interface) for managing (installing, updating, + running) scripts, such as bridges or gateways that expose and + control simpler devices as WoT Things.
+This specification does not make assumptions on + how the WoT Runtime handles and runs + scripts, including single or multiple tenancy, script + deployment and lifecycle management. The API already supports + the generic mechanisms that make it possible to implement + script management, for instance by exposing a manager + Thing whose Actions (action + handlers) implement script lifecycle management + operations.
+For an introduction on how scripts could be used in Web of Things, check the Primer + document. For some background on API design decisions check the + Rationale + document.
+This section is non-normative.
+The following scripting use cases are supported in this + specification:
+ExposedThing
to be exposed, based on
+ a Thing Description provided in
+ string serialized format, or out of a template or an
+ existing ConsumedThing
object.
+ WoT
objectThe WoT object is the API entry point and it is exposed by + an implementation of the WoT Runtime. The + WoT object + does not expose properties, only methods for discovering, + consuming and exposing a Thing.
+Browser implementations SHOULD use a namespace object such as
+ wot
, and Node.js-like runtimes MAY provide the API object through
+ the require()
+ or
+ import
mechanism.
interface+WoT
{ +Observable
<ConsumedThing
> discover(optionalThingFilter
filter); + Promise<ThingDescription
> fetch(USVString url); +ConsumedThing
consume(ThingDescription
td); +ExposedThing
produce(ThingModel
model); +}; + +typedef USVStringThingDescription
; + +typedef (ThingTemplate
orThingDescription
)ThingModel
;
The algorithms for the WoT methods will be + specified later, including error handling and security + considerations.
+discover()
+ methodStarts the discovery process that will provide
+
+ objects that match the optional argument ConsumedThing
. When the argument
+ is not provided, starts the widest discovery the Thing Description and Protocol Bindings allow and support. Returns an
+ ThingFilter
Observable
+ object that can be subscribed to and unsubscribed from.
DiscoveryMethod
+ enumerationtypedef DOMString DiscoveryMethod
;
+ DiscoveryMethod
+ represents the discovery type to be used:
ThingFilter
+ dictionaryThe ThingFilter
+ dictionary that represents the constraints for discovering
+ Things as key-value pairs.
dictionary ThingFilter
{
+ DiscoveryMethod
method
= "any";
+ USVString url
;
+ USVString query
;
+ sequence<Dictionary> constraints
;
+};
+ The method
property represents the
+ discovery type that should be used in the discovery
+ process. The possible values are defined by the
+
enumeration
+ that can be extended by string values defined by solutions
+ (with no guarantee of interoperability).DiscoveryMethod
The DiscoveryMethod
enumeration can be
+ extended by the Thing Description
+ with values that are not specified here. This
+ extensibility of DiscoveryMethod
by proprietary or
+ private methods is a working assumption until consensus
+ is formed and may be removed later.
The url
property represents additional
+ information for the discovery method, such as the URL of
+ the target entity serving the discovery request, such as a
+ Thing Directory or a Thing.
The query
property represents a
+ query string accepted by the implementation, for instance a
+ SPARQL query.
The constraints
property
+ represents additional information for the discovery method
+ in the form of a list of sets of property-value pairs
+ (dictionaries). The list elements (dictionaries) are in OR
+ relationship, and within a constraint dictionary the
+ key-value pairs are in AND relationship. Implementations
+ SHOULD make the
+ following mapping from the constraint dictionaries to
+ SemanticAnnotations
:
+ for each property-value pair in a constraint
+ dictionary,
name
property of a defined
+ SemanticType
on the
+ target Thing object, or the name of a
+ Property on the target
+ Thing.
+ Constraints are experimental feature, + implementations are not required to support them.
+fetch()
methodAccepts an url
argument and returns a
+ Promise
that resolves with a
+ ThingDescription
.
ThingDescription
+ typeRepresentation of the Thing + Description, standardized in the + + Wot Things Description specification.
+In this version of the API, Thing Descriptions are represented + as opaque strings, denoting a serialized form, for instance + JSON or JSON-LD. See Issue + 38 and Issue + 45.
+consume()
+ methodAccepts an td
argument of type
and returns a
+ ThingDescription
ConsumedThing
object
+ instantiated based on that description.
produce()
methodAccepts a model
argument of type
+
and
+ returns an ThingModel
ExposedThing
object,
+ locally created based on the provided initialization
+ parameters. An ExposedThing
can be created in the
+ following ways:
ConsumedThing
object), then adding
+ request handlers.
+ ThingModel
typeA Thing model is used for producing a new ExposedThing
and can be either a
+ ThingTemplate
, or a
+ ThingDescription
.
SemanticAnnotations
+ dictionaryA dictionary that provides the semantic types and semantic + metadata.
+dictionary SemanticAnnotations
{
+ sequence<SemanticType
> semanticType
;
+ sequence<SemanticMetadata
> metadata
;
+};
+ The semanticType
+ property denotes a list of SemanticType
objects that define the
+ semantic types that can be used in semantic metadata
+ type-value pairs.
The metadata
property
+ denotes a list of SemanticMetadata
objects (type-value
+ pairs).
SemanticType
+ dictionarydictionary SemanticType
{
+ required DOMString name
;
+ required USVString context
;
+ DOMString prefix
;
+};
+ Represents a semantic type annotation, containing a name, + a context and a prefix.
+name
attribute represents the
+ name of the semantic type in the given context.context
attribute represents
+ an URL link to the context of the semantic
+ classification.prefix
attribute represents a
+ short prefix associated with a context.Semantic type examples to be added.
+SemanticMetadata
+ dictionarydictionary SemanticMetadata
{
+ SemanticType
type
;
+ any value
;
+};
+ The SemanticMetadata
+ dictionary describes a pair of semantic type and value:
type
+ attribute represents the semantic type name defined by a
+ SemanticType
+ object.
+ value
attribute
+ represents the metadata value.ThingTemplate
+ dictionaryA Thing Template is a dictionary that provides a user
+ given name, and the semantic types and semantic metadata
+ attached to the ExposedThing
Thing Description's root level.
dictionary ThingTemplate
: SemanticAnnotations
{
+ required DOMString name
;
+};
+ The ThingTemplate
+ dictionary extends SemanticAnnotations
and contains
+ properties to initialize a Thing:
name
attribute represents the
+ user given name of the Thing.
+ Support for configuration and security data + might be added later.
+let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let subscription = wot.discover(discoveryFilter).subscribe(
+ thing => { console.log("Found Thing " + thing.name); },
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log("Discovery timeout");
+ },
+ 5000);
+ Note that canceling a discovery (through
+ unsubscribe()
) may not be successful in all
+ cases, for instance when discovery is based on open ended
+ broadcast requests. However, once
+ unsubscribe()
has been called, implementations
+ MUST suppress further
+ event handling ( i.e. further discoveries and errors) on
+ the Observable. Also, a discovery error may not mean the
+ end of the discovery process. However, in order to respect
+ Observable semantics (error always terminates processing),
+ implementations MUST
+ close or suppress further event handling on the
+ Observable.
let subscription = wot.discover({ method: "local" }).subscribe(
+ thing => { console.log("Found local Thing " + thing.name); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({ method: "local" }).subscribe({
+ thing => { console.log("Found local Thing " + thing.name); },
+ error: err => { console.log("Discovery error: " + err.message); },
+ complete: () => { console.log("Discovery finished successfully");}
+});
+ let subscription = wot.discover({
+ method: "nearby",
+ constraints: [{ protocol: "BLE-4.2" }, { protocol: "NFC"}]
+}).subscribe(
+ thing => { console.log("Found nearby Thing " + thing.name); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({
+ method: "other",
+ constraints: [{ solution: "XYZ123", key: "..."}]
+}).subscribe(
+ thing => { console.log("Found Thing " + thing.name); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ ConsumedThing
interfaceThe ConsumedThing
interface
+ is a client API for sending requests to servers in order to
+ retrieve or update Properties, invoke
+ Actions, and observe Properties and Events.
interface ConsumedThing
{
+ readonly attribute DOMString name
;
+ ThingDescription
getThingDescription();
+ Promise<any> readProperty(DOMString name);
+ Promise<void> writeProperty(DOMString name, any value);
+ Promise<any> invokeAction(DOMString name, any parameters);
+ Observable
onPropertyChange(DOMString name);
+ Observable
onEvent(DOMString name);
+ Observable
onTDChange();
+};
+ ConsumedThing
represents a local proxy object
+ of the remote Thing.
name
propertyThe name
property represents the name of the
+ Thing as specified in the TD. In this version it
+ is read only.
getThingDescription()
+ methodReturns the Thing Description of + the Thing.
+In this version, introspection based on + TD is out of scope. Parsing and exposing Thing Descriptions is discussed in + Issue + 38.
+readProperty()
+ methodTakes the Property name as the name
+ argument, then requests from the underlying platform and the
+ Protocol Bindings to retrieve the
+ Property on the remote Thing and return the
+ result. Returns a Promise
that
+ resolves with the Property value or
+ rejects with an Error.
writeProperty()
+ methodTakes the Property name as the name
+ argument and the new value as the value argument,
+ then requests from the underlying platform and the Protocol Bindings to update the Property on the remote Thing and return the
+ result. Returns a Promise
that
+ resolves on success or rejects with an Error.
invokeAction()
+ methodTakes the Action name from the name
+ argument and the list of parameters, then requests from the
+ underlying platform and the Protocol
+ Bindings to invoke the Action on the remote
+ Thing and return the result. Returns a
+ Promise
that resolves with
+ the return value or rejects with an Error.
onPropertyChange()
+ methodReturns an Observable
for the
+ Property specified in the name argument,
+ allowing subscribing to and unsubscribing from
+ notifications.
The callback function passed to the
+ subscribe()
method when invoked on the returned
+ observer will receive the new property value each time it is
+ changed.
onEvent()
methodReturns an Observable
for the
+ Event specified in the name argument,
+ allowing subscribing to and unsubscribing from
+ notifications.
The callback function passed to the
+ subscribe()
method when invoked on the returned
+ observer will receive the event data each time the event is
+ fired.
onTDChange()
+ methodReturns an Observable
, allowing
+ subscribing to and unsubscribing from notifications to the
+ Thing Description.
The callback function passed to the
+ subscribe()
method when invoked on the returned
+ observer will receive the new Thing Description each time it is changed.
Below a
interface example
+ is given.ConsumedThing
try { + let td = await wot.fetch("http://mmyservice.org/mySensor"); + let thing = wot.consume(td); + console.log("Thing " + thing.name + " has been consumed."); + let subscription = thing.onPropertyChange("temperature") + .subscribe(function(value) { + console.log("Temperature + " has changed to " + value); + }); + thing.invokeAction("startMeasurement", { units: "Celsius" }) + .then(() => { console.log("Temperature measurement started."); }) + .catch(e => { + console.log("Error starting measurement."); + subscription.unsubscribe(); + }) +} catch(error) { + console.log("Error during fetch or consume: " + error.message); +};+
ExposedThing
interfaceThe ExposedThing
interface is
+ the server API that allows defining request handlers,
+ properties, Actions, and Events to a
+ Thing. It also implements the ConsumedThing
interface. An ExposedThing
is created by the produce() method.
It is under consideration to use a constructor
+ for ExposedThing
instead of
+ a factory method.
+ExposedThing
implementsConsumedThing
; + +interfaceExposedThing
{ + // define how to expose and run the Thing + Promise<void> start(); + Promise<void> stop(); + Promise<void> register(optional USVString directory); + Promise<void> unregister(optional USVString directory); + Promise<void> emitEvent(DOMString eventName, any payload); + // define Thing Description modifiers +ExposedThing
addProperty(ThingProperty
property); +ExposedThing
removeProperty(DOMString name); +ExposedThing
addAction(ThingAction
action); +ExposedThing
removeAction(DOMString name); +ExposedThing
addEvent(ThingEvent
event); +ExposedThing
removeEvent(DOMString name); + // define request handlers +ExposedThing
setPropertyReadHandler(DOMString name, +PropertyReadHandler
readHandler); +ExposedThing
setPropertyWriteHandler(DOMString name, +PropertyWriteHandler
writeHandler); +ExposedThing
setActionHandler(DOMString name,ActionHandler
action); +}; + +callbackPropertyReadHandler
= Promise<any> (); + +callbackPropertyWriteHandler
= Promise<void> (any value); + +callbackActionHandler
= Promise<any> (any parameters);
start()
+ methodStart serving external requests for the Thing.
+stop()
methodStop serving external requests for the Thing.
+register()
+ methodGenerates the Thing Description
+ given the properties, Actions and Event defined for this object. If a
+ directory
argument is given, make a request to
+ register the Thing Description with
+ the given WoT repository by invoking its
+ register
Action.
unregister()
+ methodIf a directory
argument is given, make a
+ request to unregister the Thing
+ Description with the given WoT repository by invoking its
+ unregister
Action. Then, and in
+ the case no arguments were provided to this function, stop
+ the Thing and remove the Thing Description.
emitEvent()
+ methodEmits an the event initialized with the event name
+ specified by the eventName
argument and data
+ specified by the payload
argument.
DataSchema
typetypedef USVString DataSchema
;
+ The DataSchema
type
+ represents a data type
+
+ specified
+ in the Thing Description in a serialized
+ form.
DataSchema
is under
+ development, currently it can denote any type supported by
+ the Thing Description and the WoT Runtime.
addProperty()
+ methodAdds a Property defined by the argument and + updates the Thing Description. + Throws on error. Returns a reference to the same object for + supporting chaining.
+ThingProperty
+ dictionarydictionary ThingProperty
: SemanticAnnotations
{
+ required DOMString name
;
+ required DataSchema
schema
;
+ any value
;
+ boolean writable
= false;
+ boolean observable
= false;
+};
+ Represents the Thing Property + description.
+name
+ attribute represents the name of the Property.
+ schema
attribute represents
+ the data type for the Property
+ described by DataSchema
.
+ value
+ attribute represents the value of the Property.
+ writable
attribute
+ defines whether the Property can be
+ updated. The default value is false
.
+ observable
attribute
+ defines whether the Property changes
+ can be observed by an external client. The default
+ value is false
.
+ removeProperty()
+ methodRemoves the Property specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addAction()
+ methodAdds an Action to the Thing object as
+ defined by the action
argument of type ThingAction
and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
ThingAction
+ dictionarydictionary ThingAction
: SemanticAnnotations
{
+ required DOMString name
;
+ DataSchema
inputSchema
;
+ DataSchema
outputSchema
;
+};
+ The ThingAction
+ dictionary describes the arguments and the return
+ value.
name
attribute provides the
+ Action name.
+ inputSchema
+ attribute provides the description of the input arguments
+ (argument list is represented by an object). If missing,
+ it means the action does not accept arguments.outputSchema
+ attribute provides the description of the returned data.
+ If missing, it means the action does not return
+ data.removeAction()
+ methodRemoves the Action specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addEvent()
+ methodAdds an event to the Thing object as
+ defined by the event
argument of type ThingEvent
and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
ThingEvent
+ dictionarydictionary ThingEvent
: SemanticAnnotations
{
+ required DOMString name
;
+ DataSchema
schema
;
+};
+ name
attribute represents the
+ event name.schema
attribute represents
+ the type of the data that is attached to the event. If
+ missing, it means the event does not carry data.removeEvent()
+ methodRemoves the event specified by the name
+ argument and updates the Thing
+ Description. Returns a reference to the same object for
+ supporting chaining.
PropertyReadHandler
+ callbackA function that returns a Promise and resolves it with the
+ value of the Property matching the
+ name
argument to the
+ setPropertyReadHandler
function, or rejects with
+ an error if the property is not found or the value cannot be
+ retrieved.
PropertyWriteHandler
+ callbackA function called with value
as argument that
+ returns a Promise which is resolved when the value of the
+ Property matching the name
argument to
+ the setPropertyReadHandler
function is updated
+ with value
, or rejects with an error if the
+ property is not found or the value cannot be updated.
Note that this function is invoked by
+ implementations before the property is updated, so the code
+ in this callback function can invoke the
+ readProperty()
method to find out the old
+ value of the property, if needed. Therefore the old value
+ is not provided to this method.
ActionHandler
+ callbackA function called with a parameters
+ dictionary argument assembled by the WoT runtime based on the Thing Description and the external client request.
+ It returns a Promise that rejects with an error or resolves
+ if the action is successful or ongoing (may also resolve with
+ a control object such as an Observable
for actions that need
+ progress notifications or that can be canceled).
setPropertyReadHandler()
+ methodTakes name
as string argument and
+ readHandler
as argument of type PropertyReadHandler
.
+ Sets the handler function for reading the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
The readHandler
callback function will
+ implement reading a Property and
+ SHOULD be called by
+ implementations when a request for reading a Property is received from the underlying
+ platform.
There SHOULD be at + most one handler for any given Property and + newly added handlers replace the old handlers. If no handler + is initialized for any given Property, + implementations SHOULD implement a default property read + handler.
+setPropertyWriteHandler()
+ methodTakes name
as string argument and
+ writeHandler
as argument of type PropertyWriteHandler
.
+ Sets the handler function for writing the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
There SHOULD be at + most one write handler for any given Property and newly added handlers replace the old + handlers. If no write handler is initialized for any given + Property, implementations SHOULD implement default property update + and notifying observers on change.
+setActionHandler()
+ methodTakes name
as string argument and
+ action
as argument of type ActionHandler
. Sets the handler
+ function for the specified Action matched by
+ name
. Throws on error. Returns a reference to
+ the same object for supporting chaining.
If provided, this callback function will implement
+ invoking an Action and SHOULD be called by implementations when
+ a request for invoking a Action is received
+ from the underlying platform. The callback will receive a
+ parameters
dictionary argument.
There SHOULD be + exactly one handler for any given Action. If no + handler is initialized for any given Action, + implementations SHOULD return error if the action is invoked by + any client.
+Below some
interface examples
+ are given.ExposedThing
+ try {
+ var thing = WoT.produce({ name: "tempSensor" });
+ // manually add Interactions
+ thing.addProperty({
+ name: "temperature",
+ value: 0.0,
+ schema: '{ "type": "number" }'
+ // use default values for the rest
+ }).addProperty({
+ name: "max",
+ value: 0.0,
+ schema: '{ "type": "number" }'
+ // use default values for the rest
+ }).addAction({
+ name: "reset",
+ // no input, no output
+ }).addEvent({
+ name: "onchange",
+ schema: '{ "type": "number" }'
+ });
+ // add server functionality
+ thing.setActionHandler("reset", () => {
+ console.log("Resetting maximum");
+ thing.writeProperty("max", 0.0);
+ });
+ thing.start().then(() => {
+ thing.register();
+ });
+ // define Thing business logic
+ setInterval( async () => {
+ let mock = Math.random()*100;
+ thing.writeProperty("temperature", mock);
+ let old = await thing.readProperty("max");
+ if (old < mock) {
+ thing.writeProperty("max", mock);
+ thing.emitEvent("onchange");
+ }
+ }, 1000);
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ let thingDescription = '{ "@context": [ "https://w3c.github.io/wot/w3c-wot-td-context.jsonld", "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ], "@type": [ "Thing", "Sensor" ], "name": "mySensor", "geo:location": "testspace", "interaction": [ { "@type": [ "Property", "Temperature" ], "name": "prop1", "schema": { "type": "number" }, "saref:TemperatureUnit": "degree_Celsius" } ] }';
+try {
+ // note that produce() fails if thingDescription contains error
+ let thing = WoT.produce(thingDescription);
+ // Interactions were added from TD
+ // WoT adds generic handler for reading any property
+ // define a specific handler for one property
+ let name = "examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log("Handling read request for " + name);
+ return new Promise((resolve, reject) => {
+ let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log("Error");
+ });
+ });
+ thing.start();
+} catch(err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ // fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+ // WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+ // Interactions were added from TD
+ // add server functionality
+ // ...
+});
+ This section is non-normative.
+The ThingDescription
related
+ functionality, such as enumerating Properties,
+ Actions, Events and links (introspection) is an
+ API extension that is out of scope for this specification.
+ However, the draft interfaces are defined here for informative
+ purposes.
partial interface ConsumedThing
{
+ sequence<ThingProperty
> getProperties();
+ sequence<ThingAction
> getActions();
+ sequence<ThingEvent
> getEvents();
+ sequence<TDLink
> getLinks();
+};
+ getProperties()
+ methodReturns the list of Properties defined in
+ the Thing Description of the Thing in the form of a list of ThingProperty
objects.
getActions()
+ methodReturns the list of Actions defined in the
+ Thing Description of the Thing in the form of a list of ThingAction
objects.
getEvents()
+ methodReturns the list of Events defined in the
+ Thing Description of the Thing in the form of a list of ThingEvent
objects.
getLinks()
+ methodReturns the list of linked resources in Thing Description of the Thing in the
+ form of a list of TDLink
objects.
TDLink
dictionaryContains a hyperlink reference, a relation type and a + media type.
+ +The TDLink
dictionary
+ contains the following properties:
href
attribute represents a
+ hyperlink reference.
+ rel
attribute represents a
+ relation type.
+ mediaType
attribute
+ represents a IANA media type.
+ For TDs there will be registered
+ media types, so applications will be able to check
+ whether an href
link points to a TD, i.e. whether the link is fetcheable with
+ this API.
+ This section is non-normative.
+Observables are proposed to + be included in ECMAScript and are used for handling pushed data + associated with various possible sources, for instance events, + timers, streams, etc. A minimal required implementation is + described here.
+This section is informal and contains rather + laconic information for implementations on what to support + for interoperability.
+interface+Observable
{ +Subscription
subscribe
((Observer
orOnNext
) next, + optionalOnError
error, + optionalOnComplete
complete); +}; + +interfaceSubscription
{ + voidunsubscribe
(); + readonly attribute booleanclosed
; +}; + +interfaceObserver
{ + void next(any value); + void error(Error error); + void complete(); +}; + +callbackOnNext
= void (any value); + +callbackOnError
= void (Error error); + +callbackOnComplete
= void ();
Observer
interfaceThe Observer
interface
+ defines the callbacks needed to handle an Observable
:
next()
function,
+ as well as the OnNext
callback takes the next
+ sample for the data in the value
+ argument.error()
+ function, as well as the OnError
callback
+ takes an error in the value
argument. It is
+ called when an error occured in producing the data the
+ client should know about.complete()
+ function, as well as the OnComplete
+ callback is called when the data source has finished
+ sending values.Subscription
interfaceContains the closed
property of
+ type boolean
that tells if the subscription is
+ closed or active.
Also, contains the unsubscribe
()
+ method that cancels the subscription, i.e. makes a request to
+ the underlying platform to stop receiving data from the
+ source, and sets the closed
property to
+ false
.
Observable
interfaceThe Observable
interface
+ enabled subscribing to pushed data notifications by the
+ subscribe
()
+ method:
subscribe()
method is called with
+ an Observer
object,
+ initialize the data, error and completion handling
+ callbacks from that object, or throw on error.
+ subscribe()
method is
+ called with a function, initialize the data handler
+ callback with that function. If the next argument is
+ provided and is a function, initialize the error handling
+ callback with that function, or throw on error. If the
+ third argument is provided and is a function, initialize
+ the completion handler with that function, or throw on
+ error.Please see the WoT Security and + Privacy repository for work in progress regarding threat + models, assets, risks, recommended mitigations, and best + practices for security and privacy for systems using the Web + of Things. Once complete, security and privacy considerations + relevant to the Scripting API will be summarized in this + section.
+The generic WoT terminology is defined in [WOT-ARCHITECTURE]: + Thing, Thing Description (in short + TD), + Web of + Things (in short WoT), WoT Interface, + Protocol + Bindings, WoT Runtime, Consuming a Thing + Description, Thing Directory, + WoT + Interactions, Property, + Action, Event etc.
+JSON-LD is
+ defined in [JSON-LD] as a JSON document that is
+ augmented with support for Linked Data by providing a
+ @context
property with a defining URI .
The terms URL and URL path are defined in + [URL].
+ +The following terms are defined in [HTML52] and are used in the context + of browser implementations: + + + browsing + context, + + + top-level browsing + context, + + + global + object, + + + incumbent settings + object, + + + Document, + + + document + base URL, + + + Window, + + + WindowProxy, + + + origin, + + + ASCII + serialized origin, + + executing algorithms + + + in parallel, + + + queue a task, + + + task source, + + + iframe, + + + valid MIME type.
+ +A browsing context refers to the
+ environment in which Document objects are
+ presented to the user. A given browsing context
+ has a single WindowProxy
+ object, but it can have many Document
+ objects, with their associated Window
+ objects. The script execution context
+ associated with the browsing context identifies the
+ entity which invokes this API, which can be a web app, a
+ web page, or an iframe.
The term + secure + context is defined in [WEBAPPSEC].
+Error, EvalError, RangeError, ReferenceError, SyntaxError, + TypeError, + URIError , + script execution + context, + Promise, + + JSON, + JSON.stringify and + JSON.parse are defined in + [ECMASCRIPT].
+DOMString, USVString, ArrayBuffer, BufferSource and any are defined in + [WEBIDL].
+The algorithms utf-8 encode, and utf-8 decode are defined in + [ENCODING].
+IANA media + types (formerly known as MIME types) are defined in + RFC2046.
+The terms hyperlink reference and + relation + type are defined in [HTML52] and RFC8288.
+As well as sections marked as non-normative, all authoring + guidelines, diagrams, examples, and notes in this specification + are non-normative. Everything else in this specification is + normative.
+The key words MAY, MUST, and + SHOULD are to be interpreted as + described in [RFC2119].
+This document defines conformance criteria that apply to a + single product: the UA (user agent) that implements the interfaces + it contains.
+This specification can be used for implementing the WoT + Scripting API in multiple programming languages. The interface + definitions are specified in [WEBIDL].
+The user agent (UA) may be implemented in the browser, or in + a separate runtime environment, such as Node.js or small embedded + runtimes.
+Implementations that use ECMAScript executed in a browser to + implement the APIs defined in this document MUST implement them in a manner consistent + with the ECMAScript Bindings defined in the Web IDL + specification [WEBIDL].
+Implementations that use TypeScript or ECMAScript in a + runtime to implement the APIs defined in this document + MUST implement them in a + manner consistent with the TypeScript Bindings defined in the + TypeScript specification [TYPESCRIPT].
+This document serves a general description of the WoT + Scripting API. Language and runtime specific issues are + discussed in separate extensions of this document.
+The following is a list of major changes to the document. + For a complete list of changes, see the github + change log. You can also view the + recently closed bugs.
+ThingDescription
, ThingTemplate
,
+ SemanticAnnotations
, SemanticType
,
+ SemanticMetadata
, input and output data
+ descriptions, etc.
+ consume()
to fetch()
+ and consume()
.expose()
to accept a Thing Template.
+ addListener()
,
+ removeListener()
introduced
+ onEvent()
, onPropertyChange()
,
+ onTDChange()
.ExposedThing
handlers for Property,
+ Action and Event.Observable
.The following problems are being discussed and need most + attention:
+DataSchema
better (https://github.com/w3c/wot-scripting-api/issues/89).
+ ExposedThing
(https://github.com/w3c/wot-scripting-api/issues/45).
+ Special thanks to former editor Johannes Hund (until August + 2017, when at Siemens AG) for developing this specification. + Also, the editors would like to thank Dave Raggett, Matthias + Kovatsch, Michael Koster and Michael McCool for their comments + and guidance.
+
+
+Copyright
+
+©
+2017
+
+2017-2018
+
+
+
+W3C
+
+
+
+®
+
+(
+
+
+MIT
+
+,
+
+
+ERCIM
+
+,
+
+Keio
+,
+
+Beihang
+
+).
+
+W3C
+
+
+liability
+,
+
+trademark
+
+and
+
+permissive
+document
+license
+
+rules
+apply.
+
+The + +Web +of +Things + +(WoT) +provides +layered +interoperability +between + +Things + +by +using +the + +WoT +Interface + +s. +
+
+This
+specification
+describes
+a
+programming
+interface
+representing
+the
+
+WoT
+Interface
+
+that
+allows
+scripts
+run
+on
+a
+
+Thing
+
+to
+discover
+and
+consume
+(retrieve)
+other
+
+Thing
+
+s
+and
+to
+expose
+
+Things
+
+characterized
+by
+properties,
+
+
+WoT
+Interactions
+,
+i.e.
+
+Properties
+,
+Actions
+
+and
+
+Events
+.
+
+Scripting +is +an +optional +"convenience" +building +block +in +WoT +and +it +is +typically +used +in +gateways +that +are +able +to +run +a + +WoT +Runtime + +and + +script +management +, +providing +a +convenient +way +to +extend +WoT +support +to +new +types +of +endpoints +and +implement +WoT +applications +like + +Thing +Directory +. +
++ +This +section +describes +the +status +of +this +document +at +the +time +of +its +publication. +Other +documents +may +supersede +this +document. +A +list +of +current + +W3C + +publications +and +the +latest +revision +of +this +technical +report +can +be +found +in +the + + +W3C + +technical +reports +index + +at +https://www.w3.org/TR/. + +
++Implementers +need +to +be +aware +that +this +specification +is +considered +unstable. +Vendors +interested +in +implementing +this +specification +before +it +eventually +reaches +the +Candidate +Recommendation +phase +should +subscribe +to +the + +repository + +and +take +part +in +the +discussions. +
++Please +contribute +to +this +draft +using +the + +GitHub +Issue + +feature +of +the + +WoT +Scripting +API + +repository. +For +feedback +on +security +and +privacy +considerations, +please +use +the + +WoT +Security +and +Privacy + +Issues. +
+
+This
+document
+was
+published
+by
+the
+
+Web
+of
+Things
+Working
+Group
+
+as
+a
+First
+Public
+
+Working
+Draft.
+This
+document
+is
+intended
+to
+become
+a
+
+W3C
+
+Recommendation.
+Comments
+regarding
+this
+document
+are
+welcome.
+Please
+send
+them
+to
+
+public-wot-wg@w3.org
+
+(
+
+subscribe
+,
+
+archives
+
+).
+
+Changes +from +the +previous +publication +can +be +found +in + +Appendix +A +. +A + +diff-marked +version + +of +this +document +is +also +available +for +comparison +purposes. +
+Publication
+as
+a
+First
+Public
+
+Working
+Draft
+does
+not
+imply
+endorsement
+by
+the
+
+W3C
+
+Membership.
+This
+is
+a
+draft
+document
+and
+may
+be
+updated,
+replaced
+or
+obsoleted
+by
+other
+documents
+at
+any
+time.
+It
+is
+inappropriate
+to
+cite
+this
+document
+as
+other
+than
+work
+in
+progress.
+
+This
+document
+was
+produced
+by
+a
+group
+operating
+under
+the
+5
+February
+2004
+
+
+
+W3C
+
+Patent
+Policy
+.
+
+W3C
+
+maintains
+a
+
+public
+list
+of
+any
+patent
+disclosures
+
+made
+in
+connection
+with
+the
+deliverables
+of
+the
+group;
+that
+page
+also
+includes
+instructions
+for
+disclosing
+a
+patent.
+An
+individual
+who
+has
+actual
+knowledge
+of
+a
+patent
+which
+the
+individual
+believes
+contains
+
+Essential
+Claim(s)
+
+must
+disclose
+the
+information
+in
+accordance
+with
+
+section
+6
+of
+the
+
+W3C
+
+Patent
+Policy
+.
+
+This
+document
+is
+governed
+by
+the
+
+1
+March
+2017
+
+February
+2018
+
+
+W3C
+
+Process
+Document
+.
+
+The +overall +WoT +concepts +are +described +in +the + +WoT +Architecture + +document. +The +Web +of +Things +is +made +of +entities +( + +Thing + +s) +that +can +describe +their +capabilities +in +a +machine-interpretable +format, +the + +Thing +Description + +(TD) +and +expose +these +capabilities +through +the + +WoT +Interface +. +Support +for +scripting +is +optional +for +WoT +devices. +
+
+By
+
+consuming
+a
+TD
+,
+a
+client
+
+Thing
+
+creates
+a
+runtime
+resource
+model
+that
+allows
+accessing
+the
+properties,
+
+
+Properties
+,
+Actions
+
+and
+
+Events
+
+exposed
+by
+the
+server
+
+Thing
+.
+
+Exposing
+a
+
+Thing
+
+requires
+defining
+a
+
+Thing
+Description
+
+(TD)
+
+and
+instantiating
+a
+software
+stack
+needed
+to
+serve
+requests
+for
+accessing
+the
+exposed
+properties,
+
+
+Properties
+,
+Actions
+
+and
+
+Events
+.
+This
+specification
+describes
+how
+to
+expose
+and
+consume
+
+Thing
+
+s
+by
+a
+script.
+
+Typically +scripts +are +meant +to +be +used +on +devices +able +to +provide +resources +(with +a + +WoT +interface + +) +for +managing +(installing, +updating, +running) +scripts, +such +as +bridges +or +gateways +that +expose +and +control +simpler +devices +as +WoT + +Thing + +s. +
++This +specification +does +not +make +assumptions +on +how +the + +WoT +Runtime + +handles +and +runs +scripts, +including +single +or +multiple +tenancy, +script +deployment +and +lifecycle +management. +The +API +already +supports +the +generic +mechanisms +that +make +it +possible +to +implement +script +management, +for +instance +by +exposing +a +manager + +Thing + +whose + +Actions + +(action +handlers) +implement +script +lifecycle +management +operations. +
+For +an +introduction +on +how +scripts +could +be +used +in + +Web +of +Things +, +check +the + +Primer + +document. +For +some +background +on +API +design +decisions +check +the + +Rationale + +document. +
++ +This +section +is +non-normative. + +
+
+The
+following
+scripting
+use
+cases
+are
+covered
+
+supported
+
+in
+this
+specification:
+
+ExposedThing
+
+
+to
+be
+exposed,
+
+based
+on
+a
+
+Thing
+Description
+
+ConsumedThing
+
+object.
+
+
+WoT
+
+
+object
+
+The
+WoT
+object
+is
+the
+main
+
+API
+entry
+point
+and
+it
+is
+exposed
+by
+an
+implementation
+of
+the
+
+WoT
+Runtime
+.
+The
+
+WoT
+object
+
+has
+no
+internal
+state
+and
+provides
+
+does
+not
+expose
+properties,
+only
+
+methods
+for
+discovering,
+consuming
+and
+exposing
+a
+
+Thing
+.
+
+Browser
+implementations
+
+SHOULD
+
+use
+a
+namespace
+object
+such
+as
+
+wot
+
,
+and
+
+Node.js
+
+-like
+runtimes
+
+MAY
+
+provide
+the
+API
+object
+through
+the
+
+
+require()
+
+
+or
+
+
+import
+
+
+mechanism.
+
interface "idlInterfaceID"><a data-lt="WoT" href="#dom-wot" class= +"internalDFN" data-link-type="dfn" data-for= +""> { +<span class="idlMethod" id="idl-def-wot-discover(filter)" data-idl= + +"idlInterfaceID">+WoT
{ + "idlMethType"><a href="#dfn-observable" class="internalDFN" +data-link-type="dfn">Observable<<a href="#dom-consumedthing" +class="internalDFN" data-link-type= + +"idlMethType">Observable
< +"dfn">ConsumedThing
> "idlMethName"><a data-lt="discover()|discover()|discover" +data-lt-nodefault="" href="#dom-wot-discover()" class="internalDFN" +data-link-type="dfn" data-for= +"WoT">discover<a href="#dom-thingfilter" +class="internalDFN" data-link-type= + +"idlMethName">discover(optional +"dfn">ThingFilter
filter); +<span class="idlMethod" id="idl-def-wot-consume(url)" data-idl="" +data-title="consume" data-dfn-for="wot"> <span class= ++data-title="fetch" data-dfn-for="wot"> +"idlMethType">"https://heycam.github.io/webidl/#idl-promise">Promise<<a href="#dom-consumedthing" + +"https://heycam.github.io/webidl/#idl-promise">Promise< +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-lt="consume()|consume()|consume" +data-lt-nodefault="" href="#dom-wot-consume()" class="internalDFN" +data-link-type="dfn" data-for="WoT">consume(<span class= ++"dfn">ThingDescription
> fetch( +"idlParam">USVString url); +<span class="idlMethod" id="idl-def-wot-expose(init)" data-idl="" +data-title="expose" data-dfn-for="wot"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<<a href="#dom-exposedthing" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-lt="expose()|expose()|expose" +data-lt-nodefault="" href="#dom-wot-expose()" class="internalDFN" +data-link-type="dfn" data-for="WoT">expose(<span class= +"idlParam"><a href="#dom-thinginit" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">init +}; ++data-title="consume" data-dfn-for="wot">ConsumedThing
consume(ThingDescription
td); + +data-title="produce" data-dfn-for="wot">ExposedThing
produce(ThingModel
model); +}; + +data-title="ThingDescription">typedef USVStringThingDescription
; + +data-title="ThingModel">typedef (ThingTemplate
orThingDescription
) ++ThingModel +
+; + + +
+The
+algorithms
+for
+the
+WoT
+methods
+will
+be
+specified
+later.
+
+later,
+including
+error
+handling
+and
+security
+considerations.
+
+
+discover()
+
+
+method
+
+Starts
+the
+discovery
+process
+that
+will
+provide
+
+
+
+objects
+that
+match
+the
+optional
+argument
+
+ConsumedThing
+
+
+
+
+
.
+When
+the
+argument
+is
+not
+provided,
+starts
+the
+widest
+discovery
+the
+
+Thing
+Description
+
+and
+
+Protocol
+Bindings
+
+
+ThingFilter
+
+
+.
+
+allow.
+
+allow
+and
+support.
+
+Returns
+an
+
+
+Observable
+
+
+object
+that
+can
+be
+subscribed
+to
+
+and
+unsubscribed
+to.
+
+from.
+
+
+DiscoveryMethod
+
+enumeration
+
+"idl-def-discoverymethod" data-idl="" data-title=
+"DiscoveryMethod">typedef DOMString
+
+DiscoveryMethod
+
+;
+
+DiscoveryMethod
+
+represents
+the
+discovery
+type
+to
+be
+used:
+
+ThingFilter
+
+
+dictionary
+
+The
+
+
+ThingFilter
+
+
+dictionary
+that
+represents
+the
+constraints
+for
+discovering
+
+Thing
+
+s
+as
+key-value
+pairs.
+
"ThingFilter">dictionary <a data-lt=
+"ThingFilter" href="#dom-thingfilter" class="internalDFN"
+data-link-type="dfn" data-for=
+""> {
+
+"ThingFilter">dictionary ThingFilter
{
+
+ "idlMemberType">(DiscoveryType or <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="method"
+href="#dom-thingfilter-method" class="internalDFN" data-link-type=
+"dfn" data-for=
+"ThingFilter"> = <span class=
+
+"idlMemberType">DiscoveryMethod
method
=
+"idlMemberValue">"any";
+ "https://heycam.github.io/webidl/#idl-USVString">USVString<a data-lt="url"
+href="#dom-thingfilter-url" class="internalDFN" data-link-type=
+"dfn" data-for="ThingFilter">
+<span class="idlMember" id="idl-def-thingfilter-description"
+data-idl="" data-title="description" data-dfn-for=
+"thingfilter"> <span class=
+"idlMemberType">Dictionary <span class=
+"idlMemberName"><a data-lt="description" href=
+"#dom-thingfilter-description" class="internalDFN" data-link-type=
+"dfn" data-for=
+"ThingFilter">
+
+"https://heycam.github.io/webidl/#idl-USVString">USVString url
;
+
+data-title="query" data-dfn-for="thingfilter"> USVString query
;
+
+data-idl="" data-title="constraints" data-dfn-for=
+"thingfilter"> sequence<Dictionary> constraints
;
+
+};
+
+
+
+The
+
+
+method
+
+
+property
+represents
+the
+discovery
+type
+that
+should
+be
+used
+in
+the
+discovery
+process.
+The
+possible
+values
+are
+defined
+by
+the
+
+
+
+enumeration
+that
+can
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+
+DiscoveryMethod
+
+
+
+The
+
+
+DiscoveryMethod
+
+
+enumeration
+can
+be
+extended
+by
+the
+
+Thing
+Description
+
+with
+values
+that
+are
+not
+specified
+here.
+This
+extensibility
+of
+
+
+DiscoveryMethod
+
+
+by
+proprietary
+or
+private
+methods
+is
+a
+working
+assumption
+until
+consensus
+is
+formed
+and
+may
+be
+removed
+later.
+
+The
+
+
+
+
+property
+represents
+additional
+information
+for
+the
+discovery
+method,
+such
+as
+the
+URL
+of
+the
+target
+entity
+serving
+the
+discovery
+request,
+such
+as
+a
+
+Thing
+Directory
+
+
+ThingFilter
+
+url
+
+dictionary
+may
+be
+extended
+later
+with
+further
+attributes.
+
+or
+a
+Thing.
+
+
+The
+
+
+
+
+DiscoveryMethod
+
+query
+
+enumeration
+<span class="idlEnum" id=
+"idl-def-discoverymethod" data-idl="" data-title=
+"DiscoveryMethod">enum <a data-lt=
+"DiscoveryMethod" href="#dom-discoverymethod" class="internalDFN"
+data-link-type="dfn" data-for=
+""> {
+ <a href="#dom-discoverymethod-any" class=
+"idlEnumItem">"any",
+ <a href="#dom-discoverymethod-local" class=
+"idlEnumItem">"local",
+ <a href="#dom-discoverymethod-nearby" class=
+"idlEnumItem">"nearby",
+ <a href="#dom-discoverymethod-directory" class=
+"idlEnumItem">"directory",
+ <a href="#dom-discoverymethod-broadcast" class=
+"idlEnumItem">"broadcast",
+ <a href="#dom-discoverymethod-other" class=
+"idlEnumItem">"other"
+};
+
+property
+represents
+a
+query
+string
+accepted
+by
+the
+implementation,
+for
+instance
+a
+SPARQL
+query.
+
+The
+
+
+
+DiscoveryMethod
+
+constraints
+
+enumeration
+
+
+property
+
+represents
+additional
+information
+for
+
+the
+discovery
+type
+
+method
+in
+the
+form
+of
+a
+list
+of
+sets
+of
+property-value
+pairs
+(dictionaries).
+The
+list
+elements
+(dictionaries)
+are
+in
+OR
+relationship,
+and
+within
+a
+constraint
+dictionary
+the
+key-value
+pairs
+are
+in
+AND
+relationship.
+Implementations
+
+SHOULD
+
+make
+the
+following
+mapping
+from
+the
+constraint
+dictionaries
+
+to
+be
+used:
+"
+
+
+
+
+any
+
+SemanticAnnotations
+
+"
+does
+not
+provide
+any
+restriction
+
+:
+for
+each
+property-value
+pair
+in
+a
+constraint
+dictionary,
+
+local
+
+name
+
+
+
+nearby
+
+SemanticType
+
+
++Constraints +are +experimental +feature, +implementations +are +not +required +to +support +them. +
+Semantic
+annotations
+need
+revisiting
+in
+order
+to
+simplify
+their
+representation.
+In
+the
+[
+
+WOT-TD
+
+
+]
+specification
+they
+represent
+the
+
+
+
+construct.
+At
+the
+moment
+only
+directory
+
+@type
+
+@context
+
,
+@type
+
+and
+
+@id
+
+
+constructs
+are
+used
+in
+the
+
+TD
+.
+broadcast
+
+fetch()
+
+
+
+
+Accepts
+
+an
+open
+ended
+discovery
+based
+on
+sending
+
+
+url
+
+argument
+and
+returns
+
+a
+request
+to
+
+
+
+Promise
+
+that
+resolves
+with
+
+a
+broadcast
+address
+"
+
+
+
+
.other
+
+ThingDescription
+
+ThingDescription
+
+
+
+
+Representation
+of
+
+the
+solution.
+
+
+Thing
+Description
+,
+standardized
+in
+the
+
+Wot
+Things
+Description
+
+specification.
+
+In +this +version +of +the +API, + +Thing +Description + +s +are +represented +as +opaque +strings, +denoting +a +serialized +form, +for +instance +JSON +or +JSON-LD. +See + +Issue +38 + +and + +Issue +45 +.
+consume()
+
+
+method
+
+Accepts
+an
+
+
+argument
+url
+
+td
+
+and
+returns
+a
+
+of
+type
+
+
+
+Promise
+
+
+
+ThingDescription
+
+
+of
+
+and
+returns
+
+a
+
+
+ConsumedThing
+
+.
+
+
+object
+instantiated
+based
+on
+that
+description.
+
+
+expose()
+
+produce()
+
+
+
+method
+
+Returns
+
+Accepts
+
+a
+
+model
+
+argument
+of
+type
+
+
+ThingModel
+
+Promise
+
+
+of
+a
+locally
+created
+
+and
+returns
+an
+
+
+ExposedThing
+
+
+object,
+locally
+created
+
+based
+on
+the
+provided
+initialization
+parameters.
+Editor's
+note
+The
+reason
+
+An
+
+
+ExposedThing
+
+
+s
+are
+
+can
+be
+
+created
+by
+
+in
+the
+following
+ways:
+
+ConsumedThing
+
+object),
+then
+adding
+request
+handlers.
+
+ThingModel
+
+type
+
+A
+Thing
+model
+
+is
+that
+an
+
+used
+for
+producing
+a
+new
+
+
+ExposedThing
+
+
+may
+
+and
+can
+
+be
+created
+in
+the
+local
+WoT
+Runtime
+
+either
+a
+
+ThingTemplate
+
,
+or
+in
+
+a
+remote
+runtime.
+Even
+though
+currently
+only
+local
+creation
+is
+supported,
+the
+method
+is
+designed
+with
+this
+possible
+future
+compatibility
+in
+mind.
+
+
+
+ThingDescription
+
.
+
+ThingInit
+
+SemanticAnnotations
+
+
+
+dictionary
++A +dictionary +that +provides +the +semantic +types +and +semantic +metadata. +
+"idl-def-thinginit" data-idl="" data-title=
+"ThingInit">dictionary <a data-lt=
+"ThingInit" href="#dom-thinginit" class="internalDFN"
+data-link-type="dfn" data-for=
+""> {
+<span class="idlMember" id="idl-def-thinginit-name" data-idl=""
+data-title="name" data-dfn-for="thinginit"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-thinginit-name" class="internalDFN" data-link-type="dfn"
+data-for="ThingInit">
+<span class="idlMember" id="idl-def-thinginit-url" data-idl=""
+data-title="url" data-dfn-for="thinginit"> <span class=
+
+"idl-def-semanticannotations" data-idl="" data-title=
+"SemanticAnnotations">dictionary SemanticAnnotations
{
+
+"idl-def-semanticannotations-semantictype" data-idl="" data-title=
+"semanticType" data-dfn-for="semanticannotations">
+"idlMemberType">"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-lt="url"
+href="#dom-thinginit-url" class="internalDFN" data-link-type="dfn"
+data-for="ThingInit">
+<span class="idlMember" id="idl-def-thinginit-description"
+data-idl="" data-title="description" data-dfn-for=
+"thinginit"> <span class=
+"idlMemberType">Dictionary <span class=
+"idlMemberName"><a data-lt="description" href=
+"#dom-thinginit-description" class="internalDFN" data-link-type=
+"dfn" data-for=
+"ThingInit">
+
+"https://heycam.github.io/webidl/#idl-sequence">sequence<SemanticType
> semanticType
;
+
+data-idl="" data-title="metadata" data-dfn-for=
+"semanticannotations"> sequence<SemanticMetadata
> metadata
;
+
+};
+
+
+
+The
+
+
+
+property
+denotes
+a
+list
+of
+ThingInit
+
+semanticType
+
+SemanticType
+
+objects
+that
+define
+the
+semantic
+types
+that
+can
+be
+used
+in
+semantic
+metadata
+type-value
+pairs.
+
+The
+
+metadata
+
+property
+denotes
+a
+list
+of
+
+SemanticMetadata
+
+
+
+objects
+(type-value
+pairs).
+
+SemanticType
+
+dictionary
+"idl-def-semantictype" data-idl="" data-title=
+"SemanticType">dictionary SemanticType
{
+
+data-title="name" data-dfn-for=
+"semantictype"> required DOMString name
;
+
+"" data-title="context" data-dfn-for=
+"semantictype"> required USVString context
;
+
+"" data-title="prefix" data-dfn-for=
+"semantictype"> DOMString prefix
;
+};
+
+Represents
+
+a
+Thing
+:
+
+semantic
+type
+annotation,
+containing
+a
+name,
+a
+context
+and
+a
+prefix.
+
+
+name
+
+
+attribute
+represents
+the
+
+url
+
+context
+
+
+
+attribute
+represents
+an
+URL
+link
+to
+
+the
+
+description
+
+prefix
+
+attribute
+represents
+a
+short
+prefix
+associated
+with
+a
+context.
++Semantic +type +examples +to +be +added. +
+SemanticMetadata
+
+dictionary
+
+"idl-def-semanticmetadata" data-idl="" data-title=
+"SemanticMetadata">dictionary SemanticMetadata
{
+
+data-idl="" data-title="type" data-dfn-for=
+"semanticmetadata"> SemanticType
type
;
+
+data-idl="" data-title="value" data-dfn-for=
+"semanticmetadata"> any value
;
+};
+
+The
+
+SemanticMetadata
+
+dictionary
+describes
+a
+pair
+of
+semantic
+type
+and
+value:
+
+type
+
+
+
+attribute
+represents
+the
+semantic
+type
+name
+defined
+by
+a
+
+SemanticType
+
+object.
+
+value
+
+attribute
+represents
+the
+metadata
+value.
+
+ThingTemplate
+
+dictionary
+
+A
+Thing
+Template
+is
+a
+dictionary
+that
+provides
+a
+user
+given
+name,
+and
+the
+semantic
+types
+and
+semantic
+metadata
+attached
+to
+the
+
+ExposedThing
+
+Thing
+Description
+
+'s
+root
+level.
+
+"idl-def-thingtemplate" data-idl="" data-title=
+"ThingTemplate">dictionary ThingTemplate
: SemanticAnnotations
{
+
+data-title="name" data-dfn-for=
+"thingtemplate"> required DOMString name
;
+};
+
+The
+
+ThingTemplate
+
+dictionary
+extends
+
+SemanticAnnotations
+
+and
+contains
+properties
+to
+initialize
+a
+
+Thing
+:
+name
+
+attribute
+represents
+the
+user
+given
+name
+
+of
+the
+
+Thing
+.
++Support +for +configuration +and +security +data +might +be +added +later. +
"hljs-keyword">let discoveryFilter = {
+ method:
+"hljs-string">"directory",
+ url:
+"hljs-string">"http://directory.wotservice.org"
+};
+
+"hljs-keyword">let subscription = wot.discover(discoveryType).subscribe(
+
+"hljs-keyword">let subscription = wot.discover(discoveryFilter).subscribe(
+
+ thing => { console.log("hljs-string">"Found Thing " + thing.url); },
+
+"hljs-string">"Found Thing " + thing.name); },
+
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout(
+ <span class=
+"hljs-params">()); },
+
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log(
+"hljs-string">"Discovery timeout");
+ },
+
+
+5000
+
+);
+
+
+Note
+that
+canceling
+a
+discovery
+(through
+unsubscribe)
+
+
+unsubscribe()
+
+)
+
+may
+not
+be
+successful
+in
+all
+cases,
+for
+instance
+when
+discovery
+is
+based
+on
+open
+ended
+broadcast
+requests.
+However,
+once
+
+unsubscribe()
+
+has
+been
+called,
+implementations
+
+MUST
+
+suppress
+further
+event
+handling
+(
+i.e.
+further
+discoveries
+and
+errors)
+on
+the
+Observable.
+Also,
+a
+discovery
+error
+may
+not
+mean
+the
+end
+of
+the
+discovery
+process.
+However,
+in
+order
+to
+respect
+Observable
+semantics
+(error
+always
+terminates
+processing),
+implementations
+
+MUST
+
+close
+or
+suppress
+further
+event
+handling
+on
+the
+Observable.
+
let subscription = wot.discover({ method: "local" }).subscribe(
+ thing => { console.log("hljs-string">"Found local Thing " + thing.url); },
+
+"hljs-string">"Found local Thing " + thing.name); },
+
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+
+"hljs-keyword">let subscription = wot.discover({ method: "local" }).subscribe({
+ thing => { console.log("Found local Thing " + thing.name); },
+ error:
+"hljs-function">err => { console.log("Discovery error: " + err.message); },
+ complete:
+"hljs-function">() => { console.log("Discovery finished successfully");}
+});
+
"hljs-keyword">let subscription = wot.discover({
+ method:
+"hljs-string">"nearby",
+ constraints: [{
+"hljs-attr">protocol: "BLE-4.2" }, { protocol: "NFC"}]
+}).subscribe(
+
+ thing => { console.log("hljs-string">"Found nearby Thing " + thing.url); },
+
+"hljs-string">"Found nearby Thing " + thing.name); },
+
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+"hljs-keyword">let subscription = wot.discover({
+ method:
+"hljs-string">"other",
+ constraints: [{
+"hljs-attr">solution: "XYZ123", key: "..."}]
+}).subscribe(
+
+ thing => { console.log("hljs-string">"Found Thing " + thing.url); },
+
+"hljs-string">"Found Thing " + thing.name); },
+
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+
+ConsumedThing
+
+
+interface
+
+The
+
+
+ConsumedThing
+
+
+interface
+is
+a
+client
+API
+for
+sending
+requests
+to
+servers
+in
+order
+to
+retrieve
+or
+update
+properties,
+
+
+Properties
+,
+invoke
+
+Actions
+,
+and
+observe
+properties,
+Actions
+
+
+Properties
+
+
+and
+
+Events
+.
+
"ConsumedThing">interface <a data-lt=
+"ConsumedThing" href="#dom-consumedthing" class="internalDFN"
+data-link-type="dfn" data-for=
+""> {
+
+"ConsumedThing">interface ConsumedThing
{
+
+ readonly attribute "https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-consumedthing-name" class="internalDFN" data-link-type=
+"dfn" data-for="ConsumedThing">
+<span class="idlAttribute" id="idl-def-consumedthing-url" data-idl=
+"" data-title="url" data-dfn-for=
+"consumedthing"> readonly attribute <span class=
+"idlAttrType"><a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-lt="url"
+href="#dom-consumedthing-url" class="internalDFN" data-link-type=
+"dfn" data-for="ConsumedThing">
+<span class="idlAttribute" id="idl-def-consumedthing-description"
+data-idl="" data-title="description" data-dfn-for=
+"consumedthing"> readonly attribute <span class=
+"idlAttrType"><a href="#dom-thingdescription" class="internalDFN"
+
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString name
;
+
+"idl-def-consumedthing-getthingdescription" data-idl="" data-title=
+"getThingDescription" data-dfn-for="consumedthing">
+data-link-type=
+"dfn">ThingDescription
"idlAttrName"><a data-lt="description" href=
+"#dom-consumedthing-description" class="internalDFN"
+data-link-type="dfn" data-for=
+"ConsumedThing">
+<span class="idlMethod" id=
+"idl-def-consumedthing-invokeaction(name,parameters)" data-idl=""
+data-title="invokeAction" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="invokeAction()|invokeaction()|invokeAction"
+data-lt-nodefault="" href="#dom-consumedthing-invokeaction()"
+class="internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">invokeAction(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+<span class="idlMethod" id=
+"idl-def-consumedthing-setproperty(name,value)" data-idl=""
+data-title="setProperty" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="setProperty()|setproperty()|setProperty"
+data-lt-nodefault="" href="#dom-consumedthing-setproperty()" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">setProperty(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+
+"idlMethName">getThingDescription();
+
+"idl-def-consumedthing-getproperty(name)" data-idl="" data-title=
+"getProperty" data-dfn-for="consumedthing"> <span class=
+
+"idl-def-consumedthing-readproperty-name" data-idl="" data-title=
+"readProperty" data-dfn-for="consumedthing">
+"idlMethType">"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="getProperty()|getproperty()|getProperty"
+data-lt-nodefault="" href="#dom-consumedthing-getproperty()" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">getProperty(<span class=
+
+"https://heycam.github.io/webidl/#idl-promise">Promise<any> readProperty(
+"idlParam">DOMString name);
+"idl-def-consumedthing-addlistener(eventname,listener)" data-idl=""
+data-title="addListener" data-dfn-for=
+
+"idl-def-consumedthing-writeproperty-name-value" data-idl=""
+data-title="writeProperty" data-dfn-for=
+
+"consumedthing"> "#dom-consumedthing" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-lt="addListener()|addlistener()|addListener"
+data-lt-nodefault="" href="#dom-consumedthing-addlistener()" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">addListener(<span class=
+
+"https://heycam.github.io/webidl/#idl-promise">Promise<void> writeProperty(
+"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a href="#dom-thingeventlistener"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">listener
+
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString name, any value);
+
+"idl-def-consumedthing-removelistener(eventname,listener)"
+data-idl="" data-title="removeListener" data-dfn-for=
+
+"idl-def-consumedthing-invokeaction-name-parameters" data-idl=""
+data-title="invokeAction" data-dfn-for=
+
+"consumedthing"> "#dom-consumedthing" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-lt=
+"removeListener()|removelistener()|removeListener"
+data-lt-nodefault="" href="#dom-consumedthing-removelistener()"
+class="internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">removeListener(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString,
+ <span class=
+
+"https://heycam.github.io/webidl/#idl-promise">Promise<any> invokeAction(
+"idlParam">"#dom-thingeventlistener" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">listener
+
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString name, any parameters);
+
+"idl-def-consumedthing-removealllisteners(eventname)" data-idl=""
+data-title="removeAllListeners" data-dfn-for=
+
+"idl-def-consumedthing-onpropertychange-name" data-idl=""
+data-title="onPropertyChange" data-dfn-for=
+
+"consumedthing"> "#dom-consumedthing" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-lt=
+"removeAllListeners()|removealllisteners()|removeAllListeners"
+data-lt-nodefault="" href="#dom-consumedthing-removealllisteners()"
+class="internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">removeAllListeners(<span class=
+"idlParam">optional <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+<span class="idlMethod" id=
+"idl-def-consumedthing-observe(name,requesttype)" data-idl=""
+data-title="observe" data-dfn-for="consumedthing"> <span class=
+"idlMethType"><a href="#dfn-observable" class="internalDFN"
+data-link-type="dfn">Observable <span class=
+"idlMethName"><a data-lt="observe()|observe()|observe"
+data-lt-nodefault="" href="#dom-consumedthing-observe()" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ConsumedThing">observe(<span class=
+
+"#dom-observable" class="internalDFN" data-link-type=
+"dfn">Observable
onPropertyChange(
+"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a href="#dom-requesttype"
+
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString name);
+
+data-idl="" data-title="onEvent" data-dfn-for=
+"consumedthing"> Observable
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">requestType
+};
+<span class="idlCallback" id="idl-def-thingeventlistener" data-idl=
+"" data-title="ThingEventListener">callback <span class=
+"idlCallbackID"><a data-lt="ThingEventListener" href=
+"#dom-thingeventlistener" class="internalDFN" data-link-type="dfn"
+data-for=
+""> = <span class=
+"idlCallbackType">void<span class=
+"idlParamType"><a href="#dfn-event" class="internalDFN"
+data-link-type="dfn">Event <span class=
+"idlParamName">
+event
+);
+
+"dfn">onEvent(DOMString name);
+
+data-idl="" data-title="onTDChange" data-dfn-for=
+"consumedthing"> Observable
onTDChange();
+};
+
+
+
+
+Represents
+
+
+ConsumedThing
+
+represents
+
+a
+local
+proxy
+object
+of
+the
+remote
+
+Thing
+.
+
+name
+
+
+
+The
+
+
+url
+
+name
+
+read-only
+attribute
+
+property
+
+represents
+the
+URL
+
+name
+
+of
+the
+
+Thing
+
+as
+specified
+in
+the
+
+TD
+
+.
+In
+this
+version
+it
+is
+read
+only.
+
+description
+
+getThingDescription()
+
+
+
+
+Returns
+
+the
+description
+
+
+Thing
+Description
+
+of
+the
+
+Thing
+.
+
+In +this +version, +introspection +based +on + +TD + +is +out +of +scope. + +Parsing +and +exposing + +Thing +Description + +s +is +discussed +in + +Issue +38 +. +
+
+invokeAction()
+
+readProperty()
+
+
+
+method
+
+Takes
+the
+Action
+
+
+Property
+
+
+name
+from
+
+as
+
+the
+
+name
+
+argument
+and
+the
+list
+of
+parameters,
+
+argument,
+
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+invoke
+
+retrieve
+
+the
+Action
+
+
+Property
+
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+the
+return
+
+
+Property
+
+value
+or
+rejects
+with
+an
+
+Error
+.
+
+setProperty()
+
+writeProperty()
+
+
+
+method
+
+Takes
+the
+
+Property
+
+name
+as
+the
+
+name
+
+argument
+and
+the
+new
+value
+as
+the
+
+value
+
+argument,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+update
+the
+
+Property
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+on
+success
+or
+rejects
+with
+an
+
+Error
+.
+
+getProperty()
+
+invokeAction()
+
+
+
+method
+
+Takes
+the
+Property
+
+
+Action
+
+
+name
+as
+
+from
+
+the
+
+name
+
+argument,
+
+argument
+and
+the
+list
+of
+parameters,
+
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+
+Protocol
+Bindings
+
+to
+retrieve
+
+invoke
+
+the
+Property
+
+
+Action
+
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+the
+Property
+
+return
+
+value
+or
+rejects
+with
+an
+
+Error
+.
+
+addListener()
+
+onPropertyChange()
+
+
+
+method
+
+Adds
+the
+listener
+provided
+in
+the
+argument
+listener
+to
+the
+Event
+name
+provided
+in
+the
+argument
+eventName
+.
+4.5
+The
+
+Returns
+an
+
+
+
+removeListener()
+
+Observable
+
+method
+Removes
+a
+listener
+from
+
+
+for
+
+the
+Event
+
+
+Property
+
+
+identified
+by
+
+specified
+in
+
+the
+provided
+
+
+eventName
+
+name
+
+
+argument,
+allowing
+subscribing
+to
+
+and
+listener
+argument.
+
+unsubscribing
+from
+notifications.
+
+
+The
+callback
+function
+passed
+to
+the
+
+
+
+method
+removeAllListeners()
+
+subscribe()
+
+Removes
+all
+listeners
+for
+
+when
+invoked
+on
+
+the
+Event
+provided
+by
+
+returned
+observer
+will
+receive
+
+the
+eventName
+optional
+argument,
+or
+if
+that
+was
+not
+provided,
+then
+removes
+all
+listeners
+from
+all
+Events
+.
+
+new
+property
+value
+each
+time
+it
+is
+changed.
+
+
+observe()
+
+onEvent()
+
+
+
+method
+
+Returns
+an
+
+
+Observable
+
+
+for
+the
+Property
+,
+
+
+Event
+
+or
+Action
+
+specified
+in
+the
+
+name
+
+argument,
+allowing
+subscribing
+to
+
+and
+unsubscribing
+to
+
+from
+
+notifications.
+The
+requestType
+specifies
+whether
+a
+Property
+,
+an
+Event
+or
+an
+Action
+is
+observed.
+Editor's
+note
+The
+observe()
+method
+could
+replace
+addListener()
+and
+removeListener()
+,
+though
+they
+could
+be
+kept
+for
+convenience.
+
+
+The
+ThingEventListener
+
+callback
+A
+
+function
+called
+with
+an
+Event
+object
+when
+an
+event
+is
+emitted.
+4.9
+Events
+Clients
+can
+subscribe
+
+passed
+
+to
+the
+Events
+defined
+in
+ExposedThing
+events
+.
+The
+event
+types
+are
+described
+in
+this
+section.
+4.9.1
+The
+PropertyChangeEvent
+interface
+<span class="idlInterface" id=
+"idl-def-propertychangeevent" data-idl="" data-title=
+"PropertyChangeEvent">[<span class=
+"extAttrName"><a href=
+"https://heycam.github.io/webidl/#Constructor">Constructor<a href="#dom-propertychangeeventinit"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">init]
+interface <a data-lt=
+"PropertyChangeEvent" href="#dom-propertychangeevent" class=
+"internalDFN" data-link-type="dfn" data-for=
+""> : <span class=
+"idlSuperclass"><a href="#dfn-event" class="internalDFN"
+data-link-type="dfn">Event {
+<span class="idlAttribute" id="idl-def-propertychangeevent-data"
+data-idl="" data-title="data" data-dfn-for=
+"propertychangeevent"> readonly attribute <span class=
+"idlAttrType"><a href="#dom-propertychangeeventinit" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlAttrName"><a data-lt="data" href=
+"#dom-propertychangeevent-data" class="internalDFN" data-link-type=
+"dfn" data-for=
+"PropertyChangeEvent">
+};
+The
+data
+attribute
+represents
+the
+changed
+Property
+.
+4.9.1.1
+The
+PropertyChangeEventInit
+dictionary
+<span class="idlDictionary" id=
+"idl-def-propertychangeeventinit" data-idl="" data-title=
+"PropertyChangeEventInit">dictionary <span class=
+"idlDictionaryID"><a data-lt="PropertyChangeEventInit" href=
+"#dom-propertychangeeventinit" class="internalDFN" data-link-type=
+"dfn" data-for=""> {
+<span class="idlMember" id="idl-def-propertychangeeventinit-name"
+data-idl="" data-title="name" data-dfn-for=
+"propertychangeeventinit"> <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-propertychangeeventinit-name" class="internalDFN"
+data-link-type="dfn" data-for=
+"PropertyChangeEventInit">
+<span class="idlMember" id="idl-def-propertychangeeventinit-value"
+data-idl="" data-title="value" data-dfn-for=
+"propertychangeeventinit"> <a href=
+"https://heycam.github.io/webidl/#idl-any">any<a data-lt="value"
+href="#dom-propertychangeeventinit-value" class="internalDFN"
+data-link-type="dfn" data-for=
+"PropertyChangeEventInit">
+};
+The
+
+
+
+name
+>
+attribute
+represents
+the
+Property
+name.
+The
+value
+
+subscribe()
+
+attribute
+represents
+the
+new
+value
+of
+
+method
+when
+invoked
+on
+
+the
+Property
+.
+4.9.2
+The
+ActionInvocationEvent
+interface
+<span class="idlInterface" id=
+"idl-def-actioninvocationevent" data-idl="" data-title=
+"ActionInvocationEvent">[<span class=
+"extAttrName"><a href=
+"https://heycam.github.io/webidl/#Constructor">Constructor<a href="#dom-actioninvocationeventinit"
+class="internalDFN" data-link-type=
+"dfn">]
+interface <a data-lt=
+"ActionInvocationEvent" href="#dom-actioninvocationevent" class=
+"internalDFN" data-link-type="dfn" data-for=
+""> : <span class=
+"idlSuperclass"><a href="#dfn-event" class="internalDFN"
+data-link-type="dfn">Event {
+<span class="idlAttribute" id="idl-def-actioninvocationevent-data"
+data-idl="" data-title="data" data-dfn-for=
+"actioninvocationevent"> readonly attribute <span class=
+"idlAttrType"><a href="#dom-actioninvocationeventinit" class=
+"internalDFN" data-link-type=
+"dfn"><a data-lt="data"
+href="#dom-actioninvocationevent-data" class="internalDFN"
+data-link-type="dfn" data-for=
+"ActionInvocationEvent">
+};
+The
+data
+attribute
+represents
+
+returned
+observer
+will
+receive
+
+the
+notification
+
+event
+
+data
+from
+the
+Action
+invocation.
+4.9.2.1
+The
+ActionInvocationEventInit
+dictionary
+<span class="idlDictionary" id=
+"idl-def-actioninvocationeventinit" data-idl="" data-title=
+"ActionInvocationEventInit">dictionary <span class=
+"idlDictionaryID"><a data-lt="ActionInvocationEventInit" href=
+"#dom-actioninvocationeventinit" class="internalDFN"
+data-link-type="dfn" data-for=
+""> {
+<span class="idlMember" id=
+"idl-def-actioninvocationeventinit-actionname" data-idl=""
+data-title="actionName" data-dfn-for=
+"actioninvocationeventinit"> <span class=
+"idlMemberType"><a data-lt="actionName"
+href="#dom-actioninvocationeventinit-actionname" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ActionInvocationEventInit">
+<span class="idlMember" id=
+"idl-def-actioninvocationeventinit-returnvalue" data-idl=""
+data-title="returnValue" data-dfn-for=
+"actioninvocationeventinit"> <span class=
+"idlMemberType"><a data-lt="returnValue"
+href="#dom-actioninvocationeventinit-returnvalue" class=
+"internalDFN" data-link-type="dfn" data-for=
+"ActionInvocationEventInit">
+};
+Editor's
+note
+Action
+parameters
+could
+be
+also
+included,
+but
+it's
+debatable
+because
+privacy
+reasons.
+The
+actionName
+attribute
+represents
+the
+name
+of
+the
+Action
+that
+has
+been
+invoked.
+The
+returnValue
+attribute
+represents
+the
+return
+value
+of
+
+each
+time
+
+the
+Action
+.
+
+event
+is
+fired.
+
+
+ThingDescriptionChangeEvent
+
+onTDChange()
+
+
+
+
+The
+
+Returns
+an
+
+
+
+data
+
+Observable
+
+attribute
+represents
+the
+changes
+that
+occurred
+
+,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications
+
+to
+the
+
+Thing
+Description
+.
+
+The
+property
+value
+tells
+
+callback
+function
+passed
+to
+
+the
+operation
+was
+applied
+on
+a
+Property
+definition.
+The
+
+
+
+action
+
+subscribe()
+
+value
+tells
+the
+operation
+was
+applied
+
+method
+when
+invoked
+
+on
+a
+action
+definition.
+The
+event
+value
+tells
+
+the
+operation
+was
+applied
+on
+an
+event
+definition.
+4.9.3.1.3
+The
+TDChangeData
+type
+Represents
+
+returned
+observer
+will
+receive
+
+the
+new
+description
+of
+the
+changed
+element.
+Depending
+on
+the
+change
+type,
+
+
+Thing
+Description
+
+each
+time
+
+it
+can
+be
+either
+a
+ThingPropertyInit
+,
+ThingActionInit
+,
+or
+ThingEventInit
+.
+
+is
+changed.
+
+
+Below
+a
+
+
+
+interface
+example
+is
+given.
+
+ConsumedThing
+
+
+
try { + let td = await wot.fetch("http://mmyservice.org/mySensor"); + let thing = wot.consume(td); + console.log("Thing " + thing.name + " has been consumed."); + let subscription = thing.onPropertyChange("temperature") + .subscribe(function(value) { + console.log("Temperature + " has changed to " + value); + }); + thing.invokeAction("startMeasurement", { units: "Celsius" }) + .then(() => { console.log("Temperature measurement started."); }) + .catch(e => { + console.log("Error starting measurement."); + subscription.unsubscribe(); + }) +} catch(error) { + console.log("Error during fetch or consume: " + error.message); +}; + ++
+ExposedThing
+
+
+interface
+
+The
+
+
+ExposedThing
+
+
+interface
+is
+the
+server
+API
+that
+allows
+defining
+request
+handlers,
+properties,
+
+Actions
+,
+and
+
+Events
+
+to
+a
+
+Thing
+.
+It
+also
+implements
+the
+
+ConsumedThing
+
+interface.
+An
+
+ExposedThing
+
+is
+created
+by
+the
+
+produce()
+
+method.
+
+
+It
+is
+under
+consideration
+to
+use
+a
+constructor
+for
+
+ExposedThing
+
+instead
+of
+a
+factory
+method.
+
+"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn">+ExposedThing
implementsConsumedThing
; + +interface "idlInterfaceID"><a data-lt="ExposedThing" href="#dom-exposedthing" +class="internalDFN" data-link-type="dfn" data-for= +""> { + +"idlInterfaceID">ExposedThing
{ + +"idlSectionComment"> // define how to expose and run the Thing + +data-title="start" data-dfn-for="exposedthing"> Promise<void> start(); + +data-title="stop" data-dfn-for="exposedthing"> Promise<void> stop(); + +"idl-def-exposedthing-register-directory" data-idl="" data-title= +"register" data-dfn-for="exposedthing"> Promise<void> register(optional USVString directory); + +"idl-def-exposedthing-unregister-directory" data-idl="" data-title= +"unregister" data-dfn-for="exposedthing"> Promise<void> unregister(optional USVString directory); + +"idl-def-exposedthing-emitevent-eventname-payload" data-idl="" +data-title="emitEvent" data-dfn-for="exposedthing"> Promise<void> emitEvent(DOMString eventName, any payload); + + // define Thing Description modifiers +"idl-def-exposedthing-addproperty(property)" data-idl="" +data-title="addProperty" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= + +"idl-def-exposedthing-addproperty-property" data-idl="" data-title= +"addProperty" data-dfn-for="exposedthing"> +"dfn">ExposedThing
"idlMethName"><a data-lt="addProperty()|addproperty()|addProperty" +data-lt-nodefault="" href="#dom-exposedthing-addproperty()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">addProperty(<span class= +"idlParam"><a href= +"#dom-thingpropertyinit" class="internalDFN" data-link-type= +"dfn"> <span class= + +"idlMethName">addProperty(ThingProperty
+"idlParamName">property); +"idl-def-exposedthing-removeproperty(name)" data-idl="" data-title= + +"idl-def-exposedthing-removeproperty-name" data-idl="" data-title= + +"removeProperty" data-dfn-for="exposedthing">ExposedThing
"idlMethName"><a data-lt= +"removeProperty()|removeproperty()|removeProperty" +data-lt-nodefault="" href="#dom-exposedthing-removeproperty()" +class="internalDFN" data-link-type="dfn" data-for= +"ExposedThing">removeProperty(<span class= + +"idlMethName">removeProperty( +"idlParam">DOMString name); +<span class="idlMethod" id="idl-def-exposedthing-addaction(action)" ++ExposedThing
"idlMethName"><a data-lt="addAction()|addaction()|addAction" +data-lt-nodefault="" href="#dom-exposedthing-addaction()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">addAction(<span class= +"idlParam"><a href= +"#dom-thingactioninit" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">action +<span class="idlMethod" id= +"idl-def-exposedthing-removeaction(name)" data-idl="" data-title= +"removeAction" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" + +"idlMethName">addAction( +data-link-type= +"dfn">ThingAction
action); + +data-idl="" data-title="removeAction" data-dfn-for= +"exposedthing"> +"dfn">ExposedThing
"idlMethName"><a data-lt= +"removeAction()|removeaction()|removeAction" data-lt-nodefault="" +href="#dom-exposedthing-removeaction()" class="internalDFN" +data-link-type="dfn" data-for= +"ExposedThing">removeAction(<span class= + +"idlMethName">removeAction( +"idlParam">DOMString name); +<span class="idlMethod" id="idl-def-exposedthing-addevent(event)" ++ExposedThing
"idlMethName"><a data-lt="addEvent()|addevent()|addEvent" +data-lt-nodefault="" href="#dom-exposedthing-addevent()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">addEvent(<span class= +"idlParam"><a href="#dom-thingeventinit" + +"idlMethName"> +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">event +<span class="idlMethod" id="idl-def-exposedthing-removeevent(name)" ++"dfn">addEvent(ThingEvent
event); +ExposedThing
"idlMethName"><a data-lt="removeEvent()|removeevent()|removeEvent" +data-lt-nodefault="" href="#dom-exposedthing-removeevent()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">removeEvent(<span class= +"idlParam"><a href= + +"idlMethName">removeEvent( +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name); + // define request handlers +"idl-def-exposedthing-onretrieveproperty(handler)" data-idl="" +data-title="onRetrieveProperty" data-dfn-for= + +"idl-def-exposedthing-setpropertyreadhandler-name-readhandler" +data-idl="" data-title="setPropertyReadHandler" data-dfn-for= + +"exposedthing">ExposedThing
"idlMethName"><a data-lt= +"onRetrieveProperty()|onretrieveproperty()|onRetrieveProperty" +data-lt-nodefault="" href="#dom-exposedthing-onretrieveproperty()" +class="internalDFN" data-link-type="dfn" data-for= +"ExposedThing">onRetrieveProperty(<span class= +"idlParam"><a href="#dom-requesthandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">handler + +"idlMethName">setPropertyReadHandler(DOMString name, + +"idlParam">PropertyReadHandler
readHandler); + +"idl-def-exposedthing-onupdateproperty(handler)" data-idl="" +data-title="onUpdateProperty" data-dfn-for= + +"idl-def-exposedthing-setpropertywritehandler-name-writehandler" +data-idl="" data-title="setPropertyWriteHandler" data-dfn-for= + +"exposedthing">ExposedThing
"idlMethName"><a data-lt= +"onUpdateProperty()|onupdateproperty()|onUpdateProperty" +data-lt-nodefault="" href="#dom-exposedthing-onupdateproperty()" +class="internalDFN" data-link-type="dfn" data-for= +"ExposedThing">onUpdateProperty(<span class= +"idlParam"><a href="#dom-requesthandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">handler + +"idlMethName">setPropertyWriteHandler(DOMString name, + +"idlParam">PropertyWriteHandler
writeHandler); + +"idl-def-exposedthing-oninvokeaction(handler)" data-idl="" +data-title="onInvokeAction" data-dfn-for= + +"idl-def-exposedthing-setactionhandler-name-action" data-idl="" +data-title="setActionHandler" data-dfn-for= + +"exposedthing">ExposedThing
"idlMethName"><a data-lt= +"onInvokeAction()|oninvokeaction()|onInvokeAction" +data-lt-nodefault="" href="#dom-exposedthing-oninvokeaction()" +class="internalDFN" data-link-type="dfn" data-for= +"ExposedThing">onInvokeAction(<span class= +"idlParam"><a href="#dom-requesthandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">handler +<span class="idlMethod" id= +"idl-def-exposedthing-onobserve(handler)" data-idl="" data-title= +"onObserve" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" +data-link-type= +"dfn"> <span class= +"idlMethName"><a data-lt="onObserve()|onobserve()|onObserve" +data-lt-nodefault="" href="#dom-exposedthing-onobserve()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">onObserve(<span class= +"idlParam"><a href="#dom-requesthandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">handler +<span class= +"idlSectionComment"> // define how to expose and run the Thing +<span class="idlMethod" id= +"idl-def-exposedthing-register(directory)" data-idl="" data-title= +"register" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="register()|register()|register" +data-lt-nodefault="" href="#dom-exposedthing-register()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">register(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id= +"idl-def-exposedthing-unregister(directory)" data-idl="" +data-title="unregister" data-dfn-for= +"exposedthing"> <a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="unregister()|unregister()|unregister" +data-lt-nodefault="" href="#dom-exposedthing-unregister()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">unregister(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id="idl-def-exposedthing-start()" data-idl= +"" data-title="start" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="start()|start()|start" +data-lt-nodefault="" href="#dom-exposedthing-start()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">start +<span class="idlMethod" id="idl-def-exposedthing-stop()" data-idl= +"" data-title="stop" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="stop()|stop()|stop" +data-lt-nodefault="" href="#dom-exposedthing-stop()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">stop +<span class="idlMethod" id= +"idl-def-exposedthing-emitevent(eventname,payload)" data-idl="" +data-title="emitEvent" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-lt="emitEvent()|emitevent()|emitEvent" +data-lt-nodefault="" href="#dom-exposedthing-emitevent()" class= +"internalDFN" data-link-type="dfn" data-for= +"ExposedThing">emitEvent(<span class= + +"idlMethName">setActionHandler( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,ActionHandler
action); + +}; +<a href="#dom-exposedthing" class= +"internalDFN" data-link-type= +"dfn"> implements <a href= +"#dom-consumedthing" class="internalDFN" data-link-type= +"dfn"> ++data-idl="" data-title="PropertyReadHandler">callbackPropertyReadHandler
= Promise<any> (); + +ConsumedThing ++data-idl="" data-title="PropertyWriteHandler">callbackPropertyWriteHandler
= Promise<void> (any value); + +data-title="ActionHandler">callbackActionHandler
= +Promise + + +; ++< + +href="https://heycam.github.io/webidl/#idl-any"> +any + +> + +( + +any + +parameters + +); + + +
+ThingDescription
+
+start()
+
+
+
+
+WoT
+provides
+a
+unified
+representation
+
+Start
+serving
+external
+requests
+
+for
+data
+exchange
+between
+Thing
+s,
+standardized
+in
+the
+Wot
+Things
+Description
+specification.
+Note
+In
+this
+version
+of
+
+the
+API,
+
+
+Thing
+Description
+s
+are
+represented
+as
+opaque
+strings,
+denoting
+a
+serialized
+form,
+for
+instance
+JSON
+or
+JSON-LD.
+See
+Issue
+38
+and
+Issue
+45
+
+.
+Parsing
+and
+composing
+Thing
+Description
+s
+is
+left
+for
+external
+libraries
+until
+standardized
+here.
+
+
+Request
+
+stop()
+
+
+
+
+Represents
+an
+incoming
+request
+
+Stop
+serving
+external
+requests
+for
+
+the
+
+Thing
+.
+ExposedThing
+
+register()
+
+
+
+method
+
+Generates
+the
+
+Thing
+Description
+
+
+is
+supposed
+to
+handle,
+for
+instance
+retrieving
+and
+updating
+
+given
+the
+
+properties,
+invoking
+
+
+Actions
+
+and
+observing
+Events
+
+
+Event
+
+
+(WoT
+interactions).
+The
+type
+attribute
+represents
+the
+type
+of
+the
+request
+as
+
+defined
+in
+RequestType
+.
+The
+
+for
+this
+object.
+If
+a
+
+
+
+from
+
+directory
+
+attribute
+represents
+the
+address
+of
+the
+client
+device
+issuing
+the
+request.
+The
+type
+of
+the
+address
+(URL,
+UUID
+or
+other)
+
+argument
+
+is
+defined
+by
+
+given,
+make
+a
+request
+to
+register
+
+the
+
+Thing
+Description
+.
+The
+name
+attribute
+represents
+the
+name
+of
+the
+Property
+
+
+to
+be
+retrieved
+or
+updated,
+or
+the
+name
+of
+the
+invoked
+Action
+,
+or
+the
+event
+name
+to
+be
+observed.
+The
+options
+attribute
+represents
+the
+options
+relevant
+to
+the
+request
+(e.g.
+the
+format
+or
+measurement
+units
+for
+
+with
+
+the
+returned
+value)
+as
+key-value
+pairs.
+The
+exact
+format
+is
+specified
+
+given
+WoT
+repository
+
+by
+the
+Thing
+Description
+.
+The
+
+invoking
+its
+
+
+
+data
+
+register
+
+attribute
+represents
+the
+value
+of
+the
+Property
+,
+or
+the
+input
+data
+(arguments)
+of
+an
+
+
+Action
+.
+It
+is
+not
+used
+for
+retrieve
+requests
+and
+event
+requests,
+only
+for
+Property
+update
+and
+Action
+invocation
+requests.
+5.2.1
+The
+RequestType
+
+
+property
+
+unregister()
+
+
+
+
+If
+
+a
+Property
+.
+The
+value
+"
+action
+"
+represents
+requests
+to
+invoke
+an
+Action
+.
+The
+value
+"
+event
+"
+represents
+requests
+to
+emit
+an
+event.
+The
+value
+"
+
+
+
+td
+
+directory
+
+"
+represents
+requests
+
+argument
+is
+given,
+make
+a
+request
+
+to
+change
+
+unregister
+
+the
+
+Thing
+Description
+,
+i.e.
+to
+add,
+remove
+or
+modify
+properties,
+Actions
+
+
+or
+Events
+.
+Editor's
+note
+This
+functionality
+is
+here
+for
+
+with
+
+the
+sake
+of
+completeness
+for
+future
+versions
+of
+
+given
+WoT
+repository
+by
+invoking
+its
+
+unregister
+
+Action
+.
+Then,
+and
+in
+
+the
+API.
+Currently
+there
+is
+
+case
+
+no
+corresponding
+functionality
+at
+
+arguments
+were
+provided
+to
+this
+function,
+stop
+
+the
+ConsumedThing
+
+
+Thing
+
+
+level
+
+and
+it
+is
+not
+guaranteed
+that
+a
+
+remove
+the
+
+Thing
+Description
+could
+be
+remotely
+changed
+by
+scripting.
+
+.
+
+respond()
+
+emitEvent()
+
+
+
+method
+
+Sends
+a
+positive
+response
+to
+
+Emits
+an
+the
+event
+initialized
+with
+the
+event
+name
+specified
+by
+
+the
+
+
+Request
+
+eventName
+
+based
+on
+the
+Protocol
+Bindings
+
+argument
+
+and
+includes
+the
+
+data
+specified
+by
+the
+data
+
+
+payload
+
+argument.
+
+respondWithError()
+
+DataSchema
+
+
+
+
+"idl-def-dataschema" data-idl="" data-title=
+"DataSchema">typedef USVString
+
+
+Request
+
+DataSchema
+
+
+
+based
+on
+the
+Protocol
+Bindings
+and
+includes
+the
+error
+specified
+by
+the
+error
+argument.
+
+5.3
+
+
+;
+
+The
+
+
+
+RequestHandler
+
+DataSchema
+
+callback
+Callback
+function
+for
+handling
+interaction
+requests.
+Receives
+an
+argument
+request
+of
+
+
+type
+represents
+a
+data
+type
+
+specified
+
+in
+the
+
+Thing
+Description
+
+in
+a
+serialized
+form.
+
+
+
+
+Request
+
+DataSchema
+
+and
+should
+return
+an
+object
+or
+value
+that
+
+is
+used
+by
+Protocol
+Bindings
+to
+reply
+to
+the
+request.
+The
+returned
+
+under
+development,
+currently
+it
+can
+denote
+any
+
+type
+is
+defined
+
+supported
+
+by
+the
+
+Thing
+Description
+
+and
+the
+
+WoT
+Runtime
+
+.
+
+addProperty()
+
+
+method
++Adds +a + +Property + +defined +by +the +argument +and +updates +the + +Thing +Description +. +Throws +on +error. +Returns +a +reference +to +the +same +object +for +supporting +chaining. + +
+
+ThingPropertyInit
+
+ThingProperty
+
+
+
+dictionary
+"idl-def-thingpropertyinit" data-idl="" data-title=
+"ThingPropertyInit">dictionary <span class=
+"idlDictionaryID"><a data-lt="ThingPropertyInit" href=
+"#dom-thingpropertyinit" class="internalDFN" data-link-type="dfn"
+data-for=""> {
+<span class="idlMember" id="idl-def-thingpropertyinit-name"
+data-idl="" data-title="name" data-dfn-for=
+"thingpropertyinit"> <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-thingpropertyinit-name" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+<span class="idlMember" id="idl-def-thingpropertyinit-configurable"
+data-idl="" data-title="configurable" data-dfn-for=
+"thingpropertyinit"> <a href=
+"https://heycam.github.io/webidl/#idl-boolean">boolean<a data-lt="configurable"
+href="#dom-thingpropertyinit-configurable" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+<span class="idlMember" id="idl-def-thingpropertyinit-enumerable"
+data-idl="" data-title="enumerable" data-dfn-for=
+"thingpropertyinit"> <a href=
+"https://heycam.github.io/webidl/#idl-boolean">boolean<a data-lt="enumerable"
+href="#dom-thingpropertyinit-enumerable" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+<span class="idlMember" id="idl-def-thingpropertyinit-writable"
+
+"idl-def-thingproperty" data-idl="" data-title=
+"ThingProperty">dictionary ThingProperty
: SemanticAnnotations
{
+
+data-title="name" data-dfn-for=
+"thingproperty"> required DOMString name
;
+
+"" data-title="schema" data-dfn-for=
+"thingproperty"> required DataSchema
schema
;
+
+"" data-title="value" data-dfn-for=
+"thingproperty"> any value
;
+"thingpropertyinit"> <a href=
+"https://heycam.github.io/webidl/#idl-boolean">boolean<a data-lt="writable"
+href="#dom-thingpropertyinit-writable" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit"> = <span class=
+"idlMemberValue">true
+<span class="idlMember" id=
+"idl-def-thingpropertyinit-semantictypes" data-idl="" data-title=
+"semanticTypes" data-dfn-for="thingpropertyinit"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-semantictype"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="semanticTypes" href=
+"#dom-thingpropertyinit-semantictypes" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+<span class="idlMember" id="idl-def-thingpropertyinit-description"
+data-idl="" data-title="description" data-dfn-for=
+"thingpropertyinit"> <a href=
+"#dom-thingdescription" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="description" href=
+"#dom-thingpropertyinit-description" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+<span class="idlMember" id="idl-def-thingpropertyinit-value"
+data-idl="" data-title="value" data-dfn-for=
+"thingpropertyinit"> <a href=
+"https://heycam.github.io/webidl/#idl-any">any<a data-lt="value"
+href="#dom-thingpropertyinit-value" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingPropertyInit">
+
+"thingproperty"> boolean writable
= false;
+
+data-idl="" data-title="observable" data-dfn-for=
+"thingproperty"> boolean observable
= false;
+
+};
+
+
++Represents +the + +Thing + + +Property + +description. +
+
+name
+
+
+attribute
+represents
+the
+name
+of
+the
+
+Property
+.
+
+value
+
+schema
+
+
+
+attribute
+represents
+the
+
+DataSchema
+
+.
+
+configurable
+
+value
+
+
+
+attribute
+
+enumerable
+
+writable
+
+
+
+attribute
+defines
+whether
+the
+
+Property
+
+can
+be
+
+true
+
+false
+
+
.
+
+writable
+
+observable
+
+
+
+attribute
+defines
+whether
+the
+
+Property
+
+changes
+
+can
+be
+
+true
+
+false
+
+
.
+
+removeProperty()
+
+
+method
+
+Removes
+the
+
+Property
+
+specified
+by
+the
+
+name
+
+argument,
+
+argument
+and
+
+updates
+the
+
+Thing
+Description
+and
+returns
+
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+
+the
+object.
+
+same
+object
+for
+supporting
+chaining.
+
+
+addAction()
+
+
+method
+
+Adds
+an
+
+Action
+
+to
+the
+
+Thing
+
+object
+as
+defined
+by
+the
+
+action
+
+argument
+of
+type
+
+
+
+
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+ThingActionInit
+
+ThingAction
+
+
+ThingActionInit
+
+ThingAction
+
+
+
+dictionary
+"idl-def-thingactioninit" data-idl="" data-title=
+"ThingActionInit">dictionary <span class=
+"idlDictionaryID"><a data-lt="ThingActionInit" href=
+"#dom-thingactioninit" class="internalDFN" data-link-type="dfn"
+data-for=""> {
+<span class="idlMember" id="idl-def-thingactioninit-name" data-idl=
+"" data-title="name" data-dfn-for=
+"thingactioninit"> <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-thingactioninit-name" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingActionInit">
+<span class="idlMember" id=
+"idl-def-thingactioninit-inputdatadescription" data-idl=""
+data-title="inputDataDescription" data-dfn-for=
+"thingactioninit"> <a href=
+"#dom-thingdescription" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="inputDataDescription" href=
+"#dom-thingactioninit-inputdatadescription" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingActionInit">
+<span class="idlMember" id=
+"idl-def-thingactioninit-outputdatadescription" data-idl=""
+data-title="outputDataDescription" data-dfn-for=
+"thingactioninit"> <a href=
+"#dom-thingdescription" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="outputDataDescription" href=
+"#dom-thingactioninit-outputdatadescription" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingActionInit">
+<span class="idlMember" id="idl-def-thingactioninit-semantictypes"
+data-idl="" data-title="semanticTypes" data-dfn-for=
+"thingactioninit"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-semantictype"
+
+"idl-def-thingaction" data-idl="" data-title=
+"ThingAction">dictionary ThingAction
: SemanticAnnotations
{
+
+data-title="name" data-dfn-for=
+"thingaction"> required DOMString
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="semanticTypes" href=
+"#dom-thingactioninit-semantictypes" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingActionInit">
+<span class="idlMember" id="idl-def-thingactioninit-action"
+data-idl="" data-title="action" data-dfn-for=
+"thingactioninit"> <span class=
+"idlMemberType">Function <span class=
+"idlMemberName"><a data-lt="action" href=
+"#dom-thingactioninit-action" class="internalDFN" data-link-type=
+"dfn" data-for=
+"ThingActionInit">
+
+"dfn">name
;
+
+data-idl="" data-title="inputSchema" data-dfn-for=
+"thingaction"> DataSchema
inputSchema
;
+
+data-idl="" data-title="outputSchema" data-dfn-for=
+"thingaction"> DataSchema
outputSchema
;
+
+};
+
+
+
+The
+
+
+
+
+dictionary
+describes
+the
+arguments
+and
+the
+return
+value.
+ThingActionInit
+
+ThingAction
+
+
+name
+
+
+attribute
+provides
+the
+
+Action
+
+name.
+
+inputDataDescription
+
+inputSchema
+
+
+
+attribute
+provides
+the
+description
+of
+the
+input
+arguments
+(argument
+list
+is
+represented
+by
+an
+object).
+If
+missing,
+it
+means
+the
+action
+does
+not
+accept
+
+arguments.
+
+outputDataDescription
+
+outputSchema
+
+
+
+attribute
+provides
+the
+description
+of
+the
+returned
+data.
+
+removeAction()
+
+
+method
+
+Removes
+the
+
+Action
+
+specified
+by
+the
+
+name
+
+argument,
+
+argument
+and
+
+updates
+the
+
+Thing
+Description
+and
+returns
+
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+
+the
+object.
+
+same
+object
+for
+supporting
+chaining.
+
+
+addEvent()
+
+
+method
+
+Adds
+an
+event
+to
+the
+
+Thing
+
+object
+as
+defined
+by
+the
+
+event
+
+argument
+of
+type
+
+
+
+
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+ThingEventInit
+
+ThingEvent
+
+
+ThingEventInit
+
+ThingEvent
+
+
+
+dictionary
+"idl-def-thingeventinit" data-idl="" data-title=
+"ThingEventInit">dictionary <span class=
+"idlDictionaryID"><a data-lt="ThingEventInit" href=
+"#dom-thingeventinit" class="internalDFN" data-link-type="dfn"
+data-for=""> {
+<span class="idlMember" id="idl-def-thingeventinit-name" data-idl=
+"" data-title="name" data-dfn-for="thingeventinit"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-lt="name"
+href="#dom-thingeventinit-name" class="internalDFN" data-link-type=
+"dfn" data-for=
+"ThingEventInit">
+<span class="idlMember" id="idl-def-thingeventinit-semantictypes"
+data-idl="" data-title="semanticTypes" data-dfn-for=
+"thingeventinit"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-semantictype"
+
+"idl-def-thingevent" data-idl="" data-title=
+"ThingEvent">dictionary ThingEvent
: SemanticAnnotations
{
+
+data-title="name" data-dfn-for=
+"thingevent"> required DOMString
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="semanticTypes" href=
+"#dom-thingeventinit-semantictypes" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingEventInit">
+<span class="idlMember" id="idl-def-thingeventinit-datadescription"
+data-idl="" data-title="dataDescription" data-dfn-for=
+"thingeventinit"> <a href=
+"#dom-thingdescription" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-lt="dataDescription" href=
+"#dom-thingeventinit-datadescription" class="internalDFN"
+data-link-type="dfn" data-for=
+"ThingEventInit">
+
+"dfn">name
;
+
+data-title="schema" data-dfn-for=
+"thingevent"> DataSchema
schema
;
+
+};
+
+
+
+name
+
+
+attribute
+represents
+the
+event
+name.
+
+dataDescription
+
+schema
+
+
+
+attribute
+represents
+the
+
+removeEvent()
+
+
+method
+
+Removes
+the
+event
+specified
+by
+the
+
+name
+
+argument,
+
+argument
+and
+
+updates
+the
+
+Thing
+Description
+and
+returns
+
+.
+Returns
+a
+reference
+to
+
+the
+object.
+
+same
+object
+for
+supporting
+chaining.
+
+
+onRetrieveProperty()
+
+PropertyReadHandler
+
+
+
+
+Registers
+the
+handler
+
+A
+
+function
+for
+
+that
+returns
+a
+Promise
+and
+resolves
+it
+with
+the
+value
+of
+the
+
+Property
+
+retrieve
+requests
+received
+for
+
+matching
+
+the
+Thing
+,
+as
+defined
+by
+
+
+name
+
+argument
+to
+
+the
+
+
+function,
+or
+rejects
+with
+an
+error
+if
+the
+
+property
+handler
+
+setPropertyReadHandler
+
+of
+type
+
+is
+not
+found
+or
+the
+value
+cannot
+be
+retrieved.
+
+RequestHandler
+
+PropertyWriteHandler
+
+
+
+callback
+
+A
+function
+called
+with
+
+value
+
+
+.
+The
+handler
+will
+receive
+an
+
+as
+
+argument
+request
+
+that
+returns
+a
+Promise
+which
+is
+resolved
+when
+the
+value
+
+of
+type
+
+the
+
+Property
+
+matching
+the
+
+
+name
+
+argument
+to
+the
+
+
+
+function
+is
+updated
+with
+Request
+
+setPropertyReadHandler
+
+
+value
+
,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+updated.
+
+Note
+that
+this
+function
+
+is
+defined
+and
+represents
+
+invoked
+by
+implementations
+before
+
+the
+name
+
+property
+is
+updated,
+so
+the
+code
+in
+this
+callback
+function
+can
+invoke
+the
+
+readProperty()
+
+method
+to
+find
+out
+the
+old
+value
+
+of
+the
+Property
+
+property,
+if
+needed.
+Therefore
+the
+old
+value
+is
+not
+provided
+
+to
+be
+retrieved.
+
+this
+method.
+
+
+onUpdateProperty()
+
+ActionHandler
+
+
+
+
+Defines
+the
+handler
+
+A
+
+function
+for
+Property
+
+called
+with
+a
+
+parameters
+
+dictionary
+argument
+assembled
+by
+the
+
+WoT
+runtime
+
+
+update
+requests
+received
+for
+
+based
+on
+
+the
+
+Thing
+,
+as
+defined
+by
+
+Description
+
+and
+the
+external
+client
+request.
+It
+returns
+a
+Promise
+that
+rejects
+with
+an
+error
+or
+resolves
+if
+
+the
+action
+is
+successful
+or
+ongoing
+(may
+also
+resolve
+with
+a
+control
+object
+such
+as
+an
+
+
+
+handler
+
+Observable
+
+property
+of
+type
+
+
+for
+actions
+that
+need
+progress
+notifications
+or
+that
+can
+be
+canceled).
+
+RequestHandler
+
+setPropertyReadHandler()
+
+
+
+method
+
+Takes
+
+name
+
+
+.
+The
+handler
+will
+receive
+an
+
+as
+string
+argument
+and
+
+readHandler
+
+as
+
+argument
+request
+
+of
+type
+
+
+
+Request
+
+PropertyReadHandler
+
+where
+request.name
+defines
+
+.
+Sets
+
+the
+name
+of
+
+handler
+function
+for
+reading
+
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+
+to
+be
+retrieved
+
+the
+same
+object
+for
+supporting
+chaining.
+
+The
+
+readHandler
+
+callback
+function
+will
+implement
+reading
+a
+
+Property
+
+and
+request.data
+defines
+
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+reading
+a
+
+Property
+
+is
+received
+from
+
+the
+new
+value
+of
+
+underlying
+platform.
+
+There
+
+SHOULD
+
+be
+at
+most
+one
+handler
+for
+any
+given
+
+Property
+
+and
+newly
+added
+handlers
+replace
+
+the
+old
+handlers.
+If
+no
+handler
+is
+initialized
+for
+any
+given
+
+Property
+.
+
+,
+implementations
+
+SHOULD
+
+implement
+a
+default
+property
+read
+handler.
+
+
+onInvokeAction()
+
+setPropertyWriteHandler()
+
+
+
+method
+
+Defines
+the
+handler
+function
+for
+Action
+invocation
+requests
+received
+for
+the
+Thing
+,
+as
+defined
+by
+the
+
+Takes
+
+
+
+handler
+
+name
+
+property
+of
+type
+
+as
+string
+argument
+and
+
+
+
+RequestHandler
+
+writeHandler
+
+.
+The
+handler
+will
+receive
+an
+
+as
+
+argument
+request
+
+of
+type
+
+
+
+Request
+
+PropertyWriteHandler
+
+where
+request.name
+defines
+
+.
+Sets
+
+the
+name
+of
+
+handler
+function
+for
+writing
+
+the
+Action
+
+specified
+
+Property
+
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+
+to
+be
+invoked
+and
+request.data
+defines
+
+the
+input
+arguments
+
+same
+object
+
+for
+the
+Action
+
+supporting
+chaining.
+
+There
+
+SHOULD
+
+be
+at
+most
+one
+write
+handler
+for
+any
+given
+
+Property
+
+
+as
+defined
+by
+
+and
+newly
+added
+handlers
+replace
+
+the
+Thing
+Description
+.
+
+old
+handlers.
+If
+no
+write
+handler
+is
+initialized
+for
+any
+given
+
+Property
+,
+implementations
+
+SHOULD
+
+implement
+default
+property
+update
+and
+notifying
+observers
+on
+change.
+
+
+onObserve()
+
+setActionHandler()
+
+
+
+method
+
+Defines
+the
+handler
+function
+for
+observe
+requests
+received
+for
+the
+Thing
+,
+
+Takes
+
+name
+
+as
+defined
+by
+the
+
+string
+argument
+and
+
+
+
+handler
+
+action
+
+property
+
+as
+argument
+
+of
+type
+
+
+
+RequestHandler
+
+ActionHandler
+
+.
+The
+
+.
+Sets
+the
+
+handler
+function
+for
+the
+specified
+
+Action
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+If
+provided,
+this
+callback
+function
+
+will
+receive
+
+implement
+invoking
+
+an
+argument
+
+
+Action
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+
+request
+of
+type
+
+for
+invoking
+a
+
+Action
+
+is
+received
+from
+the
+underlying
+platform.
+The
+callback
+will
+receive
+a
+
+parameters
+
+dictionary
+argument.
+
+There + +SHOULD + +be +exactly +one +handler +for +any +given + +Action +. +If +no +handler +is +initialized +for +any +given + +Action +, +implementations + +SHOULD + +return +error +if +the +action +is +invoked +by +any +client. +
+Below
+some
+
+
+
+
+
+
+
+Request
+
+ExposedThing
+
+where
+
+interface
+examples
+are
+given.
+
+
try {
+"hljs-keyword">var thing = WoT.produce({ name: "tempSensor" });
+ // manually add Interactions
+ thing.addProperty({
+ name:
+"hljs-string">"temperature",
+ value:
+"hljs-number">0.0,
+ schema:
+"hljs-string">'{ "type": "number" }'
+
+"hljs-comment">// use default values for the rest
+ }).addProperty({
+ name:
+"hljs-string">"max",
+ value:
+"hljs-number">0.0,
+ schema:
+"hljs-string">'{ "type": "number" }'
+
+"hljs-comment">// use default values for the rest
+ }).addAction({
+ name:
+"hljs-string">"reset",
+ // no input, no output
+ }).addEvent({
+ name:
+"hljs-string">"onchange",
+ schema:
+"hljs-string">'{ "type": "number" }'
+ });
+ // add server functionality
+ thing.setActionHandler("reset", () => {
+ console.log(
+"hljs-string">"Resetting maximum");
+ thing.writeProperty("max", 0.0);
+ });
+ thing.start().then(() => {
+ thing.register();
+ });
+ // define Thing business logic
+ setInterval( async () => {
+ let mock =
+"hljs-built_in">Math.random()*100;
+ thing.writeProperty("temperature", mock);
+ let old =
+"hljs-keyword">await thing.readProperty("max");
+ if (old < mock) {
+ thing.writeProperty("max", mock);
+ thing.emitEvent("onchange");
+ }
+ }, 1000);
+} catch (err) {
+ console.log(
+"hljs-string">"Error creating ExposedThing: " + err);
+}
+
+"hljs-keyword">let thingDescription = '{ "@context": [ "https://w3c.github.io/wot/w3c-wot-td-context.jsonld", "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ], "@type": [ "Thing", "Sensor" ], "name": "mySensor", "geo:location": "testspace", "interaction": [ { "@type": [ "Property", "Temperature" ], "name": "prop1", "schema": { "type": "number" }, "saref:TemperatureUnit": "degree_Celsius" } ] }';
+try {
+"hljs-comment">// note that produce() fails if thingDescription contains error
+
+"hljs-keyword">let thing = WoT.produce(thingDescription);
+
+"hljs-comment">// Interactions were added from TD
+
+"hljs-comment">// WoT adds generic handler for reading any property
+
+"hljs-comment">// define a specific handler for one property
+ let name =
+"hljs-string">"examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log(
+"hljs-string">"Handling read request for " + name);
+ return
+"hljs-keyword">new Promise((resolve, reject) => {
+
+"hljs-keyword">let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log(
+"hljs-string">"Error");
+ });
+ });
+ thing.start();
+} catch(err) {
+ console.log(
+"hljs-string">"Error creating ExposedThing: " + err);
+}
+
+"hljs-comment">// fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+
+"hljs-comment">// WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+"hljs-comment">// Interactions were added from TD
+ // add server functionality // ...
+});
+
+request.options.observeType
+
+
+This
+section
+
+is
+of
+type
+
+non-normative.
+
+The
+
+
+
+
+RequestType
+
+ThingDescription
+
+and
+defines
+whether
+a
+Property
+change
+or
+
+related
+functionality,
+such
+as
+enumerating
+
+Properties
+,
+Action
+
+invocation
+or
+event
+emitting
+is
+observed,
+or
+the
+changes
+to
+the
+Thing
+Description
+
+s,
+
+Event
+
+
+are
+observed.
+request.options.subscribe
+is
+true
+if
+subscription
+is
+turned
+or
+kept
+being
+turned
+on,
+
+s
+
+and
+it
+
+links
+(introspection)
+
+is
+false
+when
+subscription
+
+an
+API
+extension
+that
+
+is
+turned
+off.
+
+out
+of
+scope
+for
+this
+specification.
+However,
+the
+draft
+interfaces
+are
+defined
+here
+for
+informative
+purposes.
+
+"idl-def-consumedthing-partial-1" data-idl="" data-title=
+"ConsumedThing">partial interface ConsumedThing
{
+
+data-idl="" data-title="getProperties" data-dfn-for=
+"consumedthing"> sequence<ThingProperty
> getProperties();
+
+data-idl="" data-title="getActions" data-dfn-for=
+"consumedthing"> sequence<ThingAction
> getActions();
+
+data-idl="" data-title="getEvents" data-dfn-for=
+"consumedthing"> sequence<ThingEvent
> getEvents();
+
+data-idl="" data-title="getLinks" data-dfn-for=
+"consumedthing"> sequence<TDLink
> getLinks();
+};
+
+register()
+
+getProperties()
+
+
+
+method
+
+Generates
+the
+Thing
+Description
+given
+
+Returns
+
+the
+properties,
+Actions
+and
+Event
+
+list
+of
+
+Properties
+
+
+defined
+for
+this
+object.
+If
+a
+directory
+argument
+is
+given,
+make
+a
+request
+to
+register
+
+in
+
+the
+
+Thing
+Description
+
+with
+
+of
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+
+
+Thing
+
+in
+the
+form
+of
+a
+list
+of
+
+
+
+register
+
+ThingProperty
+
+Action
+.
+
+
+objects.
+
+
+unregister()
+
+getActions()
+
+
+
+method
+
+If
+a
+directory
+argument
+is
+given,
+make
+a
+request
+to
+unregister
+the
+Thing
+Description
+with
+
+Returns
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+unregister
+
+list
+of
+
+Action
+.
+Then,
+and
+
+
+s
+defined
+
+in
+the
+case
+no
+arguments
+were
+provided
+to
+this
+function,
+stop
+the
+
+
+Thing
+Description
+
+
+and
+remove
+
+of
+
+the
+
+Thing
+Description
+.
+
+
+in
+the
+form
+of
+a
+list
+of
+
+ThingAction
+
+objects.
+
+
+start()
+
+getEvents()
+
+
+
+method
+
+Start
+serving
+external
+requests
+for
+
+Returns
+
+the
+list
+of
+
+Event
+
+s
+defined
+in
+the
+
+Thing
+.
+
+Description
+
+of
+the
+
+Thing
+
+in
+the
+form
+of
+a
+list
+of
+
+ThingEvent
+
+objects.
+
+
+stop()
+
+getLinks()
+
+
+
+method
+
+Stop
+serving
+external
+requests
+for
+
+Returns
+
+the
+list
+of
+linked
+resources
+in
+
+Thing
+.
+
+Description
+
+of
+the
+
+Thing
+
+in
+the
+form
+of
+a
+list
+of
+
+TDLink
+
+objects.
+
+
+emitEvent()
+
+TDLink
+
+
+
+
+Emits
+an
+the
+event
+initialized
+with
+the
+event
+name
+specified
+by
+the
+eventName
+argument
+
+Contains
+a
+hyperlink
+reference,
+a
+relation
+type
+
+and
+data
+specified
+by
+the
+payload
+argument.
+
+a
+media
+type.
+
+
"idl-def-tdlink" data-idl="" data-title= +"TDLink">dictionary+TDLink
{ + +data-title="href" data-dfn-for="tdlink"> required USVStringhref
; + +data-title="mediaType" data-dfn-for= +"tdlink"> USVStringmediaType
; + +data-title="rel" data-dfn-for="tdlink"> DOMStringrel
; +}; + + +Events +supported +by +ExposedThing ++
+The
+following
+default
+events
+SHOULD
+be
+supported
+by
+
+
+
+
+
+ExposedThing
+
+TDLink
+
+implementations:
+
+dictionary
+contains
+the
+following
+properties:
+
+
+PropertyChangeEvent
+
+href
+
+
+
+attribute
+represents
+a
+
+hyperlink
+reference
+.
+
+ActionInvocationEvent
+
+rel
+
+
+
+ThingDescriptionChangeEvent
+
+mediaType
+
+
+
+attribute
+represents
+a
+
+IANA
+media
+type
+
+.
+For
+
+TD
+
+s
+there
+will
+be
+registered
+media
+types,
+so
+applications
+will
+be
+able
+to
+check
+whether
+an
+
+href
+
+link
+points
+to
+a
+
+TD
+,
+i.e.
+whether
+the
+link
+is
+fetcheable
+with
+this
+API.
+
+
+Below
+some
+
+
+This
+section
+is
+non-normative.
+
+ExposedThing
+
+
+
+Observables
+
+are
+
+proposed
+
+
+interface
+examples
+
+to
+be
+included
+in
+ECMAScript
+and
+
+are
+given.
+
+used
+for
+handling
+pushed
+data
+associated
+with
+various
+possible
+sources,
+for
+instance
+events,
+timers,
+streams,
+etc.
+A
+minimal
+required
+implementation
+is
+described
+here.
+
+
+This +section +is +informal +and +contains +rather +laconic +information +for +implementations +on +what +to +support +for +interoperability. +
+"idl-def-observable" data-idl="" data-title= +"Observable">interface+Observable
{ + +"idl-def-observable-subscribe-next-error-complete" data-idl="" +data-title="subscribe" data-dfn-for="observable">Subscription
subscribe
((Observer
orOnNext
) next, + +"idlParam">optionalOnError
error, + +"idlParam">optionalOnComplete
complete); +}; + +data-title="Subscription">interfaceSubscription
{ + +data-idl="" data-title="unsubscribe" data-dfn-for= +"subscription"> voidunsubscribe
(); + +data-idl="" data-title="closed" data-dfn-for= +"subscription"> readonly attribute booleanclosed
; +}; + +data-title="Observer">interfaceObserver
{ + +"" data-title="next" data-dfn-for="observer"> void next(any value); + +"" data-title="error" data-dfn-for="observer"> void error(Error error); + +data-title="complete" data-dfn-for="observer"> void complete(); +}; + +data-title="OnNext">callbackOnNext
= void (any value); + +data-title="OnError">callbackOnError
= void (Error error); + +data-title="OnComplete">callbackOnComplete
= +void + +(); + + +<pre class="highlight hljs javascript" aria-busy="false" aria-live= +"polite">WoT.createExposedThing(thingDescription) + .then(<span class= +"hljs-keyword">function(<span class= +"hljs-params">thing{ + <span class= +"hljs-comment">// manually add properties, actions, and events + thing.addProperty({ + : <span class= +"hljs-string">"temperature", + : <span class= +"hljs-string">"0", + : <span class= +"hljs-literal">false + <span class= +"hljs-comment">// use default values for the rest + }).addEvent({ + : <span class= +"hljs-string">"onchange", + : { + : <span class= +"hljs-string">"float32" + } + }).addAction({ + : <span class= +"hljs-string">"reset", + : <span class= +"hljs-function"><span class= +"hljs-params">() { <span class= +"hljs-keyword">this.temperature = <span class= +"hljs-number">0; } + }) + + .onRetrieveProperty( <span class= +"hljs-params">request { + .log(<span class= +"hljs-string">"Handling read request"); + <span class= +"hljs-keyword">this.temperature; + }).onObserve( <span class= +"hljs-params">request { + .log(<span class= +"hljs-string">"Handling observe request"); + <span class= +"hljs-comment">// add listener identified by request.from + }).onInvokeAction( <span class= +"hljs-params">request { + .log(<span class= +"hljs-string">"Handling action request"); + }).start(); +}); ++
+Observer
+
+
+The
+
+
+Observer
+
+Example
+8
+
+
+interface
+defines
+the
+callbacks
+needed
+to
+handle
+an
+
+Observable
+
:
+next()
+
+function,
+as
+well
+as
+the
+
+OnNext
+
+callback
+takes
+the
+next
+sample
+for
+the
+data
+in
+the
+
+value
+
+argument.
+
+error()
+
+function,
+as
+well
+as
+the
+
+OnError
+
+callback
+takes
+an
+error
+in
+the
+
+value
+
+argument.
+It
+is
+called
+when
+an
+error
+occured
+in
+producing
+the
+data
+the
+client
+should
+know
+about.
+
+complete()
+
+function,
+as
+well
+as
+the
+
+OnComplete
+
+callback
+is
+called
+when
+the
+data
+source
+has
+finished
+sending
+values.
+
+Subscription
+
+interface
+
+Contains
+the
+
+closed
+
+property
+of
+type
+
+boolean
+
+that
+tells
+if
+the
+subscription
+is
+closed
+or
+active.
+
+Also,
+contains
+the
+
+unsubscribe
+
+()
+method
+that
+cancels
+the
+subscription,
+i.e.
+makes
+
+a
+new
+exposed
+Thing
+
+request
+to
+the
+underlying
+platform
+to
+stop
+receiving
+data
+
+from
+a
+Thing
+Description
+
+the
+source,
+and
+sets
+the
+
+closed
+
+property
+to
+
+false
+
.
+Observable
+
+
+interface
+
+The
+
+Observable
+
+interface
+enabled
+subscribing
+to
+pushed
+data
+notifications
+by
+the
+
+subscribe
+
+()
+method:
+
+subscribe()
+
+method
+is
+called
+with
+an
+
+Observer
+
+object,
+initialize
+the
+data,
+error
+and
+completion
+handling
+callbacks
+from
+that
+object,
+or
+throw
+on
+error.
+
+subscribe()
+
+method
+is
+called
+with
+a
+function,
+initialize
+the
+data
+handler
+callback
+with
+that
+function.
+If
+the
+next
+argument
+is
+provided
+and
+is
+a
+function,
+initialize
+the
+error
+handling
+callback
+with
+that
+function,
+or
+throw
+on
+error.
+If
+the
+third
+argument
+is
+provided
+and
+is
+a
+function,
+initialize
+the
+completion
+handler
+with
+that
+function,
+or
+throw
+on
+error.
++Please +see +the + +WoT +Security +and +Privacy + +repository +for +work +in +progress +regarding +threat +models, +assets, +risks, +recommended +mitigations, +and +best +practices +for +security +and +privacy +for +systems +using +the +Web +of +Things. +Once +complete, +security +and +privacy +considerations +relevant +to +the +Scripting +API +will +be +summarized +in +this +section. +
++The +generic +WoT +terminology +is +defined +in +[ + + +WOT-ARCHITECTURE + + +]: + +Thing +, + +Thing +Description + +(in +short + +TD + +), + +Web +of +Things + +(in +short + + +WoT + + +), + +WoT +Interface +, + +Protocol +Bindings +, + +WoT +Runtime +, + +Consuming +a +Thing +Description +, + +Thing +Directory +, + +WoT +Interactions +, +Property +, + +Action +, + +Event + +etc. +
+
+
+JSON-LD
+
+is
+defined
+in
+[
+
+
+JSON-LD
+
+
+]
+as
+a
+JSON
+document
+that
+is
+augmented
+with
+support
+for
+Linked
+Data
+by
+providing
+a
+
+@context
+
+property
+with
+a
+defining
+URI
+.
+
+The +terms + + +URL + + +and + + +URL +path + + +are +defined +in +[ + + +URL + + +]. +
+
+The
+following
+terms
+are
+defined
+in
+[
+
+HTML5
+
+
+HTML52
+
+
+
+]
+and
+are
+used
+in
+the
+context
+of
+browser
+implementations:
+
+
+browsing
+context
+
+,
+
+
+top-level
+browsing
+context
+
+,
+
+
+global
+object
+
+,
+
+
+incumbent
+settings
+object
+
+,
+
+
+Document
+
+,
+
+
+document
+base
+URL
+
+,
+
+
+Window
+
+,
+
+
+WindowProxy
+
+,
+
+
+origin
+
+,
+
+
+ASCII
+serialized
+origin
+
+,
+executing
+algorithms
+
+
+in
+parallel
+
+,
+
+
+queue
+a
+task
+
+,
+
+
+task
+source
+
+,
+
+
+iframe
+
+,
+
+
+valid
+MIME
+type
+
+.
+
+A
+
+browsing
+context
+
+refers
+to
+the
+environment
+in
+which
+
+Document
+
+objects
+are
+presented
+to
+the
+user.
+A
+given
+
+browsing
+context
+
+has
+a
+single
+
+
+WindowProxy
+
+
+object,
+but
+it
+can
+have
+many
+
+
+Document
+
+
+objects,
+with
+their
+associated
+
+
+Window
+
+
+objects.
+The
+
+script
+execution
+context
+
+associated
+with
+the
+
+browsing
+context
+
+identifies
+the
+entity
+which
+invokes
+this
+API,
+which
+can
+be
+a
+
+web
+app
+,
+a
+
+web
+page
+,
+or
+an
+
+iframe
+.
+
+The +term + + +secure +context + + +is +defined +in +[ + + +WEBAPPSEC + + +]. +
++ + +Error +, + +EvalError +, + +RangeError +, + +ReferenceError +, + +SyntaxError +, + +TypeError +, + +URIError + + +, + + +script +execution +context + +, + + +Promise + +, + + +JSON + +, + + +JSON.stringify + + +and + + +JSON.parse + + +are +defined +in +[ + + +ECMASCRIPT + + +]. +
++ + +DOMString + +, + + +USVString + +, + + +ArrayBuffer + +, + + +BufferSource + + +and + + +any + + +are +defined +in +[ + + +WEBIDL + + +]. +
+
+The
+term
+event
+and
+the
+Event
+object
+are
+defined
+in
+DOM
+and
+Node.js
+.
+Note
+This
+specification
+uses
+the
+convention
+that
+an
+event
+listener
+will
+receive
+an
+Event
+object.
+This
+should
+work
+both
+in
+a
+browser
+environment
+and
+in
+a
+Node.js
+like
+environment.
+Observable
+s
+are
+proposed
+to
+be
+included
+in
+ECMAScript.
+The
+
+algorithms
+
+
+utf-8
+encode
+
+,
+and
+
+
+utf-8
+decode
+
+
+are
+defined
+in
+[
+
+
+ENCODING
+
+
+].
+
+ +IANA +media +type + +s +(formerly +known +as +MIME +types) +are +defined +in + +RFC2046 +. +
++The +terms + +hyperlink +reference + +and + +relation +type + +are +defined +in +[ + +HTML52 + +] +and + +RFC8288 +.
++As +well +as +sections +marked +as +non-normative, +all +authoring +guidelines, +diagrams, +examples, +and +notes +in +this +specification +are +non-normative. +Everything +else +in +this +specification +is +normative. +
++The +key +words + +MAY +, + +MUST +, +and + +SHOULD + +are +to +be +interpreted +as +described +in +[ + + +RFC2119 + + +]. +
++This +document +defines +conformance +criteria +that +apply +to +a +single +product: +the + +UA + +(user +agent) +that +implements +the +interfaces +it +contains. +
++This +specification +can +be +used +for +implementing +the +WoT +Scripting +API +in +multiple +programming +languages. +The +interface +definitions +are +specified +in +[ + + +WEBIDL + + +]. +
++The +user +agent +(UA) +may +be +implemented +in +the +browser, +or +in +a +separate +runtime +environment, +such +as + +Node.js + +or +small +embedded +runtimes. +
++Implementations +that +use +ECMAScript +executed +in +a +browser +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +ECMAScript +Bindings +defined +in +the +Web +IDL +specification +[ + + +WEBIDL + + +]. +
++Implementations +that +use +TypeScript +or +ECMAScript +in +a +runtime +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +TypeScript +Bindings +defined +in +the +TypeScript +specification +[ + + +TYPESCRIPT + + +]. +
++This +document +serves +a +general +description +of +the +WoT +Scripting +API. +Language +and +runtime +specific +issues +are +discussed +in +separate +extensions +of +this +document. +
++The +following +is +a +list +of +major +changes +to +the +document. +For +a +complete +list +of +changes, +see +the + +github +change +log +. +You +can +also +view +the + +recently +closed +bugs +. +
+
+ThingDescription
+
,
+ThingTemplate
+
,
+SemanticAnnotations
+
,
+SemanticType
+
,
+SemanticMetadata
+
,
+input
+and
+output
+data
+descriptions,
+etc.
+
+consume()
+
+to
+
+fetch()
+
+and
+
+consume()
+
.
+expose()
+
+to
+accept
+a
+
+Thing
+Template
+.
+addListener()
+
,
+removeListener()
+
+introduced
+
+onEvent()
+
,
+onPropertyChange()
+
,
+onTDChange()
+
.
+ExposedThing
+
+handlers
+for
+Property,
+Action
+and
+Event.
+
+Observable
+
.+The +following +problems +are +being +discussed +and +need +most +attention: +
+
+DataSchema
+
+better
+(
+
+https://github.com/w3c/wot-scripting-api/issues/89)
+.
+ExposedThing
+
+(
+
+https://github.com/w3c/wot-scripting-api/issues/45)
+.+Special +thanks +to +former +editor +Johannes +Hund +(until +August +2017, +when +at +Siemens +AG) + +for +developing +this +specification. +Also, +the +editors +would +like +to +thank +Dave +Raggett, +Matthias +Kovatsch, +Michael +Koster +and +Michael +McCool +for +their +comments +and +guidance. +
+Copyright + © 2017-2018 W3C® + (MIT, + ERCIM, + Keio, Beihang). W3C + liability, + trademark and + permissive document license rules apply.
+The overall Web of Things (WoT) concepts are + described in the WoT Architecture + document. The Web of Things is made of entities (Things) that can describe their capabilities in a + machine-interpretable format, the Thing Description (TD) and expose these capabilities + through the WoT Interface, that is, network + interactions modeled as Properties for reading + and writing values, Actions to execute remote procedures + with or without return values and Events for signaling + notifications.
+This specification describes a programming interface + representing the WoT Interface that + allows scripts run on a Thing to discover and + consume (retrieve) other Thing Descriptions + and to expose Things characterized by WoT Interactions specified by a script.
+Scripting is an optional "convenience" building block in WoT + and it is typically used in gateways that are able to run a + WoT Runtime and + script management, providing a convenient way to extend WoT + support to new types of endpoints and implement WoT + applications like + Thing Directory.
+This section describes the status of this document at + the time of its publication. Other documents may supersede this + document. A list of current W3C publications and the + latest revision of this technical report can be found in the + W3C technical reports + index at https://www.w3.org/TR/.
+Implementers need to be aware that this specification is + considered unstable. Vendors interested in implementing this + specification before it eventually reaches the Candidate + Recommendation phase should subscribe to the repository and + take part in the discussions.
+Please contribute to this draft using the + GitHub + Issue feature of the WoT Scripting + API repository. For feedback on security and privacy + considerations, please use the WoT Security and + Privacy Issues.
+This document was published by the Web of Things Working Group as + a Working Draft. This document is intended to become a W3C + Recommendation.
+Comments regarding this document are welcome. Please send + them to public-wot-wg@w3.org + (subscribe, + archives).
+Changes from the previous publication can be found in + Appendix A. A diff-marked version of this document is also + available for comparison purposes.
+Publication as a Working Draft does not imply endorsement by + the W3C + Membership. This is a draft document and may be updated, + replaced or obsoleted by other documents at any time. It is + inappropriate to cite this document as other than work in + progress.
+This document was produced by a group operating under the + W3C Patent Policy. + W3C maintains a + public list + of any patent disclosures made in connection with the + deliverables of the group; that page also includes instructions + for disclosing a patent. An individual who has actual knowledge + of a patent which the individual believes contains Essential + Claim(s) must disclose the information in accordance with + section + 6 of the W3C + Patent Policy.
+This document is governed by the 1 February 2018 + W3C Process + Document.
+WoT provides layered interoperability based on how Things are modeled: as being "consumed" and + "exposed".
+By consuming a TD, a client Thing creates a runtime resource model that allows + accessing the Properties, Actions and + Events exposed by the server Thing exposed on a + remote device.
+Exposing a Thing requires defining a Thing Description (TD) and instantiating a software + stack to serve requests for accessing the exposed Properties, Actions and Events. This specification describes how to expose + and consume Things by a script.
+Typically scripts are meant to be used on devices + able to provide resources (with a WoT Interface) for managing (installing, updating, + running) scripts, such as bridges or gateways that expose and + control simpler devices as WoT Things.
+This specification does not make assumptions on + how the WoT Runtime handles and runs + scripts, including single or multiple tenancy, script + deployment and lifecycle management. The API already supports + the generic mechanisms that make it possible to implement + script management, for instance by exposing a manager + Thing whose Actions (action + handlers) implement script lifecycle management + operations.
+For an introduction on how scripts could be used in Web of Things, check the Primer + document. For some background on API design decisions check the + Rationale + document.
+This section is non-normative.
+The following scripting use cases are supported in this + specification:
+ExposedThing
to be exposed, based on
+ a Thing Description provided in
+ string serialized format, or out of a template or an
+ existing ConsumedThing
object.
+ WoT
+ objectThe WoT object is the API entry point and it is exposed by + an implementation of the WoT Runtime. The + WoT object + does not expose properties, only methods for discovering, + consuming and exposing a Thing.
+Browser implementations SHOULD use a namespace object such as
+ navigator.wot
. Node.js-like runtimes MAY provide the API object through
+ the require() or
+
+ import mechanism.
// [SecureContext] +// [NamespaceObject] +interface+WoT
{ +Observable
discover
(optionalThingFilter
filter); + Promise<ThingDescription
>fetch
(USVString url); +ConsumedThing
consume
(ThingDescription
td); +ExposedThing
produce
(ThingModel
model); + Promise<void>register
(USVString directory,ExposedThing
thing); + Promise<void>unregister
(USVString directory,ExposedThing
thing); +}; +typedef objectThingFragment
; +typedef objectPropertyFragment
; +typedef objectActionFragment
; +typedef objectEventFragment
; +typedef objectDataSchema
; +typedef objectSecurityScheme
; +typedef objectLink
; +typedef objectForm
; +typedef USVStringThingDescription
; +typedef (ThingFragment
orThingDescription
)ThingModel
;
The algorithms for the WoT methods will be + specified later, including error handling and security + considerations.
+The ThingModel
type represents
+ either a ThingFragment
, or a
+ ThingDescription
.
discover()
+ methodStarts the discovery process that will provide ThingDescription
s that match the
+ optional argument filter of type
. Returns an
+ [ThingFilter
Observable
](https://github.com/tc39/proposal-observable)
+ object that can be subscribed to and unsubscribed from. The
+ handler function provided to the Observable during
+ subscription will receive an argument of type
+ USVString
representing a ThingDescription
.
DiscoveryMethod
+ enumerationtypedef DOMString DiscoveryMethod
;
+ DiscoveryMethod
+ represents the discovery type to be used:
ThingFilter
+ dictionaryThe ThingFilter
+ dictionary that represents the constraints for discovering
+ Things as key-value pairs.
dictionary ThingFilter
{
+ (DiscoveryMethod
or DOMString) method
= "any";
+ USVString? url
;
+ USVString? query
;
+ ThingFragment
? fragment
;
+};
+ The method
+ property represents the discovery type that should be used
+ in the discovery process. The possible values are defined
+ by the
enumeration
+ that MAY be extended
+ by string values defined by solutions (with no guarantee of
+ interoperability).DiscoveryMethod
The url
property
+ represents additional information for the discovery method,
+ such as the URL of the target entity serving the discovery
+ request, for instance a Thing
+ Directory (if method
is
+ "directory"
) or a Thing (otherwise).
The query
+ property represents a query string accepted by the
+ implementation, for instance a SPARQL or JSON query.
+ Support may be implemented locally in the WoT Runtime or remotely as a service in a
+ Thing Directory.
The fragment
property
+ represents a ThingFragment
dictionary used for
+ matching property by property against discovered Things.
The discover(filter)
method MUST run the following steps:
discover()
is not allowed for
+ the current scripting context for security reasons, throw
+ SecurityError
and terminate these steps.Observable
obs and
+ execute the next steps in parallel.
+ obs.subscribe(handler, errorHandler,
+ complete)
is called, execute the following
+ sub-steps:
+ TypeError
and terminate the algorithm.
+ Otherwise configure handler to be invoked
+ when a discovery hit happens.TypeError
and terminate these steps.
+ Otherwise if defined, save it to be invoked in error
+ conditions.TypeError
and terminate these steps.
+ Otherwise if defined, save it to be invoked when the
+ discovery process finished for other reasons than
+ having been canceled.NotSupported
error and terminate these
+ steps.
+ ThingFragment
,
+ throw TypeError
and terminate these steps.
+ Otherwise save the object for matching the discovered
+ items against it.
+ "any"
, use the widest
+ discovery method supported by the underlying
+ platform.
+ "local"
, use the local Thing Directory for
+ discovery. Usually that defines Things deployed in the same device, or
+ connected to the device in slave mode (e.g.
+ sensors connected via Bluetooth or a serial
+ connection).
+
+ "directory"
, use the remote Thing Directory
+ specified in filter.url.
+ "multicast"
, use all the multicast
+ discovery protocols supported by the underlying
+ platform.false
, discard td and
+ continue the discovery process.false
in any checks, discard td
+ and continue the discovery process.Error
whose
+ message
property is set to
+ UnknownError
unless there was an error code
+ provided by the Protocol Bindings,
+ in which case set it to that value.
+ obs.unsubscribe()
method is
+ called, run the following cancel discovery steps:
+ false
.fetch()
+ methodAccepts an url
argument of type
+ USVString
that represents a URL (e.g.
+ "file://..."
or "https://..."
) and
+ returns a Promise
that resolves with a
+ ThingDescription
(a
+ serialized JSON-LD document of type
+ USVString
).
The fetch(url)
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ fetch()
is not allowed for the
+ current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.TypeError
and
+ terminate these steps.application/td+json
), as far
+ as a valid Thing Description
+ can be obtained as defined in [WOT-TD]. Let td
+ be the Thing Description
+ string-serialized from the returned content, as specified
+ in the
+ Thing Description serialization.
+ Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ consume()
+ methodAccepts an td
argument of type
and returns a
+ ThingDescription
ConsumedThing
object
+ instantiated based on parsing that description.
The consume(td)
method must run the following
+ steps:
TypeError
and terminate these steps.ThingFragment
with a default value,
+ add that property and value to stub.
+ ConsumedThing
object
+ thing initialized from stub that
+ implements Observable
.
+ read()
and write()
+ methods to the ThingProperty
elements so that they
+ make requests to access the remote Things and
+ wait for the reply, as defined by the Protocol Bindings. Also, all
+ ThingProperty
+ elements SHOULD
+ implement Observable
, i.e.
+ define a subscribe()
method that should make
+ request to observe the given Properties
+ as defined by the Protocol Bindings.
+ invoke()
methods to the ThingAction
elements so that they
+ make requests to the remote Thing to invoke its
+ actions, as defined by the Protocol
+ Bindings.
+ subscribe()
method to all
+ ThingEvent
elements
+ so that they make requests to subscribe to the events
+ defined by the remote Thing, as defined
+ by the Protocol Bindings.
+ produce()
+ methodAccepts a model
argument of type
+
and
+ returns an ThingModel
ExposedThing
+ object.
The produce(model)
method MUST run the following steps:
produce()
is not allowed for
+ the current scripting context for security reasons, throw
+ SecurityError
and terminate these steps.TypeError
and terminate these steps.ThingFragment
with a default value,
+ add that property and value to model.
+ ExposedThing
object thing
+ initialized from model.
+ ExposedThing
defined in ThingFragment
, initialize the
+ property based on the provided initial or default values
+ provided to the local WoT Runtime
+ implementation, for instance initialize:
+ id
property to be the final unique
+ identifier of the Thing,
+ security
object of type SecurityScheme
to
+ represent the actual security scheme and its properties
+ as set up by the implementation,
+ properties
property to be an
+ object with all properties being ThingProperty
+ objects in which the read()
and
+ write()
methods are provided to define
+ local methods to get and set the Property values,
+ actions
property to be an object
+ with all properties being ThingAction
objects in which the
+ invoke()
method is provided to define a
+ local method to run the defined Actions,
+ events
property to be an object
+ with all properties being ExposedEvent
objects in which
+ the emit()
method is provided to define a
+ local way to trigger sending notifications to all
+ subscribed clients,
+ The TD parsing algorithm + takes a string td as argument and runs the + following steps:
+register()
+ methodTakes two mandatory arguments:
+directory
denoting a Thing Directory, and
+ thing
denoting an ExposedThing
object.
+ Generate the Thing Description as
+ td, given the Properties, Actions and Events defined for
+ this ExposedThing
object.
+ Then make a request to register td to the given
+ WoT Thing Directory.
+ unregister()
methodTakes two mandatory arguments:
+directory
denoting a Thing Directory, and
+ thing
denoting an ExposedThing
object.
+ Makes a request to unregister the thing
from
+ the given WoT Thing Directory.
let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let subscription = wot.discover(discoveryFilter).subscribe(
+ td => {
+ console.log("Found Thing " + td.name);
+ // fetch the TD and create a ConsumedThing
+ let thing = wot.consume(td);
+ },
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log("Discovery timeout");
+ },
+ 5000);
+ let subscription = wot.discover({ method: "local" }).subscribe(
+ td => { console.log("Found local Thing " + td.name); },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+ let subscription = wot.discover({ method: "local" }).subscribe({
+ td => { console.log("Found local Thing " + td.name); },
+ error: err => { console.log("Discovery error: " + err.message); },
+ complete: () => { console.log("Discovery finished successfully");}
+});
+ ConsumedThing
+ interfaceRepresents an object that extends a ThingFragment
with methods for client
+ interactions (send request for reading and writing Properties), invoke Actions, subscribe and
+ unsubscribe for Property changes and Events.
interface+ConsumedThing
:ThingFragment
{ + readonly attribute DOMStringid
; + readonly attribute DOMStringname
; + readonly attribute DOMString?base
; + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeEventMap
events
; + // getter for ThingFragment properties + getter any (DOMString name); +}; +[NoInterfaceObject] +interfacePropertyMap
{ + readonly maplike<DOMString,ThingProperty
>; +}; +[NoInterfaceObject] +interfaceActionMap
{ + readonly maplike<DOMString,ThingAction
>; +}; +[NoInterfaceObject] +interfaceEventMap
{ + readonly maplike<DOMString,ThingEvent
>; +}; +ConsumedThing
includesObservable
; // for TD changes
The id
attribute
+ represents the unique identifier of the Thing instance,
+ typically a URI, IRI, or URN as USVString
.
The name
attribute
+ represents the name of the Thing as
+ DOMString
.
The base
attribute
+ represents the base URI that is valid for all defined local
+ interaction resources.
The properties
+ attribute represents a dictionary of ThingProperty
items. The
+ PropertyMap
interface
+ represents a maplike dictionary where all values are ThingProperty
objects. The
+ read()
and write()
methods make a
+ request to access the Properties on the remote
+ Thing represented by this ConsumedThing
proxy object.
The actions
+ attribute represents a dictionary of ThingAction
items. The
+ ActionMap
interface represents a
+ maplike dictionary where all values are ThingAction
objects. The
+ invoke()
method represents a request to invoke the
+ Action on the remote Thing.
The events
+ attribute represents a dictionary of ThingEvent
items. The EventMap
interface
+ represents a maplike dictionary where all values are ThingEvent
objects. Subscribing to the
+ events involves setting up an observation (subscription)
+ mechanism on the remote object.
Below a
interface example
+ is given.ConsumedThing
try {
+ let subscription = wot.discover({ method: "local" }).subscribe(
+ td => {
+ let thing = wot.consume(td);
+ console.log("Thing " + thing.name + " has been consumed.");
+ let subscription = thing["temperature"].subscribe(function(value) {
+ console.log("Temperature: " + value);
+ });
+ thing.actions["startMeasurement"].invoke({ units: "Celsius" })
+ .then(() => { console.log("Temperature measurement started."); })
+ .catch(e => {
+ console.log("Error starting measurement.");
+ subscription.unsubscribe();
+ })
+ },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+ );
+} catch(error) {
+ console.log("Error: " + error.message);
+};
+ ExposedThing
+ interfaceThe ExposedThing
interface is
+ the server API that allows defining request handlers,
+ properties, Actions, and Events to a
+ Thing. It also implements the Observable
interface. An ExposedThing
is created by the produce() method.
interface+ExposedThing
:ThingFragment
{ + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeExposedEvents
events
; + // getter for ThingFragment properties + getter any (DOMString name); + // setter for ThingFragment properties + setter void (DOMString name, any value); + // methods to expose and destroy the Thing + Promise<void>expose
(); + Promise<void>destroy
(); + // define Properties +ExposedThing
addProperty
(DOMString name,PropertyFragment
property, optional any initValue); +ExposedThing
setPropertyReadHandler
(DOMString name,PropertyReadHandler
readHandler); +ExposedThing
setPropertyWriteHandler
(DOMString name,PropertyWriteHandler
writeHandler); +ExposedThing
removeProperty
(DOMString name); + // define Actions +ExposedThing
addAction
(DOMString name,ActionFragment
init,ActionHandler
action); +ExposedThing
removeAction
(DOMString name); +ExposedThing
setActionHandler
(DOMString name,ActionHandler
action); + // define Events +ExposedThing
addEvent
(DOMString name,EventFragment
event); +ExposedThing
removeEvent
(DOMString name); +}; +[NoInterfaceObject] +interfaceExposedEvents
{ + maplike<DOMString,ExposedEvent
>; +}; +callbackPropertyReadHandler
= Promise<any> (); +callbackPropertyWriteHandler
= Promise<void> (any value); +callbackActionHandler
= Promise<any> (any parameters);
The properties
+ attribute represents a dictionary of ThingProperty
items in which the
+ read()
and write()
methods define
+ local methods that access the physical representations of the
+ Properties.
The actions
+ attribute represents a dictionary of ThingAction
items in which the
+ invoke()
method represents a local method to
+ invoke the Action.
The events
+ attribute represents a dictionary of ExposedEvent
items that add the
+ emit()
method to the ThingEvent
definition. The
+ ExposedEvents
interface
+ represents a maplike dictionary where all values are ExposedEvent
objects.
expose()
methodStart serving external requests for the Thing, so that WoT Interactions + using Properties, Actions and + Events will be possible.
+The expose()
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ expose()
is not allowed for
+ the current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ destroy()
methodStop serving external requests for the Thing and destroy the object. Note that eventual + unregistering should be done before invoking this method.
+The destroy()
method MUST run the following steps:
Promise
promise and
+ execute the next steps in parallel.
+ destroy()
is not allowed for
+ the current scripting context for security reasons, reject
+ promise with SecurityError
and
+ terminate these steps.Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ addProperty()
methodAdds a Property with name defined by the
+ name argument, the data schema provided by the
+ property argument of type PropertyFragment
, and optionally an
+ initial value provided in the argument initValue
+ whose type should match the one defined in the
+ type
property according to the value-matching algorithm. If
+ initValue is not provided, it SHOULD be initialized as
+ undefined
. Implementations SHOULD update the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
removeProperty()
methodRemoves the Property specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addAction()
methodAdds to the actions
property of a Thing object an Action with name
+ defined by the name argument, defines input and
+ output data format by the init argument of type
+ ActionFragment
, and
+ adds the function provided in the action argument
+ as a handler, then updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
The provided action callback function will
+ implement invoking an Action and SHOULD be called by
+ implementations when a request for invoking the Action is received from the underlying platform.
+ The callback will receive a parameters
+ dictionary argument according to the definition in the
+ init.input argument and will return a value of
+ type defined by the init.output argument according
+ to the value-matching
+ algorithm.
There SHOULD be
+ exactly one handler for any given Action. If no
+ handler is initialized for any given Action,
+ implementations SHOULD throw a TypeError
.
removeAction()
methodRemoves the Action specified by the
+ name
argument and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
addEvent()
methodAdds an event with name defined by the name
+ argument and qualifiers and initialization value provided by
+ the event argument of type EventFragment
to the Thing object and updates the Thing Description. Throws on error. Returns a
+ reference to the same object for supporting chaining.
removeEvent()
methodRemoves the event specified by the name
+ argument and updates the Thing
+ Description. Returns a reference to the same object for
+ supporting chaining.
PropertyReadHandler
+ callbackA function that is called when an external request for
+ reading a Property is received. It should
+ return a Promise and resolves it with the value of the
+ Property matching the name
argument to
+ the setPropertyReadHandler
function, or rejects
+ with an error if the property is not found or the value
+ cannot be retrieved.
PropertyWriteHandler
+ callbackA function that is called when an external request for
+ writing a Property is received. It is given
+ the requested new value
as argument and should
+ return a Promise which is resolved when the value of the
+ Property that matches the name
+ argument has been updated with value
, or rejects
+ with an error if the property is not found or the value
+ cannot be updated.
Note that this function is invoked by
+ implementations before the property is updated and it
+ actually defines what to do when a write request is
+ received. The code in this callback function can invoke the
+ read()
method to find out the old value of the
+ property, if needed. Therefore the old value is not
+ provided to this function.
ActionHandler
+ callbackA function called with a parameters
+ dictionary argument assembled by the WoT runtime based on the Thing Description and the external client request.
+ It returns a Promise that rejects with an error or resolves
+ if the action is successful or ongoing (may also resolve with
+ a control object such as an Observable
for actions that need
+ progress notifications or that can be canceled).
setPropertyReadHandler()
methodTakes name
as string argument and
+ readHandler
as argument of type PropertyReadHandler
.
+ Sets the handler function for reading the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
The readHandler
callback function will
+ implement reading a Property and
+ SHOULD be called by
+ implementations when a request for reading a Property is received from the underlying
+ platform.
There SHOULD be at + most one handler for any given Property and + newly added handlers replace the old handlers. If no handler + is initialized for any given Property, + implementations SHOULD implement a default property read + handler.
+When an external request for reading Property propertyName is received, the + runtime SHOULD + execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ setPropertyWriteHandler()
methodTakes name
as string argument and
+ writeHandler
as argument of type PropertyWriteHandler
.
+ Sets the handler function for writing the specified Property matched by name
. Throws on
+ error. Returns a reference to the same object for supporting
+ chaining.
There SHOULD be at + most one write handler for any given Property and newly added handlers replace the old + handlers. If no write handler is initialized for any given + Property, implementations SHOULD implement default property update + and notifying observers on change.
+When an external request for writing a Property propertyName with a new value + value is received, the runtime SHOULD execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ setActionHandler()
methodTakes name
as string argument and
+ action
as argument of type ActionHandler
. Sets the handler
+ function for the specified Action matched by
+ name
. Throws on error. Returns a reference to
+ the same object for supporting chaining.
The action
callback function will implement
+ an Action and SHOULD be called by implementations when a
+ request for invoking the Action is received
+ from the underlying platform.
There SHOULD be at + most one handler for any given Action and newly added + handlers replace the old handlers.
+When an external request for invoking the Action identified by name is received, + the runtime SHOULD + execute the following steps:
+Promise
promise and
+ execute the next steps in parallel.
+ ReferenceError
and
+ terminate these steps.
+ ReferenceError
and terminate these steps.
+ Below some
interface examples
+ are given.ExposedThing
+ try {
+ var temperatureValueDefinition = {
+ type: "number",
+ minimum: -50,
+ maximum: 10000
+ };
+ var temperaturePropertyDefinition = temperatureValueDefinition;
+ // add the 'forms' property
+ temperaturePropertyDefinition.forms = [ ... ];
+ var thing = WoT.produce({
+ name: "tempSensor",
+ properties: {
+ temperature: temperaturePropertyDefinition
+ },
+ actions: {
+ reset: {
+ description: "Reset the temperature sensor",
+ input: {
+ temperature: temperatureValueDefinition
+ },
+ output: null,
+ forms: []
+ },
+ },
+ events: {
+ onchange: temperatureValueDefinition
+ },
+ links: []
+ });
+ await thing.expose();
+ await wot.register("https://mydirectory.org", thing);
+ // define Thing business logic
+ setInterval( async () => {
+ let mock = Math.random()*100;
+ let old = await thing["temperature"].read();
+ if (old < mock) {
+ await thing["temperature"].write(mock);
+ thing.emitEvent("onchange", mock);
+ }
+ }, 1000);
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ try {
+ var statusValueDefinition = {
+ type: "object",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true
+ },
+ rgb: {
+ type: "array",
+ "minItems": 3,
+ "maxItems": 3,
+ items : {
+ "type" : "number",
+ "minimum": 0,
+ "maximum": 255
+ }
+ }
+ };
+ var statusPropertyDefinition = statusValueDefinition;
+ // add the 'forms' property
+ statusPropertyDefinition["forms"] = [];
+ var thing = WoT.produce({
+ name: "mySensor",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true,
+ },
+ status: statusPropertyDefinition
+ },
+ actions: {
+ status: {
+ description: "Get status object",
+ input: null,
+ output: {
+ status : statusValueDefinition;
+ },
+ forms: []
+ },
+ },
+ events: {
+ onstatuschange: statusValueDefinition;
+ },
+ links: []
+ });
+ thing.expose().then(() => {
+ thing.register();
+ });
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ let thingDescription = '{ \
+ "name": "mySensor", \
+ "@context": [ "http://www.w3.org/ns/td",\
+ "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ],\
+ "@type": [ "Thing", "Sensor" ], \
+ "geo:location": "testspace", \
+ "properties": { \
+ "prop1": { \
+ "type": "number",\
+ "@type": [ "Property", "Temperature" ], \
+ "saref:TemperatureUnit": "degree_Celsius" \
+ } } }';
+try {
+ // note that produce() fails if thingDescription contains error
+ let thing = WoT.produce(thingDescription);
+ // Interactions were added from TD
+ // WoT adds generic handler for reading any property
+ // define a specific handler for one property
+ let name = "examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log("Handling read request for " + name);
+ return new Promise((resolve, reject) => {
+ let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log("Error");
+ });
+ });
+ thing.expose();
+} catch(err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+ // fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+ // WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+ // Interactions were added from TD
+ // add server functionality
+ // ...
+});
+ The [WOT-TD] specification defines the + + WoT information model, i.e. the data types and data + structures used in WoT Interactions. In + this API these definitions translate to dictionary objects that + are extended with methods by the interfaces defined in this + specification.
+In order to avoid duplication of definitions, references to + these data types and structures is defined in this section, but + for their full description please refer to the Thing + Description specification.
+DataSchema
+ dictionary and its subclassesValue types basically represent types that may be used in
+ JSON object definitions and are used in ThingFragment
to define Properties, Events and Action parameters. Value types are represented as
+ dictionary objects whose properties and possible sub-classes
+ are defined in the
+ DataSchema section of [WOT-TD].
One property of all DataSchema
dictionary is the
+ type
property whose value is from a set of
+ enumerated strings defined in the DataSchema
+ section of [WOT-TD] and is referred as
+ DataType in
+ this specification.
Based on type
, the following sub-classes of
+ DataSchema
are defined in
+ [WOT-TD]: BooleanSchema, NumberSchema, IntegerSchema, StringSchema, ObjectSchema, ArraySchema.
SecurityScheme
dictionary
+ and its subclassesSecurity metadata is represented as dictionary objects + whose properties and sub-classes are defined in the + SecurityScheme section of [WOT-TD].
+One property of the SecurityScheme
dictionary is the
+ scheme
property whose value is from a set of
+ enumerated strings defined in the
+ SecurityScheme section of [WOT-TD]. Based on type
,
+ multiple subclasses of SecurityScheme
are defined.
Link
dictionaryRepresents a Web Link with + properties defined in the Link + section of [WOT-TD].
+Form
dictionaryRepresents metadata describing service details, with + properties defined in the Form + section of [WOT-TD].
+InteractionFragment
+ dictionaryRepresents the common properties of WoT Interactions, one of Property,
+ Action or Event, as defined in the
+ InteractionPattern section of [WOT-TD]. Its subclasses are
+ referred as PropertyFragment
, ActionFragment
and EventFragment
.
PropertyFragment
+ dictionaryRepresents the Property interaction
+ data that initializes a ThingProperty
object. Its properties
+ are defined in the Property
+ and
+ InteractionPattern sections of [WOT-TD].
ActionFragment
+ dictionaryRepresents the Action interaction data that
+ initializes a ThingAction
object. Its
+ properties are defined in the Action
+ and
+ InteractionPattern sections of [WOT-TD].
EventFragment
+ dictionaryRepresents the Event interaction data that
+ initializes a ThingEvent
object. Its
+ properties are defined in the Event
+ section of [WOT-TD].
ThingFragment
+ dictionaryThe ThingFragment
+ dictionary is defined as Thing
+ in [WOT-TD]. It is a dictionary that
+ contains properties representing semantic metadata and
+ interactions (Properties, Actions and
+ Events). It is used for initializing an internal
+ representation of a Thing Description and
+ its properties may be used in ThingFilter
.
ThingDescription
+ typeSerialized representation of the Thing Description (a JSON-LD document).
+In this version of the API, Thing Descriptions are represented
+ as an opaque USVString
that can be transmitted
+ between devices.
The data types and structures imported from [WOT-TD] are extended by + this specification in order to provide the interfaces for + WoT Interactions.
+Every Thing describes its metadata as
+ defined in ThingFragment
, and basic
+ interactions defined as Properties, Actions and Events. The following interfaces are
+ used for representing these interactions.
Interaction
+ interfaceThe Interaction
interface
+ is an abstract class to represent Thing
+ interactions: Properties, Actions and
+ Events.
The InteractionFragment
+ dictionary holds the common properties of PropertyFragment
, ActionFragment
and EventFragment
dictionaries used for
+ initializing ThingProperty
, ThingAction
and ThingEvent
objects in a ThingFragment
dictionary used for
+ creating an ExposedThing
+ object.
interface+Interaction
{ + readonly attribute (Form
or FrozenArray<Form
>)forms
; +}; +Interaction
includesInteractionFragment
;
The forms
read-only
+ property represents the protocol bindings initialization data
+ and is initialized by the WoT Runtime.
ThingProperty
+ interfaceThe ThingProperty
interface
+ is used in ConsumedThing
and
+ ExposedThing
objects to
+ represent Thing Property
+ interactions.
The PropertyFragment
+ dictionary is used for initializing Property objects
+ in a ThingFragment
+ dictionary used for creating an ExposedThing
object. It MUST implement one of the
+ DataSchema
dictionaries.
interface+ThingProperty
:Interaction
{ + // getter for PropertyFragment properties + getter any (DOMString name); + // get and set interface for the Property + Promise<any>read
(); + Promise<void>write
(any value); +}; +ThingProperty
includesPropertyFragment
; +ThingProperty
includesObservable
;
The ThingProperty
interface
+ contains all the properties defined on PropertyFragment
as read-only
+ properties.
The type
+ read-only property represents the type definition for the
+ Property as a DataSchema
dictionary object.
The writable read-only property tells
+ whether the Property value can be updated. If it
+ is false
, then the set(value)
+ method SHOULD always
+ reject.
The observable read-only
+ property tells whether the Property supports
+ subscribing to value change notifications. If it is
+ false
, then the subscribe()
method
+ SHOULD always
+ fail.
The constant read-only property
+ - defined in DataSchema
- tells
+ whether the Property value is a constant. If
+ true
, the set()
and
+ subscribe()
methods SHOULD always fail.
The required read-only property
+ - defined in DataSchema
- tells
+ whether the Property should be always present on
+ the ExposedThing
+ object.
The read()
+ method will fetch the value of the Property.
+ Returns a Promise that resolves with the
+ value, or rejects with an error.
The
+ write()
method will attempt to set the value of
+ the Propertyspecified in the
+ value
argument whose type SHOULD match the one specified by the
+ type
property. Returns a Promise that
+ resolves on success, or rejects on an error.
ThingAction
+ interfaceinterface+ThingAction
:Interaction
{ + Promise<any>invoke
(optional any inputValue); +}; +ThingAction
includesActionFragment
;
The
+ invoke()
method when invoked, starts the
+ Action interaction with the input value provided by
+ the inputValue argument. If inputValue
+ is null
, the action does not take any arguments
+ and rejects if any arguments are provided. If the value is
+ undefined
, the action will ignore any arguments
+ provided. Otherwise the type of inputValue
+ SHOULD match the
+ DataSchema
definition in the
+ input
property. Returns a Promise that
+ will reject with an error or will resolve with a value of
+ type defined by the output
property.
ThingEvent
interfaceinterface+ThingEvent
:Interaction
{ +}; +ThingEvent
includesEventFragment
; +ThingEvent
includesThingProperty
;
Since ThingEvent
implements
+ Observable
through the ThingProperty
interface, event
+ subscription is done by invoking the subscribe()
+ method on the event object that returns a cancelable Subscription
.
ExposedEvent
+ interfaceinterface ExposedEvent
: ThingEvent
{
+ void emit
(any payload);
+};
+ emit()
+ methodEmits an event that carries data specified by the
+ payload
argument.
The value-matching algorithm is applied to a
+ value input in relation to a valueType
+ property of type DataSchema
, for instance the
+ value
and type
properties of a
+ PropertyFragment
+ object, or the inputValue parameter to the
+ invoke()
method of a ThingAction
object in relation to the
+ same object. It executes the following steps:
false
.
+ "null"
: if value is
+ null
, return true
, otherwise
+ return false
."boolean"
: if value is either
+ true
or false
, then return
+ true
, otherwise return
+ false
."integer"
: if value is not an
+ integer type defined by the underlying platform (such as
+ long
or long long
), then return
+ false
, otherwise execute the following
+ sub-steps:
+ true
."number"
, if value is not an
+ integer or floating point type defined by the underlying
+ platform (such as long
or long
+ long
or double
), then return
+ false
, otherwise otherwise execute the
+ following sub-steps:
+ true
."string"
: if value is not a string
+ type defined by the underlying platform, then return
+ false
, otherwise return true
. In this
+ case the algorithm expects a third parameter
+ valueType.enum and runs the following
+ sub-steps:
+ "array"
, execute the following sub-steps:
+ false
.undefined
, return false
.null
, return true
(i.e. any
+ type is accepted as array element, including
+ heterogenous arrays).false
, then return
+ false
.
+ true
."object"
,
+ execute the following sub-steps:
+ Object
,
+ return false
.false
.null
, return true
(i.e.
+ accept any object value).false
.true
.This section is non-normative.
+Observables are proposed to + be included in ECMAScript and are used for handling pushed data + associated with various possible sources, for instance events, + timers, streams, etc. A minimal required implementation is + described here.
+This section is informal and contains rather + laconic information for implementations on what to support + for interoperability.
+interface+Observable
{ +Subscription
subscribe
(EventHandler handler, + optionalErrorHandler
errorHandler, + optionalOnComplete
onComplete); +}; +interfaceSubscription
{ + voidunsubscribe
(); + readonly attribute booleanclosed
; +}; +callbackEventHandler
= void (any value); +callbackErrorHandler
= void (Error error); +callbackOnComplete
= void ();
The following callbacks can be provided when subscribing to
+ an Observable
:
EventHandler
callback takes
+ the next sample for the data in the value
+ argument.ErrorHandler
callback takes
+ an error in the value
argument. It is called
+ when an error occurred in producing the data the client should
+ know about.OnComplete
callback is called
+ when the data source has finished sending values.Subscription
+ interfaceContains the closed
+ property of type boolean
that tells if the
+ subscription is closed or active.
Also, contains the unsubscribe
()
+ method that cancels the subscription, i.e. makes a request to
+ the underlying platform to stop receiving data from the
+ source, and sets the closed
property to
+ false
.
Observable
interfaceThe Observable
interface
+ enabled subscribing to pushed data notifications by the
+ subscribe
()
+ method:
In general the security measures taken to protect a WoT + system will depend on the threats and attackers that system may + face and the value of the assets needs to protect. A detailed + discussion of security and privacy considerations for the Web + of Things, including a threat model that can be adapted to + various circumstances, is presented in the informative document + [WOT-SECURITY-CONSIDERATIONS]. + This section includes only normative recommendations relevant + to the WoT Thing Description.
+When designing new devices and services + for use with the WoT, we have documented a set of best + practices in [WOT-SECURITY-BEST-PRACTICES] + that SHOULD be + followed. This best-practices document may be updated as + security measures evolve. Following these practices does not + guarantee security, but it at least will help to avoid common + known vulnerabilities and pitfalls.
+Below are specific recommendations related to WoT runtime + implementations:
+Some additional specific recommendations relevant for WoT + script developers:
+The generic WoT terminology is defined in [WOT-ARCHITECTURE]: + Thing, Thing Description (in short + TD), + Web of + Things (in short WoT), WoT Interface, + Protocol + Bindings, WoT Runtime, Consuming a Thing + Description, Thing Directory, + WoT + Interactions, Property, + Action, Event etc.
+JSON-LD is + defined in [JSON-LD] as a JSON document that is + augmented with support for Linked Data.
+The terms URL and URL path are defined in + [URL].
+The following terms are defined in [HTML52] and are used in the context + of browser implementations: + + + browsing + context, + + + top-level browsing + context, + + + global + object, + + + incumbent settings + object, + + + Document, + + + document base URL, + + + Window, + + + WindowProxy, + + + origin, + + + ASCII + serialized origin, + + executing algorithms + + + in parallel, + + + queue a task, + + + task source, + + + iframe, + + + valid MIME type.
+ +A browsing context refers to the
+ environment in which Document objects are
+ presented to the user. A given browsing context
+ has a single WindowProxy
+ object, but it can have many Document
+ objects, with their associated Window
+ objects. The script execution context
+ associated with the browsing context identifies the
+ entity which invokes this API, which can be a web app, a
+ web page, or an iframe.
The term + secure + context is defined in [WEBAPPSEC].
+Error, EvalError, RangeError, ReferenceError, SyntaxError, + TypeError, + URIError , + script execution + context, + Promise, + + JSON, + JSON.stringify and + JSON.parse are defined in + [ECMASCRIPT].
+DOMString, USVString, ArrayBuffer, BufferSource and any are defined in + [WEBIDL].
+The algorithms utf-8 encode, and utf-8 decode are defined in + [ENCODING].
+IANA media + types (formerly known as MIME types) are defined in + RFC2046.
+The terms hyperlink reference and + relation + type are defined in [HTML52] and RFC8288.
+As well as sections marked as non-normative, all authoring + guidelines, diagrams, examples, and notes in this specification + are non-normative. Everything else in this specification is + normative.
+The key words MAY, MUST, SHOULD, and SHOULD NOT + are to be interpreted as described in [RFC2119].
+This document defines conformance criteria that apply to a + single product: the UA (user agent) that implements the interfaces + it contains.
+This specification can be used for implementing the WoT + Scripting API in multiple programming languages. The interface + definitions are specified in [WEBIDL].
+The user agent (UA) may be implemented in the browser, or in + a separate runtime environment, such as Node.js or small embedded + runtimes.
+Implementations that use ECMAScript executed in a browser to + implement the APIs defined in this document MUST implement them in a manner consistent + with the ECMAScript Bindings defined in the Web IDL + specification [WEBIDL].
+Implementations that use TypeScript or ECMAScript in a + runtime to implement the APIs defined in this document + MUST implement them in a + manner consistent with the TypeScript Bindings defined in the + TypeScript specification [TYPESCRIPT].
+This document serves a general description of the WoT + Scripting API. Language and runtime specific issues are + discussed in separate extensions of this document.
+The following is a list of major changes to the document. + For a complete list of changes, see the github + change log. You can also view the + recently closed issues.
+The following problems are being discussed and need most + attention:
+ExposedThing
+ (https://github.com/w3c/wot-scripting-api/issues/45).
+ Special thanks to former editor Johannes Hund (until August + 2017, when at Siemens AG) for developing this specification. + Also, the editors would like to thank Dave Raggett, Matthias + Kovatsch, Michael Koster and Michael McCool for their comments + and guidance.
++ +Copyright + +© +2017-2018 + + +W3C + + + +® + +( + + +MIT + +, + + +ERCIM + +, + +Keio +, + +Beihang + +). + +W3C + + +liability +, + +trademark + +and + +permissive +document +license + +rules +apply. +
+
+The
+overall
+
+
+Web
+of
+Things
+
+(WoT)
+provides
+layered
+interoperability
+between
+
+concepts
+are
+described
+in
+the
+
+WoT
+Architecture
+
+document.
+The
+Web
+of
+
+Things
+is
+made
+of
+entities
+(
+
+Thing
+
+
+by
+using
+
+s)
+that
+can
+describe
+their
+capabilities
+in
+a
+machine-interpretable
+format,
+the
+
+Thing
+Description
+
+(TD)
+and
+expose
+these
+capabilities
+through
+
+the
+
+WoT
+Interface
+,
+that
+is,
+network
+interactions
+modeled
+as
+
+Properties
+
+
+s.
+
+for
+reading
+and
+writing
+values,
+
+Action
+
+s
+to
+execute
+remote
+procedures
+with
+or
+without
+return
+values
+and
+
+Event
+
+s
+for
+signaling
+notifications.
+
+
+This
+specification
+describes
+a
+programming
+interface
+representing
+the
+
+WoT
+Interface
+
+that
+allows
+scripts
+run
+on
+a
+
+Thing
+
+to
+discover
+and
+consume
+(retrieve)
+other
+
+Thing
+Description
+
+
+s
+and
+to
+expose
+
+Things
+
+characterized
+by
+
+WoT
+Interactions
+,
+i.e.
+Properties
+,
+Actions
+
+
+and
+Events
+.
+
+specified
+by
+a
+script.
+
+
+Scripting +is +an +optional +"convenience" +building +block +in +WoT +and +it +is +typically +used +in +gateways +that +are +able +to +run +a + +WoT +Runtime + +and + +script +management +, +providing +a +convenient +way +to +extend +WoT +support +to +new +types +of +endpoints +and +implement +WoT +applications +like + +Thing +Directory +. +
++ +This +section +describes +the +status +of +this +document +at +the +time +of +its +publication. +Other +documents +may +supersede +this +document. +A +list +of +current + +W3C + +publications +and +the +latest +revision +of +this +technical +report +can +be +found +in +the + + +W3C + +technical +reports +index + +at +https://www.w3.org/TR/. + +
++Implementers +need +to +be +aware +that +this +specification +is +considered +unstable. +Vendors +interested +in +implementing +this +specification +before +it +eventually +reaches +the +Candidate +Recommendation +phase +should +subscribe +to +the + +repository + +and +take +part +in +the +discussions. +
++Please +contribute +to +this +draft +using +the + +GitHub +Issue + +feature +of +the + +WoT +Scripting +API + +repository. +For +feedback +on +security +and +privacy +considerations, +please +use +the + +WoT +Security +and +Privacy + +Issues. +
++This +document +was +published +by +the + +Web +of +Things +Working +Group + +as +a +Working +Draft. +This +document +is +intended +to +become +a +W3C +Recommendation. +
++Comments +regarding +this +document +are +welcome. +Please +send +them +to + +public-wot-wg@w3.org + +( + +subscribe +, + +archives + +). +
++Changes +from +the +previous +publication +can +be +found +in + +Appendix +A +. +A + +diff-marked +version + +of +this +document +is +also +available +for +comparison +purposes. +
++Publication +as +a +Working +Draft +does +not +imply +endorsement +by +the + +W3C + +Membership. +This +is +a +draft +document +and +may +be +updated, +replaced +or +obsoleted +by +other +documents +at +any +time. +It +is +inappropriate +to +cite +this +document +as +other +than +work +in +progress. +
++This +document +was +produced +by +a +group +operating +under +the + + +W3C + +Patent +Policy +. + +W3C + +maintains +a + +public +list +of +any +patent +disclosures + +made +in +connection +with +the +deliverables +of +the +group; +that +page +also +includes +instructions +for +disclosing +a +patent. +An +individual +who +has +actual +knowledge +of +a +patent +which +the +individual +believes +contains + +Essential +Claim(s) + +must +disclose +the +information +in +accordance +with + +section +6 +of +the + +W3C + +Patent +Policy +. +
++This +document +is +governed +by +the + +1 +February +2018 + +W3C + +Process +Document +. +
+
+The
+overall
+
+WoT
+concepts
+are
+described
+in
+the
+WoT
+Architecture
+document.
+The
+Web
+of
+Things
+is
+made
+of
+entities
+(
+Thing
+s)
+that
+can
+describe
+their
+capabilities
+in
+a
+machine-interpretable
+format,
+the
+
+provides
+layered
+interoperability
+based
+on
+how
+
+Thing
+Description
+
+
+(TD)
+
+s
+are
+modeled:
+as
+being
+"consumed"
+
+and
+expose
+these
+capabilities
+through
+the
+WoT
+Interface
+.
+Support
+for
+scripting
+is
+optional
+for
+WoT
+devices.
+
+"exposed".
+
+
+By
+
+consuming
+a
+TD
+,
+a
+client
+
+Thing
+
+creates
+a
+runtime
+resource
+model
+that
+allows
+accessing
+the
+
+Properties
+,
+
+Actions
+
+and
+
+Events
+
+exposed
+by
+the
+server
+
+Thing
+.
+
+
+exposed
+on
+a
+remote
+device.
+
+
+Exposing
+a
+
+Thing
+
+requires
+defining
+a
+
+Thing
+Description
+
+(TD)
+and
+instantiating
+a
+software
+stack
+needed
+
+to
+serve
+requests
+for
+accessing
+the
+exposed
+
+Properties
+,
+
+Actions
+
+and
+
+Events
+.
+This
+specification
+describes
+how
+to
+expose
+and
+consume
+
+Thing
+
+s
+by
+a
+script.
+
+Typically
+scripts
+are
+meant
+to
+be
+used
+on
+devices
+able
+to
+provide
+resources
+(with
+a
+
+WoT
+interface
+
+Interface
+
+
+)
+for
+managing
+(installing,
+updating,
+running)
+scripts,
+such
+as
+bridges
+or
+gateways
+that
+expose
+and
+control
+simpler
+devices
+as
+WoT
+
+Thing
+
+s.
+
+This +specification +does +not +make +assumptions +on +how +the + +WoT +Runtime + +handles +and +runs +scripts, +including +single +or +multiple +tenancy, +script +deployment +and +lifecycle +management. +The +API +already +supports +the +generic +mechanisms +that +make +it +possible +to +implement +script +management, +for +instance +by +exposing +a +manager + +Thing + +whose + +Actions + +(action +handlers) +implement +script +lifecycle +management +operations. +
++For +an +introduction +on +how +scripts +could +be +used +in + +Web +of +Things +, +check +the + +Primer + +document. +For +some +background +on +API +design +decisions +check +the + +Rationale + +document. +
++ +This +section +is +non-normative. + +
++The +following +scripting +use +cases +are +supported +in +this +specification: +
+
+ExposedThing
+
+
+to
+be
+exposed,
+based
+on
+a
+
+Thing
+Description
+
+provided
+in
+string
+serialized
+format,
+or
+out
+of
+a
+template
+or
+an
+existing
+
+
+ConsumedThing
+
+
+object.
+
+WoT
+
+
+object
+
+
++The +WoT +object +is +the +API +entry +point +and +it +is +exposed +by +an +implementation +of +the + +WoT +Runtime +. +The + +WoT +object + +does +not +expose +properties, +only +methods +for +discovering, +consuming +and +exposing +a + +Thing +. +
+
+Browser
+implementations
+
+SHOULD
+
+use
+a
+namespace
+object
+such
+as
+
+
.
+
+Node.js
+
+-like
+runtimes
+
+MAY
+
+provide
+the
+API
+object
+through
+the
+
+require()
+
+or
+
+import
+
+mechanism.
+wot
+,
+and
+
+navigator.wot
+
data-idl="" data-title="WoT">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-wot" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-wot-discover-filter" data-idl= +"" data-title="discover" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-observable" class="internalDFN" +data-link-type="dfn"><<a href= +"#dom-consumedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="wot" data-lt= +"discover()|discover" href="#dom-wot-discover" class="internalDFN" +data-link-type="dfn">discover(<span class= +"idlParam">optional <a href= +"#dom-thingfilter" class="internalDFN" data-link-type= + +data-idl="" data-title="WoT">// [SecureContext] +// [NamespaceObject] +interface +data-link-for="" data-lt="" href="#dom-wot" class="internalDFN" +data-link-type="dfn">+WoT
{ + +data-link-type= +"dfn">Observable
discover
(optional +"dfn">ThingFilter
"idlParamName">filter +<span class="idlMethod" id="idl-def-wot-fetch-url" data-idl="" +data-title="fetch" data-dfn-for="wot"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<<a href="#dom-thingdescription" +class="internalDFN" data-link-type= + +"idlParamName">filter); + +"https://heycam.github.io/webidl/#idl-promise">Promise< +"dfn">ThingDescription
> "fetch()|fetch" href="#dom-wot-fetch" class="internalDFN" +data-link-type="dfn">fetch(<span class= + +"wot.fetch()|wot.fetch|fetch()|fetch" href="#dom-wot-fetch" class= +"internalDFN" data-link-type= +"dfn">fetch
( +"idlParam">"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id="idl-def-wot-consume-td" data-idl="" +data-title="consume" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-consumedthing" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-USVString">USVString url); + "dfn"><a data-no-default="" +data-link-for="wot" data-lt="consume()|consume" href= + +"dfn">ConsumedThing
+"#dom-wot-consume" class="internalDFN" data-link-type= +"dfn">consume<span class= +"idlParamType"><a href="#dom-thingdescription" class="internalDFN" +data-link-type= ++"dfn">consume
( +"dfn">ThingDescription
"idlParamName">td +<span class="idlMethod" id="idl-def-wot-produce-model" data-idl="" +data-title="produce" data-dfn-for="wot"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" + +"idlParamName">td); + "dfn"><a data-no-default="" +data-link-for="wot" data-lt="produce()|produce" href= +"#dom-wot-produce" class="internalDFN" data-link-type= +"dfn">produce<span class= +"idlParamType"><a href="#dom-thingmodel" class="internalDFN" + +"dfn">ExposedThing
produce
(ThingModel
model); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>register
(USVString directory,ExposedThing
thing); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unregister
(USVString directory,ExposedThing
thing); +}; +typedef objectThingFragment
; +typedef objectPropertyFragment
; +typedef objectActionFragment
; +typedef objectEventFragment
; +typedef objectDataSchema
; +typedef objectSecurityScheme
; +typedef object +data-link-type= +"dfn"> +}; +<span class="idlTypedef" id="idl-def-thingdescription" data-idl="" +data-title="ThingDescription">typedef <span class= +"idlTypedefType"><a href= ++"dfn">Link
; +typedef objectForm
; +typedef +"https://heycam.github.io/webidl/#idl-USVString">USVString "dfn"> +<span class="idlTypedef" id="idl-def-thingmodel" data-idl="" +data-title="ThingModel">typedef <span class= +"idlTypedefType">(<a href="#dom-thingtemplate" class="internalDFN" +data-link-type="dfn"> or <a href= + +"dfn">ThingDescription
; +typedef (ThingFragment
or +"#dom-thingdescription" class="internalDFN" data-link-type= +"dfn">ThingDescription
) ++ThingModel +
+ + +; + +
+The +algorithms +for +the +WoT +methods +will +be +specified +later, +including +error +handling +and +security +considerations. +
+
+The
+
+ThingModel
+
+type
+represents
+either
+a
+
+ThingFragment
+
,
+or
+a
+
+ThingDescription
+
.
+discover()
+
+
+method
+
+
+
+Starts
+the
+discovery
+process
+that
+will
+provide
+
+
+
+
+ConsumedThing
+
+ThingDescription
+
+objects
+
+s
+
+that
+match
+the
+optional
+argument
+
+filter
+
+of
+type
+
+
+
+
.
+
+ThingFilter
+
+
+When
+the
+argument
+is
+not
+provided,
+starts
+the
+widest
+discovery
+the
+Thing
+Description
+and
+Protocol
+Bindings
+allow
+and
+support.
+
+Returns
+an
+[
+
+
+Observable
+
+](https://github.com/tc39/proposal-observable)
+
+object
+that
+can
+be
+subscribed
+to
+and
+unsubscribed
+from.
+The
+handler
+function
+provided
+to
+the
+Observable
+during
+subscription
+will
+receive
+an
+argument
+of
+type
+
+USVString
+
+representing
+a
+
+ThingDescription
+
.
+
+DiscoveryMethod
+
+
+enumeration
+
+
+"DiscoveryMethod">typedef <a href=
+
+"DiscoveryMethod">typedef
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+
+DiscoveryMethod
+
+
+
+;
+
+
+
+
+
+DiscoveryMethod
+
+
+represents
+the
+discovery
+type
+to
+be
+used:
+
+ThingFilter
+
+
+dictionary
+
+
+
+The
+
+
+ThingFilter
+
+
+dictionary
+that
+represents
+the
+constraints
+for
+discovering
+
+Thing
+
+s
+as
+key-value
+pairs.
+
dictionary "dfn"> {
+<span class="idlMember" id="idl-def-thingfilter-method" data-idl=""
+data-title="method" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href="#dom-discoverymethod" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-no-default="" data-link-for="thingfilter"
+data-lt="" href="#dom-thingfilter-method" class="internalDFN"
+data-link-type="dfn"> = <span class=
+"idlMemberValue">"any"
+<span class="idlMember" id="idl-def-thingfilter-url" data-idl=""
+data-title="url" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+
+"dfn">ThingFilter
{
+ (DiscoveryMethod
or DOMString) method
= "any";
+
+"https://heycam.github.io/webidl/#idl-USVString">USVString?
+data-link-for="thingfilter" data-lt="" href="#dom-thingfilter-url"
+class="internalDFN" data-link-type=
+"dfn">
+<span class="idlMember" id="idl-def-thingfilter-query" data-idl=""
+data-title="query" data-dfn-for="thingfilter"> <span class=
+"idlMemberType"><a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+
+"dfn">url
;
+
+"https://heycam.github.io/webidl/#idl-USVString">USVString?
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-query" class="internalDFN" data-link-type=
+"dfn">
+<span class="idlMember" id="idl-def-thingfilter-constraints"
+data-idl="" data-title="constraints" data-dfn-for=
+"thingfilter"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<a data-no-default=""
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-constraints" class="internalDFN" data-link-type=
+"dfn">
+
+"dfn">query
;
+
+data-link-type=
+"dfn">ThingFragment
? fragment
;
+
+};
+
+
+
+The
+
+
+method
+
+
+property
+represents
+the
+discovery
+type
+that
+should
+be
+used
+in
+the
+discovery
+process.
+The
+possible
+values
+are
+defined
+by
+the
+
+
+
+enumeration
+that
+
+DiscoveryMethod
+
+
+can
+
+
+MAY
+
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+
+The
+
+
+url
+
+
+property
+represents
+additional
+information
+for
+the
+discovery
+method,
+such
+as
+the
+URL
+of
+the
+target
+entity
+serving
+the
+discovery
+request,
+such
+as
+
+for
+instance
+
+a
+
+Thing
+Directory
+
+(if
+
+method
+
+is
+
+"directory"
+
+)
+
+or
+a
+Thing.
+
+Thing
+(otherwise).
+
+
+The
+
+
+query
+
+
+property
+represents
+a
+query
+string
+accepted
+by
+the
+implementation,
+for
+instance
+a
+SPARQL
+or
+JSON
+
+query.
+Support
+may
+be
+implemented
+locally
+in
+the
+
+WoT
+Runtime
+
+or
+remotely
+as
+a
+service
+in
+a
+
+Thing
+Directory
+.
+
+The
+
+
+
+
+property
+represents
+constraints
+
+fragment
+
+additional
+information
+
+a
+
+ThingFragment
+
+dictionary
+used
+
+for
+the
+discovery
+
+matching
+property
+by
+property
+against
+discovered
+
+Thing
+
+s.
+
+The
+
+discover(filter)
+
+method
+in
+
+
+MUST
+
+run
+
+the
+form
+of
+a
+list
+of
+sets
+of
+property-value
+pairs
+(dictionaries).
+The
+list
+elements
+(dictionaries)
+are
+in
+OR
+relationship,
+
+following
+steps:
+
+discover()
+
+is
+not
+allowed
+for
+the
+current
+scripting
+context
+for
+security
+reasons,
+throw
+
+SecurityError
+
+and
+
+Observable
+
+obs
+
+and
+execute
+
+the
+
+obs.subscribe(handler,
+errorHandler,
+complete)
+
+is
+called,
+execute
+
+the
+following
+
+TypeError
+
+and
+terminate
+the
+algorithm.
+Otherwise
+configure
+
+handler
+
+to
+be
+invoked
+when
+a
+discovery
+hit
+happens.
+
+SemanticAnnotations
+
+TypeError
+
+
+
+TypeError
+
+and
+terminate
+these
+steps.
+Otherwise
+if
+defined,
+save
+it
+to
+be
+invoked
+when
+the
+discovery
+process
+finished
+for
+other
+reasons
+than
+having
+been
+canceled.
+
+name
+
+NotSupported
+
+
+
+SemanticType
+
+ThingFragment
+
+
+
+TypeError
+
+and
+terminate
+these
+steps.
+Otherwise
+save
+
+the
+
+"any"
+
,
+use
+the
+widest
+discovery
+method
+supported
+by
+the
+underlying
+platform.
+
+"local"
+
,
+use
+the
+local
+
+Thing
+Directory
+
+
+
+"directory"
+
,
+use
+
+the
+
+"multicast"
+
,
+use
+all
+
+the
+
+false
+
,
+discard
+
+td
+
+and
+continue
+
+the
+
+false
+
+in
+any
+checks,
+discard
+
+td
+
+and
+continue
+the
+discovery
+process.
+
+
+@type
+
+Error
+
+
+
+@context
+,
+
+message
+
+property
+is
+set
+to
+
+
+@type
+
+UnknownError
+
+
+unless
+there
+was
+an
+error
+code
+provided
+by
+the
+
+Protocol
+Bindings
+,
+in
+which
+case
+set
+it
+to
+that
+value.
+
+@id
+
+obs.unsubscribe()
+
+
+
+false
+
.
+fetch()
+
+
+method
+
+
+
+Accepts
+an
+
+url
+
+argument
+of
+type
+
+USVString
+
+that
+represents
+a
+URL
+(e.g.
+
+"file://..."
+
+or
+
+"https://..."
+
+)
+
+and
+returns
+a
+
+
+Promise
+
+
+that
+resolves
+with
+a
+
+
+ThingDescription
+
+.
+
+
+(a
+serialized
+
+JSON-LD
+
+document
+of
+type
+
+USVString
+
+).
+
+
+The
+
+
+ThingDescription
+
+fetch(url)
+
+type
+Representation
+of
+
+method
+
+MUST
+
+run
+
+the
+Thing
+Description
+,
+standardized
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+fetch()
+
+is
+not
+allowed
+for
+
+the
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+application/td+json
+
+),
+as
+far
+as
+a
+valid
+
+Thing
+
+Description
+
+
+Error
+
+object
+
+error
+
+with
+
+error.message
+
+set
+to
+the
+error
+code
+seen
+by
+the
+
+Protocol
+Bindings
+
+
+and
+
+consume()
+
+
+method
+
+
+
+Accepts
+an
+
+td
+
+argument
+of
+type
+
+
+
+and
+returns
+a
+
+
+ThingDescription
+
+
+
+ConsumedThing
+
+
+object
+instantiated
+based
+on
+parsing
+
+that
+description.
+
+The
+
+consume(td)
+
+method
+must
+run
+the
+following
+steps:
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+ThingFragment
+
+with
+a
+default
+value,
+add
+that
+property
+and
+value
+to
+
+stub
+.
+ConsumedThing
+
+object
+
+thing
+
+initialized
+from
+
+stub
+
+that
+implements
+
+Observable
+
.
+read()
+
+and
+
+write()
+
+methods
+to
+the
+
+ThingProperty
+
+elements
+so
+that
+they
+make
+requests
+to
+access
+the
+remote
+
+Thing
+
+s
+and
+wait
+for
+the
+reply,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+Also,
+all
+
+ThingProperty
+
+elements
+
+SHOULD
+
+implement
+
+Observable
+
,
+i.e.
+define
+a
+
+subscribe()
+
+method
+that
+should
+make
+request
+to
+observe
+the
+given
+
+Properties
+
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+invoke()
+
+methods
+to
+the
+
+ThingAction
+
+elements
+so
+that
+they
+make
+requests
+to
+the
+remote
+
+Thing
+
+to
+invoke
+its
+actions,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+subscribe()
+
+method
+to
+all
+
+ThingEvent
+
+elements
+so
+that
+they
+make
+requests
+to
+subscribe
+to
+the
+events
+defined
+by
+the
+remote
+
+Thing
+,
+as
+defined
+by
+the
+
+Protocol
+Bindings
+.
+produce()
+
+
+method
+
+
+
+Accepts
+a
+
+model
+
+argument
+of
+type
+
+
+
+and
+returns
+an
+
+
+ThingModel
+
+
+
+ExposedThing
+
+
+object,
+locally
+created
+based
+on
+the
+provided
+initialization
+parameters.
+An
+
+object.
+
+The
+
+
+
+ExposedThing
+
+produce(model)
+
+can
+be
+created
+in
+
+method
+
+MUST
+
+run
+
+the
+following
+ways:
+
+steps:
+
+
+produce()
+
+is
+not
+allowed
+for
+the
+current
+scripting
+context
+for
+security
+reasons,
+throw
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+TypeError
+
+and
+terminate
+these
+steps.
+
+ConsumedThing
+
+ThingFragment
+
+
+
+
+ThingModel
+
+ExposedThing
+
+
+
+ExposedThing
+
+
+
+ThingTemplate
+
+ThingFragment
+
+
+,
+initialize
+the
+property
+based
+on
+the
+provided
+initial
+
+or
+
+ThingDescription
+
+id
+
+
+
+security
+
+object
+of
+type
+
+
+SemanticAnnotations
+
+SecurityScheme
+
+
+
+semanticType
+
+properties
+
+
+property
+
+SemanticType
+
+ThingProperty
+
+
+
+objects
+
+read()
+
+and
+
+write()
+
+methods
+are
+provided
+to
+
+define
+local
+methods
+to
+get
+and
+set
+the
+
+Property
+
+values,
+
+metadata
+
+actions
+
+
+property
+
+SemanticMetadata
+
+ThingAction
+
+
+
+objects
+
+SemanticType
+
+invoke()
+
+
+
+events
+
+property
+to
+be
+an
+object
+with
+all
+properties
+being
+
+
+name
+
+ExposedEvent
+
+
+
+context
+
+emit()
+
+
+
+The
+prefix
+
+
+TD
+parsing
+algorithm
+
+
+attribute
+represents
+
+takes
+
+a
+short
+prefix
+associated
+with
+
+string
+
+td
+
+as
+argument
+and
+runs
+the
+following
+steps:
+
+SemanticMetadata
+
+register()
+
+
+
+
+The
+
+Takes
+two
+mandatory
+arguments:
+
+SemanticMetadata
+
+directory
+
+
+
+type
+
+thing
+
+
+
+SemanticType
+
+ExposedThing
+
+
+
+object.
+
+A
+
+Generate
+the
+
+Thing
+Template
+is
+a
+dictionary
+that
+provides
+a
+user
+
+Description
+
+as
+
+td
+,
+given
+name,
+and
+
+the
+semantic
+types
+
+
+Properties
+,
+Action
+
+s
+
+and
+semantic
+metadata
+attached
+to
+the
+
+
+Event
+
+s
+defined
+for
+this
+
+
+
+ExposedThing
+
+
+object.
+Then
+make
+a
+request
+to
+register
+
+td
+
+to
+the
+given
+WoT
+
+Thing
+Description
+'s
+root
+level.
+
+Directory
+.
+
+ThingTemplate
+
+unregister()
+
+
+
+method
+
+
++Takes +two +mandatory +arguments: +
+SemanticAnnotations
+
+directory
+
+
+
+name
+
+thing
+
+
+denoting
+an
+
+
+ExposedThing
+
+object.
+
+Makes
+a
+request
+to
+unregister
+
+the
+user
+given
+name
+of
+
+
+thing
+
+from
+
+the
+given
+WoT
+
+Thing
+Directory
+
+.
+Editor's
+note
+Support
+for
+configuration
+and
+security
+data
+might
+be
+added
+later.
+
+
let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let subscription = wot.discover(discoveryFilter).subscribe(
+ "hljs-params">thing { <span class=
+"hljs-built_in">console.log(<span class=
+"hljs-string">"Found Thing " + thing.name); },
+
+"hljs-params">td => {
+ console.log(
+"hljs-string">"Found Thing " + td.name);
+
+"hljs-comment">// fetch the TD and create a ConsumedThing
+ let thing = wot.consume(td);
+ },
+
+ error => { console.log("Discovery finished because an error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+setTimeout( () => {
+ subscription.unsubscribe();
+ console.log("Discovery timeout");
+ },
+
+5000
+
+);
+
+let subscription = wot.discover({ method: "local" }).subscribe(
+ "hljs-params">thing { <span class=
+
+"hljs-params">td => {
+"hljs-built_in">console.log("hljs-string">"Found local Thing " + thing.name); },
+
+"hljs-string">"Found local Thing " + td.name); },
+
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+);
+
+let subscription = wot.discover({ method: "local" }).subscribe({
+ thing => { <span class=
+
+ td => {
+"hljs-built_in">console.log("hljs-string">"Found local Thing " + thing.name); },
+
+"hljs-string">"Found local Thing " + td.name); },
+
+ error: err => { console.log("Discovery error: " + err.message); },
+ complete: () => { console.log("Discovery finished successfully");}
+});
+
+
+ConsumedThing
+
+
+interface
+
+
+
+The
+
+Represents
+an
+object
+that
+extends
+a
+
+
+
+
+ConsumedThing
+
+ThingFragment
+
+interface
+is
+a
+
+with
+methods
+for
+
+client
+API
+
+interactions
+(send
+request
+
+for
+sending
+requests
+to
+servers
+in
+order
+to
+retrieve
+or
+update
+
+reading
+and
+writing
+
+Properties
+,
+
+
+),
+
+invoke
+Actions
+,
+
+
+Action
+
+s,
+subscribe
+
+and
+observe
+Properties
+
+unsubscribe
+for
+
+Property
+
+
+changes
+
+and
+
+Events
+.
+
+Event
+
+s.
+
+
interface "dfn"> { +<span class="idlAttribute" id="idl-def-consumedthing-name" +data-idl="" data-title="name" data-dfn-for= +"consumedthing"> readonly attribute <span class= +"idlAttrType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-no-default="" +data-link-for="consumedthing" data-lt="" href= +"#dom-consumedthing-name" class="internalDFN" data-link-type= +"dfn"> +<span class="idlMethod" id= +"idl-def-consumedthing-getthingdescription" data-idl="" data-title= +"getThingDescription" data-dfn-for="consumedthing"> <span class= +"idlMethType"><a href="#dom-thingdescription" class="internalDFN" + +"dfn">+ConsumedThing
: +data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="getthingdescription()|getThingDescription" href= +"#dom-consumedthing-getthingdescription" class="internalDFN" +data-link-type="dfn">getThingDescription +<span class="idlMethod" id= +"idl-def-consumedthing-readproperty-name" data-idl="" data-title= +"readProperty" data-dfn-for="consumedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt="readproperty()|readProperty" +href="#dom-consumedthing-readproperty" class="internalDFN" +data-link-type="dfn">readProperty(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-writeproperty-name-value" data-idl="" +data-title="writeProperty" data-dfn-for= +"consumedthing"> <a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt= +"writeproperty()|writeProperty" href= +"#dom-consumedthing-writeproperty" class="internalDFN" +data-link-type="dfn">writeProperty(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-invokeaction-name-parameters" data-idl="" +data-title="invokeAction" data-dfn-for= +"consumedthing"> <a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="consumedthing" data-lt="invokeaction()|invokeAction" +href="#dom-consumedthing-invokeaction" class="internalDFN" +data-link-type="dfn">invokeAction(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id= +"idl-def-consumedthing-onpropertychange-name" data-idl="" +data-title="onPropertyChange" data-dfn-for= +"consumedthing"> <a href= +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="onpropertychange()|onPropertyChange" href= +"#dom-consumedthing-onpropertychange" class="internalDFN" +data-link-type="dfn">onPropertyChange(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-consumedthing-onevent-name" +data-idl="" data-title="onEvent" data-dfn-for= +"consumedthing"> <a href= +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="onevent()|onEvent" href="#dom-consumedthing-onevent" +class="internalDFN" data-link-type= +"dfn">onEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-consumedthing-ontdchange" +data-idl="" data-title="onTDChange" data-dfn-for= +"consumedthing"> <a href= ++"dfn">ThingFragment
{ + readonly attribute DOMStringid
; + readonly attribute DOMStringname
; + readonly attribute DOMString?base
; + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeEventMap
events
; + // getter for ThingFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); +}; +[NoInterfaceObject] +interfacePropertyMap
{ + readonly maplike<DOMString,ThingProperty
>; +}; +[NoInterfaceObject] +interfaceActionMap
{ + readonly maplike<DOMString,ThingAction
>; +}; +[NoInterfaceObject] +interfaceEventMap
{ + readonly maplike<DOMString,ThingEvent
>; +}; + +"dfn">ConsumedThing
includes +"#dom-observable" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="consumedthing" +data-lt="ontdchange()|onTDChange" href= +"#dom-consumedthing-ontdchange" class="internalDFN" data-link-type= +"dfn">onTDChange +}; ++"dfn">Observable
; +// +for +TD +changes + + +
+The
+
+
+
+
+attribute
+
+represents
+ConsumedThing
+
+id
+
+a
+local
+proxy
+object
+
+the
+unique
+identifier
+
+of
+the
+remote
+
+
+Thing
+.
+
+
+instance,
+typically
+a
+URI,
+IRI,
+or
+URN
+as
+
+USVString
+
.
+
+The
+
+
+name
+
+
+property
+The
+name
+property
+
+attribute
+
+represents
+the
+name
+of
+the
+
+Thing
+
+as
+specified
+in
+the
+TD
+.
+In
+this
+version
+it
+is
+read
+only.
+
+
+DOMString
+
.
+
+The
+
+
+
+
+getThingDescription()
+
+base
+
+method
+Returns
+the
+Thing
+Description
+of
+
+attribute
+represents
+
+the
+Thing
+.
+Editor's
+note
+In
+this
+version,
+introspection
+based
+on
+TD
+is
+out
+of
+scope.
+Parsing
+and
+exposing
+Thing
+Description
+s
+
+base
+URI
+that
+
+is
+discussed
+in
+Issue
+38
+.
+
+valid
+for
+all
+defined
+local
+interaction
+resources.
+
+
+The
+
+
+
+
+readProperty()
+
+properties
+
+method
+Takes
+the
+Property
+name
+as
+the
+name
+argument,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+Protocol
+Bindings
+to
+retrieve
+the
+Property
+on
+the
+remote
+Thing
+and
+return
+the
+result.
+Returns
+
+attribute
+represents
+
+a
+dictionary
+of
+
+
+ThingProperty
+
+Promise
+
+
+items.
+The
+
+
+PropertyMap
+
+
+that
+resolves
+with
+the
+Property
+value
+or
+rejects
+with
+an
+Error
+.
+
+4.4
+The
+
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+writeProperty()
+
+ThingProperty
+
+method
+Takes
+the
+Property
+
+
+name
+as
+the
+name
+argument
+and
+the
+new
+value
+as
+the
+value
+argument,
+then
+requests
+from
+the
+underlying
+platform
+
+objects.
+The
+
+read()
+
+and
+the
+Protocol
+Bindings
+
+
+write()
+
+methods
+make
+a
+request
+
+to
+update
+
+access
+
+the
+
+Property
+
+Properties
+
+
+on
+the
+remote
+
+Thing
+
+and
+return
+the
+result.
+Returns
+a
+
+represented
+by
+this
+
+
+ConsumedThing
+
+Promise
+
+
+that
+resolves
+on
+success
+or
+rejects
+with
+an
+Error
+.
+
+proxy
+object.
+
+
+The
+
+
+
+
+invokeAction()
+
+actions
+
+method
+Takes
+the
+Action
+name
+from
+the
+name
+argument
+and
+the
+list
+of
+parameters,
+then
+requests
+from
+the
+underlying
+platform
+and
+the
+Protocol
+Bindings
+to
+invoke
+the
+Action
+on
+the
+remote
+Thing
+and
+return
+the
+result.
+Returns
+
+attribute
+represents
+
+a
+Promise
+
+dictionary
+of
+
+
+ThingAction
+
+
+that
+resolves
+with
+the
+return
+value
+or
+rejects
+with
+an
+Error
+.
+
+4.6
+
+
+items.
+
+The
+
+
+
+
+onPropertyChange()
+
+ActionMap
+
+method
+Returns
+an
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+
+Observable
+
+ThingAction
+
+for
+the
+Property
+specified
+in
+the
+name
+argument,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications.
+
+objects.
+
+The
+callback
+function
+passed
+to
+the
+
+
+
+method
+subscribe()
+
+invoke()
+
+when
+invoked
+on
+
+represents
+a
+request
+to
+invoke
+
+the
+returned
+observer
+will
+receive
+
+
+Action
+
+on
+
+the
+new
+property
+value
+each
+time
+it
+is
+changed.
+
+remote
+
+Thing
+.
+
+The
+
+
+
+
+onEvent()
+
+events
+
+method
+Returns
+an
+
+attribute
+represents
+a
+dictionary
+of
+
+
+
+
+Observable
+
+ThingEvent
+
+for
+the
+Event
+specified
+in
+the
+name
+argument,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications.
+The
+callback
+function
+passed
+to
+the
+subscribe()
+method
+when
+invoked
+on
+the
+returned
+observer
+will
+receive
+the
+event
+data
+each
+time
+the
+event
+is
+fired.
+4.8
+
+items.
+
+The
+
+
+
+
+onTDChange()
+
+EventMap
+
+method
+Returns
+an
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+Observable
+
+ThingEvent
+
+,
+allowing
+subscribing
+to
+and
+unsubscribing
+from
+notifications
+to
+the
+Thing
+Description
+.
+The
+callback
+function
+passed
+
+
+objects.
+Subscribing
+
+to
+the
+subscribe()
+method
+when
+invoked
+
+events
+involves
+setting
+up
+an
+observation
+(subscription)
+mechanism
+
+on
+the
+returned
+observer
+will
+receive
+the
+new
+Thing
+Description
+each
+time
+it
+is
+changed.
+
+remote
+object.
+
+
+Below
+a
+
+
+
+interface
+example
+is
+given.
+
+ConsumedThing
+
+
+
"hljs-keyword">try {
+
+"hljs-keyword">let subscription = wot.discover({ method: "local" }).subscribe(
+
+"hljs-params">td => {
+
+"hljs-keyword">let thing = wot.consume(td);
+ console.log(
+"hljs-string">"Thing " + thing.name + " has been consumed.");
+
+"hljs-keyword">let subscription = thing["temperature"].subscribe(function(value) {
+
+"hljs-built_in">console.log("Temperature: " + value);
+ });
+ thing.actions["startMeasurement"].invoke({ units: "Celsius" })
+ .then(() => { console.log("Temperature measurement started."); })
+ .catch(e => {
+
+"hljs-built_in">console.log("Error starting measurement.");
+ subscription.unsubscribe();
+ })
+ },
+ error => { console.log("Discovery error: " + error.message); },
+ () => { console.log("Discovery finished successfully");}
+ );
+} catch(error) {
+ console.log(
+"hljs-string">"Error: " + error.message);
+
+};
+
+
+ExposedThing
+
+
+interface
+
+
+
+The
+
+
+ExposedThing
+
+
+interface
+is
+the
+server
+API
+that
+allows
+defining
+request
+handlers,
+properties,
+
+Actions
+,
+and
+
+Events
+
+to
+a
+
+Thing
+.
+It
+also
+implements
+the
+
+
+
+
+interface.
+An
+
+ConsumedThing
+
+Observable
+
+
+ExposedThing
+
+
+is
+created
+by
+the
+
+produce()
+
+method.
+
"idl-def-exposedthing" data-idl="" data-title= +"ExposedThing">interface +"idlInterfaceID">"dfn"> { +<span class= +"idlSectionComment"> // define how to expose and run the Thing +<span class="idlMethod" id="idl-def-exposedthing-start" data-idl="" +data-title="start" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="start()|start" href= +"#dom-exposedthing-start" class="internalDFN" data-link-type= +"dfn">start +<span class="idlMethod" id="idl-def-exposedthing-stop" data-idl="" +data-title="stop" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="stop()|stop" href= +"#dom-exposedthing-stop" class="internalDFN" data-link-type= +"dfn">stop +<span class="idlMethod" id= +"idl-def-exposedthing-register-directory" data-idl="" data-title= +"register" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default="" +data-link-for="exposedthing" data-lt="register()|register" href= +"#dom-exposedthing-register" class="internalDFN" data-link-type= +"dfn">register(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id= +"idl-def-exposedthing-unregister-directory" data-idl="" data-title= +"unregister" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= + +"dfn">+ExposedThing
:ThingFragment
{ + readonly attributePropertyMap
properties
; + readonly attributeActionMap
actions
; + readonly attributeExposedEvents
events
; + // getter for ThingFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); + // setter for ThingFragment properties + setter void ( +"idlParam">DOMString name, any value); + // methods to expose and destroy the Thing + Promise<void> data-link-for="exposedthing" data-lt="unregister()|unregister" +href="#dom-exposedthing-unregister" class="internalDFN" +data-link-type="dfn">unregister(<span class= +"idlParam">optional <a href= +"https://heycam.github.io/webidl/#idl-USVString">USVString +<span class="idlMethod" id= +"idl-def-exposedthing-emitevent-eventname-payload" data-idl="" +data-title="emitEvent" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href= + +data-link-for="exposedthing" data-lt= +"exposedthing.expose()|exposedthing.expose|expose()|expose" href= +"#dom-exposedthing-expose" class="internalDFN" data-link-type= +"dfn">expose
(); + Promise<void> data-link-for="exposedthing" data-lt="emitevent()|emitEvent" href= +"#dom-exposedthing-emitevent" class="internalDFN" data-link-type= +"dfn">emitEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class= +"idlSectionComment"> // define Thing Description modifiers +<span class="idlMethod" id= +"idl-def-exposedthing-addproperty-property" data-idl="" data-title= +"addProperty" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" +data-link-type= +"dfn"> <span class= + +data-link-for="exposedthing" data-lt= +"exposedthing.destroy()|exposedthing.destroy|destroy()|destroy" +href="#dom-exposedthing-destroy" class="internalDFN" +data-link-type="dfn">destroy
(); + // define Properties + +"internalDFN" data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="addproperty()|addProperty" href= +"#dom-exposedthing-addproperty" class="internalDFN" data-link-type= +"dfn">addProperty<span class= +"idlParamType"><a href="#dom-thingproperty" class="internalDFN" + +data-lt= +"exposedthing.addproperty()|exposedthing.addproperty|addproperty()|addproperty" +href="#dom-exposedthing-addproperty" class="internalDFN" + +data-link-type= +"dfn"> <span class= +"idlParamName">property +<span class="idlMethod" id= +"idl-def-exposedthing-removeproperty-name" data-idl="" data-title= +"removeProperty" data-dfn-for="exposedthing"> <span class= +"idlMethType"><a href="#dom-exposedthing" class="internalDFN" ++"dfn">addProperty
(DOMString name,PropertyFragment
property, optional any initValue); + "dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="removeproperty()|removeProperty" href= +"#dom-exposedthing-removeproperty" class="internalDFN" +data-link-type="dfn">removeProperty(<span class= + +data-lt= +"exposedthing.setpropertyreadhandler()|exposedthing.setpropertyreadhandler|setpropertyreadhandler()|setpropertyreadhandler" +href="#dom-exposedthing-setpropertyreadhandler" class="internalDFN" +data-link-type= +"dfn">setPropertyReadHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-exposedthing-addaction-action" +data-idl="" data-title="addAction" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="addaction()|addAction" href="#dom-exposedthing-addaction" +class="internalDFN" data-link-type= +"dfn">addAction<span class= +"idlParamType"><a href="#dom-thingaction" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,PropertyReadHandler
readHandler); + "dfn"> <span class= +"idlParamName">action +<span class="idlMethod" id="idl-def-exposedthing-removeaction-name" +data-idl="" data-title="removeAction" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="removeaction()|removeAction" href= +"#dom-exposedthing-removeaction" class="internalDFN" +data-link-type="dfn">removeAction(<span class= + +data-lt= +"exposedthing.setpropertywritehandler()|exposedthing.setpropertywritehandler|setpropertywritehandler()|setpropertywritehandler" +href="#dom-exposedthing-setpropertywritehandler" class= +"internalDFN" data-link-type= +"dfn">setPropertyWriteHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class="idlMethod" id="idl-def-exposedthing-addevent-event" +data-idl="" data-title="addEvent" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="addevent()|addEvent" href="#dom-exposedthing-addevent" +class="internalDFN" data-link-type= +"dfn">addEvent<span class= +"idlParamType"><a href="#dom-thingevent" class="internalDFN" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,PropertyWriteHandler
writeHandler); + "dfn"> +<span class="idlMethod" id="idl-def-exposedthing-removeevent-name" +data-idl="" data-title="removeEvent" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlMethName"><a data-no-default="" data-link-for="exposedthing" +data-lt="removeevent()|removeEvent" href= +"#dom-exposedthing-removeevent" class="internalDFN" data-link-type= +"dfn">removeEvent<span class= +"idlParamType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString +<span class= +"idlSectionComment"> // define request handlers +<span class="idlMethod" id= +"idl-def-exposedthing-setpropertyreadhandler-name-readhandler" +data-idl="" data-title="setPropertyReadHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"dfn">ExposedThing
+"idlMethName">data-lt="setpropertyreadhandler()|setPropertyReadHandler" href= +"#dom-exposedthing-setpropertyreadhandler" class="internalDFN" +data-link-type="dfn">setPropertyReadHandler(<span class= + +data-lt= +"exposedthing.removeproperty()|exposedthing.removeproperty|removeproperty()|removeproperty" +href="#dom-exposedthing-removeproperty" class="internalDFN" +data-link-type= +"dfn">removeProperty
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString, + <span class= + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name); + // define Actions + +"internalDFN" data-link-type= +"dfn">ExposedThing
addAction
( +"idlParam">"#dom-propertyreadhandler" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">readHandler +<span class="idlMethod" id= +"idl-def-exposedthing-setpropertywritehandler-name-writehandler" +data-idl="" data-title="setPropertyWriteHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name,ActionFragment
init,ActionHandler
action); + +data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="setpropertywritehandler()|setPropertyWriteHandler" href= +"#dom-exposedthing-setpropertywritehandler" class="internalDFN" + +data-lt= +"exposedthing.removeaction()|exposedthing.removeaction|removeaction()|removeaction" +href="#dom-exposedthing-removeaction" class="internalDFN" + +data-link-type= +"dfn">setPropertyWriteHandler, + <span class= ++"dfn">removeAction
( +"idlParam">"#dom-propertywritehandler" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">writeHandler +<span class="idlMethod" id= +"idl-def-exposedthing-setactionhandler-name-action" data-idl="" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name); +data-title="setActionHandler" data-dfn-for= +"exposedthing"> <a href= +"#dom-exposedthing" class="internalDFN" data-link-type= +"dfn"> <span class= ++"exposedthing"> + +data-link-type= +"dfn">ExposedThing
+"idlMethName">data-lt="setactionhandler()|setActionHandler" href= +"#dom-exposedthing-setactionhandler" class="internalDFN" +data-link-type="dfn">setActionHandler(<span class= + +data-lt= +"exposedthing.setactionhandler()|exposedthing.setactionhandler|setactionhandler()|setactionhandler" +href="#dom-exposedthing-setactionhandler" class="internalDFN" +data-link-type= +"dfn">setActionHandler
( +"idlParam">"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a href="#dom-actionhandler" +class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">action +}; +<span class="idlCallback" id="idl-def-propertyreadhandler" +data-idl="" data-title="PropertyReadHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-propertyreadhandler" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType"><a href= +"https://heycam.github.io/webidl/#idl-promise">Promise +<span class="idlCallback" id="idl-def-propertywritehandler" +data-idl="" data-title="PropertyWriteHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-propertywritehandler" class="internalDFN" +data-link-type="dfn"> +<span class="idlCallback" id="idl-def-actionhandler" data-idl="" +data-title="ActionHandler">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" + +"https://heycam.github.io/webidl/#idl-DOMString">DOMString name, +href="#dom-actionhandler" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType"><a href= ++"dfn">ActionHandler
action); + // define Events + +"internalDFN" data-link-type= +"dfn">ExposedThing
addEvent
(DOMString name,EventFragment
event); + +data-link-type= +"dfn">ExposedThing
removeEvent
(DOMString name); +}; +[NoInterfaceObject] +interfaceExposedEvents
{ + maplike<DOMString,ExposedEvent
>; +}; +callbackPropertyReadHandler
= Promise<any> (); +callbackPropertyWriteHandler
= Promise<void> (any value); +callbackActionHandler
= +"https://heycam.github.io/webidl/#idl-promise"> +Promise + +< + +any + +> + +( + + + +any + + + +parameters + + +); + +
+Start
+serving
+external
+requests
+for
+the
+Thing
+.
+5.2
+
+The
+
+
+
+
+stop()
+
+properties
+
+method
+Stop
+serving
+external
+requests
+for
+the
+Thing
+.
+5.3
+The
+
+attribute
+represents
+a
+dictionary
+of
+
+
+
+register()
+
+ThingProperty
+
+method
+Generates
+the
+Thing
+Description
+
+
+given
+
+items
+in
+which
+
+the
+properties,
+Actions
+
+
+read()
+
+and
+Event
+defined
+for
+this
+object.
+If
+a
+
+
+
+directory
+
+write()
+
+argument
+is
+given,
+make
+a
+request
+to
+register
+
+methods
+define
+local
+methods
+that
+access
+
+the
+Thing
+Description
+with
+
+physical
+representations
+of
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+register
+Action
+
+
+Properties
+
+.
+
+The
+
+
+
+
+unregister()
+
+actions
+
+method
+If
+
+attribute
+represents
+
+a
+dictionary
+of
+
+
+
+directory
+
+ThingAction
+
+argument
+is
+given,
+make
+a
+request
+to
+unregister
+the
+Thing
+Description
+
+
+with
+
+items
+in
+which
+
+the
+given
+WoT
+repository
+by
+invoking
+its
+
+
+
+unregister
+
+invoke()
+
+Action
+.
+Then,
+and
+in
+the
+case
+no
+arguments
+were
+provided
+
+method
+represents
+a
+local
+method
+
+to
+this
+function,
+stop
+the
+Thing
+and
+remove
+
+invoke
+
+the
+Thing
+Description
+
+
+Action
+
+.
+
+The
+
+
+
+
+emitEvent()
+
+events
+
+method
+Emits
+an
+the
+event
+initialized
+with
+the
+event
+name
+specified
+by
+
+attribute
+represents
+a
+dictionary
+of
+
+ExposedEvent
+
+items
+that
+add
+
+the
+
+
+eventName
+
+emit()
+
+argument
+and
+data
+specified
+by
+
+method
+to
+
+the
+
+
+
+payload
+
+ThingEvent
+
+argument.
+
+5.6
+
+
+definition.
+
+The
+
+
+
+
+DataSchema
+
+ExposedEvents
+
+type
+<span class="idlTypedef" id=
+"idl-def-dataschema" data-idl="" data-title=
+"DataSchema">typedef <a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+data-link-for="" data-lt="" href="#dom-dataschema" class=
+"internalDFN" data-link-type=
+"dfn">
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+
+
+objects.
+DataSchema
+
+ExposedEvent
+
+
+DataSchema
+
+expose()
+
+
+
+method
+
+
+
+Start
+serving
+external
+requests
+for
+
+the
+
+Thing
+Description
+
+,
+so
+that
+
+WoT
+Interactions
+
+
+in
+a
+serialized
+form.
+
+using
+
+Properties
+,
+Action
+
+s
+and
+
+Event
+
+s
+will
+be
+possible.
+
+
+The
+
+
+
+DataSchema
+
+expose()
+
+is
+under
+development,
+currently
+it
+can
+denote
+any
+type
+supported
+by
+
+method
+
+MUST
+
+run
+
+the
+Thing
+Description
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+
+the
+
+addProperty()
+
+expose()
+
+
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+Error
+
+object
+
+error.message
+
+set
+to
+the
+error
+code
+seen
+by
+the
+
+Protocol
+Bindings
+
+and
+terminate
+these
+steps.
+
+ThingProperty
+
+destroy()
+
+
+
+
+Represents
+
+Stop
+serving
+external
+requests
+for
+
+the
+
+Thing
+
+Property
+description.
+
+and
+destroy
+the
+object.
+Note
+that
+eventual
+unregistering
+should
+be
+done
+before
+invoking
+this
+method.
+
+
+The
+
+
+name
+
+destroy()
+
+attribute
+represents
+
+method
+
+MUST
+
+run
+
+the
+name
+of
+
+following
+steps:
+
+Promise
+
+promise
+
+and
+execute
+
+the
+
+schema
+
+destroy()
+
+
+
+DataSchema
+
+SecurityError
+
+
+
+writable
+
+Error
+
+
+
+error.message
+
+set
+to
+
+the
+
+observable
+
+addProperty()
+
+
+
+
+Adds
+a
+
+
+Property
+
+changes
+can
+be
+observed
+
+with
+name
+defined
+by
+the
+
+name
+
+argument,
+the
+data
+schema
+provided
+
+by
+the
+
+property
+
+argument
+of
+type
+
+PropertyFragment
+
,
+and
+optionally
+
+an
+external
+client.
+The
+default
+
+initial
+
+value
+provided
+in
+the
+argument
+
+initValue
+
+whose
+type
+should
+match
+the
+one
+defined
+in
+the
+
+type
+
+property
+according
+to
+the
+
+value-matching
+algorithm
+.
+If
+
+initValue
+
+is
+not
+provided,
+it
+
+SHOULD
+
+be
+initialized
+as
+
+
+
.
+Implementations
+
+SHOULD
+
+update
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+false
+
+undefined
+
+
+removeProperty()
+
+
+method
+
+
+
+Removes
+the
+
+Property
+
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+addAction()
+
+
+method
+
+
+
+Adds
+an
+Action
+
+to
+the
+
+actions
+
+property
+of
+a
+
+Thing
+
+object
+as
+
+an
+
+Action
+
+with
+name
+
+defined
+by
+the
+action
+
+
+name
+
+argument,
+defines
+input
+and
+output
+data
+format
+by
+the
+
+init
+
+argument
+of
+type
+
+
+
+,
+and
+adds
+the
+function
+provided
+in
+the
+
+action
+
+argument
+as
+a
+handler,
+then
+
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+ThingAction
+
+ActionFragment
+
+
+The
+ThingAction
+
+provided
+
+action
+
+callback
+function
+will
+implement
+invoking
+an
+
+Action
+
+
+dictionary
+describes
+the
+arguments
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+invoking
+
+the
+return
+value.
+The
+name
+attribute
+provides
+the
+
+
+Action
+
+name.
+The
+inputSchema
+attribute
+provides
+the
+description
+of
+the
+input
+arguments
+(argument
+list
+
+is
+represented
+by
+an
+object).
+If
+missing,
+it
+means
+
+received
+from
+
+the
+action
+does
+not
+accept
+arguments.
+
+underlying
+platform.
+
+The
+callback
+will
+receive
+a
+
+
+
+outputSchema
+
+parameters
+
+attribute
+provides
+
+dictionary
+argument
+according
+to
+
+the
+description
+
+definition
+in
+the
+
+init.input
+
+argument
+and
+will
+return
+a
+value
+
+of
+type
+defined
+by
+
+the
+returned
+data.
+If
+missing,
+it
+means
+
+
+init.output
+
+argument
+according
+to
+
+the
+action
+does
+not
+return
+data.
+
+
+value-matching
+algorithm
+.
+There
+
+SHOULD
+
+be
+exactly
+one
+handler
+for
+any
+given
+
+Action
+.
+If
+no
+handler
+is
+initialized
+for
+any
+given
+
+Action
+,
+implementations
+
+SHOULD
+
+throw
+a
+
+TypeError
+
.
+removeAction()
+
+
+method
+
+
+
+Removes
+the
+
+Action
+
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+addEvent()
+
+
+method
+
+
+
+Adds
+an
+event
+to
+the
+Thing
+object
+as
+
+with
+name
+
+defined
+by
+the
+
+name
+
+argument
+and
+qualifiers
+and
+initialization
+value
+provided
+by
+the
+
+event
+
+argument
+of
+type
+
+
+
+
+to
+the
+
+Thing
+
+object
+
+and
+updates
+the
+
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+ThingEvent
+
+EventFragment
+
+
+removeEvent()
+
+
+method
+
+
+
+Removes
+the
+event
+specified
+by
+the
+
+name
+
+argument
+and
+updates
+the
+
+Thing
+Description
+.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+PropertyReadHandler
+
+
+callback
+
+
+
+A
+function
+that
+returns
+
+is
+called
+when
+an
+external
+request
+for
+reading
+a
+
+Property
+
+is
+received.
+It
+should
+return
+
+a
+Promise
+and
+resolves
+it
+with
+the
+value
+of
+the
+
+Property
+
+matching
+the
+
+name
+
+argument
+to
+the
+
+setPropertyReadHandler
+
+function,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+retrieved.
+
+PropertyWriteHandler
+
+
+callback
+
+
+
+A
+function
+that
+is
+
+called
+with
+
+when
+an
+external
+request
+for
+writing
+a
+
+Property
+
+is
+received.
+It
+is
+given
+the
+requested
+new
+
+
+value
+
+as
+argument
+that
+returns
+
+and
+should
+return
+
+a
+Promise
+which
+is
+resolved
+when
+the
+value
+of
+the
+
+Property
+
+matching
+
+that
+matches
+
+the
+
+name
+
+argument
+to
+the
+setPropertyReadHandler
+function
+is
+
+has
+been
+
+updated
+with
+
+value
+
,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+updated.
+
+Note
+that
+this
+function
+is
+invoked
+by
+implementations
+before
+the
+property
+is
+updated,
+so
+the
+
+updated
+and
+it
+actually
+defines
+what
+to
+do
+when
+a
+write
+request
+is
+received.
+The
+
+code
+in
+this
+callback
+function
+can
+invoke
+the
+
+
+method
+to
+find
+out
+the
+old
+value
+of
+the
+property,
+if
+needed.
+Therefore
+the
+old
+value
+is
+not
+provided
+to
+this
+readProperty()
+
+read()
+
+method.
+
+function.
+
+
+ActionHandler
+
+
+callback
+
+
+
+A
+function
+called
+with
+a
+
+parameters
+
+dictionary
+argument
+assembled
+by
+the
+
+WoT
+runtime
+
+based
+on
+the
+
+Thing
+Description
+
+and
+the
+external
+client
+request.
+It
+returns
+a
+Promise
+that
+rejects
+with
+an
+error
+or
+resolves
+if
+the
+action
+is
+successful
+or
+ongoing
+(may
+also
+resolve
+with
+a
+control
+object
+such
+as
+an
+
+
+Observable
+
+
+for
+actions
+that
+need
+progress
+notifications
+or
+that
+can
+be
+canceled).
+
+setPropertyReadHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+readHandler
+
+as
+argument
+of
+type
+
+
+PropertyReadHandler
+
+.
+Sets
+the
+handler
+function
+for
+reading
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+The
+
+readHandler
+
+callback
+function
+will
+implement
+reading
+a
+
+Property
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+reading
+a
+
+Property
+
+is
+received
+from
+the
+underlying
+platform.
+
+There + +SHOULD + +be +at +most +one +handler +for +any +given + +Property + +and +newly +added +handlers +replace +the +old +handlers. +If +no +handler +is +initialized +for +any +given + +Property +, +implementations + +SHOULD + +implement +a +default +property +read +handler. +
++When +an +external +request +for +reading + +Property + +propertyName + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+setPropertyWriteHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+writeHandler
+
+as
+argument
+of
+type
+
+
+PropertyWriteHandler
+
+.
+Sets
+the
+handler
+function
+for
+writing
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+There + +SHOULD + +be +at +most +one +write +handler +for +any +given + +Property + +and +newly +added +handlers +replace +the +old +handlers. +If +no +write +handler +is +initialized +for +any +given + +Property +, +implementations + +SHOULD + +implement +default +property +update +and +notifying +observers +on +change. +
++When +an +external +request +for +writing +a + +Property + +propertyName + +with +a +new +value + +value + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+.
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+setActionHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+action
+
+as
+argument
+of
+type
+
+
+ActionHandler
+
+.
+Sets
+the
+handler
+function
+for
+the
+specified
+
+Action
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+If
+provided,
+this
+
+The
+
+action
+
+callback
+function
+will
+implement
+invoking
+
+an
+
+Action
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+invoking
+a
+
+the
+
+Action
+
+is
+received
+from
+the
+underlying
+platform.
+The
+callback
+will
+receive
+a
+parameters
+dictionary
+argument.
+
+
+There
+
+SHOULD
+
+be
+exactly
+
+at
+most
+
+one
+handler
+for
+any
+given
+
+Action
+
+and
+newly
+added
+handlers
+replace
+the
+old
+handlers.
+
+When +an +external +request +for +invoking +the + +Action + +identified +by + +name + +is +received, +the +runtime + +SHOULD + +execute +the +following +steps: +
+Promise
+
+promise
+
+and
+execute
+the
+next
+steps
+
+in
+parallel
+
+.
+
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+ReferenceError
+
+and
+terminate
+these
+steps.
+
+Below
+some
+
+
+
+interface
+examples
+are
+given.
+
+ExposedThing
+
+
+
+ try {
+ "hljs-keyword">var thing = WoT.produce({ <span class=
+"hljs-attr">name: <span class=
+"hljs-string">"tempSensor" });
+
+ thing.addProperty({
+ : <span class=
+"hljs-string">"temperature",
+ : <span class=
+"hljs-number">0.0,
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ <span class=
+"hljs-comment">// use default values for the rest
+ }).addProperty({
+ : <span class=
+"hljs-string">"max",
+ : <span class=
+"hljs-number">0.0,
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ <span class=
+"hljs-comment">// use default values for the rest
+ }).addAction({
+ : <span class=
+"hljs-string">"reset",
+
+ }).addEvent({
+
+"hljs-keyword">var temperatureValueDefinition = {
+ type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">-50,
+ maximum:
+"hljs-number">10000
+ };
+
+"hljs-keyword">var temperaturePropertyDefinition = temperatureValueDefinition;
+ // add the 'forms' property
+ temperaturePropertyDefinition.forms = [ ... ];
+ var thing = WoT.produce({
+ name: "hljs-string">"onchange",
+ : <span class=
+"hljs-string">'{ "type": "number" }'
+ });
+
+ thing.setActionHandler(<span class=
+"hljs-string">"reset", () => {
+ .log(<span class=
+"hljs-string">"Resetting maximum");
+ thing.writeProperty(<span class=
+"hljs-string">"max");
+ });
+ thing.start().then(<span class=
+"hljs-params">() {
+ thing.register();
+
+"hljs-string">"tempSensor",
+ properties: {
+"hljs-attr">temperature: temperaturePropertyDefinition
+ },
+ actions: { reset: { description:
+"hljs-string">"Reset the temperature sensor",
+ input: {
+"hljs-attr">temperature: temperatureValueDefinition
+ },
+ output:
+"hljs-literal">null,
+ forms: []
+ },
+ },
+ events: {
+"hljs-attr">onchange: temperatureValueDefinition
+ },
+ links: []
+ });
+ await thing.expose();
+ await wot.register("hljs-string">"https://mydirectory.org", thing);
+
+ // define Thing business logic
+ setInterval( async () => {
+ let mock = Math.random()*100;
+ thing.writeProperty(<span class=
+"hljs-string">"temperature", mock);
+
+ let old = "hljs-keyword">await thing.readProperty(<span class=
+"hljs-string">"max");
+
+"hljs-keyword">await thing["temperature"].read();
+
+ if (old < mock) {
+ thing.writeProperty(<span class=
+"hljs-string">"max", mock);
+ thing.emitEvent();
+
+ await thing["hljs-string">"temperature"].write(mock);
+ thing.emitEvent("onchange", mock);
+
+ }
+ }, 1000);
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+
+ try {
+ var statusValueDefinition = {
+ type: "hljs-string">"object",
+ properties: { brightness: { type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">0.0,
+ maximum:
+"hljs-number">100.0,
+ required:
+"hljs-literal">true
+ },
+ rgb: { type:
+"hljs-string">"array",
+ "minItems":
+"hljs-number">3,
+ "maxItems":
+"hljs-number">3,
+ items : { "type" :
+"hljs-string">"number",
+
+"hljs-string">"minimum": 0,
+
+"hljs-string">"maximum": 255
+ }
+ }
+ };
+
+"hljs-keyword">var statusPropertyDefinition = statusValueDefinition;
+ // add the 'forms' property
+ statusPropertyDefinition["forms"] = [];
+ var thing = WoT.produce({ name:
+"hljs-string">"mySensor",
+ properties: { brightness: { type:
+"hljs-string">"number",
+ minimum:
+"hljs-number">0.0,
+ maximum:
+"hljs-number">100.0,
+ required:
+"hljs-literal">true,
+ },
+
+"hljs-attr">status: statusPropertyDefinition
+ },
+ actions: { status: { description:
+"hljs-string">"Get status object",
+ input:
+"hljs-literal">null,
+ output: {
+"hljs-attr">status : statusValueDefinition;
+ },
+ forms: []
+ },
+ },
+ events: {
+"hljs-attr">onstatuschange: statusValueDefinition;
+ },
+ links: []
+ });
+ thing.expose().then(() => {
+ thing.register();
+ });
+} catch (err) {
+ console.log(
+"hljs-string">"Error creating ExposedThing: " + err);
+}
+
+ let thingDescription = "hljs-string">'{ "@context": [ "https://w3c.github.io/wot/w3c-wot-td-context.jsonld", "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ], "@type": [ "Thing", "Sensor" ], "name": "mySensor", "geo:location": "testspace", "interaction": [ { "@type": [ "Property", "Temperature" ], "name": "prop1", "schema": { "type": "number" }, "saref:TemperatureUnit": "degree_Celsius" } ] }';
+
+"hljs-string">'{ \
+ "name": "mySensor", \
+ "@context": [ "http://www.w3.org/ns/td",\
+ "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ],\
+ "@type": [ "Thing", "Sensor" ], \
+ "geo:location": "testspace", \
+ "properties": { \
+ "prop1": { \
+ "type": "number",\
+ "@type": [ "Property", "Temperature" ], \
+ "saref:TemperatureUnit": "degree_Celsius" \
+ } } }';
+
+try {
+ // note that produce() fails if thingDescription contains error
+ let thing = WoT.produce(thingDescription);
+ // Interactions were added from TD
+ // WoT adds generic handler for reading any property
+ // define a specific handler for one property
+ let name = "examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ console.log("Handling read request for " + name);
+ return new Promise((resolve, reject) => {
+ let examplePropertyValue = 5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ console.log("Error");
+ });
+ });
+ thing.start();
+
+ thing.expose();
+
+} catch(err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+
+ // fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch("http://myservice.org/mySensor/description").then(td => {
+ // WoT.produce() ignores instance-specific metadata (security, form)
+ let thing = WoT.produce(td);
+ // Interactions were added from TD
+ // add server functionality
+ // ...
+});
+
+
+The
+[
+
+This
+section
+is
+non-normative.
+
+
+WOT-TD
+
+
+]
+specification
+defines
+the
+
+WoT
+information
+model
+,
+i.e.
+the
+data
+types
+and
+data
+structures
+used
+in
+
+WoT
+Interactions
+.
+In
+this
+API
+these
+definitions
+translate
+to
+dictionary
+objects
+that
+are
+extended
+with
+methods
+by
+the
+interfaces
+defined
+in
+this
+specification.
+
+
+In +order +to +avoid +duplication +of +definitions, +references +to +these +data +types +and +structures +is +defined +in +this +section, +but +for +their +full +description +please +refer +to +the + +Thing +Description +specification +.
+ThingDescription
+
+DataSchema
+
+
+
+dictionary
+and
+its
+subclasses
+
+
+
+Value
+types
+basically
+represent
+types
+that
+may
+be
+used
+in
+
+JSON
+
+object
+definitions
+and
+are
+used
+in
+
+ThingFragment
+
+to
+define
+
+Properties
+,
+Action
+s,
+
+
+Event
+
+s
+and
+links
+(introspection)
+
+
+Action
+
+parameters.
+Value
+types
+are
+represented
+as
+dictionary
+objects
+whose
+properties
+and
+possible
+sub-classes
+are
+defined
+in
+the
+
+DataSchema
+
+section
+of
+[
+
+WOT-TD
+
+].
+
+One
+property
+of
+all
+
+DataSchema
+
+dictionary
+
+is
+an
+API
+extension
+that
+
+the
+
+type
+
+property
+whose
+value
+
+is
+out
+
+from
+a
+set
+
+of
+scope
+for
+
+enumerated
+strings
+defined
+in
+the
+
+DataSchema
+
+section
+of
+[
+
+WOT-TD
+
+]
+and
+is
+referred
+as
+
+DataType
+
+in
+
+this
+specification.
+However,
+
+
+Based
+on
+
+type
+
,
+the
+draft
+interfaces
+
+following
+sub-classes
+of
+
+DataSchema
+
+are
+defined
+here
+for
+informative
+purposes.
+<span class="idlInterface" id=
+"idl-def-consumedthing-partial-1" data-idl="" data-title=
+"ConsumedThing">partial interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-consumedthing" class="internalDFN" data-link-type=
+"dfn"> {
+<span class="idlMethod" id="idl-def-consumedthing-getproperties"
+data-idl="" data-title="getProperties" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingproperty"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getproperties()|getProperties" href=
+"#dom-consumedthing-getproperties" class="internalDFN"
+data-link-type="dfn">getProperties
+<span class="idlMethod" id="idl-def-consumedthing-getactions"
+data-idl="" data-title="getActions" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingaction"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getactions()|getActions" href=
+"#dom-consumedthing-getactions" class="internalDFN" data-link-type=
+"dfn">getActions
+<span class="idlMethod" id="idl-def-consumedthing-getevents"
+data-idl="" data-title="getEvents" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-thingevent"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getevents()|getEvents" href="#dom-consumedthing-getevents"
+class="internalDFN" data-link-type=
+"dfn">getEvents
+<span class="idlMethod" id="idl-def-consumedthing-getlinks"
+data-idl="" data-title="getLinks" data-dfn-for=
+"consumedthing"> <a href=
+"https://heycam.github.io/webidl/#idl-sequence">sequence<<a href="#dom-tdlink"
+class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="consumedthing"
+data-lt="getlinks()|getLinks" href="#dom-consumedthing-getlinks"
+class="internalDFN" data-link-type=
+"dfn">getLinks
+};
+
+in
+[
+
+
+WOT-TD
+
+
+]:
+
+BooleanSchema
+
+6.1
+
+,
+
+
+NumberSchema
+,
+IntegerSchema
+,
+StringSchema
+,
+ObjectSchema
+,
+ArraySchema
+.
+getProperties()
+
+SecurityScheme
+
+
+
+
+Returns
+the
+list
+of
+Properties
+
+Security
+metadata
+is
+represented
+as
+dictionary
+objects
+whose
+properties
+and
+sub-classes
+are
+
+defined
+in
+the
+Thing
+Description
+
+
+SecurityScheme
+
+
+section
+of
+[
+
+WOT-TD
+
+].
+
+One
+property
+
+of
+the
+Thing
+
+
+
+SecurityScheme
+
+
+dictionary
+is
+the
+
+scheme
+
+property
+whose
+value
+is
+from
+a
+set
+of
+enumerated
+strings
+defined
+
+in
+the
+form
+
+
+SecurityScheme
+
+section
+
+of
+a
+list
+
+[
+
+WOT-TD
+
+].
+Based
+on
+
+type
+
,
+multiple
+subclasses
+
+of
+
+
+
+
+ThingProperty
+
+SecurityScheme
+
+objects.
+
+are
+defined.
+
+
+getActions()
+
+Link
+
+
+
+
+Returns
+
+Represents
+a
+
+Web
+Link
+
+with
+properties
+defined
+in
+
+the
+list
+
+
+Link
+
+section
+
+of
+Action
+
+[
+
+WOT-TD
+
+
+s
+
+
+].
+
+Form
+
+dictionary
+
+Represents
+metadata
+describing
+service
+details,
+with
+properties
+
+defined
+in
+the
+Thing
+Description
+
+
+Form
+
+
+section
+
+of
+[
+
+WOT-TD
+
+].
+
+InteractionFragment
+
+dictionary
+
+Represents
+
+the
+Thing
+
+common
+properties
+of
+
+WoT
+Interactions
+,
+one
+of
+
+Property
+,
+Action
+
+
+or
+
+Event
+,
+as
+defined
+
+in
+the
+form
+
+
+InteractionPattern
+
+section
+
+of
+[
+
+WOT-TD
+
+].
+Its
+subclasses
+are
+referred
+as
+
+PropertyFragment
+
,
+ActionFragment
+
+and
+
+EventFragment
+
.
+PropertyFragment
+
+dictionary
+
+Represents
+the
+
+Property
+
+interaction
+data
+that
+initializes
+
+a
+list
+
+
+
+ThingProperty
+
+object.
+Its
+properties
+are
+defined
+in
+the
+
+Property
+
+and
+
+InteractionPattern
+
+sections
+
+of
+[
+
+WOT-TD
+
+].
+
+ActionFragment
+
+dictionary
+
+Represents
+the
+
+Action
+
+interaction
+data
+that
+initializes
+a
+
+
+
+ThingAction
+
+
+objects.
+
+object.
+Its
+properties
+are
+defined
+in
+the
+
+Action
+
+and
+
+InteractionPattern
+
+sections
+of
+[
+
+WOT-TD
+
+].
+
+
+getEvents()
+
+EventFragment
+
+
+
+
+Returns
+
+Represents
+
+the
+list
+of
+
+
+Event
+
+s
+
+interaction
+data
+that
+initializes
+a
+
+ThingEvent
+
+object.
+Its
+properties
+are
+
+defined
+in
+the
+Thing
+Description
+
+
+Event
+
+
+section
+
+of
+the
+
+[
+
+WOT-TD
+
+].
+
+ThingFragment
+
+dictionary
+
+The
+
+ThingFragment
+
+dictionary
+is
+defined
+as
+
+Thing
+
+
+in
+the
+form
+of
+
+[
+
+WOT-TD
+
+].
+It
+is
+
+a
+list
+
+dictionary
+that
+contains
+properties
+representing
+semantic
+metadata
+and
+interactions
+(
+
+Properties
+,
+Action
+
+s
+and
+
+Event
+
+s).
+It
+is
+used
+for
+initializing
+an
+internal
+representation
+
+of
+a
+
+Thing
+Description
+
+and
+its
+properties
+may
+be
+used
+in
+
+
+
+ThingEvent
+
+ThingFilter
+
+objects.
+
+.
+
+getLinks()
+
+ThingDescription
+
+
+
+
+Returns
+the
+list
+
+Serialized
+representation
+
+of
+linked
+resources
+in
+
+the
+
+
+Thing
+Description
+
+(a
+
+JSON-LD
+
+document).
+
+In
+this
+version
+
+of
+the
+API,
+
+Thing
+Description
+
+s
+are
+represented
+as
+an
+opaque
+
+USVString
+
+that
+can
+be
+transmitted
+between
+devices.
+
+The
+data
+types
+and
+structures
+imported
+from
+[
+
+WOT-TD
+
+]
+are
+extended
+by
+this
+specification
+
+in
+order
+to
+provide
+
+the
+form
+of
+a
+list
+of
+
+interfaces
+for
+
+WoT
+Interactions
+.
+Every
+
+Thing
+
+describes
+its
+metadata
+as
+defined
+in
+
+
+
+,
+and
+basic
+interactions
+defined
+as
+
+Properties
+,
+Action
+
+
+TDLink
+
+ThingFragment
+
+objects.
+
+s
+and
+
+Event
+
+s.
+The
+following
+interfaces
+are
+used
+for
+representing
+these
+interactions.
+
+
+TDLink
+
+Interaction
+
+
+
+
+Contains
+a
+hyperlink
+reference,
+a
+relation
+type
+
+The
+
+Interaction
+
+interface
+is
+an
+abstract
+class
+to
+represent
+
+Thing
+
+interactions:
+
+Properties
+,
+Actions
+
+and
+
+Events
+.
+The
+
+InteractionFragment
+
+dictionary
+holds
+the
+common
+properties
+of
+
+PropertyFragment
+
,
+ActionFragment
+
+and
+
+EventFragment
+
+dictionaries
+used
+for
+initializing
+
+ThingProperty
+
,
+ThingAction
+
+and
+
+ThingEvent
+
+objects
+in
+
+a
+media
+type.
+
+
+
+ThingFragment
+
+dictionary
+used
+for
+creating
+an
+
+ExposedThing
+
+object.
+
+
"idl-def-interaction" data-idl="" data-title= +"Interaction">interface+Interaction
{ + readonly attribute (Form
or FrozenArray<Form
>) +class="internalDFN" data-link-type= +"dfn"> +<span class="idlMember" id="idl-def-tdlink-rel" data-idl="" +data-title="rel" data-dfn-for="tdlink"> <span class= +"idlMemberType"><a href= +"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-no-default="" +data-link-for="tdlink" data-lt="" href="#dom-tdlink-rel" class= +"internalDFN" data-link-type= +"dfn"> +}; ++"dfn">forms
; +}; + +"dfn">Interaction
includes ++InteractionFragment +
+; + + +
+The
+
+
+
+read-only
+property
+represents
+the
+protocol
+bindings
+initialization
+data
+and
+is
+initialized
+by
+the
+
+WoT
+Runtime
+.TDLink
+
+forms
+
+ThingProperty
+
+interface
+
+The
+
+ThingProperty
+
+interface
+is
+used
+in
+
+ConsumedThing
+
+and
+
+ExposedThing
+
+objects
+to
+represent
+
+Thing
+
+Property
+
+interactions.
+
+The
+
+PropertyFragment
+
+
+
+dictionary
+contains
+
+is
+used
+for
+initializing
+
+Property
+
+objects
+in
+a
+
+ThingFragment
+
+dictionary
+used
+for
+creating
+an
+
+ExposedThing
+
+object.
+It
+
+MUST
+
+implement
+one
+of
+
+the
+following
+properties:
+
+
+
+DataSchema
+
+dictionaries.
+
+
"idl-def-thingproperty" data-idl="" data-title= +"ThingProperty">interfaceThingProperty
:Interaction
{ + // getter for PropertyFragment properties + getter +"https://heycam.github.io/webidl/#idl-any">any (DOMString name); + // get and set interface for the Property + +"https://heycam.github.io/webidl/#idl-promise">Promise<any>read
(); + +"https://heycam.github.io/webidl/#idl-promise">Promise<void>write
(any value); +}; + +"dfn">ThingProperty
includesPropertyFragment
; + +"dfn">ThingProperty
includes ++Observable +
+; +
+The
+
+
+
+
+interface
+contains
+all
+the
+properties
+defined
+on
+href
+
+ThingProperty
+
+
+PropertyFragment
+
+as
+read-only
+properties.
+
+The
+
+type
+
+
+attribute
+
+read-only
+property
+
+represents
+the
+type
+definition
+for
+the
+
+Property
+
+as
+
+a
+hyperlink
+reference
+
+
+
+DataSchema
+
+dictionary
+object.
+
+The
+
+writable
+
+read-only
+property
+tells
+whether
+the
+
+Property
+
+value
+can
+be
+updated.
+If
+it
+is
+
+false
+
,
+then
+the
+
+set(value)
+
+method
+
+SHOULD
+
+always
+reject.
+
+The
+
+observable
+
+read-only
+property
+tells
+whether
+the
+
+Property
+
+supports
+subscribing
+to
+value
+change
+notifications.
+If
+it
+is
+
+false
+
,
+then
+the
+
+subscribe()
+
+method
+
+SHOULD
+
+always
+fail.
+
+The
+
+constant
+
+read-only
+property
+-
+defined
+in
+
+DataSchema
+
+-
+tells
+whether
+the
+
+Property
+
+value
+is
+a
+constant.
+If
+
+true
+
,
+the
+
+set()
+
+and
+
+subscribe()
+
+methods
+
+SHOULD
+
+always
+fail.
+
+The
+
+required
+
+read-only
+property
+-
+defined
+in
+
+DataSchema
+
+-
+tells
+whether
+the
+
+Property
+
+should
+be
+always
+present
+on
+the
+
+ExposedThing
+
+object.
+
+The
+
+read()
+
+method
+will
+fetch
+the
+value
+of
+the
+
+Property
+
+.
+Returns
+a
+
+Promise
+
+that
+resolves
+with
+the
+value,
+or
+rejects
+with
+an
+error.
+
+The
+
+
+
+
+rel
+
+write()
+
+attribute
+represents
+
+method
+will
+attempt
+to
+set
+the
+value
+of
+the
+
+Property
+
+specified
+in
+the
+
+value
+
+argument
+whose
+type
+
+SHOULD
+
+match
+the
+one
+specified
+by
+the
+
+type
+
+property.
+Returns
+
+a
+relation
+
+
+Promise
+
+that
+resolves
+on
+success,
+or
+rejects
+on
+an
+error.
+
+ThingAction
+
+interface
++"idl-def-thingaction" data-idl="" data-title= +"ThingAction">interfaceThingAction
:Interaction
{ + +"https://heycam.github.io/webidl/#idl-promise">Promise<any>invoke
(optional any inputValue); +}; + +"dfn">ThingAction
includes ++ActionFragment +
+; +
+The
+
+invoke()
+
+method
+when
+invoked,
+starts
+the
+
+Action
+
+interaction
+with
+the
+input
+value
+provided
+by
+the
+
+inputValue
+
+argument.
+If
+
+inputValue
+
+is
+
+null
+
,
+the
+action
+does
+not
+take
+any
+arguments
+and
+rejects
+if
+any
+arguments
+are
+provided.
+If
+the
+value
+is
+
+undefined
+
,
+the
+action
+will
+ignore
+any
+arguments
+provided.
+Otherwise
+the
+
+type
+of
+
+inputValue
+
+SHOULD
+
+match
+the
+
+DataSchema
+
+definition
+in
+the
+
+input
+
+property.
+Returns
+a
+
+Promise
+
+that
+will
+reject
+with
+an
+error
+or
+will
+resolve
+with
+a
+value
+of
+type
+defined
+by
+the
+
+output
+
+property.
+
+ThingEvent
+
+interface
++"idl-def-thingevent" data-idl="" data-title= +"ThingEvent">interfaceThingEvent
:Interaction
{ +}; + +"dfn">ThingEvent
includesEventFragment
; + +"dfn">ThingEvent
includes ++ThingProperty +
+; +
+Since
+
+ThingEvent
+
+implements
+
+Observable
+
+through
+the
+
+ThingProperty
+
+interface,
+event
+subscription
+is
+done
+by
+invoking
+the
+
+subscribe()
+
+method
+on
+the
+event
+object
+that
+returns
+a
+cancelable
+
+Subscription
+
+.
+
+mediaType
+
+ExposedEvent
+
+
+
+
+"idl-def-exposedevent" data-idl="" data-title=
+"ExposedEvent">interface ExposedEvent
: ThingEvent
{
+ void emit
(any payload);
+};
+
+emit()
+
+method
+
+Emits
+an
+event
+that
+carries
+data
+specified
+by
+the
+
+payload
+
+argument.
+
+The
+value-matching
+algorithm
+is
+applied
+to
+
+a
+IANA
+media
+
+
+value
+
+input
+in
+relation
+to
+a
+
+valueType
+
+property
+of
+
+type
+.
+For
+TD
+
+
+
+DataSchema
+
,
+for
+instance
+the
+
+value
+
+and
+
+type
+
+properties
+of
+a
+
+PropertyFragment
+
+
+s
+there
+will
+be
+registered
+media
+types,
+so
+applications
+will
+be
+able
+
+object,
+or
+the
+
+inputValue
+
+parameter
+
+to
+check
+whether
+an
+
+the
+
+
+
+href
+
+invoke()
+
+link
+points
+
+method
+of
+a
+
+ThingAction
+
+object
+in
+relation
+
+to
+the
+same
+object.
+It
+executes
+the
+following
+steps:
+
+false
+
.
+"null"
+
:
+if
+
+value
+
+is
+
+null
+
,
+return
+
+true
+
,
+otherwise
+return
+
+false
+
.
+"boolean"
+
:
+if
+
+value
+
+is
+either
+
+true
+
+or
+
+false
+
,
+then
+return
+
+true
+
,
+otherwise
+return
+
+false
+
.
+"integer"
+
:
+if
+
+value
+
+is
+not
+an
+integer
+type
+defined
+by
+
+the
+
+long
+
+or
+
+long
+long
+
+),
+then
+return
+
+false
+
,
+otherwise
+execute
+the
+following
+sub-steps:
+
+true
+
.
+"number"
+
,
+if
+
+value
+
+is
+not
+an
+integer
+or
+floating
+point
+type
+defined
+by
+the
+underlying
+platform
+(such
+as
+
+long
+
+or
+
+long
+long
+
+or
+
+double
+
+),
+then
+return
+
+false
+
,
+otherwise
+otherwise
+execute
+the
+following
+sub-steps:
+
+true
+
.
+"string"
+
:
+if
+
+value
+
+is
+not
+a
+string
+type
+defined
+by
+the
+underlying
+platform,
+then
+return
+
+false
+
,
+otherwise
+return
+
+true
+
.
+In
+
+this
+
+"array"
+
,
+execute
+the
+following
+sub-steps:
+
+false
+
.
+undefined
+
,
+return
+
+false
+
.
+null
+
,
+return
+
+true
+
+(i.e.
+any
+type
+is
+accepted
+as
+array
+element,
+including
+heterogenous
+arrays).
+
+false
+
,
+then
+return
+
+false
+
.
+true
+
.
+"object"
+
,
+execute
+the
+following
+sub-steps:
+
+Object
+
,
+return
+
+false
+
.
+false
+
.
+null
+
,
+return
+
+true
+
+(i.e.
+accept
+any
+object
+value).
+
+false
+
.
+true
+
.+ +This +section +is +non-normative. + +
++ +Observables + +are + +proposed + +to +be +included +in +ECMAScript +and +are +used +for +handling +pushed +data +associated +with +various +possible +sources, +for +instance +events, +timers, +streams, +etc. +A +minimal +required +implementation +is +described +here. +
++This +section +is +informal +and +contains +rather +laconic +information +for +implementations +on +what +to +support +for +interoperability. +
+interface "dfn"> { +<span class="idlMethod" id= +"idl-def-observable-subscribe-next-error-complete" data-idl="" +data-title="subscribe" data-dfn-for="observable"> <span class= +"idlMethType"><a href="#dom-subscription" class="internalDFN" + +"dfn">+Observable
{ +Subscription
subscribe
("idlParam">(<a href="#dom-observer" +class="internalDFN" data-link-type= +"dfn"> or <a href="#dom-onnext" class= + +"idlParam">EventHandler handler, + optionalErrorHandler
errorHandler, + optional +"internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">next, + <span class= +"idlParam">optional <a href= +"#dom-onerror" class="internalDFN" data-link-type= +"dfn"> <span class= +"idlParamName">error, + <span class= +"idlParam">optional <a href= +"#dom-oncomplete" class="internalDFN" data-link-type= ++"dfn">OnComplete
"idlParamName">complete +}; +<span class="idlInterface" id="idl-def-subscription" data-idl="" +data-title="Subscription">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-subscription" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-subscription-unsubscribe" +data-idl="" data-title="unsubscribe" data-dfn-for= +"subscription"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="subscription" +data-lt="unsubscribe|unsubscribe()" href= +"#dom-subscription-unsubscribe" class="internalDFN" data-link-type= +"dfn"> +<span class="idlAttribute" id="idl-def-subscription-closed" +data-idl="" data-title="closed" data-dfn-for= +"subscription"> readonly attribute <span class= +"idlAttrType"><a href= + +"idlParamName">onComplete); +}; +interfaceSubscription
{ + voidunsubscribe
(); + readonly attribute +"https://heycam.github.io/webidl/#idl-boolean">boolean data-link-for="subscription" data-lt="" href= +"#dom-subscription-closed" class="internalDFN" data-link-type= + +data-link-for="subscription" data-lt="subscription.closed|closed" +href="#dom-subscription-closed" class="internalDFN" data-link-type= + +"dfn">closed
; +}; +<span class="idlInterface" id="idl-def-observer" data-idl="" +data-title="Observer">interface <span class= +"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-observer" class="internalDFN" data-link-type= +"dfn"> { +<span class="idlMethod" id="idl-def-observer-next-value" data-idl= +"" data-title="next" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="next()|next" href="#dom-observer-next" class="internalDFN" +data-link-type="dfn">next(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-any">any +<span class="idlMethod" id="idl-def-observer-error-error" data-idl= +"" data-title="error" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="error()|error" href="#dom-observer-error" class= +"internalDFN" data-link-type="dfn">error(<span class= +"idlParam"><a href= +"https://heycam.github.io/webidl/#idl-Error">Error +<span class="idlMethod" id="idl-def-observer-complete" data-idl="" +data-title="complete" data-dfn-for="observer"> <span class= +"idlMethType">void <span class= +"idlMethName"><a data-no-default="" data-link-for="observer" +data-lt="complete()|complete" href="#dom-observer-complete" class= +"internalDFN" data-link-type="dfn">complete +}; +<span class="idlCallback" id="idl-def-onnext" data-idl="" +data-title="OnNext">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-onnext" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType">void<span class= ++}; +callbackEventHandler
= void ( +"idlParamType">"https://heycam.github.io/webidl/#idl-any">any +<span class="idlCallback" id="idl-def-onerror" data-idl="" +data-title="OnError">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-onerror" class="internalDFN" data-link-type= +"dfn"> = <span class= +"idlCallbackType">void<span class= + +"https://heycam.github.io/webidl/#idl-any">any value); +callbackErrorHandler
= void ( +"idlParamType">"https://heycam.github.io/webidl/#idl-Error">Error +<span class="idlCallback" id="idl-def-oncomplete" data-idl="" +data-title="OnComplete">callback <span class= +"idlCallbackID"><a data-no-default="" data-link-for="" data-lt="" +href="#dom-oncomplete" class="internalDFN" data-link-type= +"dfn"> = <span class= + +"https://heycam.github.io/webidl/#idl-Error">Error error); +callbackOnComplete
= +"idlCallbackType"> +void + +(); + +
+The
+Observer
+interface
+defines
+the
+
+following
+
+callbacks
+needed
+
+can
+be
+provided
+when
+subscribing
+
+to
+handle
+
+an
+
+
+Observable
+
+:
+
+OnNext
+
+EventHandler
+
+
+
+callback
+takes
+the
+next
+sample
+for
+the
+data
+in
+the
+
+value
+
+argument.
+
+OnError
+
+ErrorHandler
+
+
+
+callback
+takes
+an
+error
+in
+the
+
+value
+
+argument.
+It
+is
+called
+when
+an
+error
+
+OnComplete
+
+
+callback
+is
+called
+when
+the
+data
+source
+has
+finished
+sending
+values.
+
+Subscription
+
+
+interface
+
+
+
+Contains
+the
+
+
+closed
+
+
+property
+of
+type
+
+boolean
+
+that
+tells
+if
+the
+subscription
+is
+closed
+or
+active.
+
+Also,
+contains
+the
+
+
+unsubscribe
+
+
+()
+method
+that
+cancels
+the
+subscription,
+i.e.
+makes
+a
+request
+to
+the
+underlying
+platform
+to
+stop
+receiving
+data
+from
+the
+source,
+and
+sets
+the
+
+closed
+
+property
+to
+
+false
+
.
+
+Observable
+
+
+interface
+
+
+
+The
+
+
+Observable
+
+
+interface
+enabled
+subscribing
+to
+pushed
+data
+notifications
+by
+the
+
+
+subscribe
+
+
+()
+method:
+
+In
+general
+
+the
+security
+measures
+taken
+to
+protect
+a
+
+WoT
+Security
+
+system
+will
+depend
+on
+the
+threats
+
+and
+Privacy
+repository
+
+attackers
+that
+system
+may
+face
+and
+the
+value
+of
+the
+assets
+needs
+to
+protect.
+A
+detailed
+discussion
+of
+security
+and
+privacy
+considerations
+
+for
+work
+in
+progress
+regarding
+
+the
+Web
+of
+Things,
+including
+a
+
+threat
+models,
+assets,
+risks,
+recommended
+mitigations,
+
+model
+that
+can
+be
+adapted
+to
+various
+circumstances,
+is
+presented
+in
+the
+informative
+document
+[
+
+WOT-SECURITY-CONSIDERATIONS
+
+].
+This
+section
+includes
+only
+normative
+recommendations
+relevant
+to
+the
+WoT
+Thing
+Description.
+
+When
+designing
+new
+devices
+
+and
+services
+for
+use
+with
+the
+WoT,
+we
+have
+documented
+a
+set
+of
+
+best
+practices
+for
+
+in
+[
+
+WOT-SECURITY-BEST-PRACTICES
+
+]
+that
+
+SHOULD
+
+be
+followed.
+
+This
+best-practices
+document
+may
+be
+updated
+as
+
+security
+measures
+evolve.
+Following
+these
+practices
+does
+not
+guarantee
+security,
+but
+it
+at
+least
+will
+help
+to
+avoid
+common
+known
+vulnerabilities
+
+and
+privacy
+for
+systems
+
+pitfalls.
+
+Below +are +specific +recommendations +related +to +WoT +runtime +implementations: +
+Some +additional +specific +recommendations +relevant +for +WoT +script +developers: + +
++The +generic +WoT +terminology +is +defined +in +[ + + +WOT-ARCHITECTURE + + +]: + +Thing +, + +Thing +Description + +(in +short + +TD + +), + +Web +of +Things + +(in +short + + +WoT + + +), + +WoT +Interface +, + +Protocol +Bindings +, + +WoT +Runtime +, + +Consuming +a +Thing +Description +, + +Thing +Directory +, + +WoT +Interactions +, + +Property +, + +Action +, + +Event + +etc. +
+
+
+JSON-LD
+
+is
+defined
+in
+[
+
+
+JSON-LD
+
+
+]
+as
+a
+JSON
+document
+that
+is
+augmented
+with
+support
+for
+Linked
+Data
+by
+providing
+a
+@context
+property
+with
+a
+defining
+URI
+.
+
+Data.
+
+
+The +terms + + +URL + + +and + + +URL +path + + +are +defined +in +[ + + +URL + + +]. +
++The +following +terms +are +defined +in +[ + + +HTML52 + + +] +and +are +used +in +the +context +of +browser +implementations: + + +browsing +context + +, + + +top-level +browsing +context + +, + + +global +object + +, + + +incumbent +settings +object + +, + + +Document + +, + + +document +base +URL + +, + + +Window + +, + + +WindowProxy + +, + + +origin + +, + + +ASCII +serialized +origin + +, +executing +algorithms + + +in +parallel + +, + + +queue +a +task + +, + + +task +source + +, + + +iframe + +, + + +valid +MIME +type + +. +
+
+A
+
+browsing
+context
+
+refers
+to
+the
+environment
+in
+which
+
+Document
+
+objects
+are
+presented
+to
+the
+user.
+A
+given
+
+browsing
+context
+
+has
+a
+single
+
+
+WindowProxy
+
+
+object,
+but
+it
+can
+have
+many
+
+
+Document
+
+
+objects,
+with
+their
+associated
+
+
+Window
+
+
+objects.
+The
+
+script
+execution
+context
+
+associated
+with
+the
+
+browsing
+context
+
+identifies
+the
+entity
+which
+invokes
+this
+API,
+which
+can
+be
+a
+
+web
+app
+,
+a
+
+web
+page
+,
+or
+an
+
+iframe
+.
+
+The +term + + +secure +context + + +is +defined +in +[ + + +WEBAPPSEC + + +]. +
++ + +Error +, + +EvalError +, + +RangeError +, + +ReferenceError +, + +SyntaxError +, + +TypeError +, + +URIError + + +, + + +script +execution +context + +, + + +Promise + +, + + +JSON + +, + + +JSON.stringify + + +and + + +JSON.parse + + +are +defined +in +[ + + +ECMASCRIPT + + +]. +
++ + +DOMString + +, + + +USVString + +, + + +ArrayBuffer + +, + + +BufferSource + + +and + + +any + + +are +defined +in +[ + + +WEBIDL + + +]. +
++The +algorithms + + +utf-8 +encode + +, +and + + +utf-8 +decode + + +are +defined +in +[ + + +ENCODING + + +]. +
++ +IANA +media +type + +s +(formerly +known +as +MIME +types) +are +defined +in + +RFC2046 +. +
++The +terms + +hyperlink +reference + +and + +relation +type + +are +defined +in +[ + + +HTML52 + + +] +and + +RFC8288 +. +
++As +well +as +sections +marked +as +non-normative, +all +authoring +guidelines, +diagrams, +examples, +and +notes +in +this +specification +are +non-normative. +Everything +else +in +this +specification +is +normative. +
++The +key +words + +MAY +, + +MUST +, + +SHOULD +, +and + +SHOULD +NOT + + +are +to +be +interpreted +as +described +in +[ + + +RFC2119 + + +]. +
++This +document +defines +conformance +criteria +that +apply +to +a +single +product: +the + +UA + +(user +agent) +that +implements +the +interfaces +it +contains. +
++This +specification +can +be +used +for +implementing +the +WoT +Scripting +API +in +multiple +programming +languages. +The +interface +definitions +are +specified +in +[ + + +WEBIDL + + +]. +
++The +user +agent +(UA) +may +be +implemented +in +the +browser, +or +in +a +separate +runtime +environment, +such +as + +Node.js + +or +small +embedded +runtimes. +
++Implementations +that +use +ECMAScript +executed +in +a +browser +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +ECMAScript +Bindings +defined +in +the +Web +IDL +specification +[ + + +WEBIDL + + +]. +
++Implementations +that +use +TypeScript +or +ECMAScript +in +a +runtime +to +implement +the +APIs +defined +in +this +document + +MUST + +implement +them +in +a +manner +consistent +with +the +TypeScript +Bindings +defined +in +the +TypeScript +specification +[ + + +TYPESCRIPT + + +]. +
++This +document +serves +a +general +description +of +the +WoT +Scripting +API. +Language +and +runtime +specific +issues +are +discussed +in +separate +extensions +of +this +document. +
+
+The
+following
+is
+a
+list
+of
+major
+changes
+to
+the
+document.
+For
+a
+complete
+list
+of
+changes,
+see
+the
+
+github
+change
+log
+.
+You
+can
+also
+view
+the
+
+recently
+closed
+bugs
+
+issues
+
+.
+
+The +following +problems +are +being +discussed +and +need +most +attention: +
+
+ExposedThing
+
+
++Special +thanks +to +former +editor +Johannes +Hund +(until +August +2017, +when +at +Siemens +AG) +for +developing +this +specification. +Also, +the +editors +would +like +to +thank +Dave +Raggett, +Matthias +Kovatsch, +Michael +Koster +and +Michael +McCool +for +their +comments +and +guidance. +
+Copyright + © 2017-2019 W3C® + (MIT, + ERCIM, + Keio, Beihang). W3C + liability, + trademark and + permissive document license rules apply.
+The main Web of Things (WoT) concepts are + described in the WoT Architecture + document. The Web of Things is made of entities (Things) that can describe their capabilities in a + machine-interpretable Thing Description (TD) + and expose these capabilities through the WoT Interface, that is, network interactions modeled + as Properties (for reading and writing + values), Actions (to execute remote procedures + with or without return values) and Events (for signaling + notifications).
+Scripting is an optional "convenience" building block in WoT + and it is typically used in gateways that are able to run a + WoT Runtime and + script management, providing a convenient way to extend WoT + support to new types of endpoints and implement WoT + applications such as + Thing Directory.
+This specification describes a programming interface + representing the WoT Interface that + allows scripts to discover, operate Things and to + expose locally defined Things characterized by + WoT Interactions specified by a + script.
+The specification deliberately follows the WoT Thing + Description specification closely. It is possible to + implement simpler APIs on top of this API, or implementing + directly the WoT network facing interface (i.e. the WoT Interface).
+This specification is implemented at least by the + Thingweb project also + known as node-wot, + which is considered the reference open source implementation + at the moment. Check its source + code, including examples. + Other, closed source implementations have been made by WG + member companies and tested against node-wot + in plug-fests.
+This section describes the status of this document at + the time of its publication. Other documents may supersede this + document. A list of current W3C publications and the + latest revision of this technical report can be found in the + W3C technical reports + index at https://www.w3.org/TR/.
+Implementers need to be aware that this specification is + considered unstable. Vendors interested in implementing this + specification before it eventually reaches the Candidate + Recommendation phase should subscribe to the repository and + take part in the discussions.
+Please contribute to this draft using the + GitHub + Issue feature of the WoT Scripting + API repository. For feedback on security and privacy + considerations, please use the WoT Security and + Privacy Issues.
+This document was published by the Web of Things Working Group as + a Working Draft. This document is intended to become a W3C + Recommendation.
+Comments regarding this document are welcome. Please send + them to public-wot-wg@w3.org + (archives).
+Publication as a Working Draft does not imply endorsement + by the W3C + Membership. This is a draft document and may be updated, + replaced or obsoleted by other documents at any time. It is + inappropriate to cite this document as other than work in + progress.
+This document was produced by a group operating under the + W3C Patent Policy. + W3C maintains a + public list + of any patent + disclosures made in connection with the deliverables of the + group; that page also includes instructions for disclosing a + patent. An individual who has actual knowledge of a patent + which the individual believes contains Essential + Claim(s) must disclose the information in accordance with + section + 6 of the W3C + Patent Policy.
+This document is governed by the 1 March 2019 + W3C Process + Document.
+WoT provides layered interoperability based on how Things are used: "consumed" and "exposed", as + defined + in [WOT-ARCHITECTURE].
+By consuming a TD, a client Thing creates a local runtime resource model that + allows accessing the Properties, Actions and Events exposed by the server Thing on a remote device.
+Exposing a Thing requires:
+Typically scripts are meant to be used on bridges + or gateways that expose and control simpler devices as WoT + Things and have means to handle (e.g. install, + uninstall, update etc.) and run scripts.
+This specification does not make assumptions on + how the WoT Runtime handles and runs + scripts, including single or multiple tenancy, script + deployment and lifecycle management. The API already supports + the generic mechanisms that make it possible to implement + script management, for instance by exposing a manager + Thing whose Actions (action + handlers) implement script lifecycle management + operations.
+This section is non-normative.
+The following scripting use cases are supported in this + specification:
+As well as sections marked as non-normative, all authoring + guidelines, diagrams, examples, and notes in this specification + are non-normative. Everything else in this specification is + normative.
+The key words MAY, MUST, and SHOULD in + this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only + when, they appear in all capitals, as shown here.
+This specification describes the conformance criteria for + the following classes of user agent (UA).
+Due to requirements of small embedded implementations,
+ splitting WoT client and server interfaces was needed. Then,
+ discovery is a distributed application, but typical scenarios
+ have been covered by a generic discovery API in this
+ specification. This resulted in using 3 conformance classes for
+ a UA that implements this API, one for client, one for
+ server, and one for discovery. An application that uses this
+ API can introspect for the presence of the
+ consume()
, produce()
and
+ discover()
methods on the WoT API object in order to determine which
+ conformance class the UA implements.
Implementations of this conformance class MUST implement the
+
+ interface and the ConsumedThing
consume()
method on the
+ WoT API object.
Implementations of this conformance class MUST implement
interface and
+ the ExposedThing
produce()
method on the WoT API object.
Implementations of this conformance class MUST implement the
+
+ interface and the ThingDiscovery
discover()
method on the
+ WoT API object.
These conformance classes MAY be implemented in a single UA.
+This specification can be used for implementing the WoT + Scripting API in multiple programming languages. The interface + definitions are specified in [WEBIDL].
+The UA may be implemented in the browser, or in a + separate runtime environment, such as Node.js or in small embedded + runtimes.
+Implementations that use ECMAScript executed in a browser to + implement the APIs defined in this document MUST implement them in a manner consistent + with the ECMAScript Bindings defined in the Web IDL + specification [WEBIDL].
+Implementations that use TypeScript or ECMAScript in a + runtime to implement the APIs defined in this document + MUST implement them in a + manner consistent with the TypeScript Bindings defined in the + TypeScript specification [TYPESCRIPT].
+ThingDescription
+ typetypedef object ThingDescription
;
+ Represents a Thing Description + (TD) as defined in [WOT-TD]. It is expected to be a parsed + JSON object that is validated using + JSON schema validation.
+Fetching a TD given a URL should be done with + an external method, such as the Fetch API or a + HTTP client library, which offer already standardized options + on specifying fetch details.
+try {
+ let res = await fetch('https://tds.mythings.biz/sensor11');
+ // ... additional checks possible on res.headers
+ let td = await res.json();
+ let thing = new ConsumedThing(td);
+ console.log("Thing name: " + thing.getThingDescription().title);
+} catch (err) {
+ console.log("Fetching TD failed", err.message);
+}
+ Note that [WOT-TD] allows using a shortened Thing Description by the means of + defaults and requiring clients to expand them with + default values specified in [WOT-TD] for the properties that are not + explicitly defined in a given TD.
+To expand + a TD given td, run the following + steps:
+The [WOT-TD] specification defines how a
+ TD should be validated. Therefore, this API expects
+ the ThingDescription
+ objects be validated before used as parameters. This
+ specification defines a basic TD validation as
+ follows.
To validate a TD given + td, run the following steps:
+"TypeError"
and terminate these steps."TypeError"
and terminate these
+ steps.
+ "TypeError"
and terminate these
+ steps.
+ Defines the API entry point exposed as a singleton and + contains the API methods.
+WOT
interface[SecureContext, Exposed=(Window,Worker)]
+interface WOT
{
+ // methods defined in UA conformance classes
+};
+
+ consume()
+ methodpartial interface WOT
{
+ Promise<ConsumedThing
> consume
(ThingDescription
td);
+};
+ Belongs to the WoT Consumer
+ conformance class. Expects an td argument and
+ returns a Promise
+ that resolves with a ConsumedThing
object that represents
+ a client interface to operate with the Thing. The method MUST run the following steps:
SecurityError
and
+ terminate these steps.ConsumedThing
+ object constructed from td.
+ produce()
+ methodpartial interface WOT
{
+ Promise<ExposedThing
> produce
(ThingDescription
td);
+};
+ Belongs to the WoT Producer
+ conformance class. Expects a td
argument and
+ returns a Promise
+ that resolves with an ExposedThing
object that extends
+ ConsumedThing
with a
+ server interface, i.e. the ability to define request
+ handlers. The method MUST run the following steps:
SecurityError
and terminate these
+ steps.
+ ExposedThing
object constructed
+ with td.
+ discover()
+ methodpartial interface WOT
{
+ ThingDiscovery
discover
(optional ThingFilter
filter = null);
+};
+ Belongs to the WoT Discovery
+ conformance class. Starts the discovery process that will
+ provide ThingDescription
+ objects for Thing Descriptions
+ that match an optional filter argument. The
+ method MUST run the
+ following steps:
SecurityError
and terminate these
+ steps.ThingDiscovery
object
+ discovery with filter.
+ Refer to the ThingDiscovery
section for how
+ discovery should be implemented.
ConsumedThing
+ interfaceRepresents a client API to operate a Thing. Belongs to + the WoT Consumer conformance class.
+[SecureContext, Exposed=(Window,Worker)] +interface+ConsumedThing
{ +constructor
(ThingDescription
td); + Promise<any
>readProperty
(DOMString
propertyName, + optionalInteractionOptions
options = null); + Promise<PropertyMap
>readAllProperties
(optionalInteractionOptions
options = null); + Promise<PropertyMap
>readMultipleProperties
( + sequence<DOMString
> propertyNames, + optionalInteractionOptions
options = null); + Promise<void>writeProperty
(DOMString
propertyName, +any
value, + optionalInteractionOptions
options = null); + Promise<void>writeMultipleProperties
(PropertyMap
valueMap, + optionalInteractionOptions
options = null); + Promise<any
>invokeAction
(DOMString
actionName, + optionalany
params = null, + optionalInteractionOptions
options = null); + Promise<void>observeProperty
(DOMString
name, +WotListener
listener, + optionalInteractionOptions
options = null); + Promise<void>unobserveProperty
(DOMString
name); + Promise<void>subscribeEvent
(DOMString
name, +WotListener
listener, + optionalInteractionOptions
options = null); + Promise<void>unsubscribeEvent
(DOMString
name); +ThingDescription
getThingDescription
(); +}; +dictionaryInteractionOptions
{ + objecturiVariables
; +}; +typedef objectPropertyMap
; +callbackWotListener
= void(any
data);
ConsumedThing
After fetching
+ a Thing Description as a JSON object,
+ one can create a ConsumedThing
object.
To create ConsumedThing
with the ThingDescription
td, run
+ the following steps:
ConsumedThing
+ object.
+ getThingDescription()
methodReturns 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.
InteractionOptions
+ dictionaryHolds the interaction options that need to be exposed for + application scripts according to the Thing Description. In this version of the + specification only URI template variables are used, + represented as parsed + JSON objects defined in [WOT-TD].
+The support for URI variables comes from the + need exposed by [WOT-TD] to be able to describe existing + TDs that use them, but it should be possible to + write a Thing Description + that would use Actions for representing the + interactions that need URI variables and represent the URI + variables as parameters to the Action and in + that case that could be encapsulated by the implementations + and the options parameter could be dismissed + from the methods exposed by this API.
+PropertyMap
+ typeRepresents 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.
+It could be defined in Web IDL (as well as
+ ThingDescription
) as
+ a maplike
+ interface from string to any.
readProperty()
methodReads a Property value. Takes a string
+ argument propertyName and and an optional
+ InteractionOptions
+ options argument. It returns a Property value represented as any
+ type. The method MUST
+ run the following steps:
SecurityError
and
+ terminate these steps.this.getThingDescription().properties[
propertyName]
.
+ SyntaxError
,
+ otherwise return value.SyntaxError
and
+ terminate these steps.readMultipleProperties()
methodReads multiple Property values with
+ one or multiple requests. Takes the
+ propertyNames argument as a sequence of strings
+ and an optional InteractionOptions
+ options argument. It returns an object with keys
+ from propertyNames and values returned by this
+ algorithm. The method MUST run the following steps:
SecurityError
and
+ terminate these steps.null
.NotSupportedError
+ and terminate these steps.
+ SyntaxError
and
+ terminate these steps.readAllProperties()
methodReads all properties of the Thing with one or
+ multiple requests. Takes an optional InteractionOptions
+ options argument. It returns an object with keys
+ from Property names and values returned
+ by this algorithm. The method MUST run the following steps:
SecurityError
and
+ terminate these steps.null
.NotSupportedError
+ and terminate these steps.
+ writeProperty()
methodWrites a single Property. Takes a
+ string argument propertyName, a value argument
+ value and an optional InteractionOptions
+ options argument. It returns success or failure.
+ The method MUST run
+ the following steps:
SecurityError
and
+ terminate these steps.SyntaxError
and terminate these
+ steps.
+ writeMultipleProperties()
methodWrites a multiple Property values with
+ one request. Takes a properties argument as an
+ object with keys being Property names and
+ values as Property values and an optional
+ InteractionOptions
+ options argument. It returns success or failure.
+ The method MUST run
+ the following steps:
SecurityError
and
+ terminate these steps.SyntaxError
and terminate these
+ steps.
+ NotSupportedError
+ and terminate these steps.
+ WotListener
+ callbackUser provided callback that takes any
+ argument and is used for observing Property changes
+ and handling Event notifications. Since
+ subscribing to these are WoT interactions, they are not
+ modelled with software events.
observeProperty()
methodMakes a request for Property value
+ change notifications. Takes a string argument
+ propertyName, a WotListener
callback function
+ listener and an optional InteractionOptions
+ options argument. It returns success or failure.
+ The method MUST run
+ the following steps:
SecurityError
and
+ terminate these steps."TypeError"
and
+ terminate these steps.unobserveProperty()
methodMakes a request for unsubscribing from Property value change notifications. Takes a + string argument propertyName and returns success + or failure. The method MUST run the following steps:
+SecurityError
and
+ terminate these steps.invokeAction()
methodMakes a request for invoking an Action and
+ return the result. Takes a string argument
+ actionName, an optional argument
+ params of type any
and an optional
+ InteractionOptions
+ options argument. It returns the result of the
+ Action or an error. The method MUST run the following
+ steps:
SecurityError
and
+ terminate these steps.
+ SyntaxError
and terminate these steps.
+ subscribeEvent()
methodMakes a request for subscribing to Event
+ notifications. Takes a string argument
+ eventName, a WotListener
callback function
+ listener and an optional InteractionOptions
+ options argument. It returns success or failure.
+ The method MUST run
+ the following steps:
SecurityError
and
+ terminate these steps."TypeError"
and
+ terminate these steps.unsubscribeEvent()
methodMakes a request for unsubscribing from Event notifications. Takes a string argument + eventName and returns success or failure. The + method MUST run the + following steps:
+SecurityError
and
+ terminate these steps.The next example illustrates how to fetch a TD by
+ URL, create a ConsumedThing
, read metadata (title),
+ read property value, subscribe to property change, subscribe
+ to a WoT event, unsubscribe.
try {
+ let res = await fetch("https://tds.mythings.org/sensor11");
+ let td = res.json();
+ let thing = new ConsumedThing(td);
+ console.log("Thing " + thing.getThingDescription().title + " consumed.");
+} catch(e) {
+ console.log("TD fetch error: " + e.message); },
+};
+try {
+ // subscribe to property change for “temperature”
+ await thing.observeProperty("temperature", value => {
+ console.log("Temperature changed to: " + value);
+ });
+ // subscribe to the “ready” event defined in the TD
+ await thing.subscribeEvent("ready", eventData => {
+ console.log("Ready; index: " + eventData);
+ // run the “startMeasurement” action defined by TD
+ await thing.invokeAction("startMeasurement", { units: "Celsius" });
+ console.log("Measurement started.");
+ });
+} catch(e) {
+ console.log("Error starting measurement.");
+}
+setTimeout( () => {
+ console.log(“Temperature: “ + await thing.readProperty(“temperature”));
+ await thing.unsubscribe(“ready”);
+ console.log("Unsubscribed from the ‘ready’ event.");
+},
+10000);
+ ExposedThing
+ interfaceThe ExposedThing
interface is
+ the server API to operate the Thing that allows
+ defining request handlers, Property, Action, and Event interactions.
[SecureContext, Exposed=(Window,Worker)] +interface+ExposedThing
:ConsumedThing
{ +ExposedThing
setPropertyReadHandler
(DOMString
name, +PropertyReadHandler
readHandler); +ExposedThing
setPropertyWriteHandler
(DOMString
name, +PropertyWriteHandler
writeHandler); +ExposedThing
setActionHandler
(DOMString
name,ActionHandler
action); + voidemitEvent
(DOMString
name,any
data); + Promise<void>expose
(); + Promise<void>destroy
(); +}; +callbackPropertyReadHandler
= Promise<any
>( + optionalInteractionOptions
options = null); +callbackPropertyWriteHandler
= Promise<void>(any
value, + optionalInteractionOptions
options = null); +callbackActionHandler
= Promise<any
>(any
params, + optionalInteractionOptions
options = null);
ExposedThing
The ExposedThing
interface extends ConsumedThing
. It is constructed from
+ a full or partial ThingDescription
object.
Note that an existing ThingDescription
object can be
+ optionally modified (for instance by adding or removing
+ elements on its properties, actions
+ and events internal properties) and the
+ resulting object can used for constructing an ExposedThing
object. This is the
+ current way of adding and removing Property, Action and Event definitions, as illustrated in the examples.
Before invoking expose(), the ExposedThing
object does not serve
+ any requests. This allows first constructing ExposedThing
and then initialize its
+ Properties and service handlers
+ before starting serving requests.
To construct an ExposedThing
with the ThingDescription
td, run
+ the following steps:
SecurityError
and terminate these
+ steps.ExposedThing
object.
+ ConsumedThing
The readProperty()
,
+ readMultipleProperties()
,
+ readAllProperties()
,
+ writeProperty()
,
+ writeMultipleProperties()
,
+ writeAllProperties()
methods have the same
+ algorithmic steps as described in ConsumedThing
,
+ with the difference that making a request to the underlying
+ platform MAY be
+ implemented with local methods or libraries and don't
+ necessarily need to involve network operations.
The implementation of ConsumedThing
interface in an ExposedThing
provide the
+ default methods to interact with the ExposedThing
.
After constructing an ExposedThing
, a script can initialize
+ its Properties and can set up the
+ optional read, write and action request handlers (the default
+ ones are provided by the implementation). The script provided
+ handlers MAY use the
+ default handlers, thereby extending the default behavior, but
+ they can also bypass them, overriding the default behavior.
+ Finally, the script would call expose()
on the
+ ExposedThing
in order
+ to start serving external requests.
PropertyReadHandler
+ callbackA function that is called when an external request for
+ reading a Property is received and defines
+ what to do with such requests. It returns a
+ Promise
+ and resolves it when the value of the Property matching the name
argument is
+ obtained, or rejects with an error if the property is not
+ found or the value cannot be retrieved.
setPropertyReadHandler()
methodTakes name
as string argument and
+ readHandler
as argument of type PropertyReadHandler
.
+ Sets the service handler for reading the specified Property matched by name
. Throws on
+ error. Returns a reference to this object for
+ supporting chaining.
The readHandler
callback function should
+ implement reading a Property and
+ SHOULD be called by
+ implementations when a request for reading a Property is received from the underlying
+ platform.
There MUST be at + most one handler for any given Property, so + newly added handlers MUST replace the previous handlers. If no handler + is initialized for any given Property, + implementations SHOULD implement a default property read + handler based on the Thing Description.
+When a network request for reading Property propertyName is received by + the implementation, run the following steps:
+ReferenceError
in the reply and terminate
+ these steps.
+ setPropertyReadHandler()
, invoke that
+ wih propertyName, return the value with the
+ reply and terminate these steps.
+ NotSupportedError
with the reply and
+ terminate these steps.
+ When a network request for observing a Property propertyName is received by + the implementation, run the following steps:
+PropertyWriteHandler
+ callbackA function that is called when an external request for
+ writing a Property is received and defines
+ what to do with such requests. It expects the requested new
+ value
as argument and returns a
+ Promise
+ which is resolved when the value of the Property that matches the name
+ argument has been updated with value
, or rejects
+ with an error if the property is not found or the value
+ cannot be updated.
Note that the code in this callback function + can read the property before updating it in order to find + out the old value, if needed. Therefore the old value is + not provided to this function.
+setPropertyWriteHandler()
methodTakes name
as string argument and
+ writeHandler
as argument of type PropertyWriteHandler
.
+ Sets the service handler for writing the specified Property matched by name
. Throws on
+ error. Returns a reference to this object for
+ supporting chaining.
There MUST be at + most one write handler for any given Property, so newly added handlers MUST replace the previous + handlers. If no write handler is initialized for any given + Property, implementations SHOULD implement default property update + and notifying observers on change, based on the Thing Description.
+When a network request for writing a Property propertyName with a new value
+ value is received, implementations SHOULD run the following
+ update property steps,
+ given propertyName, value and
+ mode set to "single"
:
ReferenceError
in the reply and terminate
+ these steps.
+ setPropertyWriteHandler()
, or if there
+ is a default write handler,
+ "single"
, reply to the request with the
+ new value, following to the Protocol Bindings.
+
+ NotSupportedError
in the reply and terminate
+ these steps.
+ When a network request for writing multiple Properties given in an object + propertyNames is received, run the following + steps:
+"multiple"
.
+ ActionHandler
+ callbackA function that is called when an external request for
+ invoking an Action is received and defines what
+ to do with such requests. It is invoked with a
+ params
dictionary argument. It returns a
+ Promise
+ that rejects with an error or resolves if the action is
+ successful.
setActionHandler()
methodTakes name
as string argument and
+ action
as argument of type ActionHandler
. Sets the handler
+ function for the specified Action matched by
+ name
. Throws on error. Returns a reference to
+ this object for supporting chaining.
The action
callback function will implement
+ an Action and SHOULD be called by implementations when a
+ request for invoking the Action is received
+ from the underlying platform.
There MUST be at + most one handler for any given Action, so newly added + handlers MUST replace + the previous handlers.
+When a network request for invoking the Action identified by name is received, + the runtime SHOULD + execute the following steps:
+ReferenceError
in the reply and terminate
+ these steps.
+ setActionHandler()
, invoke that wih
+ name, return the resulting value with the
+ reply and terminate these steps.
+ NotSupportedError
with the reply and
+ terminate these steps.
+ emitEvent()
methodTakes name as string argument denoting an
+ Event name, and a data argument of
+ any
type. The method MUST run the following steps:
SecurityError
and terminate these
+ steps.NotFoundError
and terminate these steps.
+
+ expose()
methodStart serving external requests for the Thing, so that WoT + Interactions using Properties, Actions and Events will be + possible. The method MUST run the following steps:
+SecurityError
and
+ terminate these steps."TypeError"
and terminate these steps.
+ Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ destroy()
methodStop serving external requests for the Thing and destroy the object. Note that eventual + unregistering should be done before invoking this method. + The method MUST run + the following steps:
+SecurityError
and
+ terminate these steps.Error
object
+ error with error.message
set to
+ the error code seen by the Protocol Bindings and terminate
+ these steps.
+ The next example illustrates how to create an
+
+ based on a partial TD object constructed
+ beforehands.ExposedThing
try {
+ let temperaturePropertyDefinition = {
+ type: "number",
+ minimum: -50,
+ maximum: 10000
+ };
+ let tdFragment = {
+ properties: {
+ temperature: temperaturePropertyDefinition
+ },
+ actions: {
+ reset: {
+ description: "Reset the temperature sensor",
+ input: {
+ temperature: temperatureValueDefinition
+ },
+ output: null,
+ forms: []
+ },
+ },
+ events: {
+ onchange: temperatureValueDefinition
+ }
+ };
+ let thing1 = await WOT.produce(tdFragment);
+ // initialize Properties
+ await thing1.writeProperty("temperature", 0);
+ // add service handlers
+ thing1.setPropertyReadHandler("temperature", () => {
+ return readLocalTemperatureSensor(); // Promise
+ });
+ // start serving requests
+ await thing1.expose();
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+ The next example illustrates how to add or modify a
+ Property definition on an existing
: take its
+ td property, add or modify it, then create another
+ ExposedThing
ExposedThing
with
+ that.
try {
+ // create a deep copy of thing1's TD
+ let instance = JSON.parse(JSON.stringify(thing1.td));
+ const statusValueDefinition = {
+ type: "object",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true
+ },
+ rgb: {
+ type: "array",
+ "minItems": 3,
+ "maxItems": 3,
+ items : {
+ "type" : "number",
+ "minimum": 0,
+ "maximum": 255
+ }
+ }
+ };
+ instance["name"] = "mySensor";
+ instance.properties["brightness"] = {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true,
+ };
+ instance.properties["status"] = statusValueDefinition;
+ instance.actions["getStatus"] = {
+ description: "Get status object",
+ input: null,
+ output: {
+ status : statusValueDefinition;
+ },
+ forms: [...]
+ };
+ instance.events["onstatuschange"] = statusValueDefinition;
+ instance.forms = [...]; // update
+ var thing2 = new ExposedThing(instance);
+ // TODO: add service handlers
+ await thing2.expose();
+ });
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+ ThingDiscovery
+ interfaceDiscovery is a distributed application that requires + provisioning and support from participating network nodes + (clients, servers, directory services). This API models the + client side of typical discovery schemes supported by various + IoT deployments.
+The ThingDiscovery
object is
+ constructed given a filter and provides the properties and
+ methods controlling the discovery process.
[SecureContext, Exposed=(Window,Worker)]
+interface ThingDiscovery
{
+ constructor
(optional ThingFilter
filter = null);
+ readonly attribute ThingFilter
? filter
;
+ readonly attribute boolean active
;
+ readonly attribute boolean done
;
+ readonly attribute Error? error
;
+ void start
();
+ Promise<ThingDescription
> next
();
+ void stop
();
+};
+ The ThingDiscovery
interface has a
+ next()
method and a done
property,
+ but it is not an Iterable. Look into Issue
+ 177 for rationale.
The discovery results internal slot
+ is an internal queue for temporarily storing the found ThingDescription
objects until they are
+ consumed by the application using the next() method. Implementations MAY optimize the size of this queue
+ based on e.g. the available resources and the frequency of
+ invoking the next() method.
The filter
+ property represents the discovery filter of type ThingFilter
specified for the
+ discovery.
The active
+ property is true
when the discovery is actively
+ ongoing on protocol level (i.e. new TDs may still arrive)
+ and false
otherwise.
The done
+ property is true
if the discovery has been
+ completed with no more results to report and discovery results is also empty.
The error
+ property represents the last error that occured during the
+ discovery process. Typically used for critical errors that stop
+ discovery.
ThingDiscovery
To create ThingDiscovery
with the ThingFilter
filter, run
+ the following steps:
null
, throw "TypeError"
and
+ terminate these steps.ThingDiscovery
+ object.
+
+ false
. Set error to
+ null
.
+ The start() method sets
+ active to
+ true
. The stop()
+ method sets active
+ to false, but done may be still
+ false
if there are ThingDescription
objects in the
+ discovery results not yet consumed
+ with next().
During successive calls of next(), active may be
+ true
or false
, but done is set to
+ false
by next()
+ only when both active is false
+ and discovery results is empty.
DiscoveryMethod
+ enumerationtypedef DOMString
DiscoveryMethod
;
+ Represents the discovery type to be used:
+ThingFilter
+ dictionaryRepresents an object containing the constraints for + discovering Things as key-value pairs.
+dictionary ThingFilter
{
+ (DiscoveryMethod
or DOMString
) method
= "any";
+ USVString? url
;
+ USVString? query
;
+ object? fragment
;
+};
+ The method
+ property represents the discovery type that should be used in
+ the discovery process. The possible values are defined by the
+
+ enumeration that MAY be
+ extended by string values defined by solutions (with no
+ guarantee of interoperability).DiscoveryMethod
The url
property represents
+ additional information for the discovery method, such as the
+ URL of the target entity serving the discovery request, for
+ instance the URL of a Thing Directory (if
+ method
is "directory"
) or that of a
+ Thing (otherwise).
The query
property represents a
+ query string accepted by the implementation, for instance a
+ SPARQL or JSON query. Support may be implemented locally in
+ the WoT Runtime or remotely as a service
+ in a Thing Directory.
The fragment
property represents a
+ template object used for matching property by property
+ against discovered Things.
+ start()
methodStarts the discovery process. The method MUST run the following + steps:
+SecurityError
and
+ terminate these steps.NotSupportedError
and terminate these
+ steps.NotSupportedError
and terminate these
+ steps.
+ ThingDescription
+ objects.
+ "any"
, use the widest discovery
+ method supported by the underlying platform."local"
, use the local Thing Directory for
+ discovery. Usually that defines Things
+ deployed in the same device, or connected to the
+ device in slave mode (e.g. sensors connected via
+ Bluetooth or a serial connection).
+ "directory"
, use the remote Thing Directory specified in
+ filter.url.
+ "multicast"
, use all the multicast
+ discovery protocols supported by the underlying
+ platform.active
property
+ to true
.SyntaxError
, discard td and
+ continue the discovery process.
+ false
,
+ discard td and continue the discovery
+ process.false
in any checks,
+ discard td and continue the discovery
+ process.Error
object error. Set
+ error.name to
+ 'DiscoveryError'
.this.active
to false
.false
.
+ next()
methodProvides the next discovered ThingDescription
object. The method
+ MUST run the
+ following steps:
true
, wait
+ until the discovery results
+ internal slot is not empty.
+ false
, set this.done to
+ true
and reject promise.
+ ThingDescription
object
+ td from discovery
+ results.
+
+ stop()
methodStops or suppresses the discovery process. It might not + be supported by all discovery methods and endpoints, + however, any further discovery results or errors will be + discarded and the discovery is marked inactive. The method + MUST run the + following steps:
+this.active
to
+ false
.The following example finds ThingDescription
objects of Things that are exposed by local hardware,
+ regardless how many instances of WoT Runtime it
+ is running. Note that the discovery can end (become inactive)
+ before the internal discovery results
+ queue is emptied, so we need to continue reading ThingDescription
objects until done.
+ This is typical with local and directory type
+ discoveries.
let discovery = new ThingDiscovery({ method: "local" });
+do {
+ let td = await discovery.next();
+ console.log("Found Thing Description for " + td.title);
+ let thing = new ConsumedThing(td);
+ console.log("Thing name: " + thing.getThingDescription().title);
+} while (!discovery.done);
+ The next example finds ThingDescription
objects of Things listed in a Thing Directory
+ service. We set a timeout for safety.
let discoveryFilter = {
+ method: "directory",
+ url: "http://directory.wotservice.org"
+};
+let discovery = new ThingDiscovery(discoveryFilter);
+setTimeout( () => {
+ discovery.stop();
+ console.log("Discovery stopped after timeout.");
+ },
+ 3000);
+do {
+ let td = await discovery.next();
+ console.log("Found Thing Description for " + td.title);
+ let thing = new ConsumedThing(td);
+ console.log("Thing name: " + thing.getThingDescription().title);
+} while (!discovery.done);
+if (discovery.error) {
+ console.log("Discovery stopped because of an error: " + error.message);
+}
+ The next example is for an open-ended multicast discovery, + which likely won't complete soon (depending on the underlying + protocol), so stopping it with a timeout is a good idea. It + will likely deliver results one by one.
+let discovery = new ThingDiscovery({ method: "multicast" });
+setTimeout( () => {
+ discovery.stop();
+ console.log("Stopped open-ended discovery");
+ },
+ 10000);
+do {
+ let td = await discovery.next();
+ let thing = new ConsumedThing(td);
+ console.log("Thing name: " + thing.getThingDescription().title);
+} while (!discovery.done);
+ A detailed discussion of security and privacy considerations + for the Web of Things, including a threat model that can be + adapted to various circumstances, is presented in the + informative document [WOT-SECURITY-GUIDELINES]. This section + discusses only security and privacy risks and possible + mitigations directly relevant to the scripts and WoT Scripting + API.
+A suggested set of best practices to improve security for + WoT devices and services has been documented in + [WOT-SECURITY-BEST-PRACTICES]. That document + may be updated as security measures evolve. Following these + practices does not guarantee security, but it might help avoid + common known vulnerabilities.
+The WoT security risks and possible mitigations are + concerning the following groups:
+This section is normative and contains specific risks + relevant for the WoT Scripting Runtime.
+A typical way to compromise any process is to send it a + corrupted input via one of the exposed interfaces. This can + be done to a script instance using WoT interface it + exposes.
+In case a script is compromised or misbehaving, the + underlying physical device (and potentially surrounded + environment) can be damaged if a script can use directly + exposed native device interfaces. If such interfaces lack + safety checks on their inputs, they might bring the + underlying physical device (or environment) to an unsafe + state (i.e. device overheats and explodes).
+If the WoT Scripting Runtime supports post-manufacturing + provisioning or updates of scripts, WoT Scripting Runtime + or any related data (including security credentials), it + can be a major attack vector. An attacker can try to modify + any above described element during the update or + provisioning process or simply provision attacker's code + and data directly.
+Typically the WoT Scripting Runtime needs to store the + security credentials that are provisioned to a WoT device + to operate in WoT network. If an attacker can compromise + the confidentiality or integrity of these credentials, then + it can obtain access to the WoT assets, impersonate WoT + things or devices or create Denial-Of-Service (DoS) + attacks.
+This section is non-normative.
+This section describes specific risks relevant for script + developers.
+A script instance may receive data formats defined by + the TD, or data formats defined by the applications. While + the WoT Scripting Runtime SHOULD perform validation on all input fields + defined by the TD, scripts may be still exploited by input + data.
+If a script performs a heavy functional processing on + received requests before the request is authenticated, it + presents a great risk for Denial-Of-Service (DOS) + attacks.
+During the lifetime of a WoT network, a content of a TD + can change. This includes its identifier, which might not + be an immutable one and might be updated periodically.
+While stale TDs can present a potential + problem for WoT network operation, it might not be a + security risk.
+The generic WoT terminology is defined in [WOT-ARCHITECTURE]: Thing, Thing Description (in short + TD), + Web of + Things (in short WoT), WoT Interface (same as + WoT + network interface), Protocol Bindings, + WoT + Runtime, Consuming a Thing + Description, Thing Directory, + WoT + Interactions, Property, Action, Event etc.
+JSON-LD is + defined in [JSON-LD] as a + JSON document that is augmented with support for Linked + Data.
+The terms URL, + URL + scheme, URL + host, URL + path, URL + record, parse a + URL, absolute-URL + string, path-absolute-URL + string, basic + URL parser are defined in [URL].
+The terms MIME + type, Parsing + a MIME type, Serializing + a MIME type, valid MIME + type string, JSON MIME + type are defined in [MIMESNIFF].
+The terms UTF-8 + encoding, UTF-8 + decode, encode, + decode are + defined in [ENCODING].
+string, + parse + JSON from bytes and serialize + JSON to bytes, are defined in [INFRA].
+The terms throw
,
+ creating
,
+ DOMString
,
+ Dictionary
,
+ ArrayBuffer
,
+ BufferSource
,
+ any
,
+ not
+ present, DOMException
,
+ AbortError
,
+ SyntaxError
,
+ NotSupportedError
,
+ NetworkError
,
+
+ TypeError
, NotReadableError
,
+ TimeoutError
,
+
+ NoModificationAllowedError
,
+ SecurityError
,
+ are defined in [WEBIDL].
Promise, + Error, + JSON, + JSON.stringify, + JSON.parse + and + internal slots are defined in [ECMASCRIPT].
+The terms browsing + context, + top-level browsing context, global + object, + current settings object, executing algorithms + in + parallel are defined in [HTML5] and are used in the context of + browser implementations.
+The term + secure + context is defined in [WEBAPPSEC].
+IANA media + types (formerly known as MIME types) are defined in + RFC2046.
+The terms hyperlink reference and + relation + type are defined in [HTML5] and RFC8288.
+API rationale usually belongs to a separate document, but in + the WoT case the complexity of the context justifies including + basic rationale here.
+The WoT Interest Group and Working Group have explored + different approaches to application development for WoT that + have been all implemented and tested.
+It is possible to develop WoT applications that only use + the WoT network + interface, typically exposed by a WoT gateway that + presents a REST-ful API towards clients and implements IoT + protocol plugins that communicate with supported IoT + deployments. One such implementation is the Mozilla WebThings + platform.
+WoT Things show good synergy with + software objects, so a Thing can be + represented as a software object, with Properties represented as object properties, + Actions as methods, and Events as + events. In addition, metadata is stored in special + properties. Consuming and exposing is done with factory + methods that produce a software object that directly + represents a remote Thing and its + interactions. One such implementation is the Arena Web + Hub project.
+In the next example, a Thing that
+ represents interactions with a lock would look like the
+ following: the status property and the
+ open()
method are directly exposed on the
+ object.
let lock = await WoT.consume(‘https://td.my.com/lock-00123’);
+console.log(lock.status);
+lock.open('withThisKey');
+ Since the direct mapping of Things to software + objects have had some challenges, this specification takes + another approach that exposes software objects to represent + the Thing metadata as data property + and the WoT interactions as methods. One implementation is + node-wot + in the the Eclipse + ThingWeb project, which is the current reference + implementation of the API specified in this document.
+The same example now would look like the following: the
+ status property and the open()
+ method are represented indirectly.
let res = await fetch(‘https://td.my.com/lock-00123’);
+let td = await res.json();
+let lock = new ConsumedThing(td);
+console.log(lock.readProperty(‘status’));
+lock.invokeAction(‘open’, 'withThisKey');
+ In conclusion, the WoT WG decided to explore the third + option that closely follows the [WOT-TD] specification. + Based on this, a simple API can also be implemented. Since + Scripting is an optional module in WoT, this leaves room for + applications that only use the WoT network interface. + Therefore all three approaches above are supported by + [WOT-TD].
+Moreover, the WoT network interface can be implemented in + many languages and runtimes. Consider this API an example for + what needs to be taken into consideration when designing a + Scripting API for WoT.
+The fetch(url)
method has been part of this
+ API in earlier versions. However, now fetching a TD
+ given a URL should be done with an external method, such as
+ the Fetch
+ API or a HTTP client library, which offer already
+ standardized options on specifying fetch details. The reason
+ is that while simple fetch operations (covering most use
+ cases) could be done in this API, when various fetch options
+ were needed, there was no point in duplicating existing work
+ to re-expose those options in this API.
Since fetching a TD has been scoped out, and TD + validation is defined externally in [WOT-TD], that is scoped + out, too. This specification expects a TD as parsed + JSON object that has been validated according to the + [WOT-TD] specification.
+The factory methods for consuming and exposing Things are asynchronous and fully validate the
+ input TD. In addition, one can also construct ConsumedThing
and ExposedThing
by providing a parsed and
+ validated TD. Platform initialization is then
+ done when needed during the WoT interactions. So applications
+ that prefer validating a TD themselves, may use
+ the constructors, whereas applications that leave validation
+ to implementations and prefer interactions initialized up
+ front SHOULD use the
+ factory methods on the WoT API object.
Earlier drafts used the Observer + construct, but since it has not become standard, a new design + was needed that was light enough for embedded + implementations. Therefore observing Property changes and handling WoT Events is done with callback registrations.
+This API ended up not using software events at all, for + the following reasons:
+The reason to use function names like
+ readProperty()
,
+ readMultipleProperties()
etc. instead of a
+ generic polymorphic read()
function is that the
+ current names map exactly to the "op"
vocabulary
+ from the Form
+ definition in [WOT-TD].
The following is a list of major changes to the document. + Major versions of this specification are the following:
+fetch()
for fetching a
+ TD (delegated to external API).
+ Observer
and use
+ W3C TAG recommended design patterns.
+ ThingDescription
instead.
+ ConsumedThing
and ExposedThing
.
+ For a complete list of changes, see the github + change log. You can also view the + recently closed issues.
+The following problems are being discussed and need most + attention:
+ExposedThing
(it was present in
+ earlier versions, but removed for complexity and a
+ simpler way to do it.
+ typedef object+ThingDescription
; + +[SecureContext, Exposed=(Window,Worker)] +interfaceWOT
{ + // methods defined in UA conformance classes +}; + +partial interfaceWOT
{ + Promise<ConsumedThing
>consume
(ThingDescription
td); +}; + +partial interfaceWOT
{ + Promise<ExposedThing
>produce
(ThingDescription
td); +}; + +partial interfaceWOT
{ +ThingDiscovery
discover
(optionalThingFilter
filter = null); +}; + +[SecureContext, Exposed=(Window,Worker)] +interfaceConsumedThing
{ +constructor
(ThingDescription
td); + Promise<any
>readProperty
(DOMString
propertyName, + optionalInteractionOptions
options = null); + Promise<PropertyMap
>readAllProperties
(optionalInteractionOptions
options = null); + Promise<PropertyMap
>readMultipleProperties
( + sequence<DOMString
> propertyNames, + optionalInteractionOptions
options = null); + Promise<void>writeProperty
(DOMString
propertyName, +any
value, + optionalInteractionOptions
options = null); + Promise<void>writeMultipleProperties
(PropertyMap
valueMap, + optionalInteractionOptions
options = null); + Promise<any
>invokeAction
(DOMString
actionName, + optionalany
params = null, + optionalInteractionOptions
options = null); + Promise<void>observeProperty
(DOMString
name, +WotListener
listener, + optionalInteractionOptions
options = null); + Promise<void>unobserveProperty
(DOMString
name); + Promise<void>subscribeEvent
(DOMString
name, +WotListener
listener, + optionalInteractionOptions
options = null); + Promise<void>unsubscribeEvent
(DOMString
name); +ThingDescription
getThingDescription
(); +}; +dictionaryInteractionOptions
{ + objecturiVariables
; +}; +typedef objectPropertyMap
; +callbackWotListener
= void(any
data); + +[SecureContext, Exposed=(Window,Worker)] +interfaceExposedThing
:ConsumedThing
{ +ExposedThing
setPropertyReadHandler
(DOMString
name, +PropertyReadHandler
readHandler); +ExposedThing
setPropertyWriteHandler
(DOMString
name, +PropertyWriteHandler
writeHandler); +ExposedThing
setActionHandler
(DOMString
name,ActionHandler
action); + voidemitEvent
(DOMString
name,any
data); + Promise<void>expose
(); + Promise<void>destroy
(); +}; +callbackPropertyReadHandler
= Promise<any
>( + optionalInteractionOptions
options = null); +callbackPropertyWriteHandler
= Promise<void>(any
value, + optionalInteractionOptions
options = null); +callbackActionHandler
= Promise<any
>(any
params, + optionalInteractionOptions
options = null); + +[SecureContext, Exposed=(Window,Worker)] +interfaceThingDiscovery
{ +constructor
(optionalThingFilter
filter = null); + readonly attributeThingFilter
?filter
; + readonly attribute booleanactive
; + readonly attribute booleandone
; + readonly attribute Error?error
; + voidstart
(); + Promise<ThingDescription
>next
(); + voidstop
(); +}; + +typedefDOMString
DiscoveryMethod
; + +dictionaryThingFilter
{ + (DiscoveryMethod
orDOMString
)method
= "any"; + USVString?url
; + USVString?query
; + object?fragment
; +};
Special thanks to former editor Johannes Hund (until August + 2017, when at Siemens AG) and Kazuaki Nimura (until December + 2018) for developing this specification. Also, the editors + would like to thank Dave Raggett, Matthias Kovatsch, Michael + Koster, Elena Reshetova, Michael McCool as well as the other + WoT WG members for their comments, contributions and + guidance.
+
+
+Copyright
+
+©
+2017-2018
+
+2017-2019
+
+
+
+W3C
+
+
+
+®
+
+(
+
+
+MIT
+
+,
+
+
+ERCIM
+
+,
+
+Keio
+,
+
+Beihang
+
+).
+W3C
+
+liability
+,
+
+trademark
+
+and
+
+permissive
+document
+license
+
+rules
+apply.
+
+The
+overall
+
+main
+
+
+Web
+of
+Things
+
+(WoT)
+concepts
+are
+described
+in
+the
+
+WoT
+Architecture
+
+document.
+The
+Web
+of
+Things
+is
+made
+of
+entities
+(
+
+Thing
+
+s)
+that
+can
+describe
+their
+capabilities
+in
+a
+machine-interpretable
+format,
+the
+
+
+Thing
+Description
+
+(TD)
+and
+expose
+these
+capabilities
+through
+the
+
+WoT
+Interface
+,
+that
+is,
+network
+interactions
+modeled
+as
+
+Properties
+
+for
+
+(for
+
+reading
+and
+writing
+values,
+
+values),
+
+Action
+
+s
+to
+
+(to
+
+execute
+remote
+procedures
+with
+or
+without
+return
+values
+
+values)
+
+and
+
+Event
+
+s
+for
+
+(for
+
+signaling
+notifications.
+This
+specification
+describes
+a
+programming
+interface
+representing
+the
+WoT
+Interface
+that
+allows
+scripts
+run
+on
+a
+Thing
+to
+discover
+and
+consume
+(retrieve)
+other
+Thing
+Description
+s
+and
+to
+expose
+Things
+characterized
+by
+WoT
+Interactions
+specified
+by
+a
+script.
+
+notifications).
+
+
+Scripting
+is
+an
+optional
+"convenience"
+building
+block
+in
+WoT
+and
+it
+is
+typically
+used
+in
+gateways
+that
+are
+able
+to
+run
+a
+
+WoT
+Runtime
+
+and
+
+script
+management
+,
+providing
+a
+convenient
+way
+to
+extend
+WoT
+support
+to
+new
+types
+of
+endpoints
+and
+implement
+WoT
+applications
+like
+
+such
+as
+
+
+Thing
+Directory
+.
+
+This +specification +describes +a +programming +interface +representing +the + +WoT +Interface + +that +allows +scripts +to +discover, +operate + +Thing + +s +and +to +expose +locally +defined + +Things + +characterized +by + +WoT +Interactions + +specified +by +a +script. +
+The +specification +deliberately +follows +the + +WoT +Thing +Description +specification + +closely. +It +is +possible +to +implement +simpler +APIs +on +top +of +this +API, +or +implementing +directly +the +WoT +network +facing +interface +(i.e. +the + +WoT +Interface + +). +
+This +specification +is +implemented +at +least +by +the + +Thingweb + +project +also +known +as + +node-wot +, +which +is +considered +the +reference +open +source +implementation +at +the +moment. +Check +its + +source +code +, +including + +examples +. +Other, +closed +source +implementations +have +been +made +by +WG +member +companies +and +tested +against + +node-wot + +in +plug-fests. +
+ +This +section +describes +the +status +of +this +document +at +the +time +of +its +publication. +Other +documents +may +supersede +this +document. +A +list +of +current + +W3C + +publications +and +the +latest +revision +of +this +technical +report +can +be +found +in +the + + +W3C + +technical +reports +index + +at +https://www.w3.org/TR/. + +
++Implementers +need +to +be +aware +that +this +specification +is +considered +unstable. +Vendors +interested +in +implementing +this +specification +before +it +eventually +reaches +the +Candidate +Recommendation +phase +should +subscribe +to +the + +repository + +and +take +part +in +the +discussions. +
++Please +contribute +to +this +draft +using +the + +GitHub +Issue + +feature +of +the + +WoT +Scripting +API + +repository. +For +feedback +on +security +and +privacy +considerations, +please +use +the + +WoT +Security +and +Privacy + +Issues. +
++This +document +was +published +by +the + +Web +of +Things +Working +Group + +as +a +Working +Draft. +This +document +is +intended +to +become +a +W3C +Recommendation. +
+
+Comments
+regarding
+this
+document
+are
+welcome.
+Please
+send
+them
+to
+
+public-wot-wg@w3.org
+
+(
+subscribe
+,
+
+
+archives
+
+).
+
+Changes
+from
+the
+previous
+publication
+can
+be
+found
+in
+Appendix
+A
+.
+A
+diff-marked
+version
+of
+this
+document
+is
+also
+available
+for
+comparison
+purposes.
+
+Publication
+as
+a
+Working
+Draft
+does
+not
+imply
+endorsement
+by
+the
+
+W3C
+
+Membership.
+This
+is
+a
+draft
+document
+and
+may
+be
+updated,
+replaced
+or
+obsoleted
+by
+other
+documents
+at
+any
+time.
+It
+is
+inappropriate
+to
+cite
+this
+document
+as
+other
+than
+work
+in
+progress.
+
+This +document +was +produced +by +a +group +operating +under +the + + +W3C + +Patent +Policy +. + +W3C + +maintains +a + +public +list +of +any +patent +disclosures + +made +in +connection +with +the +deliverables +of +the +group; +that +page +also +includes +instructions +for +disclosing +a +patent. +An +individual +who +has +actual +knowledge +of +a +patent +which +the +individual +believes +contains + +Essential +Claim(s) + +must +disclose +the +information +in +accordance +with + +section +6 +of +the + +W3C + +Patent +Policy +. +
+
+This
+document
+is
+governed
+by
+the
+
+1
+February
+2018
+
+March
+2019
+
+
+W3C
+
+Process
+Document
+.
+
+WoT
+provides
+layered
+interoperability
+based
+on
+how
+
+Thing
+
+s
+are
+modeled:
+as
+being
+
+used:
+
+"consumed"
+and
+"exposed".
+
+"exposed",
+as
+
+defined
+
+in
+[
+
+WOT-ARCHITECTURE
+
+].
+
+
+By
+
+consuming
+a
+TD
+,
+a
+client
+
+Thing
+
+creates
+a
+local
+
+runtime
+resource
+model
+that
+allows
+accessing
+the
+
+Properties
+,
+
+Actions
+
+and
+
+Events
+
+exposed
+by
+the
+server
+
+Thing
+
+exposed
+
+on
+a
+remote
+device.
+
+Exposing
+a
+
+Thing
+
+requires
+
+requires:
+
+Typically
+scripts
+are
+meant
+to
+be
+used
+on
+devices
+able
+to
+provide
+resources
+(with
+a
+WoT
+Interface
+)
+for
+managing
+(installing,
+updating,
+running)
+scripts,
+such
+as
+
+bridges
+or
+gateways
+that
+expose
+and
+control
+simpler
+devices
+as
+WoT
+
+Thing
+
+s.
+
+s
+and
+have
+means
+to
+handle
+(e.g.
+install,
+uninstall,
+update
+etc.)
+and
+run
+scripts.
+
+
+This +specification +does +not +make +assumptions +on +how +the + +WoT +Runtime + +handles +and +runs +scripts, +including +single +or +multiple +tenancy, +script +deployment +and +lifecycle +management. +The +API +already +supports +the +generic +mechanisms +that +make +it +possible +to +implement +script +management, +for +instance +by +exposing +a +manager + +Thing + +whose + +Actions + +(action +handlers) +implement +script +lifecycle +management +operations. +
++ +This +section +is +non-normative. + +
++The +following +scripting +use +cases +are +supported +in +this +specification: +
++As +well +as +sections +marked +as +non-normative, +all +authoring +guidelines, +diagrams, +examples, +and +notes +in +this +specification +are +non-normative. +Everything +else +in +this +specification +is +normative. +
+The
+key
+words
+
+MAY
+,
+MUST
+,
+and
+
+SHOULD
+
+in
+this
+document
+are
+to
+be
+interpreted
+as
+described
+in
+
+BCP
+14
+
+[
+
+
+RFC2119
+
+
+]
+[
+
+Editor's
+note
+
+
+RFC8174
+
+The
+algorithms
+for
+the
+WoT
+methods
+will
+be
+specified
+later,
+including
+error
+handling
+
+
+]
+when,
+
+and
+security
+considerations.
+
+only
+when,
+they
+appear
+in
+all
+capitals,
+as
+shown
+here.
+
+
+The
+ThingModel
+
+This
+specification
+describes
+the
+conformance
+criteria
+for
+the
+following
+classes
+of
+
+user
+agent
+
+
+type
+represents
+either
+
+(
+
+UA
+
+).
+
+Due
+to
+requirements
+of
+small
+embedded
+implementations,
+splitting
+WoT
+client
+and
+server
+interfaces
+was
+needed.
+Then,
+discovery
+is
+
+a
+ThingFragment
+,
+or
+
+distributed
+application,
+but
+typical
+scenarios
+have
+been
+covered
+by
+
+a
+generic
+discovery
+API
+in
+this
+specification.
+This
+resulted
+in
+using
+3
+conformance
+classes
+for
+a
+
+UA
+
+that
+implements
+this
+API,
+one
+for
+client,
+one
+for
+server,
+and
+one
+for
+discovery.
+An
+application
+that
+uses
+this
+API
+can
+introspect
+for
+the
+presence
+of
+the
+
+
+
,ThingDescription
+
+consume()
+
+produce()
+
+
+.
+3.1
+The
+
+and
+
+
+discover()
+
+methods
+on
+the
+
+WoT
+API
+object
+
+in
+order
+to
+determine
+which
+conformance
+class
+the
+
+UA
+
+implements.
+
+Starts
+the
+discovery
+process
+that
+will
+provide
+ThingDescription
+s
+that
+match
+the
+optional
+argument
+filter
+
+Implementations
+
+of
+type
+
+this
+conformance
+class
+
+MUST
+
+implement
+the
+
+
+
+
+
+
+
+ThingFilter
+
+ConsumedThing
+
+.
+Returns
+an
+[
+Observable
+
+](https://github.com/tc39/proposal-observable)
+object
+that
+can
+be
+subscribed
+to
+
+interface
+
+and
+unsubscribed
+from.
+The
+handler
+function
+provided
+to
+
+the
+Observable
+during
+subscription
+will
+receive
+an
+argument
+of
+type
+USVString
+representing
+a
+
+
+
+method
+on
+the
+
+WoT
+API
+object
+
+.
+ThingDescription
+
+consume()
+
+
+Implementations
+of
+this
+conformance
+class
+
+MUST
+
+implement
+
+
+interface
+and
+the
+
+
+
+DiscoveryMethod
+
+ExposedThing
+
+;
+
+
+produce()
+
+method
+on
+the
+
+WoT
+API
+object
+.
+Implementations
+of
+this
+conformance
+class
+
+MUST
+
+implement
+the
+
+
+
+interface
+and
+
+the
+
+
+
+DiscoveryMethod
+
+ThingDiscovery
+
+represents
+
+discovery
+type
+to
+
+
+discover()
+
+method
+on
+the
+
+WoT
+API
+object
+.
+These
+conformance
+classes
+
+MAY
+
+be
+used:
+
+implemented
+in
+a
+single
+
+UA
+.
+
+This
+specification
+can
+be
+used
+for
+implementing
+the
+WoT
+Scripting
+API
+in
+multiple
+programming
+languages.
+The
+interface
+definitions
+are
+specified
+in
+[
+
+"any"
+does
+not
+provide
+any
+restriction
+
+
+WEBIDL
+
+"local"
+for
+discovering
+Thing
+
+
+].
+
+The
+
+UA
+
+
+s
+defined
+
+may
+be
+implemented
+
+in
+the
+same
+device
+
+browser,
+
+or
+connected
+to
+the
+device
+by
+wired
+
+in
+a
+separate
+runtime
+environment,
+such
+as
+
+Node.js
+
+or
+wireless
+means.
+"directory"
+for
+discovery
+based
+on
+
+in
+small
+embedded
+runtimes.
+
+Implementations
+that
+use
+ECMAScript
+executed
+in
+
+a
+service
+provided
+by
+
+browser
+to
+implement
+the
+APIs
+defined
+in
+this
+document
+
+MUST
+
+implement
+them
+in
+
+a
+Thing
+Directory
+.
+
+manner
+consistent
+with
+the
+ECMAScript
+Bindings
+defined
+in
+the
+Web
+IDL
+specification
+[
+
+"multicast"
+for
+discovering
+Thing
+
+
+WEBIDL
+
+
+s
+
+
+].
+
+Implementations
+that
+use
+TypeScript
+or
+ECMAScript
+
+in
+a
+runtime
+to
+implement
+
+the
+device's
+network
+by
+using
+
+APIs
+defined
+in
+this
+document
+
+MUST
+
+implement
+them
+in
+
+a
+supported
+multicast
+protocol.
+
+manner
+consistent
+with
+the
+TypeScript
+Bindings
+defined
+in
+the
+TypeScript
+specification
+[
+
+TYPESCRIPT
+
+].
+
+ThingFilter
+
+ThingDescription
+
+
+
+"idl-def-thingdescription" data-title=
+"ThingDescription">typedef object
+
+
+ThingFilter
+
+ThingDescription
+
+
+
+dictionary
+that
+represents
+the
+constraints
+for
+discovering
+Thing
+s
+as
+key-value
+pairs.
+<span class="idlDictionary" id=
+"idl-def-thingfilter" data-idl="" data-title=
+"ThingFilter">dictionary <span class=
+"idlDictionaryID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-thingfilter" class="internalDFN" data-link-type=
+"dfn"> {<span class="idlMember"
+id="idl-def-thingfilter-method" data-idl="" data-title="method"
+data-dfn-for="thingfilter">
+ (<a data-link-for="" href="#dom-discoverymethod" class=
+"internalDFN" data-link-type=
+"dfn"> or <a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<a data-no-default=""
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-method" class="internalDFN" data-link-type=
+"dfn"> = <span class=
+"idlMemberValue">"any"<span class="idlMember" id=
+"idl-def-thingfilter-url" data-idl="" data-title="url"
+data-dfn-for="thingfilter">
+ <a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+data-link-for="thingfilter" data-lt="" href="#dom-thingfilter-url"
+class="internalDFN" data-link-type=
+"dfn"><span class="idlMember"
+id="idl-def-thingfilter-query" data-idl="" data-title="query"
+data-dfn-for="thingfilter">
+ <a href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString<a data-no-default=""
+data-link-for="thingfilter" data-lt="" href=
+"#dom-thingfilter-query" class="internalDFN" data-link-type=
+"dfn"><span class="idlMember"
+id="idl-def-thingfilter-fragment" data-idl="" data-title="fragment"
+data-dfn-for="thingfilter">
+ <a data-link-for="" href="#dom-thingfragment" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMemberName"><a data-no-default="" data-link-for="thingfilter"
+data-lt="" href="#dom-thingfilter-fragment" class="internalDFN"
+data-link-type="dfn">
+};
+
+;
+
+
+
+
+The
+method
+property
+represents
+the
+discovery
+type
+that
+should
+be
+used
+in
+the
+discovery
+process.
+The
+possible
+values
+are
+
+Represents
+a
+
+Thing
+Description
+
+(
+
+TD
+
+)
+as
+
+defined
+by
+the
+DiscoveryMethod
+
+in
+[
+
+
+WOT-TD
+
+
+enumeration
+that
+MAY
+
+
+].
+It
+is
+expected
+to
+
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+The
+url
+property
+represents
+additional
+information
+for
+the
+discovery
+method,
+such
+as
+the
+URL
+of
+the
+target
+entity
+serving
+the
+discovery
+request,
+for
+instance
+
+a
+Thing
+Directory
+
+
+parsed
+JSON
+object
+
+
+(if
+method
+
+that
+
+is
+"directory"
+)
+or
+
+validated
+using
+
+JSON
+schema
+validation
+.
+Fetching
+
+a
+query
+string
+accepted
+by
+the
+implementation,
+for
+instance
+
+
+TD
+
+given
+
+a
+SPARQL
+or
+JSON
+query.
+Support
+may
+
+URL
+should
+
+be
+implemented
+locally
+in
+
+done
+with
+an
+external
+method,
+such
+as
+
+the
+WoT
+Runtime
+
+
+Fetch
+API
+
+
+or
+remotely
+as
+
+a
+service
+in
+
+HTTP
+client
+library,
+which
+offer
+already
+standardized
+options
+on
+specifying
+fetch
+details.
+
"hljs-keyword">try {
+ let res =
+"hljs-keyword">await fetch('https://tds.mythings.biz/sensor11');
+
+"hljs-comment">// ... additional checks possible on res.headers
+ let td =
+"hljs-keyword">await res.json();
+ let thing =
+"hljs-keyword">new ConsumedThing(td);
+ console.log(
+"hljs-string">"Thing name: " + thing.getThingDescription().title);
+} catch (err) {
+ console.log(
+"hljs-string">"Fetching TD failed", err.message);
+}
+
+
+property
+represents
+
+
+
+Note
+that
+[
+
+WOT-TD
+
+
+dictionary
+used
+for
+matching
+property
+by
+property
+against
+discovered
+
+
+]
+allows
+using
+a
+shortened
+
+Thing
+Description
+
+
+s.
+
+by
+the
+means
+of
+
+defaults
+
+and
+requiring
+clients
+to
+expand
+them
+with
+default
+values
+specified
+in
+[
+
+WOT-TD
+
+]
+for
+the
+properties
+that
+are
+not
+explicitly
+defined
+in
+a
+given
+
+TD
+.
+
+The
+discover(filter)
+method
+MUST
+
+To
+
+expand
+a
+TD
+
+given
+
+td
+,
+run
+the
+following
+steps:
+
+The
+[
+
+
+WOT-TD
+
+
+obs
+and
+execute
+
+
+]
+specification
+defines
+how
+a
+
+TD
+
+should
+be
+validated.
+Therefore,
+this
+API
+expects
+
+the
+next
+steps
+in
+parallel
+.
+If
+
+
+
+
+obs.subscribe(handler,
+errorHandler,
+complete)
+
+ThingDescription
+
+is
+called,
+execute
+
+
+objects
+be
+validated
+before
+used
+as
+parameters.
+This
+specification
+defines
+a
+basic
+
+TD
+
+validation
+as
+follows.
+
+To
+
+validate
+a
+TD
+
+given
+
+td
+,
+run
+
+the
+following
+sub-steps:
+
+steps:
+
+TypeError
+
+"TypeError"
+
+
+and
+terminate
+
+TypeError
+
+"TypeError"
+
+
+and
+terminate
+these
+steps.
+
+TypeError
+
+"TypeError"
+
+
+and
+terminate
+these
+steps.
+
+Defines
+
+the
+discovery
+process.
+If
+queries
+are
+not
+supported,
+implementations
+SHOULD
+throw
+
+API
+entry
+point
+exposed
+as
+
+a
+NotSupported
+error
+and
+terminate
+these
+steps.
+If
+filter.fragment
+is
+defined,
+
+singleton
+
+and
+if
+it
+
+contains
+other
+properties
+than
+
+the
+ones
+defined
+in
+
+API
+methods.
+
+ThingFragment
+
+WOT
+
+
+
+"idl-def-wot" data-title="WOT">[SecureContext, Exposed=(Window,Worker)]
+interface WOT
{
+ // methods defined in UA conformance classes
+
+};
+
+Browser
+implementations
+should
+use
+a
+namespace
+object
+such
+as
+
+
+
.
+Standalone
+runtimes
+may
+expose
+
+the
+API
+
+object
+TypeError
+and
+terminate
+these
+steps.
+Otherwise
+save
+
+navigator.wot
+for
+matching
+the
+discovered
+items
+against
+it.
+Request
+the
+underlying
+platform
+to
+start
+the
+discovery
+process,
+with
+the
+following
+parameters:
+If
+filter.method
+is
+not
+defined
+
+through
+mechanisms
+like
+
+require()
+
+or
+the
+value
+is
+
+
+import
+.
+"any"
+,
+use
+the
+widest
+discovery
+
+consume()
+
+method
+"idl-def-wot-partial-1" data-title=
+"WOT">partial interface WOT
{
+
+"interface" href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<ConsumedThing
> consume
(ThingDescription
td);
+};
+
+Belongs
+to
+
+the
+underlying
+platform.
+Otherwise
+if
+
+
+WoT
+Consumer
+
+conformance
+class.
+Expects
+an
+
+
+filter.method
+
+td
+
+
+is
+"local"
+,
+use
+the
+local
+Thing
+Directory
+
+argument
+and
+returns
+a
+
+Promise
+
+
+for
+discovery.
+Usually
+
+that
+defines
+Thing
+s
+deployed
+in
+the
+same
+device,
+or
+connected
+to
+the
+device
+in
+slave
+mode
+(e.g.
+sensors
+connected
+via
+Bluetooth
+or
+
+resolves
+with
+
+a
+serial
+connection).
+Otherwise
+if
+filter.method
+is
+
+
+
+
+
+"directory"
+,
+use
+the
+remote
+Thing
+Directory
+
+ConsumedThing
+specified
+in
+filter.url
+.
+Otherwise
+if
+filter.method
+is
+"multicast"
+,
+use
+all
+the
+multicast
+discovery
+protocols
+supported
+by
+the
+underlying
+platform.
+Whenever
+
+object
+that
+represents
+
+a
+new
+item
+td
+is
+discovered
+by
+
+client
+interface
+to
+operate
+with
+
+the
+underlying
+platform,
+
+
+Thing
+.
+The
+method
+
+MUST
+
+run
+the
+following
+sub-steps:
+
+steps:
+
+false
+
+SecurityError
+
+
+
+UnknownError
+
+ConsumedThing
+
+
+
+fetch()
+
+produce()
+
+
+
+method
+
+
+"idl-def-wot-partial-2" data-title=
+"WOT">partial interface WOT
{
+
+"interface" href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<ExposedThing
> produce
(ThingDescription
td);
+};
+
+Accepts
+an
+url
+argument
+of
+type
+USVString
+that
+represents
+
+Belongs
+to
+the
+
+WoT
+Producer
+
+conformance
+class.
+Expects
+
+a
+URL
+(e.g.
+"file://..."
+or
+
+
+
+"https://..."
+
+td
+
+)
+
+argument
+
+and
+returns
+a
+
+Promise
+
+that
+resolves
+with
+a
+
+an
+
+
+
+
+ThingDescription
+
+ExposedThing
+
+(a
+serialized
+JSON-LD
+document
+of
+type
+
+object
+that
+extends
+
+
+
+USVString
+
+ConsumedThing
+
+).
+
+
+with
+a
+server
+interface,
+i.e.
+the
+ability
+to
+define
+request
+handlers.
+
+The
+fetch(url)
+
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+ExposedThing
+
+object
+constructed
+with
+
+td
+.
+TypeError
+
+discover()
+
+
+
+"idl-def-wot-partial-3" data-title=
+"WOT">partial interface WOT
{
+
+"internalDFN" data-link-type=
+"idl">ThingDiscovery
discover
(optional ThingFilter
filter = null);
+};
+
+Belongs
+
+to
+fetch
+the
+content
+of
+url
+as
+described
+by
+
+the
+Protocol
+Bindings
+
+
+WoT
+Discovery
+
+
+and
+wait
+for
+the
+reply.
+Implementations
+encapsulate
+
+conformance
+class.
+Starts
+
+the
+fetching
+
+discovery
+
+process
+and
+the
+accepted
+media
+types
+(such
+as
+
+that
+will
+provide
+
+
+
+application/td+json
+
+ThingDescription
+
+),
+as
+far
+as
+a
+valid
+
+
+objects
+for
+
+
+Thing
+Description
+
+can
+be
+obtained
+as
+defined
+in
+[
+WOT-TD
+].
+Let
+
+s
+that
+match
+an
+optional
+
+
+td
+
+filter
+
+
+be
+the
+Thing
+Description
+string-serialized
+from
+the
+returned
+content,
+as
+specified
+in
+
+argument.
+The
+method
+
+MUST
+
+run
+
+the
+Thing
+Description
+serialization
+.
+
+following
+steps:
+
+error.message
+
+SecurityError
+
+
+
+ThingDiscovery
+
+object
+
+
+
+Refer
+to
+the
+
+ThingDiscovery
+
+section
+for
+how
+discovery
+should
+be
+implemented.
+
+consume()
+
+ConsumedThing
+
+
+
+
+Accepts
+an
+
+Represents
+a
+client
+API
+to
+operate
+a
+
+Thing
+.
+Belongs
+to
+the
+
+WoT
+Consumer
+
+conformance
+class.
+
+"idl-def-consumedthing" data-title="ConsumedThing">[SecureContext, Exposed=(Window,Worker)] +interface+ConsumedThing
{ + +"dom-consumedthing-constructor" data-idl="constructor" data-title= +"constructor" data-dfn-for="ConsumedThing" data-lt= +"ConsumedThing.constructor()|ConsumedThing.constructor|constructor()|constructor">constructor
(ThingDescription
td); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<any
>readProperty
(DOMString
propertyName, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<PropertyMap
>readAllProperties
(optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<PropertyMap
>readMultipleProperties
( + +"" data-type="dfn" href= +"https://heycam.github.io/webidl/#idl-sequence">sequence<DOMString
> propertyNames, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>writeProperty
(DOMString
propertyName, + +data-link-type="dfn" href= +"https://heycam.github.io/webidl/#idl-any">any
value, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>writeMultipleProperties
(PropertyMap
valueMap, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<any
>invokeAction
(DOMString
actionName, + optionalany
params = null, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>observeProperty
(DOMString
name, + +"#dom-wotlistener" class="internalDFN" data-link-type= +"idl">WotListener
listener, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unobserveProperty
(DOMString
name); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>subscribeEvent
(DOMString
name, + +"#dom-wotlistener" class="internalDFN" data-link-type= +"idl">WotListener
listener, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unsubscribeEvent
(DOMString
name); + +"internalDFN" data-link-type= +"idl">ThingDescription
getThingDescription
(); +}; +dictionaryInteractionOptions
{ + +"interface" href= +"https://heycam.github.io/webidl/#idl-object">objecturiVariables
; +}; +typedef objectPropertyMap
; +callbackWotListener
= void( + ++
+td ++any + +argument +of +type ++ + + +data + +); + +
+ThingDescription
+
+ConsumedThing
+
+
+
+
+
+After
+
+fetching
+
+a
+
+Thing
+Description
+
+as
+a
+JSON
+object,
+one
+can
+create
+a
+
+
+ConsumedThing
+
+
+object
+instantiated
+based
+on
+parsing
+that
+description.
+
+object.
+
+
+The
+
+To
+create
+
+
+
+consume(td)
+
+ConsumedThing
+
+method
+must
+
+
+with
+the
+
+ThingDescription
+
+td
+,
+run
+the
+following
+steps:
+
+ConsumedThing
+
+
+
+Observable
+
+getThingDescription()
+
+
+
+Returns
+
+the
+read()
+and
+write()
+methods
+to
+
+internal
+slot
+|
+
+td
+
+|
+of
+
+the
+
+
+
+
+ThingProperty
+
+ConsumedThing
+
+elements
+so
+
+object
+
+that
+they
+make
+requests
+to
+access
+
+represents
+
+the
+remote
+
+
+Thing
+Description
+
+
+s
+and
+wait
+for
+the
+reply,
+as
+defined
+by
+
+of
+
+the
+Protocol
+Bindings
+.
+Also,
+all
+
+
+
+
+.
+Applications
+may
+consult
+the
+
+Thing
+
+
+ThingProperty
+
+ConsumedThing
+
+elements
+SHOULD
+implement
+
+metadata
+stored
+in
+|
+
+td
+
+|
+in
+order
+to
+introspect
+its
+capabilities
+before
+interacting
+with
+it.
+
+subscribe()
+
+InteractionOptions
+
+
+
+Holds
+the
+interaction
+options
+
+that
+should
+make
+request
+
+need
+to
+be
+exposed
+for
+application
+scripts
+according
+
+to
+observe
+the
+given
+Properties
+as
+defined
+by
+
+the
+Protocol
+Bindings
+
+
+Thing
+Description
+
+.
+Add
+
+In
+this
+version
+of
+
+the
+invoke()
+methods
+to
+
+specification
+only
+URI
+template
+variables
+are
+used,
+represented
+as
+
+parsed
+JSON
+objects
+
+defined
+in
+[
+
+WOT-TD
+
+].
+
+The
+support
+for
+URI
+variables
+comes
+from
+
+the
+need
+exposed
+by
+[
+
+ThingAction
+
+
+WOT-TD
+
+
+]
+to
+be
+able
+to
+describe
+existing
+
+TD
+
+
+elements
+so
+
+s
+
+that
+they
+make
+requests
+
+use
+them,
+but
+it
+should
+be
+possible
+
+to
+the
+remote
+
+write
+a
+
+Thing
+Description
+
+
+to
+invoke
+its
+actions,
+as
+defined
+by
+
+that
+would
+use
+
+Action
+
+s
+for
+representing
+
+the
+Protocol
+Bindings
+.
+Add
+
+interactions
+that
+need
+URI
+variables
+and
+represent
+
+the
+subscribe()
+method
+
+URI
+variables
+as
+parameters
+
+to
+all
+ThingEvent
+
+the
+
+Action
+
+
+elements
+so
+
+and
+in
+
+that
+they
+make
+requests
+to
+subscribe
+to
+the
+events
+defined
+
+case
+that
+could
+be
+encapsulated
+
+by
+the
+remote
+Thing
+,
+as
+defined
+by
+
+implementations
+and
+
+the
+Protocol
+Bindings
+.
+Return
+
+
+thing
+.
+
+options
+
+parameter
+could
+be
+dismissed
+from
+the
+methods
+exposed
+by
+this
+API.
+
+produce()
+
+PropertyMap
+
+
+
+
+Accepts
+
+Represents
+
+a
+model
+argument
+
+map
+
+of
+type
+
+
+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.
+
+It
+could
+be
+defined
+in
+Web
+IDL
+(as
+well
+as
+
+
+
+
+)
+as
+a
+
+maplike
+
+interface
+from
+
+string
+
+to
+
+any
+.ThingModel
+
+ThingDescription
+
+
+readProperty()
+
+
+
+method
+
+Reads
+a
+
+Property
+
+value.
+Takes
+a
+string
+argument
+
+propertyName
+
+and
+
+and
+returns
+
+an
+optional
+
+
+
+
+ExposedThing
+
+InteractionOptions
+
+object.
+The
+
+
+options
+
+argument.
+It
+returns
+a
+
+Property
+
+value
+represented
+as
+
+
+
+type.
+The
+
+method
+
+MUST
+
+run
+the
+following
+steps:
+produce(model)
+
+any
+
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+this.getThingDescription().properties[
+
+propertyName
+
+]
+
.
+TypeError
+
+SyntaxError
+
,
+otherwise
+return
+
+value
+.
+SyntaxError
+
+
+and
+terminate
+these
+steps.
+
+ThingFragment
+
+readMultipleProperties()
+
+
+
+method
+
+
+
+Reads
+multiple
+
+Property
+
+values
+
+with
+one
+or
+multiple
+requests.
+Takes
+the
+
+propertyNames
+
+argument
+as
+
+a
+default
+value,
+add
+that
+property
+
+sequence
+of
+strings
+
+and
+value
+to
+model
+.
+Create
+
+an
+optional
+
+
+
+
+ExposedThing
+
+InteractionOptions
+
+object
+
+
+thing
+
+options
+
+
+initialized
+
+argument.
+It
+returns
+an
+object
+with
+keys
+
+from
+
+model
+.
+
+propertyNames
+
+and
+values
+returned
+by
+this
+algorithm.
+The
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+ExposedThing
+
+SecurityError
+
+
+
+ThingFragment
+,
+initialize
+
+null
+
.
+SecurityScheme
+
+NotSupportedError
+
+
+
+properties
+
+SyntaxError
+
+
+
+ThingProperty
+
+readAllProperties()
+
+
+
+method
+
+
+
+Reads
+all
+properties
+of
+
+the
+
+Thing
+
+with
+one
+or
+multiple
+requests.
+Takes
+an
+optional
+
+
+
+read()
+and
+write()
+
+InteractionOptions
+
+methods
+are
+provided
+to
+define
+local
+methods
+to
+get
+and
+set
+the
+
+
+
+options
+
+argument.
+It
+returns
+an
+object
+with
+keys
+from
+
+
+Property
+
+values,
+
+names
+and
+values
+returned
+by
+this
+algorithm.
+The
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+actions
+
+SecurityError
+
+
+
+invoke()
+method
+is
+provided
+to
+define
+
+null
+
.
+emit()
+
+NotSupportedError
+
+
+
+writeProperty()
+
+
+
+Writes
+a
+single
+
+Property
+.
+Takes
+
+a
+string
+argument
+
+
+td
+as
+
+propertyName
+,
+a
+value
+
+argument
+
+value
+
+and
+runs
+
+an
+optional
+
+InteractionOptions
+
+options
+
+argument.
+It
+returns
+success
+or
+failure.
+The
+method
+
+MUST
+
+run
+
+the
+following
+steps:
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+SyntaxError
+
+and
+terminate
+these
+steps.
+
+register()
+
+writeMultipleProperties()
+
+
+
+method
+
+
+
+Writes
+a
+multiple
+
+Property
+
+values
+with
+one
+request.
+
+Takes
+two
+mandatory
+arguments:
+directory
+denoting
+
+a
+Thing
+Directory
+,
+and
+thing
+denoting
+
+
+properties
+
+argument
+as
+
+an
+ExposedThing
+object.
+Generate
+the
+Thing
+Description
+
+object
+with
+keys
+being
+
+Property
+
+
+names
+and
+values
+
+as
+td
+,
+given
+the
+Properties
+,
+Action
+
+
+Property
+
+
+s
+
+values
+
+and
+Event
+s
+defined
+for
+this
+
+an
+optional
+
+
+
+
+ExposedThing
+
+InteractionOptions
+
+object.
+Then
+make
+a
+request
+to
+register
+
+
+td
+
+options
+
+
+to
+the
+given
+WoT
+Thing
+Directory
+.
+3.6
+
+argument.
+It
+returns
+success
+or
+failure.
+
+The
+unregister()
+
+method
+Takes
+two
+mandatory
+arguments:
+
+
+MUST
+
+run
+the
+following
+steps:
+
+
+thing
+
+SecurityError
+
+
+
+ExposedThing
+
+SyntaxError
+
+
+
+NotSupportedError
+
+and
+terminate
+these
+steps.
+
+ConsumedThing
+
+WotListener
+
+
+
+
+Represents
+an
+object
+
+User
+provided
+callback
+
+that
+extends
+a
+
+takes
+
+
+
+ThingFragment
+
+any
+
+with
+methods
+for
+client
+interactions
+(send
+request
+for
+reading
+and
+writing
+Properties
+),
+invoke
+Action
+s,
+subscribe
+
+argument
+
+and
+unsubscribe
+
+is
+used
+
+for
+observing
+
+
+Property
+
+changes
+and
+handling
+
+Event
+
+s.
+
+notifications.
+Since
+subscribing
+to
+these
+are
+WoT
+interactions,
+they
+are
+not
+modelled
+with
+software
+events.
+
+
+id
+
+observeProperty()
+
+
+
+
+The
+properties
+attribute
+represents
+
+Makes
+
+a
+dictionary
+of
+ThingProperty
+
+request
+for
+
+Property
+
+
+items.
+The
+
+value
+change
+notifications.
+Takes
+a
+string
+argument
+
+propertyName
+,
+a
+
+
+
+PropertyMap
+
+WotListener
+
+interface
+represents
+a
+maplike
+dictionary
+where
+all
+values
+are
+
+
+callback
+function
+
+listener
+
+and
+an
+optional
+
+
+
+
+ThingProperty
+
+InteractionOptions
+
+objects.
+
+
+options
+
+argument.
+It
+returns
+success
+or
+failure.
+
+The
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+read()
+
+SecurityError
+
+
+and
+terminate
+these
+steps.
+
+write()
+
+"TypeError"
+
+
+
+actions
+
+unobserveProperty()
+
+
+
+
+Makes
+
+a
+maplike
+dictionary
+where
+all
+values
+are
+ThingAction
+
+request
+for
+unsubscribing
+from
+
+Property
+
+
+objects.
+
+value
+change
+notifications.
+Takes
+a
+string
+argument
+
+propertyName
+
+and
+returns
+success
+or
+failure.
+
+The
+invoke()
+
+method
+represents
+a
+request
+to
+invoke
+the
+Action
+on
+
+
+MUST
+
+run
+
+the
+remote
+Thing
+.
+
+following
+steps:
+
+
+EventMap
+
+SecurityError
+
+
+
+ExposedThing
+
+invokeAction()
+
+
+
+
+The
+ExposedThing
+interface
+is
+the
+server
+API
+that
+allows
+defining
+
+Makes
+a
+
+request
+handlers,
+properties,
+Actions
+,
+and
+Events
+
+for
+invoking
+an
+
+Action
+
+
+to
+a
+Thing
+.
+It
+also
+implements
+
+and
+return
+
+the
+result.
+Takes
+a
+string
+argument
+
+actionName
+,
+an
+optional
+argument
+
+params
+
+of
+type
+
+
+
+Observable
+
+any
+
+interface.
+An
+
+and
+an
+optional
+
+
+
+
+ExposedThing
+
+InteractionOptions
+
+is
+created
+by
+
+
+options
+
+argument.
+It
+returns
+
+the
+produce()
+method.
+<span class="idlInterface" id=
+"idl-def-exposedthing" data-idl="" data-title=
+"ExposedThing">interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-exposedthing" class="internalDFN" data-link-type=
+"dfn"> : <span class=
+"idlSuperclass"><a href="#dom-thingfragment" class="internalDFN"
+data-link-type=
+"dfn"> {<span class=
+"idlAttribute" id="idl-def-exposedthing-properties" data-idl=""
+data-title="properties" data-dfn-for="exposedthing">
+ readonly attribute <a data-link-for=""
+href="#dom-propertymap" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlAttrName"><a data-no-default="" data-link-for="exposedthing"
+data-lt="exposedthing.properties|properties" href=
+"#dom-exposedthing-properties" class="internalDFN" data-link-type=
+"dfn"><span class=
+"idlAttribute" id="idl-def-exposedthing-actions" data-idl=""
+data-title="actions" data-dfn-for="exposedthing">
+ readonly attribute <a data-link-for=""
+href="#dom-actionmap" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlAttrName"><a data-no-default="" data-link-for="exposedthing"
+data-lt="exposedthing.actions|actions" href=
+"#dom-exposedthing-actions" class="internalDFN" data-link-type=
+"dfn"><span class=
+"idlAttribute" id="idl-def-exposedthing-events" data-idl=""
+data-title="events" data-dfn-for="exposedthing">
+ readonly attribute <a data-link-for=""
+href="#dom-exposedevents" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlAttrName"><a data-no-default="" data-link-for="exposedthing"
+data-lt="exposedthing.events|events" href=
+"#dom-exposedthing-events" class="internalDFN" data-link-type=
+"dfn"><span class="idlMethod"
+id="idl-def-exposedthing--name" data-idl="" data-title=""
+data-dfn-for="exposedthing">
+ // getter for ThingFragment properties
+ <a href=
+"https://heycam.github.io/webidl/#idl-any">any<span class="idlMethod"
+id="idl-def-exposedthing--name-value" data-idl="" data-title=""
+data-dfn-for="exposedthing">
+ // setter for ThingFragment properties
+ (<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<span class="idlMethod"
+id="idl-def-exposedthing-expose" data-idl="" data-title="expose"
+data-dfn-for="exposedthing"><span class=
+"idlSectionComment">
+ // methods to expose and destroy the Thing
+ <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default=""
+data-link-for="exposedthing" data-lt=
+"exposedthing.expose()|exposedthing.expose|expose()|expose" href=
+"#dom-exposedthing-expose" class="internalDFN" data-link-type=
+"dfn"><span class=
+"idlMethod" id="idl-def-exposedthing-destroy" data-idl=""
+data-title="destroy" data-dfn-for="exposedthing"><span class=
+"idlMethType">
+ <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<a data-no-default=""
+data-link-for="exposedthing" data-lt=
+"exposedthing.destroy()|exposedthing.destroy|destroy()|destroy"
+href="#dom-exposedthing-destroy" class="internalDFN"
+data-link-type="dfn"><span class="idlMethod"
+id="idl-def-exposedthing-addproperty-name-property-initvalue"
+data-idl="" data-title="addProperty" data-dfn-for=
+"exposedthing"><span class=
+"idlSectionComment">
+ // define Properties
+ <a data-link-for="" href="#dom-exposedthing" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.addproperty()|exposedthing.addproperty|addproperty()|addproperty"
+href="#dom-exposedthing-addproperty" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-propertyfragment" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">property,<span class=
+"idlParam"> optional <a href=
+"https://heycam.github.io/webidl/#idl-any">any<span class="idlMethod"
+id="idl-def-exposedthing-setpropertyreadhandler-name-readhandler"
+data-idl="" data-title="setPropertyReadHandler" data-dfn-for=
+"exposedthing">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.setpropertyreadhandler()|exposedthing.setpropertyreadhandler|setpropertyreadhandler()|setpropertyreadhandler"
+href="#dom-exposedthing-setpropertyreadhandler" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-propertyreadhandler" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">readHandler<span class=
+"idlMethod" id=
+"idl-def-exposedthing-setpropertywritehandler-name-writehandler"
+data-idl="" data-title="setPropertyWriteHandler" data-dfn-for=
+"exposedthing">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.setpropertywritehandler()|exposedthing.setpropertywritehandler|setpropertywritehandler()|setpropertywritehandler"
+href="#dom-exposedthing-setpropertywritehandler" class=
+"internalDFN" data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-propertywritehandler" class="internalDFN"
+data-link-type="dfn"><span class="idlMethod"
+id="idl-def-exposedthing-removeproperty-name" data-idl=""
+data-title="removeProperty" data-dfn-for=
+"exposedthing">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.removeproperty()|exposedthing.removeproperty|removeproperty()|removeproperty"
+href="#dom-exposedthing-removeproperty" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<span class="idlMethod"
+id="idl-def-exposedthing-addaction-name-init-action" data-idl=""
+data-title="addAction" data-dfn-for="exposedthing"><span class=
+"idlMethType">
+ // define Actions
+ <a data-link-for="" href="#dom-exposedthing" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.addaction()|exposedthing.addaction|addaction()|addaction"
+href="#dom-exposedthing-addaction" class="internalDFN"
+data-link-type="dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-actionfragment" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">init,<span class=
+"idlParam"> <a data-link-for="" href=
+"#dom-actionhandler" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">action<span class="idlMethod"
+id="idl-def-exposedthing-removeaction-name" data-idl="" data-title=
+"removeAction" data-dfn-for="exposedthing"><span class=
+"idlMethType">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.removeaction()|exposedthing.removeaction|removeaction()|removeaction"
+href="#dom-exposedthing-removeaction" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString<span class="idlMethod"
+id="idl-def-exposedthing-setactionhandler-name-action" data-idl=""
+data-title="setActionHandler" data-dfn-for=
+"exposedthing">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.setactionhandler()|exposedthing.setactionhandler|setactionhandler()|setactionhandler"
+href="#dom-exposedthing-setactionhandler" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-actionhandler" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">action<span class="idlMethod"
+id="idl-def-exposedthing-addevent-name-event" data-idl=""
+data-title="addEvent" data-dfn-for="exposedthing"><span class=
+"idlMethType">
+ // define Events
+ <a data-link-for="" href="#dom-exposedthing" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.addevent()|exposedthing.addevent|addevent()|addevent"
+href="#dom-exposedthing-addevent" class="internalDFN"
+data-link-type="dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString <a data-link-for=""
+href="#dom-eventfragment" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">event<span class="idlMethod"
+id="idl-def-exposedthing-removeevent-name" data-idl="" data-title=
+"removeEvent" data-dfn-for="exposedthing"><span class=
+"idlMethType">
+ <a data-link-for="" href="#dom-exposedthing" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="exposedthing"
+data-lt=
+"exposedthing.removeevent()|exposedthing.removeevent|removeevent()|removeevent"
+href="#dom-exposedthing-removeevent" class="internalDFN"
+data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString
+};<span class="idlInterface" id="idl-def-exposedevents"
+data-idl="" data-title="ExposedEvents">
+[<a href=
+"https://heycam.github.io/webidl/#NoInterfaceObject">NoInterfaceObject]
+interface <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-exposedevents" class=
+"internalDFN" data-link-type=
+"dfn"> {<span class=
+"idlMaplike" id="idl-def-exposedevents-maplike" data-idl=""
+data-title="iterable" data-dfn-for="exposedevents">
+ maplike<<a href=
+"https://heycam.github.io/webidl/#idl-DOMString">DOMString, <a data-link-for=""
+href="#dom-exposedevent" class="internalDFN" data-link-type=
+"dfn">
+};<span class="idlCallback" id="idl-def-propertyreadhandler"
+data-idl="" data-title="PropertyReadHandler">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-propertyreadhandler" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType"> <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<span class="idlCallback"
+id="idl-def-propertywritehandler" data-idl="" data-title=
+"PropertyWriteHandler">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-propertywritehandler" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType"> <a href=
+"https://heycam.github.io/webidl/#idl-promise">Promise<span class="idlCallback"
+id="idl-def-actionhandler" data-idl="" data-title="ActionHandler">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-actionhandler" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType"> <a href=
+"https://heycam.github.io/webidl/#idl-promise">
+Promise
+<
+<a
+href="https://heycam.github.io/webidl/#idl-any">
+any
+>
+(
+any
+
+result
+of
+the
+
+Action
+
+
+parameters
+);
+
+or
+an
+error.
+
+The
+properties
+attribute
+represents
+
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+read()
+
+SecurityError
+
+
+and
+
+ExposedEvent
+
+SyntaxError
+
+
+and
+terminate
+these
+steps.
+
+expose()
+
+subscribeEvent()
+
+
+
+method
+
+
+
+Start
+serving
+external
+requests
+
+Makes
+a
+request
+
+for
+the
+Thing
+,
+so
+that
+WoT
+Interactions
+
+subscribing
+to
+
+Event
+
+
+using
+Properties
+,
+Action
+
+notifications.
+Takes
+a
+string
+argument
+
+eventName
+,
+a
+
+WotListener
+
+
+s
+
+callback
+function
+
+listener
+
+and
+Event
+s
+will
+be
+possible.
+The
+
+an
+optional
+
+
+
+
+
+options
+
+argument.
+It
+returns
+success
+or
+failure.
+The
+
+method
+
+MUST
+
+run
+the
+following
+steps:
+expose()
+
+InteractionOptions
+
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+"TypeError"
+
+and
+terminate
+these
+steps.
+
+destroy()
+
+unsubscribeEvent()
+
+
+
+method
+
+
+
+Stop
+serving
+external
+requests
+
+Makes
+a
+request
+
+for
+the
+Thing
+
+unsubscribing
+from
+
+Event
+
+
+notifications.
+Takes
+a
+string
+argument
+
+eventName
+
+and
+destroy
+the
+object.
+Note
+that
+eventual
+unregistering
+should
+be
+done
+before
+invoking
+this
+method.
+
+returns
+success
+or
+failure.
+
+The
+destroy()
+
+method
+
+MUST
+
+run
+the
+following
+steps:
+
+SecurityError
+
+and
+terminate
+these
+steps.
+
+Adds
+
+The
+next
+example
+illustrates
+how
+to
+fetch
+
+a
+Property
+
+
+TD
+
+
+with
+name
+defined
+by
+the
+name
+argument,
+the
+data
+schema
+provided
+
+by
+the
+property
+argument
+of
+type
+
+URL,
+create
+a
+
+
+
+,
+PropertyFragment
+
+ConsumedThing
+
+and
+optionally
+an
+initial
+value
+provided
+in
+the
+argument
+initValue
+whose
+type
+should
+match
+the
+one
+defined
+in
+the
+type
+
+read
+metadata
+(title),
+read
+
+property
+according
+
+value,
+subscribe
+
+to
+the
+value-matching
+algorithm
+.
+If
+initValue
+is
+not
+provided,
+it
+SHOULD
+be
+initialized
+as
+undefined
+.
+Implementations
+SHOULD
+update
+the
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+
+property
+change,
+subscribe
+
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+a
+WoT
+event,
+unsubscribe.
+
+
+"hljs-keyword">try {
+ let res =
+"hljs-keyword">await fetch("https://tds.mythings.org/sensor11");
+ let td = res.json(); let thing =
+"hljs-keyword">new ConsumedThing(td);
+ console.log(
+"hljs-string">"Thing " + thing.getThingDescription().title + " consumed.");
+} catch(e) {
+ console.log(
+"hljs-string">"TD fetch error: " + e.message); },
+};
+try {
+"hljs-comment">// subscribe to property change for “temperature”
+
+"hljs-keyword">await thing.observeProperty("temperature", value => {
+ console.log(
+"hljs-string">"Temperature changed to: " + value);
+ });
+
+"hljs-comment">// subscribe to the “ready” event defined in the TD
+
+"hljs-keyword">await thing.subscribeEvent("ready", eventData => {
+ console.log(
+"hljs-string">"Ready; index: " + eventData);
+
+"hljs-comment">// run the “startMeasurement” action defined by TD
+
+"hljs-keyword">await thing.invokeAction("startMeasurement", { units: "Celsius" });
+ console.log(
+"hljs-string">"Measurement started.");
+ });
+} catch(e) {
+ console.log(
+"hljs-string">"Error starting measurement.");
+}
+setTimeout( () => {
+
+"hljs-built_in">console.log(“Temperature: “ + await thing.readProperty(“temperature”));
+
+"hljs-keyword">await thing.unsubscribe(“ready”);
+ console.log(
+"hljs-string">"Unsubscribed from the ‘ready’ event.");
+},
+
+10000
+
+
+);
+
+removeProperty()
+
+ExposedThing
+
+
+
+
+Removes
+the
+Property
+specified
+by
+the
+
+The
+
+
+
+name
+
+ExposedThing
+
+argument
+and
+updates
+
+
+interface
+is
+
+the
+Thing
+Description
+.
+Throws
+on
+error.
+Returns
+a
+reference
+
+server
+API
+
+to
+operate
+
+the
+same
+object
+for
+supporting
+chaining.
+
+
+Thing
+
+that
+allows
+defining
+request
+handlers,
+
+Property
+,
+Action
+,
+and
+
+Event
+
+interactions.
+
+
"idl-def-exposedthing" data-title="ExposedThing">[SecureContext, Exposed=(Window,Worker)] +interfaceExposedThing
:ConsumedThing
{ + +"internalDFN" data-link-type= +"idl">ExposedThing
setPropertyReadHandler
(DOMString
name, + +class="internalDFN" data-link-type= +"idl">PropertyReadHandler
readHandler); + +"internalDFN" data-link-type= +"idl">ExposedThing
setPropertyWriteHandler
(DOMString
name, + +"#dom-propertywritehandler" class="internalDFN" data-link-type= +"idl">PropertyWriteHandler
writeHandler); + +"internalDFN" data-link-type= +"idl">ExposedThing
setActionHandler
(DOMString
name,ActionHandler
action); + +href= +"https://heycam.github.io/webidl/#idl-void">voidemitEvent
(DOMString
name,any
data); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>expose
(); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>destroy
(); +}; +callbackPropertyReadHandler
= Promise<any
>( + optionalInteractionOptions
options = null); +callbackPropertyWriteHandler
= Promise<void>(any
value, + optionalInteractionOptions
options = null); +callbackActionHandler
= Promise<any
>(any
params, + optionalInteractionOptions
+options + + +The ++= +null); +
+addAction()
+
+ExposedThing
+
+
+
+Adds
+to
+the
+
+The
+
+
+
+actions
+
+ExposedThing
+
+property
+of
+
+interface
+extends
+
+ConsumedThing
+
.
+It
+is
+constructed
+from
+
+a
+Thing
+
+full
+or
+partial
+
+ThingDescription
+
+
+object
+
+object.
+
+Note
+that
+
+an
+Action
+
+existing
+
+ThingDescription
+
+
+with
+name
+defined
+
+object
+can
+be
+optionally
+modified
+(for
+instance
+
+by
+the
+
+adding
+or
+removing
+elements
+on
+its
+
+
+name
+
+properties
+,
+actions
+
+
+argument,
+defines
+input
+
+and
+output
+data
+format
+by
+the
+
+
+init
+
+events
+
+
+argument
+of
+type
+
+internal
+properties)
+and
+the
+resulting
+object
+can
+used
+for
+constructing
+an
+
+
+
+
+object.
+This
+is
+the
+current
+way
+of
+adding
+and
+removing
+
+Property
+
+,
+
+Action
+
+and
+ActionFragment
+
+ExposedThing
+
+adds
+the
+function
+provided
+in
+the
+action
+argument
+
+
+Event
+
+definitions,
+
+as
+a
+handler,
+then
+updates
+
+illustrated
+in
+
+the
+Thing
+Description
+
+
+examples
+
+.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+
+Before
+
+invoking
+
+expose()
+,
+the
+Action
+
+
+
+ExposedThing
+
+
+is
+received
+from
+the
+underlying
+platform.
+The
+callback
+will
+receive
+a
+
+object
+does
+not
+serve
+any
+requests.
+This
+allows
+first
+constructing
+
+
+
+parameters
+
+ExposedThing
+
+dictionary
+argument
+according
+to
+the
+definition
+in
+the
+init.input
+argument
+
+
+and
+will
+return
+a
+value
+of
+type
+defined
+by
+the
+init.output
+argument
+according
+to
+the
+value-matching
+algorithm
+.
+
+then
+initialize
+its
+
+Properties
+
+and
+service
+handlers
+before
+starting
+serving
+requests.
+
+
+There
+SHOULD
+be
+exactly
+one
+handler
+for
+any
+given
+Action
+.
+If
+no
+handler
+is
+initialized
+for
+any
+given
+Action
+,
+implementations
+SHOULD
+throw
+a
+TypeError
+.
+
+To
+construct
+an
+
+5.6
+The
+
+
+
+removeAction()
+
+ExposedThing
+
+method
+
+
+Removes
+
+with
+
+the
+Action
+
+
+
+ThingDescription
+
+
+specified
+by
+
+
+td
+,
+run
+the
+following
+steps:
+
+name
+
+SecurityError
+
+
+
+addEvent()
+
+ExposedThing
+
+
+
+EventFragment
+
+ConsumedThing
+
+
+
+
+Removes
+the
+event
+specified
+by
+
+The
+
+readProperty()
+
,
+readMultipleProperties()
+
,
+readAllProperties()
+
,
+writeProperty()
+
,
+writeMultipleProperties()
+
,
+writeAllProperties()
+
+methods
+have
+
+the
+same
+algorithmic
+steps
+as
+described
+in
+
+
+
+name
+
+ConsumedThing
+
+argument
+and
+updates
+
+,
+with
+
+the
+Thing
+Description
+.
+Returns
+
+difference
+that
+making
+
+a
+reference
+
+request
+
+to
+the
+same
+object
+for
+supporting
+chaining.
+
+underlying
+platform
+
+MAY
+
+be
+implemented
+with
+local
+methods
+or
+libraries
+and
+don't
+necessarily
+need
+to
+involve
+network
+operations.
+
+
+The
+implementation
+of
+
+
+
+PropertyReadHandler
+
+ConsumedThing
+
+callback
+
+
+interface
+in
+an
+
+ExposedThing
+
+
+provide
+the
+
+default
+
+methods
+to
+interact
+with
+the
+
+
+ExposedThing
+
.
+A
+function
+that
+is
+called
+when
+
+After
+constructing
+
+an
+external
+request
+for
+reading
+
+
+
+ExposedThing
+
,
+a
+Property
+
+script
+can
+initialize
+its
+
+Properties
+
+
+is
+received.
+It
+should
+return
+a
+Promise
+
+and
+resolves
+it
+with
+
+can
+set
+up
+
+the
+value
+of
+
+optional
+read,
+write
+and
+action
+request
+handlers
+(the
+default
+ones
+are
+provided
+by
+
+the
+Property
+matching
+
+implementation).
+The
+script
+provided
+handlers
+
+MAY
+
+use
+the
+default
+handlers,
+thereby
+extending
+the
+default
+behavior,
+but
+they
+can
+also
+bypass
+them,
+overriding
+the
+default
+behavior.
+Finally,
+
+the
+script
+would
+call
+
+
+
+name
+
+expose()
+
+argument
+to
+
+
+on
+
+the
+
+
+
+setPropertyReadHandler
+
+ExposedThing
+
+function,
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+retrieved.
+
+
+in
+order
+to
+start
+serving
+external
+requests.
+
+
+PropertyWriteHandler
+
+PropertyReadHandler
+
+
+
+callback
+
+
+
+A
+function
+that
+is
+called
+when
+an
+external
+request
+for
+writing
+
+reading
+
+a
+
+Property
+
+is
+received.
+It
+is
+given
+the
+requested
+new
+value
+as
+argument
+
+received
+
+and
+should
+return
+
+defines
+what
+to
+do
+with
+such
+requests.
+It
+returns
+
+a
+
+Promise
+which
+is
+resolved
+
+
+and
+resolves
+it
+
+when
+the
+value
+of
+the
+
+Property
+
+that
+matches
+
+matching
+
+the
+
+name
+
+argument
+has
+been
+updated
+with
+value
+,
+
+is
+obtained,
+
+or
+rejects
+with
+an
+error
+if
+the
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+updated.
+Editor's
+note
+Note
+that
+this
+function
+is
+invoked
+by
+implementations
+before
+the
+property
+is
+updated
+and
+it
+actually
+defines
+what
+to
+do
+when
+a
+write
+request
+is
+received.
+The
+code
+in
+this
+callback
+function
+can
+invoke
+the
+read()
+method
+to
+find
+out
+the
+old
+value
+of
+the
+property,
+if
+needed.
+Therefore
+the
+old
+value
+is
+not
+provided
+to
+this
+function.
+5.11
+The
+ActionHandler
+callback
+A
+function
+called
+with
+a
+parameters
+dictionary
+argument
+assembled
+by
+the
+WoT
+runtime
+based
+on
+the
+Thing
+Description
+and
+the
+external
+client
+request.
+It
+returns
+a
+Promise
+that
+rejects
+with
+an
+error
+or
+resolves
+if
+the
+action
+is
+successful
+or
+ongoing
+(may
+also
+resolve
+with
+a
+control
+object
+such
+as
+an
+Observable
+for
+actions
+that
+need
+progress
+notifications
+or
+that
+can
+be
+canceled).
+
+retrieved.
+
+
+setPropertyReadHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+readHandler
+
+as
+argument
+of
+type
+
+
+PropertyReadHandler
+
+.
+Sets
+the
+service
+
+handler
+function
+
+for
+reading
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+
+
+this
+
+object
+for
+supporting
+chaining.
+
+The
+
+readHandler
+
+callback
+function
+will
+
+should
+
+implement
+reading
+a
+
+Property
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+reading
+a
+
+Property
+
+is
+received
+from
+the
+underlying
+platform.
+
+There
+SHOULD
+
+
+MUST
+
+
+be
+at
+most
+one
+handler
+for
+any
+given
+
+Property
+and
+
+,
+so
+
+newly
+added
+handlers
+
+MUST
+
+replace
+the
+old
+
+previous
+
+handlers.
+If
+no
+handler
+is
+initialized
+for
+any
+given
+
+Property
+,
+implementations
+
+SHOULD
+
+implement
+a
+default
+property
+read
+handler.
+
+handler
+based
+on
+the
+
+Thing
+Description
+.
+
+When
+an
+external
+
+a
+network
+
+request
+for
+reading
+
+Property
+
+
+propertyName
+
+is
+received,
+
+received
+by
+
+the
+runtime
+SHOULD
+execute
+
+implementation,
+run
+
+the
+following
+steps:
+
+ReferenceError
+
+in
+the
+reply
+and
+terminate
+these
+steps.
+
+setPropertyReadHandler()
+
,
+invoke
+that
+wih
+
+propertyName
+,
+return
+the
+value
+with
+the
+reply
+
+and
+terminate
+these
+steps.
+
+NotSupportedError
+
+with
+
+the
+reply
+and
+terminate
+these
+steps.
+
+When
+a
+network
+request
+for
+observing
+a
+
+
+Property
+
+named
+
+
+propertyName
+
+provided
+
+is
+received
+
+by
+the
+runtime
+implementation
+
+implementation,
+run
+the
+following
+steps:
+
+PropertyWriteHandler
+
+callback
+
+A
+function
+that
+is
+called
+when
+an
+external
+request
+for
+writing
+a
+
+Property
+
+is
+received
+and
+defines
+what
+to
+do
+
+with
+such
+requests.
+It
+expects
+
+the
+same
+error,
+
+requested
+new
+
+value
+
+as
+argument
+
+and
+resolve
+promise
+
+returns
+a
+
+Promise
+
+which
+is
+resolved
+when
+the
+value
+of
+the
+
+Property
+
+
+that
+matches
+the
+
+name
+
+argument
+has
+been
+updated
+
+with
+
+value
+
,
+or
+rejects
+with
+an
+error
+if
+
+the
+same
+value.
+
+property
+is
+not
+found
+or
+the
+value
+cannot
+be
+updated.
+
+Note +that +the +code +in +this +callback +function +can +read +the +property +before +updating +it +in +order +to +find +out +the +old +value, +if +needed. +Therefore +the +old +value +is +not +provided +to +this +function. +
+setPropertyWriteHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+writeHandler
+
+as
+argument
+of
+type
+
+
+PropertyWriteHandler
+
+.
+Sets
+the
+service
+
+handler
+function
+
+for
+writing
+the
+specified
+
+Property
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+
+
+this
+
+object
+for
+supporting
+chaining.
+
+There
+SHOULD
+
+
+MUST
+
+
+be
+at
+most
+one
+write
+handler
+for
+any
+given
+
+Property
+and
+
+,
+so
+
+newly
+added
+handlers
+
+MUST
+
+replace
+the
+old
+
+previous
+
+handlers.
+If
+no
+write
+handler
+is
+initialized
+for
+any
+given
+
+Property
+,
+implementations
+
+SHOULD
+
+implement
+default
+property
+update
+and
+notifying
+observers
+on
+change.
+
+change,
+based
+on
+the
+
+Thing
+Description
+.
+
+When
+an
+external
+
+a
+network
+
+request
+for
+writing
+a
+
+Property
+
+
+propertyName
+
+with
+a
+new
+value
+
+value
+
+is
+received,
+the
+runtime
+
+implementations
+
+
+SHOULD
+
+execute
+
+run
+
+the
+following
+steps:
+
+
+update
+property
+steps
+,
+given
+
+propertyName
+,
+value
+
+and
+
+mode
+
+set
+to
+
+"single"
+
:
+
+ReferenceError
+
+in
+the
+reply
+
+and
+terminate
+these
+steps.
+
+setPropertyWriteHandler()
+
,
+or
+
+if
+
+"single"
+
,
+reply
+to
+the
+request
+with
+the
+new
+value,
+following
+to
+the
+
+Protocol
+Bindings
+.
+NotSupportedError
+
+in
+the
+reply
+
+and
+terminate
+these
+steps.
+
+When
+a
+network
+request
+for
+writing
+multiple
+
+Properties
+
+given
+in
+an
+object
+
+propertyNames
+
+is
+received,
+run
+
+the
+write
+handler
+associated
+
+following
+steps:
+
+"multiple"
+
.
+ActionHandler
+
+callback
+
+A
+function
+that
+is
+called
+when
+an
+external
+request
+for
+invoking
+an
+
+Action
+
+is
+received
+and
+defines
+what
+to
+do
+with
+such
+requests.
+It
+is
+invoked
+with
+a
+
+params
+
+dictionary
+argument.
+It
+returns
+a
+
+Promise
+
+that
+rejects
+with
+an
+error
+or
+resolves
+if
+the
+action
+is
+successful.
+
+setActionHandler()
+
+
+method
+
+
+
+Takes
+
+name
+
+as
+string
+argument
+and
+
+action
+
+as
+argument
+of
+type
+
+
+ActionHandler
+
+.
+Sets
+the
+handler
+function
+for
+the
+specified
+
+Action
+
+matched
+by
+
+name
+
.
+Throws
+on
+error.
+Returns
+a
+reference
+to
+the
+same
+
+
+this
+
+object
+for
+supporting
+chaining.
+
+The
+
+action
+
+callback
+function
+will
+implement
+an
+
+Action
+
+and
+
+SHOULD
+
+be
+called
+by
+implementations
+when
+a
+request
+for
+invoking
+the
+
+Action
+
+is
+received
+from
+the
+underlying
+platform.
+
+There
+SHOULD
+
+
+MUST
+
+
+be
+at
+most
+one
+handler
+for
+any
+given
+
+Action
+and
+
+,
+so
+
+newly
+added
+handlers
+
+MUST
+
+replace
+the
+old
+
+previous
+
+handlers.
+
+When
+an
+external
+
+a
+network
+
+request
+for
+invoking
+the
+
+Action
+
+identified
+by
+
+name
+
+is
+received,
+the
+runtime
+
+SHOULD
+
+execute
+the
+following
+steps:
+
+ReferenceError
+
+in
+the
+reply
+
+and
+terminate
+these
+steps.
+
+setActionHandler()
+
,
+invoke
+that
+wih
+
+
+name
+,
+
+NotSupportedError
+
+
+with
+the
+reply
+and
+terminate
+these
+steps.
+
+emitEvent()
+
+method
+
+Takes
+
+name
+
+as
+string
+argument
+denoting
+an
+
+Event
+
+name,
+and
+
+a
+
+data
+
+argument
+of
+
+
+
+type.
+The
+method
+
+MUST
+
+run
+the
+following
+steps:
+ReferenceError
+
+any
+
+SecurityError
+
+
+and
+terminate
+these
+steps.
+
+NotFoundError
+
+and
+terminate
+these
+steps.
+
+expose()
+
+method
++Start +serving +external +requests +for +the + +Thing +, +so +that + +WoT +Interactions + +using + +Properties +, +Action + +s +and + +Event + +s +will +be +possible. +The +method + +MUST + +run +the +following +steps: +
+SecurityError
+
+and
+terminate
+these
+steps.
+
+"TypeError"
+
+and
+terminate
+these
+steps.
+
+Error
+
+object
+
+error
+
+with
+
+error.message
+
+set
+to
+the
+error
+code
+seen
+by
+the
+
+Protocol
+Bindings
+
+and
+terminate
+these
+steps.
+
+destroy()
+
+method
++Stop +serving +external +requests +for +the + +Thing + +and +destroy +the +object. +Note +that +eventual +unregistering +should +be +done +before +invoking +this +method. +The +method + +MUST + +run +the +following +steps: +
+SecurityError
+
+and
+terminate
+these
+steps.
+
+Error
+
+object
+
+error
+
+with
+
+error.message
+
+set
+to
+
+the
+
+Below
+some
+
+The
+next
+example
+illustrates
+how
+to
+create
+an
+
+
+
+
+
+ExposedThing
+
+
+interface
+examples
+are
+given.
+
+based
+on
+a
+partial
+
+TD
+
+object
+constructed
+beforehands.
+
+
"hljs javascript">try {
+
+ "hljs-keyword">var temperatureValueDefinition = {
+
+"hljs-keyword">let temperaturePropertyDefinition = {
+
+ type: "number",
+ minimum: -50,
+ maximum: 10000
+ };
+ <span class=
+"hljs-keyword">var temperaturePropertyDefinition = temperatureValueDefinition;
+
+ temperaturePropertyDefinition.forms = [ ... ];
+ thing = WoT.produce({
+ : <span class=
+"hljs-string">"tempSensor",
+
+ let tdFragment = {
+ properties: {
+ temperature: temperaturePropertyDefinition
+ },
+ actions: {
+ reset: {
+ description: "Reset the temperature sensor",
+ input: {
+ temperature: temperatureValueDefinition
+ },
+ output: null,
+ forms: []
+ },
+ },
+ events: {
+ onchange: temperatureValueDefinition
+ },
+ : []
+ });
+ thing.expose();
+ wot.register(<span class=
+"hljs-string">"https://mydirectory.org", thing);
+
+ setInterval( () => {
+ mock = <span class=
+"hljs-built_in">Math.random()*<span class=
+"hljs-number">100;
+ old = <span class=
+"hljs-keyword">await thing[<span class=
+"hljs-string">"temperature"].read();
+ (old < mock) {
+ thing[<span class=
+"hljs-string">"temperature"].write(mock);
+ thing.emitEvent(<span class=
+"hljs-string">"onchange", mock);
+
+ }
+ }, );
+
+ };
+ let thing1 =
+"hljs-keyword">await WOT.produce(tdFragment);
+ // initialize Properties
+"hljs-keyword">await thing1.writeProperty("temperature", 0);
+ // add service handlers
+ thing1.setPropertyReadHandler("temperature", () => {
+
+"hljs-keyword">return readLocalTemperatureSensor(); // Promise
+ });
+ // start serving requests await thing1.expose();
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+
+
+
+The
+next
+example
+illustrates
+how
+to
+add
+or
+modify
+a
+
+Property
+
+definition
+on
+an
+existing
+
:
+take
+its
+
+td
+
+property,
+add
+or
+modify
+it,
+then
+create
+another
+
+ExposedThing
+
+ExposedThing
+
+with
+that.
+
"hljs javascript">try {
+
+"hljs-comment">// create a deep copy of thing1's TD
+ let instance =
+"hljs-built_in">JSON.parse(JSON.stringify(thing1.td));
+ const statusValueDefinition = {
+ type: "object",
+ properties: {
+ brightness: {
+ type: "number",
+ minimum: 0.0,
+ maximum: 100.0,
+ required: true
+ },
+ rgb: {
+ type: "array",
+ "minItems": 3,
+ "maxItems": 3,
+ items : {
+ "type" : "number",
+ "minimum": 0,
+ "maximum": 255
+ }
+ }
+ };
+ <span class=
+"hljs-keyword">var statusPropertyDefinition = statusValueDefinition;
+
+ statusPropertyDefinition[<span class=
+"hljs-string">"forms"] = [];
+ thing = WoT.produce({
+ : <span class=
+"hljs-string">"mySensor",
+ : {
+ : {
+ : <span class=
+
+ instance["name"] = "mySensor";
+ instance.properties["brightness"] = {
+ type: "number",
+ : <span class=
+
+ minimum: 0.0,
+ : <span class=
+
+ maximum: 100.0,
+ : <span class=
+
+ required: true,
+ },
+ <span class=
+"hljs-attr">status: statusPropertyDefinition
+ },
+ : {
+ : {
+ : <span class=
+
+ };
+ instance.properties["status"] = statusValueDefinition;
+ instance.actions["getStatus"] = {
+ description: "Get status object",
+ : <span class=
+
+ input: null,
+ : {
+ <span class=
+"hljs-attr">status : statusValueDefinition;
+ },
+ : []
+ },
+ },
+ : {
+
+ output: {
+ "hljs-attr">onstatuschange: statusValueDefinition;
+
+"hljs-attr">status : statusValueDefinition;
+
+ },
+ : []
+ });
+ thing.expose().then(<span class=
+"hljs-params">() {
+ thing.register();
+
+ forms: [...]
+ };
+ instance.events["onstatuschange"] = statusValueDefinition;
+ instance.forms = [...]; // update
+ var thing2 =
+"hljs-keyword">new ExposedThing(instance);
+ //
+"hljs-doctag">TODO: add service handlers
+ await thing2.expose();
+ });
+} catch (err) {
+ console.log("Error creating ExposedThing: " + err);
+}
+Example
+7
+:
+Create
+a
+new
+exposed
+Thing
+from
+a
+Thing
+Description
+ <span class=
+"hljs-keyword">let thingDescription = <span class=
+"hljs-string">'{ \
+ "name": "mySensor", \
+ "@context": [ "http://www.w3.org/ns/td",\
+ "https://w3c.github.io/wot/w3c-wot-common-context.jsonld" ],\
+ "@type": [ "Thing", "Sensor" ], \
+ "geo:location": "testspace", \
+ "properties": { \
+ "prop1": { \
+ "type": "number",\
+ "@type": [ "Property", "Temperature" ], \
+ "saref:TemperatureUnit": "degree_Celsius" \
+ } } }';
+ {
+ <span class=
+"hljs-comment">// note that produce() fails if thingDescription contains error
+ <span class=
+"hljs-keyword">let thing = WoT.produce(thingDescription);
+ <span class=
+"hljs-comment">// Interactions were added from TD
+ <span class=
+"hljs-comment">// WoT adds generic handler for reading any property
+ <span class=
+"hljs-comment">// define a specific handler for one property
+ name = <span class=
+"hljs-string">"examplePropertyName";
+ thing.setPropertyReadHandler(name, () => {
+ .log(<span class=
+"hljs-string">"Handling read request for " + name);
+ <span class=
+"hljs-keyword">new <span class=
+"hljs-built_in">Promise(<span class=
+"hljs-function">(<span class=
+"hljs-params">resolve, reject {
+ <span class=
+"hljs-keyword">let examplePropertyValue = <span class=
+"hljs-number">5;
+ resolve(examplePropertyValue);
+ },
+ e => {
+ .log(<span class=
+"hljs-string">"Error");
+ });
+ });
+ thing.expose();
+} (err) {
+ .log(<span class=
+"hljs-string">"Error creating ExposedThing: " + err);
+}
+Example
+8
+:
+Create
+a
+new
+exposed
+Thing
+from
+a
+TD
+URI
+
+
+ <span class=
+"hljs-comment">// fetch an external TD, e.g., to set up a proxy for that Thing
+WoT.fetch(<span class=
+"hljs-string">"http://myservice.org/mySensor/description" {
+ <span class=
+"hljs-comment">// WoT.produce() ignores instance-specific metadata (security, form)
+ thing = WoT.produce(td);
+ <span class=
+"hljs-comment">// Interactions were added from TD
+
+
+});
+
+
+
+DataSchema
+
+ThingDiscovery
+
+
+
+
+Value
+types
+basically
+represent
+types
+
+Discovery
+is
+a
+distributed
+application
+
+that
+may
+be
+used
+in
+JSON
+object
+definitions
+and
+are
+used
+in
+ThingFragment
+to
+define
+Properties
+,
+Event
+s
+and
+Action
+parameters.
+Value
+types
+are
+represented
+as
+dictionary
+objects
+whose
+properties
+
+requires
+provisioning
+
+and
+possible
+sub-classes
+are
+defined
+in
+
+support
+from
+participating
+network
+nodes
+(clients,
+servers,
+directory
+services).
+This
+API
+models
+
+the
+DataSchema
+section
+
+client
+side
+
+of
+[
+WOT-TD
+].
+
+typical
+discovery
+schemes
+supported
+by
+various
+IoT
+deployments.
+
+
+One
+property
+of
+all
+
+The
+
+
+
+
+DataSchema
+
+ThingDiscovery
+
+dictionary
+is
+the
+type
+property
+whose
+value
+
+object
+
+is
+from
+
+constructed
+given
+
+a
+set
+of
+enumerated
+strings
+defined
+in
+
+filter
+and
+provides
+
+the
+DataSchema
+section
+of
+[
+WOT-TD
+]
+
+properties
+
+and
+is
+referred
+as
+DataType
+in
+this
+specification.
+Based
+on
+type
+,
+
+methods
+controlling
+
+the
+following
+sub-classes
+of
+DataSchema
+are
+defined
+in
+[
+WOT-TD
+]:
+BooleanSchema
+,
+NumberSchema
+,
+IntegerSchema
+,
+StringSchema
+,
+ObjectSchema
+
+discovery
+process.
+
+"idl-def-thingdiscovery" data-title="ThingDiscovery">[SecureContext, Exposed=(Window,Worker)] +interface+ThingDiscovery
{ + +"dom-thingdiscovery-constructor" data-idl="constructor" data-title= +"constructor" data-dfn-for="ThingDiscovery" data-lt= +"ThingDiscovery.constructor()|ThingDiscovery.constructor|constructor()|constructor">constructor
(optionalThingFilter
filter = null); + readonly attributeThingFilter
?filter
; + readonly attribute booleanactive
; + readonly attribute booleandone
; + readonly attribute Error?error
; + +href= +"https://heycam.github.io/webidl/#idl-void">voidstart
(); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<ThingDescription
>next
(); + +href= +"https://heycam.github.io/webidl/#idl-void">voidstop
(); +}; + +, +ArraySchema ++
+The
+
+
+
+SecurityScheme
+
+ThingDiscovery
+
+dictionary
+and
+its
+subclasses
+
+
+Security
+metadata
+is
+represented
+as
+dictionary
+objects
+whose
+properties
+
+interface
+has
+a
+
+next()
+
+method
+
+and
+sub-classes
+are
+defined
+in
+the
+SecurityScheme
+section
+of
+[
+WOT-TD
+
+a
+
+done
+
+property,
+but
+it
+is
+not
+an
+
+Iterable
+.
+Look
+into
+
+Issue
+177
+
+
+].
+
+for
+rationale.
+
+
+One
+property
+of
+
+The
+
+discovery
+results
+
+internal
+slot
+is
+an
+internal
+queue
+for
+temporarily
+storing
+
+the
+found
+
+
+
+
+SecurityScheme
+
+ThingDescription
+
+dictionary
+is
+
+objects
+until
+they
+are
+consumed
+by
+
+the
+scheme
+property
+whose
+value
+is
+from
+a
+set
+of
+enumerated
+strings
+defined
+in
+
+application
+using
+
+the
+SecurityScheme
+
+
+next()
+
+
+section
+
+method.
+Implementations
+
+MAY
+
+optimize
+the
+size
+
+of
+[
+WOT-TD
+].
+Based
+
+this
+queue
+based
+
+on
+type
+,
+multiple
+subclasses
+
+e.g.
+the
+available
+resources
+and
+the
+frequency
+
+of
+SecurityScheme
+
+invoking
+the
+
+next()
+
+
+are
+defined.
+
+method.
+
+
+The
+
+
+
+
+Link
+
+filter
+
+dictionary
+Represents
+a
+Web
+Link
+with
+properties
+defined
+in
+
+property
+represents
+
+the
+Link
+section
+
+discovery
+filter
+
+of
+[
+WOT-TD
+].
+6.4
+The
+
+type
+
+
+
+Form
+
+ThingFilter
+
+dictionary
+
+
+Represents
+metadata
+describing
+service
+details,
+with
+properties
+defined
+in
+
+specified
+for
+
+the
+Form
+section
+of
+[
+WOT-TD
+].
+
+discovery.
+
+
+Represents
+the
+common
+properties
+of
+WoT
+Interactions
+,
+one
+of
+Property
+,
+Action
+or
+Event
+,
+as
+defined
+in
+the
+InteractionPattern
+section
+of
+[
+WOT-TD
+].
+Its
+subclasses
+are
+referred
+as
+
+The
+
+
+
+PropertyFragment
+
+active
+
+,
+
+
+property
+is
+
+
+
+when
+the
+discovery
+is
+actively
+ongoing
+on
+protocol
+level
+(i.e.
+new
+
+TD
+
+
+s
+may
+still
+arrive)
+
+and
+ActionFragment
+
+true
+
+
+
+EventFragment
+
+false
+
+.
+
+otherwise.
+
+
+The
+
+
+
+
+PropertyFragment
+
+done
+
+dictionary
+Represents
+the
+Property
+interaction
+data
+that
+initializes
+a
+
+property
+is
+
+
+
+ThingProperty
+
+true
+
+object.
+Its
+properties
+are
+defined
+in
+
+if
+
+the
+Property
+
+discovery
+has
+been
+completed
+with
+no
+more
+results
+to
+report
+
+and
+InteractionPattern
+sections
+of
+[
+WOT-TD
+
+
+discovery
+results
+
+
+].
+
+is
+also
+empty.
+
+
+The
+
+
+
+
+ActionFragment
+
+error
+
+dictionary
+Represents
+
+property
+represents
+
+the
+Action
+interaction
+data
+
+last
+error
+
+that
+initializes
+a
+ThingAction
+object.
+Its
+properties
+are
+defined
+in
+
+occured
+during
+
+the
+Action
+and
+InteractionPattern
+sections
+of
+[
+WOT-TD
+].
+
+discovery
+process.
+Typically
+used
+for
+critical
+errors
+that
+stop
+discovery.
+
+
+EventFragment
+
+ThingDiscovery
+
+
+
+Represents
+the
+Event
+interaction
+data
+that
+initializes
+a
+
+To
+create
+
+
+
+
+ThingEvent
+
+ThingDiscovery
+
+object.
+Its
+properties
+are
+defined
+in
+
+with
+
+the
+Event
+section
+of
+[
+WOT-TD
+].
+6.9
+The
+ThingFragment
+dictionary
+The
+
+
+
+
+
+ThingFragment
+
+ThingFilter
+
+dictionary
+is
+defined
+as
+Thing
+in
+[
+WOT-TD
+].
+It
+is
+a
+dictionary
+that
+contains
+properties
+representing
+semantic
+metadata
+and
+interactions
+(
+Properties
+,
+Action
+s
+and
+Event
+s).
+It
+
+
+filter
+,
+run
+the
+following
+steps:
+
+ThingFilter
+
+null
+
,
+throw
+
+"TypeError"
+
+
+
+ThingDescription
+
+ThingDiscovery
+
+
+
+USVString
+that
+can
+be
+transmitted
+between
+devices.
+7.
+Interfaces
+for
+WoT
+Interactions
+
+false
+
.
+Set
+
+error
+
+
+to
+
+null
+
.
+The
+data
+types
+and
+structures
+imported
+from
+[
+WOT-TD
+
+
+start()
+
+
+]
+are
+extended
+by
+this
+specification
+in
+order
+to
+provide
+the
+interfaces
+for
+WoT
+Interactions
+.
+Every
+Thing
+
+method
+sets
+
+active
+
+
+describes
+its
+metadata
+as
+defined
+in
+
+to
+
+
+
.
+The
+
+stop()
+
+
+ThingFragment
+,
+and
+basic
+interactions
+defined
+as
+Properties
+,
+Action
+
+true
+s
+and
+Event
+
+method
+sets
+
+active
+
+
+s.
+The
+following
+interfaces
+are
+used
+for
+representing
+these
+interactions.
+7.1
+The
+
+to
+
+false
+,
+but
+
+done
+
+may
+be
+still
+
+
+
+Interaction
+
+false
+
+interface
+The
+
+if
+there
+are
+
+
+
+
+Interaction
+
+ThingDescription
+
+interface
+is
+an
+abstract
+class
+to
+represent
+Thing
+interactions:
+Properties
+,
+Actions
+
+objects
+in
+the
+
+discovery
+results
+
+
+and
+Events
+
+not
+yet
+consumed
+with
+
+next()
+
+.
+
+The
+InteractionFragment
+dictionary
+holds
+the
+common
+properties
+
+During
+successive
+calls
+
+of
+PropertyFragment
+,
+ActionFragment
+and
+EventFragment
+dictionaries
+used
+for
+initializing
+ThingProperty
+
+
+next()
+
+,
+ThingAction
+
+
+active
+
+
+and
+
+may
+be
+
+
+
+ThingEvent
+
+true
+
+objects
+in
+a
+
+or
+
+
+
,
+but
+
+done
+
+
+ThingFragment
+
+false
+dictionary
+used
+for
+creating
+an
+
+is
+set
+to
+
+
+
+by
+
+next()
+
+
+ExposedThing
+
+false
+
+object.
+<span class="idlInterface" id=
+"idl-def-interaction" data-idl="" data-title=
+"Interaction">interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-interaction" class="internalDFN" data-link-type=
+"dfn"> {<span class=
+"idlAttribute" id="idl-def-interaction-forms" data-idl=""
+data-title="forms" data-dfn-for="interaction">
+ readonly attribute (<a data-link-for=""
+href="#dom-form" class="internalDFN" data-link-type=
+"dfn"> or <a href=
+"https://heycam.github.io/webidl/#idl-frozen-array">FrozenArray<<a data-link-for=""
+href="#dom-form" class="internalDFN" data-link-type=
+"dfn"> <span class=
+"idlAttrName"><a data-no-default="" data-link-for="interaction"
+data-lt="interaction.forms|forms" href="#dom-interaction-forms"
+class="internalDFN" data-link-type=
+"dfn">
+};
+<a href="#dom-interaction" class="internalDFN" data-link-type=
+"dfn"> includes <a href=
+"#dfn-interactionfragment" class="internalDFN" data-link-type=
+"dfn">
+InteractionFragment
+
+only
+when
+both
+
+active
+
+
+;
+The
+
+is
+
+
+
+forms
+
+false
+
+read-only
+property
+represents
+the
+protocol
+bindings
+initialization
+data
+
+and
+
+discovery
+results
+
+is
+initialized
+by
+the
+WoT
+Runtime
+.
+
+empty.
+
+
+ThingProperty
+
+DiscoveryMethod
+
+
+
+"idl-def-discoverymethod" data-title= +"DiscoveryMethod">typedef+DOMString
+ ++
+ +ThingProperty ++DiscoveryMethod + +interface +is +used +in +ConsumedThing ++; + +and ++
+Represents +the +discovery +type +to +be +used: +
+ThingFragment
+
+ThingFilter
+
+
+
+dictionary
+
+Represents
+an
+object
+containing
+the
+constraints
+for
+discovering
+
+Thing
+
+
+dictionaries.
+
+s
+as
+key-value
+pairs.
+
+
"idl-def-thingfilter" data-title="ThingFilter">dictionary ThingFilter
{
+ (DiscoveryMethod
or DOMString
) method
= "any";
+
+href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString? url
;
+
+href=
+"https://heycam.github.io/webidl/#idl-USVString">USVString? query
;
+
+"interface" href=
+"https://heycam.github.io/webidl/#idl-object">object? fragment
;
+};
+
+
+
+
+The
+ThingProperty
+interface
+contains
+all
+the
+properties
+defined
+on
+
+
+
+
+PropertyFragment
+
+method
+
+as
+read-only
+properties.
+The
+type
+
+
+read-only
+
+property
+represents
+the
+discovery
+
+type
+definition
+for
+the
+Property
+as
+a
+DataSchema
+dictionary
+object.
+The
+writable
+read-only
+property
+tells
+whether
+the
+Property
+value
+can
+
+that
+should
+
+be
+updated.
+If
+it
+is
+false
+,
+then
+the
+set(value)
+method
+SHOULD
+always
+reject.
+The
+observable
+read-only
+property
+tells
+whether
+the
+Property
+supports
+subscribing
+to
+value
+change
+notifications.
+If
+it
+is
+false
+,
+then
+
+used
+in
+
+the
+subscribe()
+method
+SHOULD
+always
+fail.
+
+discovery
+process.
+
+The
+constant
+read-only
+property
+-
+
+possible
+values
+are
+
+defined
+in
+DataSchema
+-
+tells
+whether
+the
+Property
+value
+is
+a
+constant.
+If
+true
+,
+
+by
+
+the
+
+
+set()
+and
+subscribe()
+methods
+SHOULD
+always
+fail.
+The
+
+required
+read-only
+property
+-
+defined
+in
+
+
+
+
+
+DataSchema
+
+DiscoveryMethod
+
+-
+tells
+whether
+the
+Property
+should
+be
+always
+present
+on
+the
+
+ExposedThing
+
+object.
+
+enumeration
+that
+
+MAY
+
+be
+extended
+by
+string
+values
+defined
+by
+solutions
+(with
+no
+guarantee
+of
+interoperability).
+
+
+The
+
+
+
+
+read()
+
+url
+
+method
+will
+fetch
+
+property
+represents
+additional
+information
+for
+
+the
+value
+
+discovery
+method,
+such
+as
+the
+URL
+
+of
+the
+Property
+.
+Returns
+a
+Promise
+that
+resolves
+with
+
+target
+entity
+serving
+
+the
+value,
+or
+rejects
+with
+an
+error.
+The
+write()
+method
+will
+attempt
+to
+set
+
+discovery
+request,
+for
+instance
+
+the
+value
+
+URL
+
+of
+the
+Property
+
+a
+
+Thing
+Directory
+
+
+specified
+in
+the
+
+(if
+
+
+
+value
+
+method
+
+argument
+whose
+type
+SHOULD
+match
+the
+one
+specified
+by
+the
+
+is
+
+
+
+type
+
+"directory"
+
+property.
+Returns
+
+)
+or
+that
+of
+
+a
+Promise
+
+
+Thing
+
+
+that
+resolves
+on
+success,
+or
+rejects
+on
+an
+error.
+
+(otherwise).
+
+
+The
+
+
+
+
+invoke()
+
+query
+
+method
+when
+invoked,
+starts
+the
+Action
+interaction
+with
+the
+input
+value
+provided
+
+property
+represents
+a
+query
+string
+accepted
+
+by
+the
+inputValue
+argument.
+If
+inputValue
+is
+null
+,
+the
+action
+does
+not
+take
+any
+arguments
+and
+rejects
+if
+any
+arguments
+are
+provided.
+If
+the
+value
+is
+undefined
+,
+the
+action
+will
+ignore
+any
+arguments
+provided.
+Otherwise
+the
+type
+of
+inputValue
+SHOULD
+match
+the
+DataSchema
+definition
+
+implementation,
+for
+instance
+a
+SPARQL
+or
+JSON
+query.
+Support
+may
+be
+implemented
+locally
+
+in
+the
+input
+property.
+Returns
+a
+Promise
+
+
+WoT
+Runtime
+
+
+that
+will
+reject
+with
+an
+error
+
+or
+will
+resolve
+with
+
+remotely
+as
+
+a
+value
+of
+type
+defined
+by
+the
+output
+property.
+
+service
+in
+a
+
+Thing
+Directory
+.
+
+The
+
+
+
+
+ThingEvent
+
+fragment
+
+interface
+<span class="idlInterface" id=
+"idl-def-thingevent" data-idl="" data-title=
+"ThingEvent">interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-thingevent" class="internalDFN" data-link-type=
+"dfn"> : <span class=
+"idlSuperclass"><a href="#dom-interaction" class="internalDFN"
+data-link-type="dfn"> {
+};
+<a href="#dom-thingevent" class="internalDFN" data-link-type=
+"dfn"> includes <a href=
+"#dom-eventfragment" class="internalDFN" data-link-type=
+"dfn"><span class=
+"idlIncludes">
+<a href="#dom-thingevent" class="internalDFN" data-link-type=
+"dfn"> includes <a href=
+"#dom-thingproperty" class="internalDFN" data-link-type=
+"dfn">
+ThingProperty
+;
+Since
+ThingEvent
+implements
+Observable
+through
+the
+ThingProperty
+interface,
+event
+subscription
+is
+done
+by
+invoking
+the
+subscribe()
+method
+on
+the
+event
+object
+that
+returns
+
+property
+represents
+
+a
+cancelable
+Subscription
+.
+
+template
+object
+used
+for
+matching
+property
+by
+property
+against
+discovered
+
+Thing
+
+s.
+
+
+ExposedEvent
+
+start()
+
+
+
+
+Starts
+the
+discovery
+process.
+
+The
+emit()
+
+method
+Emits
+an
+event
+that
+carries
+data
+specified
+by
+
+
+MUST
+
+run
+
+the
+payload
+argument.
+
+following
+steps:
+
+
+DataSchema
+
+SecurityError
+
+
+
+value
+
+NotSupportedError
+
+
+and
+
+invoke()
+
+NotSupportedError
+
+
+
+ThingAction
+
+ThingDescription
+
+
+
+
+null
+,
+return
+true
+
+"any"
+
+
,
+
+false
+,
+then
+return
+true
+
+"local"
+
+
,
+
+long
+long
+),
+then
+return
+false
+
+"directory"
+
+
,
+
+"multicast"
+
,
+use
+all
+the
+multicast
+discovery
+protocols
+supported
+by
+the
+underlying
+platform.
+
+active
+
+property
+to
+
+
+true
+
.
+
+SyntaxError
+
,
+discard
+
+
+
+false
+
,
+
+false
+
+in
+
+Error
+
+object
+
+
+
+'DiscoveryError'
+
.
+
+undefined
+,
+return
+
+this.active
+
+to
+
+
+false
+
.
+
+false
+
.
+
+"object"
+,
+execute
+
+next()
+
+method
+
+Provides
+the
+next
+discovered
+
+ThingDescription
+
+object.
+The
+method
+
+MUST
+
+run
+
+the
+following
+sub-steps:
+
+steps:
+
+false
+.
+
+true
+
,
+wait
+until
+the
+
+discovery
+results
+
+internal
+slot
+is
+not
+empty.
+
+
+null
+
+false
+
+
,
+
+true
+
+
+ThingDescription
+
+object
+
+stop()
+
+
+method
+
+
+Observables
+are
+proposed
+to
+
+Stops
+or
+suppresses
+the
+discovery
+process.
+It
+might
+not
+
+be
+included
+in
+ECMAScript
+
+supported
+by
+all
+discovery
+methods
+
+and
+are
+used
+for
+handling
+pushed
+data
+associated
+with
+various
+possible
+sources,
+for
+instance
+events,
+timers,
+streams,
+etc.
+A
+minimal
+required
+implementation
+is
+described
+here.
+Editor's
+note
+This
+section
+is
+informal
+
+endpoints,
+however,
+any
+further
+discovery
+results
+or
+errors
+will
+be
+discarded
+
+and
+contains
+rather
+laconic
+information
+for
+implementations
+on
+what
+to
+support
+for
+interoperability.
+<span class="idlInterface" id=
+"idl-def-observable" data-idl="" data-title=
+"Observable">interface <span class=
+"idlInterfaceID"><a data-no-default="" data-link-for="" data-lt=""
+href="#dom-observable" class="internalDFN" data-link-type=
+"dfn"> {<span class="idlMethod"
+id="idl-def-observable-subscribe-handler-errorhandler-oncomplete"
+data-idl="" data-title="subscribe" data-dfn-for=
+"observable">
+ <a data-link-for="" href="#dom-subscription" class="internalDFN"
+data-link-type=
+"dfn"> <span class=
+"idlMethName"><a data-no-default="" data-link-for="observable"
+data-lt="subscribe|subscribe()" href="#dom-observable-subscribe"
+class="internalDFN" data-link-type=
+"dfn">(<span class=
+"idlParam"><a href=
+"https://www.w3.org/TR/html52/single-page.html#typedefdef-eventhandler">EventHandler
+ optional<span class=
+"idlParamType"> <a data-link-for="" href="#dom-errorhandler" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">errorHandler
+ optional<span class=
+"idlParamType"> <a data-link-for="" href="#dom-oncomplete" class=
+"internalDFN" data-link-type=
+"dfn"> <span class=
+"idlParamName">onComplete
+};<span class="idlInterface" id="idl-def-subscription"
+data-idl="" data-title="Subscription">
+interface <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-subscription" class=
+"internalDFN" data-link-type=
+"dfn"> {<span class="idlMethod"
+id="idl-def-subscription-unsubscribe" data-idl="" data-title=
+"unsubscribe" data-dfn-for="subscription"><span class=
+"idlMethType">
+ void<a data-no-default=""
+data-link-for="subscription" data-lt="unsubscribe|unsubscribe()"
+href="#dom-subscription-unsubscribe" class="internalDFN"
+data-link-type=
+"dfn"><span class=
+"idlAttribute" id="idl-def-subscription-closed" data-idl=""
+data-title="closed" data-dfn-for="subscription">
+ readonly attribute <a href=
+"https://heycam.github.io/webidl/#idl-boolean">boolean<a data-no-default=""
+data-link-for="subscription" data-lt="subscription.closed|closed"
+href="#dom-subscription-closed" class="internalDFN" data-link-type=
+"dfn">
+};<span class="idlCallback" id="idl-def-eventhandler"
+data-idl="" data-title="EventHandler">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-eventhandler" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType"> void<span class=
+"idlParamType"><a href=
+"https://heycam.github.io/webidl/#idl-any">any<span class="idlCallback"
+id="idl-def-errorhandler" data-idl="" data-title="ErrorHandler">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-errorhandler" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType"> void<span class=
+"idlParamType"><a href=
+"https://heycam.github.io/webidl/#idl-Error">Error<span class="idlCallback"
+id="idl-def-oncomplete" data-idl="" data-title="OnComplete">
+callback <a data-no-default=""
+data-link-for="" data-lt="" href="#dom-oncomplete" class=
+"internalDFN" data-link-type=
+"dfn"> =<span class=
+"idlCallbackType">
+void
+();
+
+the
+discovery
+is
+marked
+inactive.
+
+The
+method
+
+MUST
+
+run
+the
+
+following
+callbacks
+can
+be
+provided
+when
+subscribing
+to
+an
+Observable
+:
+
+steps:
+
+
+OnComplete
+
+this.active
+
+
+
+Subscription
+
+false
+
.
+Contains
+the
+
+The
+following
+example
+finds
+
+
+
+closed
+
+ThingDescription
+
+property
+
+
+objects
+
+of
+type
+boolean
+
+
+Thing
+
+s
+
+that
+tells
+if
+the
+subscription
+
+are
+exposed
+by
+local
+hardware,
+regardless
+how
+many
+instances
+of
+
+WoT
+Runtime
+
+it
+
+is
+closed
+or
+active.
+Also,
+contains
+the
+unsubscribe
+()
+method
+
+running.
+Note
+
+that
+cancels
+
+the
+subscription,
+i.e.
+makes
+a
+request
+to
+
+discovery
+can
+end
+(become
+inactive)
+before
+
+the
+underlying
+platform
+
+internal
+
+discovery
+results
+
+queue
+is
+emptied,
+so
+we
+need
+
+to
+stop
+receiving
+data
+from
+the
+source,
+and
+sets
+the
+
+continue
+reading
+
+
+
+closed
+
+ThingDescription
+
+property
+to
+false
+.
+
+
+objects
+until
+done.
+This
+is
+typical
+with
+local
+and
+directory
+type
+discoveries.
+
+
"hljs-keyword">let discovery = new ThingDiscovery({ method: "local" });
+do { let td =
+"hljs-keyword">await discovery.next();
+ console.log(
+"hljs-string">"Found Thing Description for " + td.title);
+ let thing =
+"hljs-keyword">new ConsumedThing(td);
+ console.log(
+"hljs-string">"Thing name: " + thing.getThingDescription().title);
+}
+while
+
+(!discovery.done);
+
+
+interface
+
+
+
+The
+next
+example
+finds
+
+
+
+
+Observable
+
+ThingDescription
+
+interface
+enabled
+subscribing
+to
+pushed
+data
+notifications
+by
+the
+
+objects
+of
+
+Thing
+
+s
+listed
+in
+a
+
+Thing
+Directory
+
+service.
+We
+set
+a
+timeout
+for
+safety.
+
+"hljs-keyword">let discoveryFilter = {
+ method:
+"hljs-string">"directory",
+ url:
+"hljs-string">"http://directory.wotservice.org"
+};
+let discovery =
+"hljs-keyword">new ThingDiscovery(discoveryFilter);
+setTimeout( () => {
+ discovery.stop();
+ console.log(
+"hljs-string">"Discovery stopped after timeout.");
+ },
+ 3000);do { let td =
+"hljs-keyword">await discovery.next();
+ console.log(
+"hljs-string">"Found Thing Description for " + td.title);
+ let thing =
+"hljs-keyword">new ConsumedThing(td);
+ console.log(
+"hljs-string">"Thing name: " + thing.getThingDescription().title);
+} while (!discovery.done);
+if (discovery.error) { console.log(
+"hljs-string">"Discovery stopped because of an error: " + error.message);
+}
+
+
+()
+method:
+Initialize
+the
+data
+handler
+callback
+with
+the
+first
+function
+argument.
+If
+the
+
+
+
+The
+
+next
+argument
+is
+provided
+and
+
+example
+
+is
+a
+function,
+initialize
+the
+error
+handling
+callback
+with
+that
+function,
+or
+throw
+
+for
+an
+open-ended
+multicast
+discovery,
+which
+likely
+won't
+complete
+soon
+(depending
+
+on
+error.
+If
+
+the
+third
+argument
+is
+provided
+and
+
+underlying
+protocol),
+so
+stopping
+it
+with
+a
+timeout
+
+is
+a
+function,
+initialize
+the
+completion
+handler
+with
+that
+function,
+or
+throw
+on
+error.
+After
+callback
+initializations,
+the
+implementation
+should
+request
+the
+underlying
+platform
+to
+provide
+data,
+error
+and
+completion
+notifications
+for
+the
+supported
+data
+source.
+
+good
+idea.
+It
+will
+likely
+deliver
+results
+one
+by
+one.
+
+"hljs-keyword">let discovery = new ThingDiscovery({ method: "multicast" });
+setTimeout( () => {
+ discovery.stop();
+ console.log(
+"hljs-string">"Stopped open-ended discovery");
+ },
+ 10000);do { let td =
+"hljs-keyword">await discovery.next();
+ let thing =
+"hljs-keyword">new ConsumedThing(td);
+ console.log(
+"hljs-string">"Thing name: " + thing.getThingDescription().title);
+}
+while
+
+(!discovery.done);
+
+In
+general
+the
+security
+measures
+taken
+to
+protect
+a
+WoT
+system
+will
+depend
+on
+the
+threats
+and
+attackers
+that
+system
+may
+face
+and
+the
+value
+of
+the
+assets
+needs
+to
+protect.
+
+A
+detailed
+discussion
+of
+security
+and
+privacy
+considerations
+for
+the
+Web
+of
+Things,
+including
+a
+threat
+model
+that
+can
+be
+adapted
+to
+various
+circumstances,
+is
+presented
+in
+the
+informative
+document
+[
+
+WOT-SECURITY-CONSIDERATIONS
+
+
+WOT-SECURITY-GUIDELINES
+
+
+
+].
+This
+section
+includes
+
+discusses
+
+only
+normative
+recommendations
+
+security
+and
+privacy
+risks
+and
+possible
+mitigations
+directly
+
+relevant
+to
+the
+scripts
+and
+
+WoT
+Thing
+Description.
+
+Scripting
+API.
+
+
+When
+designing
+new
+devices
+and
+services
+for
+use
+with
+the
+WoT,
+we
+have
+documented
+a
+
+A
+suggested
+
+set
+of
+best
+practices
+to
+improve
+security
+for
+WoT
+devices
+and
+services
+has
+been
+documented
+
+in
+[
+
+
+WOT-SECURITY-BEST-PRACTICES
+
+
+]
+that
+SHOULD
+be
+followed.
+This
+best-practices
+
+].
+That
+
+document
+may
+be
+updated
+as
+security
+measures
+evolve.
+Following
+these
+practices
+does
+not
+guarantee
+security,
+but
+it
+at
+least
+will
+
+might
+
+help
+to
+
+avoid
+common
+known
+vulnerabilities
+and
+pitfalls.
+
+vulnerabilities.
+
+
+Below
+are
+specific
+recommendations
+related
+to
+
+The
+
+WoT
+runtime
+implementations:
+
+security
+risks
+and
+possible
+mitigations
+are
+concerning
+the
+following
+groups:
+
+
+This
+section
+
+is
+required.
+Therefore
+
+normative
+and
+contains
+specific
+risks
+relevant
+for
+
+the
+WoT
+runtime
+SHOULD
+perform
+isolation
+of
+WoT
+runtime
+instances
+
+Scripting
+Runtime.
+
+A
+typical
+way
+to
+compromise
+any
+process
+is
+to
+send
+it
+
+a
+WoT
+device
+has
+more
+than
+
+corrupted
+input
+via
+
+one
+tenant.
+Such
+isolation
+
+of
+the
+exposed
+interfaces.
+This
+
+can
+be
+performed
+within
+the
+WoT
+Runtime
+
+done
+to
+a
+script
+instance
+
+using
+platform
+security
+mechanisms
+available
+
+WoT
+interface
+it
+exposes.
+
+In
+addition
+to
+providing
+the
+isolation
+between
+
+case
+a
+
+script
+and
+runtime
+instances,
+the
+WoT
+runtime
+needs
+to
+protect
+
+is
+compromised
+or
+misbehaving,
+
+the
+underlying
+physical
+device
+from
+
+(and
+
+potentially
+misbehaving
+WoT
+scripts.
+Therefore
+
+surrounded
+environment)
+can
+be
+damaged
+if
+a
+script
+can
+use
+directly
+exposed
+native
+device
+interfaces.
+If
+such
+interfaces
+lack
+safety
+checks
+on
+their
+inputs,
+they
+might
+bring
+
+the
+underlying
+physical
+device
+(or
+environment)
+to
+an
+unsafe
+state
+(i.e.
+device
+overheats
+and
+explodes).
+
+If
+the
+WoT
+runtime
+
+Scripting
+Runtime
+
+supports
+post-manufacturing
+provisioning
+or
+update
+
+updates
+
+of
+WoT
+
+scripts,
+WoT
+runtime
+
+Scripting
+Runtime
+
+or
+any
+related
+data
+(including
+security
+credentials),
+it
+can
+be
+a
+major
+attack
+vector.
+An
+attacker
+can
+try
+to
+modify
+any
+above
+described
+part
+
+element
+
+during
+the
+update
+or
+provisioning
+process
+or
+simply
+provision
+attacker's
+code
+and
+data
+directly.
+Therefore,
+if
+WoT
+Runtime
+supports
+post-manufacturing
+
+
+Typically
+the
+WoT
+runtime
+
+Scripting
+Runtime
+
+needs
+to
+store
+the
+security
+credentials
+that
+are
+provisioned
+to
+a
+WoT
+device
+to
+operate
+in
+WoT
+network.
+The
+
+If
+an
+attacker
+can
+compromise
+the
+
+confidentiality
+or
+integrity
+of
+these
+credentials
+should
+not
+be
+compromised.
+Therefore
+
+credentials,
+then
+it
+can
+obtain
+access
+to
+
+the
+WoT
+runtime
+SHOULD
+
+assets,
+impersonate
+WoT
+things
+or
+devices
+or
+create
+Denial-Of-Service
+(DoS)
+attacks.
+
+Some
+additional
+
+
+This
+section
+is
+non-normative.
+
+This
+section
+describes
+
+specific
+recommendations
+
+risks
+
+relevant
+for
+WoT
+
+script
+developers:
+
+developers.
+
+
+A
+typical
+way
+to
+compromise
+any
+process
+is
+to
+send
+it
+a
+corrupted
+input
+via
+one
+of
+
+script
+instance
+may
+receive
+data
+formats
+defined
+by
+
+the
+exposed
+interfaces.
+Therefore
+developers
+
+TD,
+or
+data
+formats
+defined
+by
+the
+applications.
+While
+the
+WoT
+Scripting
+Runtime
+
+
+SHOULD
+
+perform
+validation
+on
+all
+WoT
+
+input
+fields
+defined
+by
+the
+TD,
+scripts
+may
+be
+still
+exploited
+by
+input
+data.
+
+If
+a
+WoT
+
+script
+performs
+a
+heavy
+functional
+processing
+on
+received
+requests
+before
+the
+request
+is
+authenticated,
+it
+presents
+a
+great
+risk
+for
+Denial-Of-Service
+(DOS)
+attacks.
+Therefore
+WoT
+scripts
+SHOULD
+
+
+During
+the
+lifetime
+of
+a
+
+WoT
+developers
+should
+remember
+that
+
+network,
+
+a
+content
+of
+a
+TD
+can
+change,
+including
+
+change.
+This
+includes
+
+its
+identified,
+id,
+
+identifier,
+
+which
+is
+
+might
+
+not
+be
+
+an
+immutable
+identifier.
+Therefore
+WoT
+scripts
+SHOULD
+
+one
+and
+might
+be
+updated
+periodically.
+
+While +stale +TDs +can +present +a +potential +problem +for +WoT +network +operation, +it +might +not +be +a +security +risk. +
+The
+generic
+WoT
+terminology
+is
+defined
+in
+[
+
+
+WOT-ARCHITECTURE
+
+
+]:
+
+Thing
+,
+
+Thing
+Description
+
+(in
+short
+
+TD
+
+),
+
+Web
+of
+Things
+
+(in
+short
+
+
+WoT
+
+
+),
+
+WoT
+Interface
+,
+
+
+(same
+as
+
+WoT
+network
+interface
+
+),
+
+Protocol
+Bindings
+,
+
+WoT
+Runtime
+,
+
+Consuming
+a
+Thing
+Description
+,
+
+Thing
+Directory
+,
+
+WoT
+Interactions
+,
+
+Property
+,
+
+Action
+,
+
+Event
+
+etc.
+
+ +JSON-LD + +is +defined +in +[ + + +JSON-LD + + +] +as +a +JSON +document +that +is +augmented +with +support +for +Linked +Data. +
+
+The
+terms
+
+
+URL
+
+,
+
+
+URL
+scheme
+
+
+and
+
+,
+
+
+URL
+host
+,
+URL
+path
+
+,
+
+
+URL
+record
+,
+parse
+a
+URL
+,
+absolute-URL
+string
+,
+path-absolute-URL
+string
+,
+
+basic
+URL
+parser
+
+
+
+are
+defined
+in
+[
+
+
+URL
+
+
+].
+
+The
+following
+
+terms
+
+
+MIME
+type
+,
+Parsing
+a
+MIME
+type
+,
+Serializing
+a
+MIME
+type
+,
+valid
+MIME
+type
+string
+,
+JSON
+MIME
+type
+
+are
+defined
+in
+[
+
+HTML52
+
+
+MIMESNIFF
+
+
+
+]
+and
+
+].
+
+The
+terms
+
+UTF-8
+encoding
+,
+UTF-8
+decode
+,
+encode
+,
+decode
+
+are
+used
+
+defined
+
+in
+the
+context
+of
+browser
+implementations:
+
+[
+
+browsing
+context
+
+
+ENCODING
+
+,
+top-level
+browsing
+context
+
+
+].
+
+,
+
+
+global
+object
+
+
+string
+
+,
+incumbent
+settings
+object
+
+,
+
+,
+
+
+parse
+JSON
+from
+bytes
+
+Document
+
+
+and
+
+,
+
+
+serialize
+JSON
+to
+bytes
+
+document
+base
+URL
+
+,
+are
+defined
+in
+[
+
+,
+
+
+INFRA
+
+Window
+
+
+].
+
+The
+terms
+
+,
+
+
+WindowProxy
+
+
+throw
+
+,
+
+
+origin
+
+,
+
+,
+ASCII
+serialized
+origin
+
+
+,
+executing
+algorithms
+
+
+creating
+
+in
+parallel
+
+
+,
+
+,
+
+queue
+a
+task
+
+
+,
+
+
+DOMString
+
+task
+source
+
+
+,
+
+,
+
+iframe
+
+
+,
+
+
+Dictionary
+
+valid
+MIME
+type
+
+
+,
+
+
+
+ArrayBuffer
+
+.
+A
+browsing
+context
+
+
+refers
+to
+the
+environment
+in
+which
+Document
+
+,
+
+
+
+BufferSource
+
+
+objects
+are
+presented
+to
+the
+user.
+A
+given
+browsing
+context
+
+,
+
+
+
+any
+
+
+has
+a
+single
+
+,
+
+
+not
+present
+,
+
+DOMException
+
+WindowProxy
+
+
+,
+
+
+
+AbortError
+
+
+object,
+but
+it
+can
+have
+many
+
+
+,
+
+
+
+SyntaxError
+
+Document
+
+
+,
+
+
+
+NotSupportedError
+
+
+objects,
+with
+their
+associated
+
+
+,
+
+
+
+NetworkError
+
+Window
+
+
+,
+
+
+
+TypeError
+
+
+objects.
+The
+script
+execution
+context
+
+
+associated
+with
+the
+browsing
+context
+identifies
+the
+entity
+which
+invokes
+this
+API,
+which
+can
+be
+a
+web
+app
+,
+a
+web
+page
+,
+or
+an
+iframe
+.
+The
+term
+secure
+context
+
+,
+
+
+
+NotReadableError
+
+
+is
+
+,
+
+
+
+TimeoutError
+
,
+NoModificationAllowedError
+
,
+SecurityError
+
,
+are
+
+defined
+in
+[
+
+WEBAPPSEC
+
+
+WEBIDL
+
+
+
+].
+
+
+Error
+,
+EvalError
+,
+RangeError
+,
+ReferenceError
+,
+SyntaxError
+,
+TypeError
+,
+URIError
+
+
+
+,
+script
+execution
+context
+
+,
+
+
+Promise
+
+,
+
+,
+
+
+Error
+,
+JSON
+
+,
+JSON.stringify
+
+,
+
+
+JSON.stringify
+
+
+and
+
+,
+
+
+JSON.parse
+
+
+and
+
+
+internal
+slots
+
+
+
+are
+defined
+in
+[
+
+
+ECMASCRIPT
+
+
+].
+
+The
+terms
+
+
+browsing
+context
+
+DOMString
+
+,
+
+,
+
+
+top-level
+browsing
+context
+
+USVString
+
+,
+
+,
+
+
+global
+object
+
+ArrayBuffer
+
+,
+
+,
+
+
+current
+settings
+object
+
+BufferSource
+
+,
+executing
+algorithms
+
+
+in
+parallel
+
+
+and
+
+any
+
+
+are
+defined
+in
+[
+
+WEBIDL
+
+
+HTML5
+
+
+
+].
+
+]
+and
+are
+used
+in
+the
+context
+of
+browser
+implementations.
+
+
+The
+algorithms
+utf-8
+encode
+,
+and
+utf-8
+decode
+
+term
+
+secure
+context
+
+
+
+are
+
+is
+
+defined
+in
+[
+
+ENCODING
+
+
+WEBAPPSEC
+
+
+
+].
+
+ +IANA +media +type + +s +(formerly +known +as +MIME +types) +are +defined +in + +RFC2046 +. +
+
+The
+terms
+
+hyperlink
+reference
+
+and
+
+relation
+type
+
+are
+defined
+in
+[
+
+HTML52
+
+
+HTML5
+
+
+
+]
+and
+
+RFC8288
+.
+
+As
+well
+as
+sections
+marked
+as
+non-normative,
+all
+authoring
+guidelines,
+diagrams,
+examples,
+and
+notes
+in
+this
+specification
+are
+non-normative.
+Everything
+else
+
+API
+rationale
+usually
+belongs
+to
+a
+separate
+document,
+but
+
+in
+this
+specification
+is
+normative.
+
+the
+WoT
+case
+the
+complexity
+of
+the
+context
+justifies
+including
+basic
+rationale
+here.
+
+
+The
+key
+words
+MAY
+,
+MUST
+,
+SHOULD
+,
+
+WoT
+Interest
+Group
+
+and
+SHOULD
+NOT
+are
+
+Working
+Group
+have
+explored
+different
+approaches
+to
+application
+development
+for
+WoT
+that
+have
+been
+all
+implemented
+and
+tested.
+
+It +is +possible + +to +develop +WoT +applications +that +only +use +the + +WoT +network +interface +, +typically +exposed +by +a +WoT +gateway +that +presents +a +REST-ful +API +towards +clients +and +implements +IoT +protocol +plugins +that +communicate +with +supported +IoT +deployments. +One +such +implementation +is +the + +Mozilla +WebThings + +platform. +
+WoT
+
+Thing
+
+s
+show
+good
+synergy
+with
+software
+objects,
+so
+a
+
+Thing
+
+can
+
+be
+interpreted
+
+represented
+
+as
+described
+
+a
+software
+object,
+with
+
+Properties
+
+represented
+as
+object
+properties,
+
+Action
+
+s
+as
+methods,
+and
+
+Event
+
+s
+as
+events.
+In
+addition,
+metadata
+is
+stored
+
+in
+special
+properties.
+Consuming
+and
+exposing
+is
+done
+with
+factory
+methods
+that
+produce
+a
+software
+object
+that
+directly
+represents
+a
+remote
+
+Thing
+
+and
+its
+interactions.
+One
+such
+implementation
+is
+the
+
+Arena
+Web
+Hub
+
+project.
+
+In
+the
+next
+example,
+a
+
+Thing
+
+that
+represents
+interactions
+with
+a
+lock
+would
+look
+like
+the
+following:
+the
+
+status
+
+property
+and
+the
+
+open()
+
+method
+are
+directly
+exposed
+on
+the
+object.
+
+"hljs-keyword">let lock = await WoT.consume(‘https://td.my.com/lock-00123’);
+console.log(lock.status);
+lock.open(
+'withThisKey'
+
+);
+
+This
+document
+defines
+conformance
+criteria
+
+Since
+the
+direct
+mapping
+of
+
+Thing
+
+s
+to
+software
+objects
+have
+had
+some
+challenges,
+this
+specification
+takes
+another
+approach
+
+that
+apply
+
+exposes
+software
+objects
+
+to
+a
+single
+product:
+
+represent
+
+the
+UA
+(user
+agent)
+that
+implements
+
+
+Thing
+
+metadata
+as
+data
+property
+and
+
+the
+interfaces
+it
+contains.
+
+WoT
+interactions
+as
+methods.
+One
+implementation
+is
+
+node-wot
+
+in
+the
+the
+
+Eclipse
+ThingWeb
+
+project,
+which
+is
+the
+current
+reference
+implementation
+of
+the
+API
+specified
+in
+this
+document.
+
+
+This
+specification
+
+The
+same
+example
+now
+would
+look
+like
+the
+following:
+the
+
+status
+
+property
+and
+the
+
+open()
+
+method
+are
+represented
+indirectly.
+
+"hljs-keyword">let res = await fetch(‘https://td.my.com/lock-00123’);
+let td =
+"hljs-keyword">await res.json();
+let lock =
+"hljs-keyword">new ConsumedThing(td);
+
+"hljs-built_in">console.log(lock.readProperty(‘status’));
+lock.invokeAction(‘open’,
+'withThisKey'
+
+);
+
+In
+conclusion,
+the
+WoT
+WG
+decided
+to
+explore
+the
+third
+option
+that
+closely
+follows
+the
+[
+
+WOT-TD
+
+]
+specification.
+Based
+on
+this,
+a
+simple
+API
+
+can
+also
+
+be
+used
+
+implemented.
+Since
+Scripting
+is
+an
+optional
+module
+in
+WoT,
+this
+leaves
+room
+
+for
+implementing
+
+applications
+that
+only
+use
+
+the
+WoT
+Scripting
+API
+in
+multiple
+programming
+languages.
+The
+interface
+definitions
+
+network
+interface.
+Therefore
+all
+three
+approaches
+above
+
+are
+specified
+in
+
+supported
+by
+
+[
+
+WEBIDL
+
+
+WOT-TD
+
+
+
+].
+
+The
+user
+agent
+(UA)
+may
+
+Moreover,
+the
+WoT
+network
+interface
+can
+
+be
+implemented
+in
+the
+browser,
+or
+
+many
+languages
+and
+runtimes.
+Consider
+this
+API
+an
+example
+for
+what
+needs
+to
+be
+taken
+into
+consideration
+when
+designing
+a
+Scripting
+API
+for
+WoT.
+
+The
+
+fetch(url)
+
+method
+has
+been
+part
+of
+this
+API
+
+in
+earlier
+versions.
+However,
+now
+fetching
+
+a
+separate
+runtime
+environment,
+
+
+TD
+
+given
+a
+URL
+should
+be
+done
+with
+an
+external
+method,
+
+such
+as
+Node.js
+
+the
+
+Fetch
+API
+
+
+or
+small
+embedded
+runtimes.
+Implementations
+
+a
+HTTP
+client
+library,
+which
+offer
+already
+standardized
+options
+on
+specifying
+fetch
+details.
+The
+reason
+is
+
+that
+while
+simple
+fetch
+operations
+(covering
+most
+
+use
+ECMAScript
+executed
+
+cases)
+could
+be
+done
+
+in
+a
+browser
+
+this
+API,
+when
+various
+fetch
+options
+were
+needed,
+there
+was
+no
+point
+in
+duplicating
+existing
+work
+
+to
+implement
+the
+APIs
+defined
+
+re-expose
+those
+options
+
+in
+this
+document
+MUST
+implement
+them
+in
+
+API.
+
+Since
+fetching
+
+a
+manner
+consistent
+with
+the
+ECMAScript
+Bindings
+
+
+TD
+
+has
+been
+scoped
+out,
+and
+
+TD
+
+validation
+is
+
+defined
+externally
+
+in
+the
+Web
+IDL
+
+[
+
+WOT-TD
+
+],
+that
+is
+scoped
+out,
+too.
+This
+
+specification
+expects
+a
+
+TD
+
+as
+
+parsed
+JSON
+object
+
+that
+has
+been
+validated
+according
+to
+the
+
+[
+
+WEBIDL
+
+
+WOT-TD
+
+
+
+].
+
+]
+specification.
+
+
+Implementations
+
+The
+factory
+methods
+for
+consuming
+and
+exposing
+
+Thing
+
+s
+are
+asynchronous
+and
+fully
+validate
+the
+input
+
+TD
+.
+In
+addition,
+one
+can
+also
+construct
+
+ConsumedThing
+
+and
+
+ExposedThing
+
+by
+providing
+a
+parsed
+and
+validated
+
+TD
+.
+Platform
+initialization
+is
+then
+done
+when
+needed
+during
+the
+WoT
+interactions.
+So
+applications
+
+that
+use
+TypeScript
+or
+ECMAScript
+in
+
+prefer
+validating
+
+a
+runtime
+to
+implement
+
+
+TD
+
+themselves,
+may
+use
+
+the
+APIs
+defined
+in
+this
+document
+MUST
+
+constructors,
+whereas
+applications
+that
+leave
+validation
+to
+implementations
+and
+prefer
+interactions
+initialized
+up
+front
+
+SHOULD
+
+
+implement
+them
+in
+a
+manner
+consistent
+with
+
+use
+
+the
+TypeScript
+Bindings
+defined
+in
+
+factory
+methods
+on
+
+the
+TypeScript
+specification
+[
+
+
+WoT
+API
+object
+.
+Earlier +drafts +used +the + +Observer + +construct, +but +since +it +has +not +become +standard, +a +new +design +was +needed +that +was +light +enough +for +embedded +implementations. +Therefore +observing + +Property + +changes +and +handling +WoT + +Event + +s +is +done +with +callback +registrations. + +
+
+This
+document
+serves
+a
+general
+description
+of
+
+API
+ended
+up
+not
+using
+software
+events
+at
+all,
+for
+
+the
+following
+reasons:
+
+The
+reason
+to
+use
+function
+names
+like
+
+readProperty()
+
,
+readMultipleProperties()
+
+etc.
+instead
+
+of
+this
+document.
+
+a
+generic
+polymorphic
+
+read()
+
+function
+is
+that
+the
+current
+names
+map
+exactly
+to
+the
+
+"op"
+
+vocabulary
+from
+the
+
+Form
+
+definition
+in
+[
+
+WOT-TD
+
+].
+
+
+The +following +is +a +list +of +major +changes +to +the +document. +Major +versions +of +this +specification +are +the +following: +
+fetch()
+
+for
+fetching
+a
+
+TD
+
+(delegated
+to
+external
+API).
+
+Observer
+
+and
+use
+
+W3C
+
+TAG
+recommended
+design
+patterns
+.
+ThingDescription
+
+instead.
+
+ConsumedThing
+
+and
+
+ExposedThing
+
.+For +a +complete +list +of +changes, +see +the + +github +change +log +. +You +can +also +view +the + +recently +closed +issues +. +
++The +following +problems +are +being +discussed +and +need +most +attention: +
+
+ExposedThing
+
+
++"idlTypedef" data-title="ThingDescription">typedef object+ThingDescription
; + +"WOT">[SecureContext, Exposed=(Window,Worker)] +interfaceWOT
{ + // methods defined in UA conformance classes +}; +"WOT">partial interfaceWOT
{ + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<ConsumedThing
>consume
(ThingDescription
td); +}; + +"WOT">partial interfaceWOT
{ + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<ExposedThing
>produce
(ThingDescription
td); +}; + +"WOT">partial interfaceWOT
{ + +"internalDFN" data-link-type= +"idl">ThingDiscovery
discover
(optionalThingFilter
filter = null); +}; + +"ConsumedThing">[SecureContext, Exposed=(Window,Worker)] +interfaceConsumedThing
{ + +"constructor" data-title="constructor" data-dfn-for="ConsumedThing" +data-lt= +"ConsumedThing.constructor()|ConsumedThing.constructor|constructor()|constructor">constructor
(ThingDescription
td); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<any
>readProperty
(DOMString
propertyName, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<PropertyMap
>readAllProperties
(optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<PropertyMap
>readMultipleProperties
( + +"" data-type="dfn" href= +"https://heycam.github.io/webidl/#idl-sequence">sequence<DOMString
> propertyNames, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>writeProperty
(DOMString
propertyName, + +data-link-type="dfn" href= +"https://heycam.github.io/webidl/#idl-any">any
value, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>writeMultipleProperties
(PropertyMap
valueMap, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<any
>invokeAction
(DOMString
actionName, + optionalany
params = null, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>observeProperty
(DOMString
name, + +"#dom-wotlistener" class="internalDFN" data-link-type= +"idl">WotListener
listener, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unobserveProperty
(DOMString
name); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>subscribeEvent
(DOMString
name, + +"#dom-wotlistener" class="internalDFN" data-link-type= +"idl">WotListener
listener, + optionalInteractionOptions
options = null); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>unsubscribeEvent
(DOMString
name); + +"internalDFN" data-link-type= +"idl">ThingDescription
getThingDescription
(); +}; +dictionaryInteractionOptions
{ + +"interface" href= +"https://heycam.github.io/webidl/#idl-object">objecturiVariables
; +}; +typedef objectPropertyMap
; +callbackWotListener
= void(any
data); + +"ExposedThing">[SecureContext, Exposed=(Window,Worker)] +interfaceExposedThing
:ConsumedThing
{ + +"internalDFN" data-link-type= +"idl">ExposedThing
setPropertyReadHandler
(DOMString
name, + +class="internalDFN" data-link-type= +"idl">PropertyReadHandler
readHandler); + +"internalDFN" data-link-type= +"idl">ExposedThing
setPropertyWriteHandler
(DOMString
name, + +"#dom-propertywritehandler" class="internalDFN" data-link-type= +"idl">PropertyWriteHandler
writeHandler); + +"internalDFN" data-link-type= +"idl">ExposedThing
setActionHandler
(DOMString
name,ActionHandler
action); + +href= +"https://heycam.github.io/webidl/#idl-void">voidemitEvent
(DOMString
name,any
data); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>expose
(); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<void>destroy
(); +}; +callbackPropertyReadHandler
= Promise<any
>( + optionalInteractionOptions
options = null); +callbackPropertyWriteHandler
= Promise<void>(any
value, + optionalInteractionOptions
options = null); +callbackActionHandler
= Promise<any
>(any
params, + optionalInteractionOptions
options = null); + +"ThingDiscovery">[SecureContext, Exposed=(Window,Worker)] +interfaceThingDiscovery
{ + +"constructor" data-title="constructor" data-dfn-for= +"ThingDiscovery" data-lt= +"ThingDiscovery.constructor()|ThingDiscovery.constructor|constructor()|constructor">constructor
(optionalThingFilter
filter = null); + readonly attributeThingFilter
?filter
; + readonly attribute booleanactive
; + readonly attribute booleandone
; + readonly attribute Error?error
; + +href= +"https://heycam.github.io/webidl/#idl-void">voidstart
(); + +"interface" href= +"https://heycam.github.io/webidl/#idl-promise">Promise<ThingDescription
>next
(); + +href= +"https://heycam.github.io/webidl/#idl-void">voidstop
(); +}; + +"DiscoveryMethod">typedefDOMString
DiscoveryMethod
; + +"ThingFilter">dictionaryThingFilter
{ + (DiscoveryMethod
orDOMString
)method
= "any"; + +href= +"https://heycam.github.io/webidl/#idl-USVString">USVString?url
; + +href= +"https://heycam.github.io/webidl/#idl-USVString">USVString?query
; + +"interface" href= +"https://heycam.github.io/webidl/#idl-object">object?fragment
; +}; + + +Acknowledgments ++
+Special
+thanks
+to
+former
+editor
+Johannes
+Hund
+(until
+August
+2017,
+when
+at
+Siemens
+AG)
+and
+Kazuaki
+Nimura
+(until
+December
+2018)
+
+for
+developing
+this
+specification.
+Also,
+the
+editors
+would
+like
+to
+thank
+Dave
+Raggett,
+Matthias
+Kovatsch,
+Michael
+Koster
+and
+
+Koster,
+Elena
+Reshetova,
+
+Michael
+McCool
+as
+well
+as
+the
+other
+WoT
+WG
+members
+
+for
+their
+comments
+
+comments,
+contributions
+
+and
+guidance.
+