Service Discovery API

Service Discovery API

This document is the API Specification for Service Discovery API.

Summary

Service discovery API

The service discovery API lets you discover which devices and services are running in you local network, without having to go through DNS. This means you can for example discover and tie together services running in your home, even though these are not available on the Internet.

Examples of use stretches from the simple to the advanced:

Support discovery of remote services may be introduced in the future. This would afford a transparent view of where services are running.

Locating devices

You'll find all devices that have been discovered in the opera.nearbyDevices property. This

for ( var i = 0, device; device = opera.nearbyDevices[i]; i++ ) {
    opera.postError(device);  
}

Locating services

Each DeviceDescriptor object has a services property which contains information on services run on the device.

for ( var i = 0, service; service = device.services[i]; i++ ) {
    opera.postError(service);
}

Example: Generate a list of links to all services and devices

This example is relatively simple, although in this example we're using regular DOM methods which makes it a bit verbose. You can use your favorite JavaScript toolkit to generate it, like JQuery or YUI.

var deviceUl = document.createElement('ul');
var serviceUl;
var li;
var a;

for ( var i, device; device = opera.nearbyDevices[i]; i++ )
{
    li = deviceUl.appendChild(document.createElement('li'));
    a = li.appendChild(document.createElement('a'));
    a.href = device.url;
    a.textContent = device.name;

    if ( ! device.services )
    {
        continue;
    }

    serviceUl = li.appendChild(document.createElement('ul'));

    for ( var j, service; service = device.services[j]; j++)
    {
        li = serviceUl.appendChild(document.createElement('li'));
        a = li.appendChild(document.createElement('a'));
        a.href = service.url;
        a.textContent = service.name;
    }
}



File Summary
service-discovery.js

Service discovery API


Service Discovery API

Documentation generated by JSDoc on Fri Aug 14 11:46:31 2009