Разбор протокола World Of Tanks

Разбор протокола World Of Tanks World of Tanks

Handling interaction data

As specified in the
Web of Things Thing Description specification,
WoT
interactions extend DataSchema and include a number
of possible Forms, out of
which one is selected for the interaction.

The
Form contains a contentType to describe the
data. For certain content types, a DataSchema is defined, based on
JSON Schema, making
possible to represent these contents as JavaScript types and
eventually set range constraints on the data.

6.1 The InteractionInput type

typedefanyDataSchemaValue;
typedef (ReadableStream 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.

6.2 The InteractionOutput interface

Belongs to the WoT Consumer conformance
class. An InteractionOutput
object is always created by the implementations and exposes
the data returned from WoT Interactions to
application scripts.

This interface exposes a convenience function which should
cover the vast majority of IoT use cases: the value() function. Its
implementation will inspect the data, parse it if adheres to
a DataSchema, or otherwise fail
early, leaving the underlying stream undisturbed so that
application scripts could attempt reading the stream
themselves, or handling the data as ArrayBuffer.

[SecureContext, Exposed=(Window,Worker)]
interface InteractionOutput {
  readonly attributeReadableStream?data;
  readonly attributebooleandataUsed;
  readonly attributeForm?form;
  readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value();
};

The data property
represents the raw payload in WoT Interactions as a
ReadableStream,
initially null.

The dataUsed
property tells whether the data stream has been
disturbed
. Initially false.

The form attribute
represents the Form
selected from the Thing Description for
this WoT
Interaction
, initially null.

The schema
attribute represents the DataSchema (defined in
[WoT-TD]) of the
payload as a JSON
object, initially null.

The [[value]] internal slot represents the
parsed value of the WoT Interaction,
initially undefined (note that null
is a valid value).

6.2.1 The
value()
function

Parses
the data returned by the WoT Interaction and
returns a value with the type described by the interaction
DataSchema if that exists,
or by the contentType of the interaction
Form. The method
MUST run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If the value of the [[value]]
    internal slot
    is not undefined,
    resolve promise with
    that value and abort these steps.
  3. If the value of the data property is not a

    ReadableStream
    or if dataUsed is
    true, or if form is
    null or if schema or its
    type are null or
    undefined, reject promise with
    NotReadableError
    and abort these steps.
  4. If form‘s contentType is not
    application/json and if a mapping is not
    available in the Protocol Bindings
    from form‘s contentType to
    [JSON-SCHEMA],
    reject promise with

    NotSupportedError
    and abort these steps.
  5. Let reader be the result of getting
    a reader
    from data. If that threw an
    exception, reject promise
    with that exception and abort these steps.
  6. Let bytes be the result of
    reading all bytes
    from data with
    reader.
  7. Set dataUsed to true.
  8. If form‘s contentType is not
    application/json and if a mapping is
    available in the Protocol Bindings
    from form‘s contentType to
    [JSON-SCHEMA],
    transform bytes with that mapping.
  9. Let json be the result of running
    parse
    JSON from bytes
    on bytes. If that throws,
    reject promise with that
    exception and abort these steps.
  10. Set [[value]] to the result of
    running check data schema
    on json and schema. If that throws,
    reject promise with that
    exception and abort these steps.
  11. Resolve promise with
    [[value]].

6.2.2 The arrayBuffer() function

When invoked,
MUST run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If data is not
    ReadableStream
    or if dataUsed is
    true, reject promise with
    NotReadableError
    and abort these steps.
  3. Let reader be the result of getting
    a reader
    from data. If that threw an
    exception, reject promise
    with that exception and abort these steps.
  4. Let bytes be the result of
    reading all bytes
    from data with
    reader.
  5. Set dataUsed to true.
  6. Let arrayBuffer be a new

    ArrayBuffer
    whose contents are
    bytes. If that throws, reject
    promise with that
    exception and abort these steps.
  7. Resolve promise with
    arrayBuffer.

6.2.3 The check data schema
algorithm

To run the
check data schema
steps on payload and schema,

  1. Let type be schema‘s type.
  2. If type is "null" and if
    payload is not null, throw
    TypeError and abort these steps,
    otherwise return null.
  3. If type is "boolean" and
    payload is a falsey value or its byte length
    is 0, return false, otherwise return
    true.
  4. If type is "integer" or
    "number",
    1. If payload is not a number, throw
      TypeError and abort these steps.
    2. If form‘s minimum is
      defined and payload is smaller, or if
      form‘s maximum is defined and
      payload is bigger, throw
      RangeError and abort these steps.
  5. If type is "string", return
    payload.
  6. If type is "array", run these
    sub-steps:
    1. If payload is not an array, throw
      TypeError and abort these steps.
    2. If form‘s minItems is
      defined and payload‘s length is
      less than that, or if form‘s
      maxItems is defined and
      payload‘s length is more than
      that, throw RangeError and abort these steps.
    3. Let payload be an array of items
      obtained by running the check data
      schema
      steps on each element item of
      payload and schema‘s items. If this
      throws at any stage, re-throw that exception and
      abort these steps.
  7. If type is "object", run
    these sub-steps:
    1. If payload or
      schema
      ‘s properties is not an
      object, throw TypeError and abort these steps.
    2. For each property key in
      payload,
      1. Let prop be the value of
        key.
      2. Let propSchema be the value of
        key in interaction‘s
        properties.
      3. Let prop be the result of running
        the check data
        schema
        steps on prop and
        propSchema. If this throws, re-throw
        that exception and abort these steps.
    3. Let required be schema‘s required if that
      is an array or an empty array otherwise.
    4. For each key in required,
      if key is not present in
      payload, throw
      SyntaxError
      and abort these steps.
  8. Return payload.

6.2.4 The create interaction
request
algorithm

For a
given ConsumedThing
object thing, in order
to create
interaction request
given a source, form and schema,
run these steps:

  1. Let idata be a new an InteractionOutput
    object whose form is set to
    form, whose schema is set to
    schema
    , whose [[value]]
    internal slot
    is undefined and whose
    data is null.
  2. If source is
    a
    ReadableStream
    object, let
    idata‘s data be source, return
    idata and abort these steps.
  3. If schema and its
    type
    are defined and not null, run
    these sub-steps:
    1. If type is "null" and
      source is
      not, throw TypeError and abort these steps.
    2. If type is "boolean" and
      source is a
      falsy value, set idata‘s [[value]]
      value to false, otherwise to
      true.
    3. If type is "integer" or
      "number" and source is not a number, or
      if form‘s
      minimum is defined and source is smaller, or if
      form‘s maximum
      is defined and source is bigger, throw
      RangeError and abort these steps.
    4. If type is "string" and
      source is not
      a string, let idata‘s [[value]] be the
      result of running
      serialize JSON to bytes
      on source. If that is
      failure, throw
      SyntaxError
      and abort these steps.
    5. If type is "array", run
      these sub-steps:
      1. If source is not an array,
        throw a TypeError and abort these
        steps.
      2. Let length be the length of
        source.
      3. If form‘s
        minItems is defined and
        length is less than that, or if
        form‘s
        maxItems is defined and
        length is more than that, throw
        RangeError and abort these
        steps.
      4. For each item in source, let
        itemschema be
        schema
        ‘s items and let
        item be the result of running the
        create
        interaction request
        steps on
        item, form and itemschema. If
        this throws, re-throw that exception and abort
        these steps.
      5. Set data‘s [[value]] to
        source.
    6. If type is "object", run
      these sub-steps:
      1. If source is not an object,
        throw TypeError and abort these
        steps.
      2. If schema‘s
        properties is not an object, throw
        TypeError and abort these
        steps.
      3. For each property key in
        source,
        1. Let value be the value of
          key.
        2. Let propschema be the value of
          key in properties.
        3. Let value be the result of
          running the create
          interaction request
          steps on
          value, form and propschema.
          If this throws, re-throw that exception and
          abort these steps.
      4. If schema‘s
        required is an array, for each
        item in required check if
        item is a property name in
        source.
        If an item is not found in
        source,
        throw
        SyntaxError
        and abort these steps.
      5. Set data‘s [[value]] to
        source.
  4. Set idata‘s data to a new

    ReadableStream
    created from
    idata‘s [[value]]
    internal slot
    as its underlying
    source
    .
  5. Return idata.
Про WoT:  Понимание коэффициента резервуарного парка: подробное руководство

6.2.5 The parse interaction
response
algorithm

For a
given ConsumedThing
object thing, in order
to parse
interaction response
given response,
form and schema, run these steps:

  1. Let result be a new InteractionOutput
    object.
  2. Let result‘s schema be schema.
  3. Let result‘s form be form.
  4. Let result‘s data be a new

    ReadableStream
    with the payload data of
    response as its underlying
    source
    .
  5. Let result‘s dataUsed be
    false.
  6. Return result.

As illustrated in the next pictures, the
InteractionOutput
interface is used every time implementations provide data to
scripts, while InteractionInput
is used when the scripts pass data to the implementation.

Разбор протокола World Of Tanks
Figure 1Data structures used when reading data

When a ConsumedThing
reads data, it receives it from the implementation as an
InteractionOutput
object.

An ExposedThingread handler
provides the read data to the implementation as
InteractionInput.

Разбор протокола World Of Tanks
Figure 2Data structures used when writing data

When a ConsumedThing
writes data, it provides it to the implementation as
InteractionInput.

An ExposedThingwrite
handler
receives data from to implementation as an
InteractionOutput
object.

Разбор протокола World Of Tanks
Figure 3Data structures used when invoking an
Action

When a ConsumedThing
invokes an Action
data, it provides the parameters as InteractionInput
and receives the output of the Action as an InteractionOutput
object.

An ExposedThingaction handler
receives arguments from the implementation as an
InteractionOutput
object and provides Action output as
InteractionInput
to the implementation.

6.4
Error handling

The algorithms in this API define the errors to be
reported to application scripts.

The errors reported to the other communication end are
mapped and encapsulated by the Protocol
Bindings
.

Разбор протокола World Of Tanks
Figure 4Error handling in WoT interactions

2 The InteractionOutput interface

Belongs to the WoT Consumer conformance
class. An InteractionOutput
object is always created by the implementations and exposes
the data returned from WoT Interactions to
application scripts.

This interface exposes a convenience function which should
cover the vast majority of IoT use cases: the value() function. Its
implementation will inspect the data, parse it if adheres to
a DataSchema, or otherwise fail
early, leaving the underlying stream undisturbed so that
application scripts could attempt reading the stream
themselves, or handling the data as ArrayBuffer.

[SecureContext, Exposed=(Window,Worker)]
interface InteractionOutput {
  readonly attributeReadableStream?data;
  readonly attributebooleandataUsed;
  readonly attributeForm?form;
  readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value();
};

The data property
represents the raw payload in WoT Interactions as a
ReadableStream,
initially null.

The dataUsed
property tells whether the data stream has been
disturbed. Initially false.

The form attribute
represents the Form
selected from the Thing Description for
this WoT
Interaction, initially null.

The schema
attribute represents the DataSchema (defined in
[WoT-TD]) of the
payload as a JSON
object, initially null.

The [[value]] internal slot represents the
parsed value of the WoT Interaction,
initially undefined (note that null
is a valid value).

6.2.1 The
value()
function

Parses
the data returned by the WoT Interaction and
returns a value with the type described by the interaction
DataSchema if that exists,
or by the contentType of the interaction
Form. The method
MUST run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If the value of the [[value]]
    internal slot
    is not undefined,
    resolve promise with
    that value and abort these steps.
  3. If the value of the data property is not a

    ReadableStream
    or if dataUsed is
    true, or if form is
    null or if schema or its
    type are null or
    undefined, reject promise with
    NotReadableError
    and abort these steps.
  4. If form‘s contentType is not
    application/json and if a mapping is not
    available in the Protocol Bindings
    from form‘s contentType to
    [JSON-SCHEMA],
    reject promise with

    NotSupportedError
    and abort these steps.
  5. Let reader be the result of getting
    a reader
    from data. If that threw an
    exception, reject promise
    with that exception and abort these steps.
  6. Let bytes be the result of
    reading all bytes
    from data with
    reader.
  7. Set dataUsed to true.
  8. If form‘s contentType is not
    application/json and if a mapping is
    available in the Protocol Bindings
    from form‘s contentType to
    [JSON-SCHEMA],
    transform bytes with that mapping.
  9. Let json be the result of running
    parse
    JSON from bytes
    on bytes. If that throws,
    reject promise with that
    exception and abort these steps.
  10. Set [[value]] to the result of
    running check data schema
    on json and schema. If that throws,
    reject promise with that
    exception and abort these steps.
  11. Resolve promise with
    [[value]].

6.2.2 The arrayBuffer() function

When invoked,
MUST run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If data is not
    ReadableStream
    or if dataUsed is
    true, reject promise with
    NotReadableError
    and abort these steps.
  3. Let reader be the result of getting
    a reader
    from data. If that threw an
    exception, reject promise
    with that exception and abort these steps.
  4. Let bytes be the result of
    reading all bytes
    from data with
    reader.
  5. Set dataUsed to true.
  6. Let arrayBuffer be a new

    ArrayBuffer
    whose contents are
    bytes. If that throws, reject
    promise with that
    exception and abort these steps.
  7. Resolve promise with
    arrayBuffer.

6.2.3 The check data schema
algorithm

To run the
check data schema
steps on payload and schema,

  1. Let type be schema‘s type.
  2. If type is "null" and if
    payload is not null, throw
    TypeError and abort these steps,
    otherwise return null.
  3. If type is "boolean" and
    payload is a falsey value or its byte length
    is 0, return false, otherwise return
    true.
  4. If type is "integer" or
    "number",
    1. If payload is not a number, throw
      TypeError and abort these steps.
    2. If form‘s minimum is
      defined and payload is smaller, or if
      form‘s maximum is defined and
      payload is bigger, throw
      RangeError and abort these steps.
  5. If type is "string", return
    payload.
  6. If type is "array", run these
    sub-steps:
    1. If payload is not an array, throw
      TypeError and abort these steps.
    2. If form‘s minItems is
      defined and payload‘s length is
      less than that, or if form‘s
      maxItems is defined and
      payload‘s length is more than
      that, throw RangeError and abort these steps.
    3. Let payload be an array of items
      obtained by running the check data
      schema
      steps on each element item of
      payload and schema‘s items. If this
      throws at any stage, re-throw that exception and
      abort these steps.
  7. If type is "object", run
    these sub-steps:
    1. If payload or
      schema
      ‘s properties is not an
      object, throw TypeError and abort these steps.
    2. For each property key in
      payload,
      1. Let prop be the value of
        key.
      2. Let propSchema be the value of
        key in interaction‘s
        properties.
      3. Let prop be the result of running
        the check data
        schema
        steps on prop and
        propSchema. If this throws, re-throw
        that exception and abort these steps.
    3. Let required be schema‘s required if that
      is an array or an empty array otherwise.
    4. For each key in required,
      if key is not present in
      payload, throw
      SyntaxError
      and abort these steps.
  8. Return payload.

6.2.4 The create interaction
request
algorithm

For a
given ConsumedThing
object thing, in order
to create
interaction request
given a source, form and schema,
run these steps:

  1. Let idata be a new an InteractionOutput
    object whose form is set to
    form, whose schema is set to
    schema
    , whose [[value]]
    internal slot
    is undefined and whose
    data is null.
  2. If source is
    a
    ReadableStream
    object, let
    idata‘s data be source, return
    idata and abort these steps.
  3. If schema and its
    type
    are defined and not null, run
    these sub-steps:
    1. If type is "null" and
      source is
      not, throw TypeError and abort these steps.
    2. If type is "boolean" and
      source is a
      falsy value, set idata‘s [[value]]
      value to false, otherwise to
      true.
    3. If type is "integer" or
      "number" and source is not a number, or
      if form‘s
      minimum is defined and source is smaller, or if
      form‘s maximum
      is defined and source is bigger, throw
      RangeError and abort these steps.
    4. If type is "string" and
      source is not
      a string, let idata‘s [[value]] be the
      result of running
      serialize JSON to bytes
      on source. If that is
      failure, throw
      SyntaxError
      and abort these steps.
    5. If type is "array", run
      these sub-steps:
      1. If source is not an array,
        throw a TypeError and abort these
        steps.
      2. Let length be the length of
        source.
      3. If form‘s
        minItems is defined and
        length is less than that, or if
        form‘s
        maxItems is defined and
        length is more than that, throw
        RangeError and abort these
        steps.
      4. For each item in source, let
        itemschema be
        schema
        ‘s items and let
        item be the result of running the
        create
        interaction request
        steps on
        item, form and itemschema. If
        this throws, re-throw that exception and abort
        these steps.
      5. Set data‘s [[value]] to
        source.
    6. If type is "object", run
      these sub-steps:
      1. If source is not an object,
        throw TypeError and abort these
        steps.
      2. If schema‘s
        properties is not an object, throw
        TypeError and abort these
        steps.
      3. For each property key in
        source,
        1. Let value be the value of
          key.
        2. Let propschema be the value of
          key in properties.
        3. Let value be the result of
          running the create
          interaction request
          steps on
          value, form and propschema.
          If this throws, re-throw that exception and
          abort these steps.
      4. If schema‘s
        required is an array, for each
        item in required check if
        item is a property name in
        source.
        If an item is not found in
        source,
        throw
        SyntaxError
        and abort these steps.
      5. Set data‘s [[value]] to
        source.
  4. Set idata‘s data to a new

    ReadableStream
    created from
    idata‘s [[value]]
    internal slot
    as its underlying
    source
    .
  5. Return idata.
Про WoT:  ТАНК КВ 1 ЭКРАНИРОВАННЫЙ

6.2.5 The parse interaction
response
algorithm

For a
given ConsumedThing
object thing, in order
to parse
interaction response
given response,
form and schema, run these steps:

  1. Let result be a new InteractionOutput
    object.
  2. Let result‘s schema be schema.
  3. Let result‘s form be form.
  4. Let result‘s data be a new

    ReadableStream
    with the payload data of
    response as its underlying
    source
    .
  5. Let result‘s dataUsed be
    false.
  6. Return result.

The ConsumedThing interface

Represents a client API to operate a Thing. Belongs to the WoT Consumer conformance
class.

[SecureContext, Exposed=(Window,Worker)]
interface ConsumedThing {constructor(ThingDescriptiontd);Promise<InteractionOutput>readProperty(DOMStringpropertyName,
                              optionalInteractionOptionsoptions = null);Promise<PropertyMap>readAllProperties(optionalInteractionOptionsoptions = null);Promise<PropertyMap>readMultipleProperties(sequence<DOMString>propertyNames,
                              optionalInteractionOptionsoptions = null);Promise<undefined>writeProperty(DOMStringpropertyName,InteractionInputvalue,
                              optionalInteractionOptionsoptions = null);Promise<undefined>writeMultipleProperties(PropertyMapvalueMap,
                              optionalInteractionOptionsoptions = null);Promise<InteractionOutput>invokeAction(DOMStringactionName,
                              optionalInteractionInputparams = null,
                              optionalInteractionOptionsoptions = null);Promise<Subscription>observeProperty(DOMStringname,InteractionListenerlistener,
                              optionalErrorListeneronerror,
                              optionalInteractionOptionsoptions = null);Promise<Subscription>subscribeEvent(DOMStringname,InteractionListenerlistener,
                              optionalErrorListeneronerror,
                              optionalInteractionOptionsoptions = null);ThingDescriptiongetThingDescription();
};

dictionary InteractionOptions {unsigned longformIndex;objecturiVariables;anydata;
};

[SecureContext, Exposed=(Window,Worker)]
interface Subscription {
  readonly attributebooleanactive;Promise<undefined>stop(optionalInteractionOptionsoptions = null);
};

typedefobjectPropertyMap;

callback InteractionListener =undefined(InteractionOutputdata);
callback ErrorListener =undefined(Errorerror);

7.1 Internal slots for ConsumedThing

A ConsumedThing
object has the following
internal slots
:

7.2 Constructing
ConsumedThing

After fetching
a Thing Description as
a JSON object, one can create a ConsumedThing
object.

7.3 The getThingDescription() method

Returns the
internal slot
[[td]] of the ConsumedThing
object that represents the Thing Description of
the ConsumedThing.
Applications may consult the Thing metadata stored in [[td]]
in order to introspect its capabilities before interacting
with it.

7.4 The readProperty() method

7.5 The readMultipleProperties() method

Reads multiple

Property

values with one
request. Takes as arguments

propertyNames

and optionally

options

. It
returns a

Promise

that resolves with a

PropertyMap

object that maps keys from

propertyNames

to values returned by
this algorithm. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. If option‘s formIndex is
    defined, let form be the Form associated with
    formIndex in [[td]]’s forms array,
    otherwise let form be a Form in [[td]]’s
    forms array whose op is
    readmultipleproperties, selected by the
    implementation.
  4. If form is failure, reject
    promise with a
    SyntaxError
    and abort these steps.
  5. Let result be an object
    and for each string name in
    propertyNames add
    a property with key name
    and the value null.
  6. Make a request to the underlying platform (via the
    Protocol Bindings)
    to retrieve the Property values given by
    propertyNames with
    form and optional URI templates given in
    options
    uriVariables
    .
  7. If this cannot be done with a single request with the
    Protocol Bindings,
    reject promise with a

    NotSupportedError
    and abort these steps.
  8. Process the response and for each key in
    result, run the following
    sub-steps:
    1. Let value be the value of
      result‘s
      key.
    2. Let schema be the value of [[td]]’s
      properties‘s key.
    3. Let property be the result of running
      parse
      interaction response
      on value,
      form and schema.
  9. If the above step throws at any point, reject
    promise with that
    exception and abort these steps.
  10. Resolve promise with
    result.

7.6 The readAllProperties() method

Reads all properties of the

Thing

with one request. Takes

options

as
optional argument. It returns a

Promise

that resolves with a

PropertyMap

object that maps keys from

Property

names to values
returned by this algorithm. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. If option‘s formIndex is
    defined, let form be the Form associated with
    formIndex in [[td]]’s forms array,
    otherwise let form be a Form in [[td]]’s
    forms array whose op is
    readallproperties, selected by the
    implementation.
  4. If form is failure, reject
    promise with a
    SyntaxError
    and abort these steps.
  5. Make a request to the underlying platform (via the
    Protocol Bindings)
    to retrieve the value of the all the Property
    definitions from the TD with form and
    optional URI templates given in options
    uriVariables.
  6. If this cannot be done with a single request with the
    Protocol Bindings
    of the Thing, then reject
    promise with a

    NotSupportedError
    and abort these steps.
  7. If the request fails, reject promise with the error received from the
    Protocol Bindings
    and abort these steps.
  8. Process the reply and let result be an object with the keys and
    values obtained in the reply.
  9. Process the response and for each key in
    result, run the following
    sub-steps:
    1. Let value be the value of
      result‘s
      key.
    2. Let schema be the value of [[td]]’s
      properties‘s key.
    3. Let property be the result of running
      parse
      interaction response
      on value,
      form and schema.
  10. Resolve promise with
    result.

7.7 The writeProperty() method

Writes a single

Property

. Takes as
arguments

propertyName

,

value

and
optionally

options

. It returns a

Promise

that resolves on success and rejects on failure. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. Let interaction be the value of [[td]]’s
    properties‘s propertyName.
  4. If option‘s formIndex is
    defined, let form be the Form associated with
    formIndex in interaction‘s
    forms array, otherwise let form be
    a Form
    in interaction‘s forms whose
    op is writeproperty, selected
    by the implementation.
  5. If form is failure, reject
    promise with a
    SyntaxError
    and abort these steps.
  6. Let data be the result of running the
    create
    interaction request
    steps on value, form and
    interaction
    . If that throws, reject
    promise
    with that exception and abort these steps.
  7. Make a request to the underlying platform (via the
    Protocol Bindings)
    to write the Property given by
    propertyName using
    data and the
    optional URI templates given in options
    uriVariables.
  8. If the request fails, reject promise with the error received from the
    Protocol Bindings
    and abort these steps.
  9. Otherwise resolve promise.

7.8 The writeMultipleProperties() method

Writes a multiple

Property

values with one
request. Takes as arguments

properties

— as an object with keys being

Про WoT:  Меч в камне и оружие Карла Великого: легендарные клинки, которые оставили след в истории - Интересное в сети! — LiveJournal

Property

names and values
as

Property

values — and
optionally

options

. It returns a

Promise

that resolves on success and rejects on failure. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. If option‘s formIndex is
    defined, let form be the Form associated with
    formIndex in [[td]]’s forms array,
    otherwise let form be a Form in [[td]]’s
    forms array whose op is
    writemultipleproperties, selected by the
    implementation.
  4. If form is failure, reject
    promise with a
    SyntaxError
    and abort these steps.
  5. Let propertyNames be an array of
    string with as elements the keys of the
    properties object.
  6. For each name in
    propertyNames
    , let property be the
    value of [[td]]’s properties‘s name. If property is
    null or undefined or is not
    writeable reject promise with
    NotSupportedError
    and abort these steps.
  7. Let result be an object
    and for each string name in
    propertyNames add a property with key
    name and let its value be
    null.
  8. Let schemas be an
    object and for each string name in propertyNames add a
    property with key name and
    let its value be the value of [[td]]’s properties‘s name.
  9. For each key key in
    properties, take its value
    as value and run the create
    interaction request
    steps on value,
    form
    and the value for schema‘s
    key. If that throws for
    any name, reject
    promise
    with that exception and abort these steps.
  10. Make a single request to the underlying platform (via
    the Protocol
    Bindings
    ) to write each Property provided in
    properties with optional
    URI templates given in options
    uriVariables.
  11. If this cannot be done with a single request with the
    Protocol Bindings
    of the Thing, then reject
    promise with a

    NotSupportedError
    and abort these steps.
  12. If the request fails, return the error received from
    the Protocol
    Bindings
    and abort these steps.
  13. Otherwise resolve promise.

7.9 The observeProperty() method

7.10 The invokeAction() method

Makes a request for invoking an

Action

and return the result.
Takes as arguments

actionName

, optionally

params

and optionally

options

. It
returns a

Promise

that resolves with the result of the

Action

represented as an

InteractionOutput

object, or rejects with an error. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. Let interaction be the value of [[td]]’s
    actions‘s actionName.
  4. If option‘s formIndex is
    defined, let form be the Form associated with
    formIndex in interaction‘s
    forms array, otherwise let form be
    a Form
    in interaction‘s forms array
    whose op is invokeaction,
    selected by the implementation.
  5. If form is failure, reject
    promise with a
    SyntaxError
    and abort these steps.
  6. Let args be the result of running the
    create
    interaction request
    steps on params, form and
    interaction. If that throws, reject
    promise
    with that exception and abort these steps.
  7. Make a request to the underlying platform (via the
    Protocol Bindings)
    to invoke the Action identified by
    actionName with
    parameters provided in args and optional URI
    templates given in options‘s
    uriVariables.
  8. If the request fails locally or returns an error over
    the network, reject promise with the error received from the
    Protocol Bindings
    and abort these steps.
  9. Let value be the reply returned in the
    reply.
  10. Let result be the result of running
    parse
    interaction response
    with value,
    form and interaction. If that
    throws, reject promise
    with that exception and abort these steps.
  11. Resolve promise with
    result.

7.11 The subscribeEvent() method

Makes a request for subscribing to

Event

notifications. Takes as
arguments

eventName

,

listener

and optionally

onerror

and

options

. It
returns a

Promise

to signal success or failure. The method

MUST

run the following steps:

  1. Return a Promisepromise and execute the
    next steps in
    parallel
    .
  2. If invoking this method is not allowed for the
    current scripting context for security reasons, reject
    promise with a
    SecurityError
    and abort these steps.
  3. If listener is not
    a Function,
    reject promise with a
    TypeError and abort these steps.
  4. If onerror is
    not null and is not a Function,
    reject promise with a
    TypeError and abort these steps.
  5. Let subscription be a new
    Subscription
    object with its
    internal slots
    set as follows:
  6. Make a request to the underlying platform via the
    Protocol Bindings
    to subscribe to an Event identified by
    eventName with [[form]],
    optional URI templates given in options
    uriVariables and optional subscription data
    given in options‘s data.
  7. If the request fails, reject promise with the error received from the
    Protocol Bindings
    and abort these steps.
  8. Otherwise resolve promise.
  9. Whenever the underlying platform detects a
    notification for this Event subscription, run the
    following sub-steps:
    1. Invoke listener with the result of
      running parse
      interaction response
      on the data provided with
      the Event, [[form]] and
      [[interaction]].
  10. Whenever the underlying platform detects an error for
    this subscription, run the following sub-steps:

7.12 The InteractionOptions dictionary

Holds the interaction options that need to be exposed for
application scripts according to the Thing
Description
.

The formIndex
property, if defined, represents an application hint for
which Form definition, identified by this index,
of the TD to use
for the given WoT interaction. Implementations SHOULD use the Form with this
index for making the interaction, but MAY override this value if the index is not
found or not valid. If not defined, implementations
SHOULD attempt to use the
Form definitions in order of appearance as
listed in the TD for the
given Wot Interaction.

The uriVariables property
if defined, represents the URI template variables to be used
with the WoT Interaction that are represented as parsed
JSON objects
defined in [WOT-TD].

The data property if defined, represents
additional opaque data that needs to be passed to the
interaction.

7.13 The PropertyMap
type

Represents a map of Property names as strings to
a value that the Property can take. It is used
as a property bag for interactions that involve multiple
Properties at
once.

C. full web
idl

typedefobjectThingDescription;[SecureContext, Exposed=(Window,Worker)]
namespace WOT {};partial namespace WOT {Promise<ConsumedThing>consume(ThingDescriptiontd);
};partial namespace WOT {Promise<ExposedThing>produce(ThingDescriptiontd);
};partial namespace WOT {ThingDiscoverydiscover(optionalThingFilterfilter = null);
};typedefanyDataSchemaValue;
typedef (ReadableStream or DataSchemaValue)InteractionInput;[SecureContext, Exposed=(Window,Worker)]
interface InteractionOutput {
  readonly attributeReadableStream?data;
  readonly attributebooleandataUsed;
  readonly attributeForm?form;
  readonly attributeDataSchema?schema;Promise<ArrayBuffer>arrayBuffer();Promise<any>value();
};[SecureContext, Exposed=(Window,Worker)]
interface ConsumedThing {constructor(ThingDescriptiontd);Promise<InteractionOutput>readProperty(DOMStringpropertyName,
                              optionalInteractionOptionsoptions = null);Promise<PropertyMap>readAllProperties(optionalInteractionOptionsoptions = null);Promise<PropertyMap>readMultipleProperties(sequence<DOMString>propertyNames,
                              optionalInteractionOptionsoptions = null);Promise<undefined>writeProperty(DOMStringpropertyName,InteractionInputvalue,
                              optionalInteractionOptionsoptions = null);Promise<undefined>writeMultipleProperties(PropertyMapvalueMap,
                              optionalInteractionOptionsoptions = null);Promise<InteractionOutput>invokeAction(DOMStringactionName,
                              optionalInteractionInputparams = null,
                              optionalInteractionOptionsoptions = null);Promise<Subscription>observeProperty(DOMStringname,InteractionListenerlistener,
                              optionalErrorListeneronerror,
                              optionalInteractionOptionsoptions = null);Promise<Subscription>subscribeEvent(DOMStringname,InteractionListenerlistener,
                              optionalErrorListeneronerror,
                              optionalInteractionOptionsoptions = null);ThingDescriptiongetThingDescription();
};

dictionary InteractionOptions {unsigned longformIndex;objecturiVariables;anydata;
};

[SecureContext, Exposed=(Window,Worker)]
interface Subscription {
  readonly attributebooleanactive;Promise<undefined>stop(optionalInteractionOptionsoptions = null);
};

typedefobjectPropertyMap;

callback InteractionListener =undefined(InteractionOutputdata);
callback ErrorListener =undefined(Errorerror);[SecureContext, Exposed=(Window,Worker)]
interface ExposedThing {ExposedThingsetPropertyReadHandler(DOMStringname,PropertyReadHandlerhandler);ExposedThingsetPropertyWriteHandler(DOMStringname,PropertyWriteHandlerhandler);ExposedThingsetPropertyObserveHandler(DOMStringname,PropertyReadHandlerhandler);ExposedThingsetPropertyUnobserveHandler(DOMStringname,PropertyReadHandlerhandler);Promise<undefined>emitPropertyChange(DOMStringname);ExposedThingsetActionHandler(DOMStringname,ActionHandleraction);ExposedThingsetEventSubscribeHandler(DOMStringname,EventSubscriptionHandlerhandler);ExposedThingsetEventUnsubscribeHandler(DOMStringname,EventSubscriptionHandlerhandler);ExposedThingsetEventHandler(DOMStringname,EventListenerHandlereventHandler);Promise<undefined>emitEvent(DOMStringname,InteractionInputdata);Promise<undefined>expose();Promise<undefined>destroy();ThingDescriptiongetThingDescription();
};

callback PropertyReadHandler =Promise<any>(
        optionalInteractionOptionsoptions = null);

callback PropertyWriteHandler =Promise<undefined>(InteractionOutputvalue,
        optionalInteractionOptionsoptions = null);

callback ActionHandler =Promise<InteractionInput>(InteractionOutputparams,
        optionalInteractionOptionsoptions = null);

callback EventSubscriptionHandler =Promise<undefined>(
        optionalInteractionOptionsoptions = null);

callback EventListenerHandler =Promise<InteractionInput>();[SecureContext, Exposed=(Window,Worker)]
interface ThingDiscovery {constructor(optionalThingFilterfilter = null);
  readonly attributeThingFilter?filter;
  readonly attributebooleanactive;
  readonly attributebooleandone;
  readonly attributeError?error;undefinedstart();Promise<ThingDescription>next();undefinedstop();
};typedefDOMStringDiscoveryMethod;dictionary ThingFilter {
  (DiscoveryMethod or DOMString)method = "any";USVString?url;USVString?query;object?fragment;
};

Оцените статью
TankMod's
Добавить комментарий