Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

device.onrequest not implemented #22

Closed
poussa opened this issue Oct 28, 2015 · 8 comments
Closed

device.onrequest not implemented #22

poussa opened this issue Oct 28, 2015 · 8 comments

Comments

@poussa
Copy link

poussa commented Oct 28, 2015

According to the spec the following should work but it does not:

device.registerResource({
    url: "/light/ambience/blue",
    deviceId: deviceId,
    connectionMode: connMode,
    resourceTypes: [ "Light" ],
    interfaces: [ "/oic/if/rw" ],
    discoverable: true,
    observable: true,
    properties: { color: "light-blue", dimmer: 0.2 }
  }).then((res) => {
    console.log("Resource " + res.id + " has been created.");
    lightResource = res;
    device.onrequest = requestHandler;
    device.enablePresence();
  })

The onrequest is newer called and you need to use:

resource._server.addEventListener( "request", requestHandler );
@sragavan
Copy link
Contributor

Sakari,

The onrequest is part of the OicServer object as per the spec ?

interface OicServer: EventTarget {
// register/unregister locally constructed resource objects with OIC
Promise registerResource(OicResourceInit init); // gets an id
Promise unregisterResource(USVString resourceId); // purge resource, then notify all

// enable/disable presence (discovery, state changes) for this device and its resources
Promise enablePresence(optional unsigned long ttl); // in seconds
Promise disablePresence();
Promise notify(USVString resourceId, OicMethod method, // mostly “update”
optional sequence updatedPropertyNames); // only for updates
// handle CRUDN requests from clients
attribute EventHandler onrequest;
};

I thought the example wasn't correct. Or did I misunderstood?

@poussa
Copy link
Author

poussa commented Oct 28, 2015

The onrequest is part of the OiCServer, yes.

The example is from the spec so it should be correct, @zolkis can you confirm.

The addEventListener is from the example code in the js/high-level-serverexample.js

@poussa
Copy link
Author

poussa commented Oct 28, 2015

Or is it so that the spec example is wrong and should be : resource.onrequest = ...

@zolkis
Copy link
Contributor

zolkis commented Oct 28, 2015

Using addEventListener is the preferred way of doing it, but onrequest=... also works because backward-compatibility. In the former case you can add multiple listeners.

@sragavan
Copy link
Contributor

@zolkis , I is it device.onrequest or resource.onrequest in the example? I assumed that the example was incorrect on the spec.

@zolkis
Copy link
Contributor

zolkis commented Oct 28, 2015

You are right, the example is incorrect there: onrequest is part of the server interface, and only resources have that, devices don't. Devices only have an info (and in the future they might expose a list of resources, to be clear on the structure). I guess it remained there from earlier API versions. Sorry for not noticing. I correct it ASAP.
Also, I will add some text to (some of) the methods on how are they supposed to work.

@sragavan
Copy link
Contributor

@zolkis Thanks for clarifying.

@zolkis
Copy link
Contributor

zolkis commented Oct 28, 2015

When looking into it, it seems that I got confused in my previous comment because I've been working on developing a simpler API. With the current JS API, the example was actually (almost) right. The model is that a device has an address, so you can make requests to a device, but you include a resource id as well. The client, and server interface is on the device. So the example was correct in that the request handler has to be installed on the device. Moreover, on a given device there is one request handler function, and all resource specific code needs to integrate there. In the example we have one resource, so this is not very visible. Perhaps I should add another resource there to make this clear.

We can also choose to break up this model, but Sakari quickly pointed out that we would run into different problems. Let's talk about this on the next meeting.

I will anyway make a PR soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants