- From: Device APIs Working Group Issue Tracker <sysbot+tracker@w3.org>
- Date: Tue, 09 Jul 2013 17:17:17 +0000
- To: public-device-apis@w3.org
DAP-ISSUE-129: Simplify Network Service Discovery API [Network Service Discovery]
http://www.w3.org/2009/dap/track/issues/129
Raised by: Jean-Claude Dufourd
On product: Network Service Discovery
from email: http://lists.w3.org/Archives/Public/public-device-apis/2013Jun/0015.html
The current NSD API is used in this sequence:
- NSD.getNetworkServices( "type", callback, errorcb)
- then in callback, you immediately set the onserviceavailable callback
and you return, because usually, the first NetworkServices object you
get is empty
- then onserviceavailable is called, and in there you call
NSD.getNetworkServices( "type", callback, errorcb) again
- then in callback, you immediately set the onserviceavailable callback
and you do the actual work.
You need to define:
- a function calling NSD.getNetworkServices( "type", successcallback,
errorcb)
- a onserviceavailable callback that calls NSD.getNetworkServices(
"type", successcallback, errorcb)
- the successcallback.
It is possible to define a wrapper around this to deal with the
onserviceavailable process transparently for the author, on top of the
existing API.
Thus, I avoid the need for the definition of onserviceavailable.
The actual code does the same as above, but the process that the webapp
author sees is:
- discover( "type", callback, errorcb)
- then in callback, you immediately do the actual work.
Why not simplify the API and get rid of the need for onserviceavaible ?
Why make the API more complex than it needs to be ?
Why expose a more intricate process that brings no advantage ?
Best regards
JC
Note: here is a possible implementation of the wrapper avoiding the need
for onserviceavailable:
function discover(serviceType, callBack, errcb) {
var thisFunction = function (services) {
services.onserviceavailable = function () {
NSD.getNetworkServices(serviceType, thisFunction, errcb);
};
if (services.length > 0) {
callBack.call(this, services);
}
};
NSD.getNetworkServices(serviceType, thisFunction, errcb);
}
Received on Tuesday, 9 July 2013 17:17:22 UTC