Skip to content

[ExposedThing] Not possible to handle event subscriptions in Scripting level #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
egekorkan opened this issue Apr 6, 2020 · 5 comments · Fixed by #218
Closed

[ExposedThing] Not possible to handle event subscriptions in Scripting level #210

egekorkan opened this issue Apr 6, 2020 · 5 comments · Fixed by #218

Comments

@egekorkan
Copy link
Contributor

egekorkan commented Apr 6, 2020

Coming from this issue in node-wot.

Use case: A reverse proxy implementation consumes a physical Thing in a local network and reexposes it as a new virtual ExposedThing to another network. A consumer of the virtual ExposedThing subscribes to an event. The issue is that there is no way to detect and handle a new subscription so that the proxy can subscribe to the event in the physical Thing. A non-optimal solution is to subscribe to the events of the physical Thing in the beginning (without any subscription) and reemit them when the events come to the proxy.

Proposal: Create two new methods in the ExposedThing interface, one to handle the subscription and one to handle unsubscription. These could be similar to setPropertyReadHandler. Example:

  • setEventSubscribeHandler(eventName, ? subscriptionPayload, ? subscriptionCount): This could also solve the handling of subscription payloads. A subscription count would be interesting if the implementation wants to limit the number of subscriptions due to resource constraints.
  • setEventUnsubscribeHandler(eventName, ? cancellationPayload, ? subscriptionCount): Similar to the above
@zolkis
Copy link
Contributor

zolkis commented Apr 6, 2020

The API would be more like

partial interface ExposedThing {
    ExposedThing setEventSubscribeHandler(DOMString name, EventListenerHandler handler);
    ExposedThing setEventUnsubscribeHandler(DOMString name, EventListenerHandler handler);
};
callback EventListenerHandler = Promise<void> (optional any additionalData,
        optional InteractionOptions options = null);

There is the same signature for both subscribe and unsubscribe, the first gets the eventual subscriptionData, the latter the cancelationData. It makes sense to expose these on the server side.

@zolkis
Copy link
Contributor

zolkis commented Apr 6, 2020

Actually, additionalData could be well added to InteractionOptions (a Scripting specific construct).

@zolkis
Copy link
Contributor

zolkis commented Apr 20, 2020

I have made these changes, but have doubts about do we really need script defined handlers for subscriptions. When writing the algorithms, I realized that implementations can trivially do/generate the code for that, which is the reason these have not been included from the start.

So we need to check if we have the same understanding on how event subscription should be implemented and what is the value to open a hook for apps.

@egekorkan
Copy link
Contributor Author

I would imagine a code snippet like the following for a proxy:

myProxy.setEventSubscribeHandler(buttonPress, {
  myRealThing.subscribe(buttonPress)
}

I don't think that this is so trivial when we don't have the Scripting API construct for it.

@zolkis
Copy link
Contributor

zolkis commented Apr 20, 2020

On the Scripting call on 20. April 2020, we clarified that these handlers would not just extend default handling, but completely define it. That would cover the proxy case.

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

Successfully merging a pull request may close this issue.

2 participants