discovery-api/Overview.src.html
author Rich Tibbett <richt@opera.com>
Mon, 11 Mar 2013 05:28:41 +0100
changeset 399 8b1d2cd4858d
parent 398 19eb703af1c9
child 402 a3626e492d27
permissions -rw-r--r--
Fix CSS rendering in NSD spec
     1 <!DOCTYPE html>
     2 <!--
     3 
     4   THIS IS THE WORKING VERSION OF THE CURRENT SPECIFICATION!
     5 
     6   This specification is built using ReSpec.js <http://dev.w3.org/2009/dap/ReSpec.js/documentation.html>
     7 
     8   From time to time it's necessary to HTML5 Tidy this document using the tool @ <http://w3c.github.com/tidy-html5/>.
     9 
    10   The command used to format this document (Overview.src.html) is as follows (replacing all = signs with - signs!):
    11 
    12   @> tidy ==new-blocklevel-tags section ==char-encoding utf8 ==tidy-mark no ==indent yes ==indent-spaces 2 ==indent-attributes yes ==wrap 120 ==fix-bad-comments yes -m Overview.src.html
    13 
    14   To publish a new compiled version (Overview.html), we need to open this file (Overview.src.html) in any web browser.
    15   Once it has loaded we press 'Ctrl + Shift + S' (or 'Cmd' + 'Shift' + 'S' on Mac) and then select
    16   'Save as HTML (Source)' from the resulting menu.
    17 
    18   We then replace Overview.html with the produced HTML source of this process.
    19 
    20   Next we run HTML5 Tidy over our new Overview.html file with the following command (replacing all = signs with - signs!):
    21 
    22   @> tidy ==new-blocklevel-tags section ==char-encoding utf8 ==tidy-mark no ==indent yes ==indent-spaces 2 ==indent-attributes yes ==wrap 120 ==hide-comments yes -m Overview.html
    23 
    24   Now the specification is ready to be published :)
    25 
    26 -->
    27 <html>
    28   <head>
    29     <title>
    30       Network Service Discovery
    31     </title>
    32     <meta http-equiv='Content-Type'
    33           content='text/html; charset=utf-8'>
    34     <script type="text/javascript"
    35           class='remove'>
    36 var respecConfig = {
    37           specStatus:   "ED",
    38           //publishDate:  "2012-10-04",
    39           shortName:    "discovery-api",
    40           edDraftURI:   "http://dvcs.w3.org/hg/dap/raw-file/tip/discovery-api/Overview.html",
    41           previousMaturity: "FPWD",
    42           previousPublishDate: "2012-08-07",
    43           editors: [
    44             {
    45               name:       "Rich Tibbett",
    46               //url:        "http://richt.me/",
    47               company:    "Opera Software ASA",
    48               companyURL: "http://opera.com/"
    49             },
    50             {
    51               name:       "Clarke Stevens",
    52               //url:      "",
    53               company:    "CableLabs",
    54               companyURL: "http://cablelabs.com/"
    55             }
    56           ],
    57 
    58           wg:           "Device APIs Working Group",
    59           wgURI:        "http://www.w3.org/2009/dap/",
    60           wgPublicList: "public-device-apis",
    61           wgPatentURI:  "http://www.w3.org/2004/01/pp-impl/43696/status",
    62 
    63 //          extraCSS:     ["http://dvcs.w3.org/hg/dap/raw-file/tip/discovery-api/css/respec.nsd.css"],
    64 //          inlineCSS:    true,
    65           noIDLIn:      true
    66 
    67       };
    68     </script>
    69     <script src='http://www.w3.org/Tools/respec/respec-w3c-common'
    70           type="text/javascript"
    71           class='remove'
    72           async=""></script>
    73     <link href="./css/respec.nsd.css" rel="stylesheet" type="text/css">
    74   </head>
    75   <body>
    76     <section id='abstract'>
    77       <p>
    78         This specification defines a mechanism for an HTML document to discover and subsequently communicate with
    79         <abbr title="Hypertext Transfer Protocol">HTTP</abbr>-based services advertised via common discovery protocols
    80         within the current network.
    81       </p>
    82     </section>
    83     <section id='sotd'>
    84       <p>
    85         This document represents the early consensus of the group on the scope and features of the proposed API.
    86       </p>
    87     </section>
    88     <section class="informative">
    89       <h3>
    90         Introduction
    91       </h3>
    92       <p>
    93         To enable Web pages to connect and communicate with Local-networked Services provided over HTTP, this
    94         specification introduces the <a href="#navigatornetworkservice"><code>NavigatorNetworkService</code></a>
    95         interface.
    96       </p>
    97       <p>
    98         Using this <abbr title="Application Programming Interface">API</abbr> consists of requesting a well-known
    99         service type, known by developers and advertised by Local-networked Devices. User authorization, where the user
   100         connects the web page to discovered services, is expected before the web page is able to interact with any
   101         Local-networked Services.
   102       </p>
   103       <p>
   104         A web page creates a request to obtain connectivity to services running in the network by specifying a
   105         well-known discovery service type that it wishes to interact with.
   106       </p>
   107       <p>
   108         The user agent, having captured all advertised services on the network from the <a>service discovery
   109         mechanisms</a> included in this recommendation, attempts to match the requested service type to a discovered
   110         service according to the processing described herein.
   111       </p>
   112       <p>
   113         If a service connectivity request is successful then the Web page is provided with the necessary information to
   114         communicate with the authorized Local-networked Service. If the request fails then the Web page will receive an
   115         error callback containing an error code describing the cause of Local-networked Service connectivity failure.
   116       </p>
   117       <p>
   118         Once connected to a Local-networked Service the Web page can send requests and receive responses to the
   119         Local-networked Service via the messaging format and appropriate channel inferred from the service type
   120         authorized via the provided API. The Web page, once connected, can also receive service-pushed events, in the
   121         messaging format supported by the Local-networked Device, if such event subscription functionality is provided
   122         by the connected Local-networked Service.
   123       </p>
   124       <p>
   125         Services available within the local network can connect and disconnect at different times during the execution of a web page. The user agent can inform a web page when the state of networked services matching any of the requested valid service types change. Web pages can use this information to enable in-page experiences for communicating the state of networked services with the ability to change the particular service or set of services the page is connected to (by re-invoking the <a href=
   126         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method defined herein).
   127       </p>
   128       <div class="example">
   129         <p>
   130           Example of requesting a DNS-SD advertised service:
   131         </p>
   132         <hr>
   133         <pre class="highlight">
   134 function showServices( services ) {
   135   // Show a list of all the services provided to the web page
   136   for(var i = 0, l = services.length; i &lt; l; i++) console.log( services[i].name );
   137 }
   138 
   139 navigator.getNetworkServices('zeroconf:_boxee-jsonrpc._tcp', showServices);
   140 </pre>
   141       </div>
   142       <div class="example">
   143         <p>
   144           Example of requesting a UPnP advertised service, also handling error conditions:
   145         </p>
   146         <hr>
   147         <pre class="highlight">
   148 function showServices( services ) {
   149   // Show a list of all the services provided to the web page
   150   for(var i = 0, l = services.length; i &lt; l; i++) console.log( services[i].name );
   151 }
   152 
   153 function error( e ) {
   154   console.log( "Error occurred: " + e.code );
   155 }
   156 
   157 navigator.getNetworkServices('upnp:urn:schemas-upnp-org:service:ContentDirectory:1', showServices, error);
   158 </pre>
   159       </div>
   160       <div class="example">
   161         <p>
   162           Example of requesting either a DNS-SD or UPnP advertised service:
   163         </p>
   164         <hr>
   165         <pre class="highlight">
   166 function showServices( services ) {
   167   // Show a list of all the services provided to the web page (+ service type)
   168   for(var i = 0, l = services.length; i &lt; l; i++)
   169      console.log( services[i].name + '(' + services[i].type + ')' );
   170 }
   171 
   172 navigator.getNetworkServices([
   173   'zeroconf:_boxee-jsonrpc._tcp',
   174   'upnp:urn:schemas-upnp-org:service:ContentDirectory:1'
   175 ], showServices);
   176 </pre>
   177       </div>
   178       <p>
   179         For more detailed examples see the <a href="#examples">Examples</a> section.
   180       </p>
   181     </section>
   182     <section id='conformance'>
   183       <p>
   184         Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or
   185         "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should",
   186         "may", etc) used in introducing the algorithm.
   187       </p>
   188       <p>
   189         Some conformance requirements are phrased as requirements on attributes, methods or objects. Such requirements
   190         are to be interpreted as requirements on user agents.
   191       </p>
   192       <p>
   193         Conformance requirements phrased as algorithms or specific steps MAY be implemented in any manner, so long as
   194         the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be
   195         easy to follow, and not intended to be performant.)
   196       </p>
   197       <p>
   198         The only conformance class defined by this specification is a <dfn>user agent</dfn>.
   199       </p>
   200       <p>
   201         User agents MAY impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial
   202         of service attacks, to guard against running out of memory, or to work around platform-specific limitations.
   203       </p>
   204       <p>
   205         When support for a feature is disabled (e.g. as an emergency measure to mitigate a security problem, or to aid
   206         in development, or for performance reasons), user agents MUST act as if they had no support for the feature
   207         whatsoever, and as if the feature was not mentioned in this specification. For example, if a particular feature
   208         is accessed via an attribute in a Web IDL interface, the attribute itself would be omitted from the objects
   209         that implement that interface - leaving the attribute on the object but making it return null or throw an
   210         exception is insufficient.
   211       </p>
   212       <section>
   213         <h3>
   214           Dependencies
   215         </h3>This specification relies on several other underlying specifications.
   216         <dl>
   217           <dt>
   218             HTML
   219           </dt>
   220           <dd>
   221             Many fundamental concepts from HTML are used by this specification. [[!HTML5]]
   222           </dd>
   223           <dt>
   224             WebIDL
   225           </dt>
   226           <dd>
   227             The IDL blocks in this specification use the semantics of the WebIDL specification. [[!WEBIDL]]
   228           </dd>
   229         </dl>
   230       </section>
   231     </section>
   232     <section>
   233       <h3>
   234         Terminology
   235       </h3>
   236       <p>
   237         The construction "a <code>Foo</code> object", where <code>Foo</code> is actually an interface, is sometimes
   238         used instead of the more accurate "an object implementing the interface <code>Foo</code>".
   239       </p>
   240       <p>
   241         The term DOM is used to refer to the API set made available to scripts in Web applications, and does not
   242         necessarily imply the existence of an actual <code>Document</code> object or of any other <code>Node</code>
   243         objects as defined in the DOM Core specifications. [[!DOM4]]
   244       </p>
   245       <p>
   246         An IDL attribute is said to be <em>getting</em> when its value is being retrieved (e.g. by author script), and
   247         is said to be <em>setting</em> when a new value is assigned to it.
   248       </p>
   249       <p>
   250         A <dfn>valid service type</dfn> is any of the following:
   251       </p>
   252       <ul>
   253         <li>a string that begins with <code>upnp:</code> or <code>zeroconf:</code> followed by one or more characters
   254         in the ranges U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, U+0030 to U+0039, U+0041 to U+005A,
   255         U+005E to U+007E.
   256         </li>
   257         <li>a string that begins with <code>dial:</code> followed by an integer version.
   258         </li>
   259       </ul>
   260       <p>
   261         A <a>valid service type</a> provided in the <code>type</code> attribute of the <a href=
   262         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method will be matched against the
   263         services currently contained in the <a>list of available service records</a> according to the algorithms
   264         defined in this specification.
   265       </p>
   266       <p>
   267         A <dfn>user-agent generated callback url</dfn> is a Local-network accessible URL endpoint that a <a>user
   268         agent</a> generates and maintains for receiving HTTP NOTIFY requests from UPnP Event sources. It is only
   269         required when the user agent implements UPnP Service Discovery as defined in this specification.
   270       </p>
   271       <p>
   272         In this specification we use the following terms to describe the processes required for Local-networked
   273         Services management:
   274       </p>
   275       <ul>
   276         <li>A <dfn>new service</dfn> is a Local-networked Service that has not previously been discovered or registered
   277         in the <a>list of available service records</a>.
   278         </li>
   279         <li>An <dfn>existing service</dfn> is a Local-networked Service that has previously been discovered and is
   280         registered in the <a>list of available service records</a>.
   281         </li>
   282         <li>A <dfn>current service</dfn> is a Local-networked Service, represented by a <a href=
   283         "#networkservice"><code>NetworkService</code></a> object, that is currently being shared with a web page via a
   284         <a href="#networkservices"><code>NetworkServices</code></a> object registered in the <a>list of active service
   285         managers</a>.
   286         </li>
   287       </ul>
   288     </section>
   289     <section>
   290       <h2>
   291         Requesting networked services
   292       </h2>
   293       <pre class="widl">
   294 [Supplemental, NoInterfaceObject]
   295 interface <dfn id="navigatornetworkservice">NavigatorNetworkService</dfn> {
   296   // Obtain a Local-networked Service
   297   void <a href="#dom-navigator-getnetworkservices">getNetworkServices</a>( in any type,
   298                            in <a href=
   299 "#navigatornetworkservicesuccesscallback">NavigatorNetworkServiceSuccessCallback</a> successCallback,
   300                            in optional <a href=
   301 "#navigatornetworkserviceerrorcallback">NavigatorNetworkServiceErrorCallback</a> errorCallback );
   302 };
   303 <a class="externalDFN"
   304      href=
   305      "http://www.whatwg.org/specs/web-apps/current-work/complete/timers.html#navigator">Navigator</a> implements <a href=
   306      "#navigatornetworkservice">NavigatorNetworkService</a>;
   307 
   308 [Callback=FunctionOnly, NoInterfaceObject]
   309 interface <dfn id="navigatornetworkservicesuccesscallback">NavigatorNetworkServiceSuccessCallback</dfn> {
   310   void handleEvent( in <a href="#networkservices">NetworkServices</a> services );
   311 };
   312 
   313 [NoInterfaceObject]
   314 interface <dfn id="navigatornetworkserviceerror">NavigatorNetworkServiceError</dfn> {
   315   const unsigned short <a href="#dom-navigatornetworkserviceerror-permission_denied">PERMISSION_DENIED_ERR</a> = 1;
   316   const unsigned short <a href="#dom-navigatornetworkserviceerror-unknown_type_prefix">UNKNOWN_TYPE_PREFIX_ERR</a> = 2;
   317   readonly attribute unsigned short <a href="#dom-navigatornetworkserviceerror-code">code</a>;
   318 };
   319 
   320 [Callback=FunctionOnly, NoInterfaceObject]
   321 interface <dfn id="navigatornetworkserviceerrorcallback">NavigatorNetworkServiceErrorCallback</dfn> {
   322   void handleEvent( in <a href="#navigatornetworkserviceerror">NavigatorNetworkServiceError</a> error );
   323 };
   324 </pre>
   325       <section>
   326         <h2>
   327           Methods
   328         </h2>
   329         <dl class="domintro">
   330           <dt>
   331             <var title="">window</var> . <code title="dom-navigator"><a href=
   332             "http://www.whatwg.org/specs/web-apps/current-work/complete/timers.html#navigator">navigator</a></code> .
   333             <code title="dom-navigator-getNetworkServices"><a href=
   334             "#dom-navigator-getnetworkservices">getNetworkServices</a></code> ( <var title="">type</var> , <var title=
   335             "">successCallback</var> [, <var title="">errorCallback</var> ] )
   336           </dt>
   337           <dd>
   338             <p>
   339               Prompts the user to select discovered network services that have advertised support for the requested
   340               service type.
   341             </p>
   342             <p>
   343               The <var title="">type</var> argument contains one or more <a>valid service type</a> tokens that the web
   344               page would like to interact with.
   345             </p>
   346             <p>
   347               If the user accepts, the <var title="">successCallback</var> is invoked, with zero or more <a href=
   348               "#networkservice"><code>NetworkService</code></a> objects as its argument.
   349             </p>
   350             <p>
   351               If the user declines, the <var title="">errorCallback</var> (if any) is invoked.
   352             </p>
   353           </dd>
   354         </dl>
   355         <div>
   356           <p>
   357             When the <dfn id="dom-navigator-getnetworkservices"
   358                title="dom-navigator-getnetworkservices"><code>getNetworkServices(type, successCallback[,
   359                errorCallback])</code></dfn> method is called, the <a>user agent</a> MUST run the following steps:
   360           </p>
   361           <ol class="rule">
   362             <li>Let <var>requested control types</var> be initially set to an empty array.
   363             </li>
   364             <li>If <var>type</var> is an array consisting of one or more <a>valid service type</a> tokens, then let
   365             <var>requested control types</var> by the value of <var>type</var>, removing any non-<a>valid service
   366             type</a> tokens from the resulting array.
   367             </li>
   368             <li>If <var>type</var> is a string consisting of one <a>valid service type</a> token, then let
   369             <var>requested control types</var> be an array containing one item with a value of <var>type</var>.
   370             </li>
   371             <li>If <var>requested control types</var> is an array that contains at least one or more <a title=
   372             "valid service type">valid service type</a> tokens then continue to the step labeled <em>process</em>
   373             below. Otherwise, the <a>user agent</a> MUST <a href=
   374             "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
   375                   class="externalDFN">queue a task</a> to invoke <var>errorCallback</var>, if it is provided and is an
   376                   object of type <code>Function</code>, with a new <a href=
   377                   "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   378                   "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 2
   379                   (<a href=
   380                   "#dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></a>) as
   381                   its argument, abort any remaining steps and return.
   382             </li>
   383             <li>
   384               <em>Process</em>: Let <var>services found</var> be an empty array.
   385             </li>
   386             <li>For each <var>available service</var> in the <a>list of available service records</a> run the following
   387             steps:
   388               <ol class="rule">
   389                 <li>For each <var>requested control type</var> in <var>requested control types</var>: If <var>available
   390                 service</var>'s <code>type</code> attribute equals the <var>requested control type</var> then let <var>
   391                   matched service</var> equal the value of <var>available service</var> and continue at the step
   392                   labeled <var>attach</var> below.
   393                 </li>
   394                 <li>Continue at the next <var>available service</var>.
   395                 </li>
   396                 <li>
   397                   <em>Attach</em>: If <var>matched service</var> is not empty then run the following steps:
   398                   <ol class="rule">
   399                     <li>Let <var>new service object</var> be a new <a href=
   400                     "#networkservice"><code>NetworkService</code></a> object, mapping the parameters of <var>matched
   401                     service</var> to this new object where possible.
   402                     </li>
   403                     <li>Append <var>new service object</var> to the <var>services found</var> array.
   404                     </li>
   405                   </ol>
   406                 </li>
   407               </ol>
   408             </li>
   409             <li>Return, and run the remaining steps asynchronously.
   410             </li>
   411             <li>Optionally, e.g. based on a previously-established user preference, for security reasons, or due to
   412             platform limitations, the <a>user agent</a> MAY <a href=
   413             "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
   414                   class="externalDFN">queue a task</a> to invoke <var>errorCallback</var>, if it is provided and is an
   415                   object of type <code>Function</code>, with a new <a href=
   416                   "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   417                   "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 1
   418                   (<a href=
   419                   "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a>) as its
   420                   argument, abort any remaining steps and return.
   421             </li>
   422             <li>The user agent MUST NOT provide the entry script's origin with a <a href=
   423             "#networkservices"><code>NetworkServices</code></a> object without prior permission given by the user.
   424               <p>
   425                 If <var>services found</var> is not an empty array then the <a>user agent</a> MAY choose to prompt the
   426                 user in a user-agent-specific manner for permission to provide the <a href=
   427                 "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   428                    class="externalDFN">entry script</a>'s <a href=
   429                    "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   430                    class="externalDFN">origin</a> with a <a href="#networkservices"><code>NetworkServices</code></a>
   431                    object representing the <a>user-authorized</a> subset of <var>services found</var>.
   432               </p>
   433               <p>
   434                 Alternatively, the user agent MAY choose to queue a task to invoke <var>successCallback</var> or
   435                 <var>errorCallback</var> immediately based on a previously-established user preference, for security
   436                 reasons, or due to platform limitations. In such an implementation, if <var>successCallback</var> is to
   437                 be fired as a result of a previously-established user preference then the <a>user agent</a> MUST
   438                 continue at the next step of this algorithm.
   439               </p>
   440               <p>
   441                 If permission has been granted by the user to access one or more networked services then the <a>user
   442                 agent</a> SHOULD include an "ongoing local-network communication" indicator.
   443               </p>
   444               <p>
   445                 If permission has been denied by the user, <a>user agent</a> or platform, then the <a>user agent</a>
   446                 MUST <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
   447                    class="externalDFN">queue a task</a> to invoke <var>errorCallback</var>, if it is provided and is an
   448                    object of type <code>Function</code>, with a new <a href=
   449                    "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object whose <a href=
   450                    "#dom-navigatornetworkserviceerror-code"><code>code</code></a> attribute has the numeric value 1
   451                    (<a href=
   452                    "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a>) as its
   453                    argument, abort any remaining steps and return.
   454               </p>
   455               <p>
   456                 If the user never responds or no previously-established user preference has been met, this algorithm
   457                 stalls on this step.
   458               </p>
   459             </li>
   460             <li>Let <var>services</var> be an empty array.
   461             </li>
   462             <li>If <var>services found</var> is not an empty array then set <var>services</var> to be an array of one
   463             or more <a href="#networkservice"><code>NetworkService</code></a> objects for which the user granted
   464             permission above - known as the current objects <dfn>user-authorized</dfn> services.
   465             </li>
   466             <li>Remove all previously whitelisted urls from the <a>entry script origin's URL whitelist</a> granted in
   467             the current <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   468                   class="externalDFN">entry script</a>'s <a href=
   469                   "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   470                   class="externalDFN">origin</a>.
   471             </li>
   472             <li>For each Object <var>service</var> in <var>services</var>, if any, run the following sub-steps:
   473               <ol class="rule">
   474                 <li>Add the <var>service</var>'s <code>url</code> parameter to the <a>entry script origin's
   475                   <abbr title="Uniform Resource Locator">URL</abbr> whitelist</a>.
   476                 </li>
   477                 <li>If <var>service</var>'s <code>type</code> parameter begins with the DOMString "<code>upnp:</code>"
   478                 and the <var>service</var>'s <code>eventsUrl</code> parameter is not empty then <a>setup a UPnP Events
   479                 Subscription</a> for <var>service</var>.
   480                 </li>
   481               </ol>
   482             </li>
   483             <li>Let <var>services manager</var> be a new <a href="#networkservices"><code>NetworkServices</code></a>
   484             object.
   485             </li>
   486             <li>Store <var>requested control types</var> against <var>services manager</var> as an internal variable.
   487             </li>
   488             <li>Set <var>services manager</var>'s <a href=
   489             "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute to the number of
   490             items currently found in the <a>list of available service records</a> whose <code>type</code> property
   491             matches any of the tokens requested in <var>requested control types</var>.
   492             </li>
   493             <li>Add <var>services</var>, if any, to the <var>services manager</var> object as its collection of
   494             <a>indexed properties</a>. If <var>services</var> is an empty array then the <var>services manager</var>
   495             does not have any <var>indexed properties</var>.
   496             </li>
   497             <li>Set <var>services manager</var>'s <a href="#dom-networkservices-length"><code>length</code></a>
   498             attribute to the number of items in <var>services</var>.
   499             </li>
   500             <li>Add <var>services manager</var> to the <a>list of active service managers</a>.
   501             </li>
   502             <li>The <a>user agent</a> MUST <a href=
   503             "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
   504                   class="externalDFN">queue a task</a> to invoke <var>successCallback</var> with <var>services
   505                   manager</var> as its argument.
   506             </li>
   507           </ol>
   508           <p>
   509             The <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#task-source"
   510                class="externalDFN">task source</a> for these <a href=
   511                "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#concept-task"
   512                class="externalDFN">tasks</a> is the <a href=
   513                "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#user-interaction-task-source"
   514                class="externalDFN">user interaction task source</a>.
   515           </p>
   516           <p>
   517             When a <a href="#networkservice"><code>NetworkService</code></a> object is provided to a Web page, the
   518             <a>user agent</a> MUST add the <code>url</code> property to the <dfn>entry script origin's URL
   519             whitelist</dfn>. This list enables the Web page to override and initiate cross-site resource requests
   520             towards these URLs, and any sub-resources of these URLs, within the current <a href=
   521             "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   522                class="externalDFN">entry script</a>'s <a href=
   523                "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   524                class="externalDFN">origin</a> via various existing mechanisms (e.g. Web Sockets, Server-Sent Events,
   525                Web Messaging, XMLHttpRequest).
   526           </p>
   527           <p>
   528             If the user navigates away from the <a href=
   529             "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
   530                class="externalDFN">entry script</a>'s <a href=
   531                "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
   532                class="externalDFN">origin</a> then the <a>user agent</a> <em class="ct">MUST</em> remove all previously
   533                whitelisted urls from the <a>entry script origin's URL whitelist</a>. There is no persistence to network
   534                service selections provided to a web page. It is not possible to access a previously white-listed
   535                networked service without the necessary user authorization in all of the following cases:
   536           </p>
   537           <ul>
   538             <li>If the current script is reloaded at any point in the same or different window.
   539             </li>
   540             <li>if the current script reinvokes the <a href=
   541             "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> method at any point in its
   542             execution.
   543             </li>
   544             <li>If the user navigates forward or back in their history to reload the current page.
   545             </li>
   546             <li>If a script is running in a different origin.
   547             </li>
   548           </ul>
   549         </div>
   550       </section>
   551       <section>
   552         <h3>
   553           Error Handling
   554         </h3>
   555         <dl class="domintro">
   556           <dt>
   557             <var title="">error</var> . <code title="dom-NavigatorNetworkServiceError-code"><a href=
   558             "#dom-navigatornetworkserviceerror-code">code</a></code>
   559           </dt>
   560           <dd>
   561             <p>
   562               Returns the current error's error code. At the current time, this will be <code>1</code> or
   563               <code>2</code>, for which the corresponding error constants <a href=
   564               "#dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></a> and <a href=
   565               "#dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></a> are
   566               defined.
   567             </p>
   568           </dd>
   569         </dl>
   570         <p>
   571           The <dfn id="dom-navigatornetworkserviceerror-code"
   572              title="dom-navigatornetworkserviceerror-code"><code>code</code></dfn> attribute of a <a href=
   573              "#navigatornetworkserviceerror"><code>NavigatorNetworkServiceError</code></a> object <em class=
   574              "ct">MUST</em> return the code for the error, which will be one of the following:
   575         </p>
   576         <dl>
   577           <dt>
   578             <dfn id="dom-navigatornetworkserviceerror-permission_denied"
   579                 title="dom-navigatornetworkserviceerror-permission_denied"><code>PERMISSION_DENIED_ERR</code></dfn>
   580                 (numeric value 1)
   581           </dt>
   582           <dd>
   583             The user or user agent denied the page permission to access any services.
   584           </dd>
   585           <dt>
   586             <dfn id="dom-navigatornetworkserviceerror-unknown_type_prefix"
   587                 title="dom-navigatornetworkserviceerror-unknown_type_prefix"><code>UNKNOWN_TYPE_PREFIX_ERR</code></dfn>
   588                 (numeric value 2)
   589           </dt>
   590           <dd>
   591             No <a>valid service type</a> tokens were provided in the method invocation.
   592           </dd>
   593         </dl>
   594       </section>
   595     </section>
   596     <section>
   597       <h2>
   598         Obtaining networked services
   599       </h2>
   600       <p>
   601         The <a href="#networkservices"><code>NetworkServices</code></a> interface represents a collection of zero or
   602         more <dfn>indexed properties</dfn> that are each a <a>user-authorized</a> <a href=
   603         "#networkservice"><code>NetworkService</code></a> object.
   604       </p>
   605       <p>
   606         A <a href="#networkservices"><code>NetworkServices</code></a> object is the top level success callback
   607         parameter from a call to <a href="#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a>.
   608       </p>
   609       <pre class="widl">
   610 [NoInterfaceObject]
   611 interface <dfn id="networkservices">NetworkServices</dfn> {
   612   readonly attribute unsigned long    <a href="#dom-networkservices-length">length</a>;
   613   getter <a href="#networkservice">NetworkService</a> (unsigned long index);
   614   <a href="#networkservice">NetworkService</a>? <a href=
   615 "#dom-networkservices-getservicebyid">getServiceById</a>(DOMString id);
   616 
   617   readonly attribute unsigned long    <a href="#dom-networkservices-servicesavailable">servicesAvailable</a>;
   618 
   619   // event handler attributes
   620            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   621      class="externalDFN">EventHandler</a>     <a href="#dom-networkservices-onserviceavailable">onserviceavailable</a>;
   622            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   623      class="externalDFN">EventHandler</a>     <a href=
   624      "#dom-networkservices-onserviceunavailable">onserviceunavailable</a>;
   625 
   626 };
   627 
   628 <a href="#networkservices">NetworkServices</a> implements <a href=
   629 "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget"
   630      class="externalDFN">EventTarget</a>;
   631 </pre>
   632 
   633       <section>
   634         <h2>
   635           Attributes
   636         </h2>
   637         <dl class="domintro">
   638           <dt>
   639             <code title="dom-networkservices-length"><a href="#dom-networkservices-length">length</a></code>
   640           </dt>
   641           <dd>
   642             <p>
   643               Returns the current number of <a>indexed properties</a> in the current object's collection.
   644             </p>
   645           </dd>
   646           <dt>
   647             <code title="dom-networkservices-servicesavailable"><a href=
   648             "#dom-networkservices-servicesavailable">servicesAvailable</a></code>
   649           </dt>
   650           <dd>
   651             <p>
   652               Returns the current number of items matching one of the app-requested <a>valid service type</a> tokens in
   653               the <a>list of available service records</a>.
   654             </p>
   655           </dd>
   656         </dl>
   657         <div>
   658           <p>
   659             The <dfn id="dom-networkservices-length"><code>length</code></dfn> attribute MUST return the number of
   660             <a href="#networkservice"><code>NetworkService</code></a> objects represented by the collection.
   661           </p>
   662           <p>
   663             The <dfn id="dom-networkservices-servicesavailable"><code>servicesAvailable</code></dfn> attribute MUST
   664             return the number of services in the <a>list of available service records</a> whose <code>type</code>
   665             attribute matches any of the <a>valid service type</a> tokens that were initially used to create the current
   666             <a href="#networkservices"><code>NetworkServices</code></a> object.
   667           </p>
   668         </div>
   669       </section>
   670       <section>
   671         <h2>
   672           Methods
   673         </h2>
   674         <dl class="domintro">
   675           <dt>
   676             <code title="networkservices-getter"><a href="#networkservices">services</a></code> [ <var title=
   677             "">index</var> ]
   678           </dt>
   679           <dd>
   680             <p>
   681               Returns the specified <a href="#networkservice"><code>NetworkService</code></a> object.
   682             </p>
   683           </dd>
   684           <dt>
   685             <code title="networkservices-getter"><a href="#networkservices">services</a></code> . <code title=
   686             "dom-networkservices-getservicebyid"><a href=
   687             "#dom-networkservices-getservicebyid">getServiceById</a></code> ( <var title="">id</var> )
   688           </dt>
   689           <dd>
   690             <p>
   691               Returns the <a href="#networkservice"><code>NetworkService</code></a> object with the given identifier,
   692               or null if no service has that identifier.
   693             </p>
   694           </dd>
   695         </dl>
   696         <p>
   697           A <a href="#networkservices"><code>NetworkServices</code></a> object represents the current collection of
   698           zero or more <a href="#networkservice"><code>NetworkService</code></a> objects - its <a>indexed
   699           properties</a>. The <a>indexed properties</a> of a <a href=
   700           "#networkservices"><code>NetworkServices</code></a> object are <span>immutable</span> meaning that <a>indexed
   701           properties</a> cannot be added and <a>indexed properties</a> cannot be removed for the lifetime of a <a href=
   702           "#networkservices"><code>NetworkServices</code></a> object.
   703         </p>
   704         <p>
   705           The <a href=
   706           "http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#supported-property-indices"
   707              class="externalDFN">supported property indices</a> of <a href=
   708              "#networkservices"><code>NetworkServices</code></a> objects at any instant are the numbers from zero to
   709              the number of the <a href="#networkservice"><code>NetworkService</code></a> objects in the collection
   710              minus one.
   711         </p>
   712         <p class="note">
   713           Each service in a <a href="#networkservices"><code>NetworkServices</code></a> object thus has an index; the
   714           first has the index 0, and each subsequent service is numbered one higher than the previous one.
   715         </p>
   716         <p>
   717           To <a href=
   718           "http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#determine-the-value-of-an-indexed-property"
   719              class="externalDFN">determine the value of an indexed property</a> for a given index <var>index</var> in a
   720              <a href="#networkservices"><code>NetworkServices</code></a> object the user agent MUST return the <a href=
   721              "#networkservice"><code>NetworkService</code></a> object that represents the <var>index</var>th item in
   722              the collection.
   723         </p>
   724         <p>
   725           The <dfn id="dom-networkservices-getservicebyid"><code>getServiceById(id)</code></dfn> method <em class=
   726           "ct">MUST</em> return the first <a href="#networkservice"><code>NetworkService</code></a> object in the
   727           collection whose <a href="#dom-networkservice-id"><code>id</code></a> attribute is equal to the value of the
   728           <var>id</var> argument provided. When no <a href="#networkservice"><code>NetworkService</code></a> objects
   729           match the given argument, the method MUST return null.
   730         </p>
   731       </section>
   732       <section>
   733         <h2>
   734           Events
   735         </h2>
   736         <p>
   737           The following are the event handlers (and their corresponding event handler event types) that <em class=
   738           "ct">MUST</em> be supported, as IDL attributes, by all objects implementing the <a href=
   739           "#networkservices"><code>NetworkServices</code></a> interface:
   740         </p>
   741         <table border="1">
   742           <thead>
   743             <tr>
   744               <th>
   745                 <span title="event handlers">Event handler</span>
   746               </th>
   747               <th>
   748                 <span>Event handler event type</span>
   749               </th>
   750             </tr>
   751           </thead>
   752           <tbody>
   753             <tr>
   754               <td>
   755                 <dfn id="dom-networkservices-onserviceavailable"
   756                     title="dom-NetworkServices-onserviceavailable"><code>onserviceavailable</code></dfn>
   757               </td>
   758               <td>
   759                 <a href="#event-serviceavailable"><code>serviceavailable</code></a>
   760               </td>
   761             </tr>
   762             <tr>
   763               <td>
   764                 <dfn id="dom-networkservices-onserviceunavailable"
   765                     title="dom-NetworkServices-onserviceunavailable"><code>onserviceunavailable</code></dfn>
   766               </td>
   767               <td>
   768                 <a href="#event-serviceunavailable"><code>serviceunavailable</code></a>
   769               </td>
   770             </tr>
   771           </tbody>
   772         </table>
   773       </section>
   774     </section>
   775     <section>
   776       <h2>
   777         Communicating with a networked service
   778       </h2>
   779       <p>
   780         The <a href="#networkservice"><code>NetworkService</code></a> interface is used to provide a set of connection
   781         information for an HTTP service endpoint and if available, service events, running on a networked device.
   782       </p>
   783       <pre class="widl">
   784 [NoInterfaceObject]
   785 interface <dfn id="networkservice">NetworkService</dfn> {
   786   readonly attribute DOMString        <a href="#dom-networkservice-id">id</a>;
   787   readonly attribute DOMString        <a href="#dom-networkservice-name">name</a>;
   788   readonly attribute DOMString        <a href="#dom-networkservice-type">type</a>;
   789   readonly attribute DOMString        <a href="#dom-networkservice-url">url</a>;
   790   readonly attribute DOMString        <a href="#dom-networkservice-config">config</a>;
   791 
   792   readonly attribute boolean          <a href="#dom-networkservice-online">online</a>;
   793 
   794   // event handler attributes
   795            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   796      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onserviceonline">onserviceonline</a>;
   797            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   798      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onserviceoffline">onserviceoffline</a>;
   799 
   800            attribute <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"
   801      class="externalDFN">EventHandler</a>     <a href="#dom-networkservice-onnotify">onnotify</a>;
   802 };
   803 
   804 <a href="#networkservice">NetworkService</a> implements <a href=
   805 "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget"
   806      class="externalDFN">EventTarget</a>;
   807 </pre>
   808       <section>
   809         <h2>
   810           Attributes
   811         </h2>
   812         <dl class="domintro">
   813           <dt>
   814             <var title="">service</var> . <code title="dom-networkservice-id"><a href=
   815             "#dom-networkservice-id">id</a></code>
   816           </dt>
   817           <dd>
   818             <p>
   819               A unique identifier for the given user-selected service instance.
   820             </p>
   821           </dd>
   822           <dt>
   823             <var title="">service</var> . <code title="dom-networkservice-name"><a href=
   824             "#dom-networkservice-name">name</a></code>
   825           </dt>
   826           <dd>
   827             <p>
   828               The name of the user-selected service.
   829             </p>
   830           </dd>
   831           <dt>
   832             <var title="">service</var> . <code title="dom-networkservice-type"><a href=
   833             "#dom-networkservice-type">type</a></code>
   834           </dt>
   835           <dd>
   836             <p>
   837               The <a>valid service type</a> token value of the user-selected service.
   838             </p>
   839           </dd>
   840           <dt>
   841             <var title="">service</var> . <code title="dom-networkservice-url"><a href=
   842             "#dom-networkservice-url">url</a></code>
   843           </dt>
   844           <dd>
   845             <p>
   846               The control URL endpoint (including any required port information) of the user-selected control service
   847               that has been added to the <a>entry script origin's URL whitelist</a>.
   848             </p>
   849           </dd>
   850           <dt>
   851             <var title="">service</var> . <code title="dom-networkservice-config"><a href=
   852             "#dom-networkservice-config">config</a></code>
   853           </dt>
   854           <dd>
   855             <p>
   856               The configuration information associated with the service depending on the requested service type.
   857             </p>
   858           </dd>
   859         </dl>
   860         <p>
   861           The <dfn id="dom-networkservice-id"><code>id</code></dfn> attribute is a unique identifier for the service.
   862           The same service provided at different times or on different objects MUST have the same <a href=
   863           "#dom-networkservice-id"><code>id</code></a> value.
   864         </p>
   865         <p>
   866           The <dfn id="dom-networkservice-name"><code>name</code></dfn> attribute represents a human-readable title for
   867           the service.
   868         </p>
   869         <p>
   870           The <dfn id="dom-networkservice-type"><code>type</code></dfn> attribute reflects the value of the <a>valid
   871           service type</a> of the service.
   872         </p>
   873         <p>
   874           The <dfn id="dom-networkservice-url"><code>url</code></dfn> attribute is an <a href=
   875           "http://www.w3.org/TR/html5/urls.html#absolute-url"
   876              class="externalDFN">absolute URL</a> pointing to the root HTTP endpoint for the service that has been
   877              added to the <a>entry script origin's URL whitelist</a>. Web pages can subsequently use this value for
   878              implicit cross-document messaging via various existing mechanisms (e.g. Web Sockets, Server-Sent Events,
   879              Web Messaging, XMLHttpRequest).
   880         </p>
   881         <p>
   882           The <dfn id="dom-networkservice-config"><code>config</code></dfn> attribute provides the raw configuration
   883           information extracted from the given network service.
   884         </p>
   885       </section>
   886       <section>
   887         <h3>
   888           States
   889         </h3>
   890         <dl class="domintro">
   891           <dt>
   892             <var title="">service</var> . <code title="dom-networkservice-online"><a href=
   893             "#dom-networkservice-online">online</a></code>
   894           </dt>
   895           <dd>
   896             <p>
   897               Returns <code>true</code> if the service is reporting that it is accessible on the local network or
   898               <code>false</code> if the service is no longer accessible (temporarily or permanently) on the local
   899               network.
   900             </p>
   901           </dd>
   902         </dl>
   903         <p>
   904           The <dfn id="dom-networkservice-online"><code>online</code></dfn> attribute indicates whether the service is
   905           either <var>online</var>, and therefore accessible on the local network, in which case this attribute will
   906           return <code>true</code> or, <var>offline</var>, and therefore not accessible on the local network, either
   907           temporarily or permanently, in which case this attribute will return <code>false</code>. This attribute MUST
   908           default to <code>true</code>.
   909         </p>
   910       </section>
   911       <section>
   912         <h3>
   913           Events
   914         </h3>
   915         <p>
   916           The following are the event handlers (and their corresponding event handler event types) that <em class=
   917           "ct">MUST</em> be supported, as IDL attributes, by all objects implementing the <a href=
   918           "#networkservice"><code>NetworkService</code></a> interface:
   919         </p>
   920         <table border="1">
   921           <thead>
   922             <tr>
   923               <th>
   924                 <span title="event handlers">Event handler</span>
   925               </th>
   926               <th>
   927                 <span>Event handler event type</span>
   928               </th>
   929             </tr>
   930           </thead>
   931           <tbody>
   932             <tr>
   933               <td>
   934                 <dfn id="dom-networkservice-onnotify"
   935                     title="dom-NetworkService-onnotify"><code>onnotify</code></dfn>
   936               </td>
   937               <td>
   938                 <a href="#event-notify"><code>notify</code></a>
   939               </td>
   940             </tr>
   941             <tr>
   942               <td>
   943                 <dfn id="dom-networkservice-onserviceonline"
   944                     title="dom-NetworkService-onserviceonline"><code>onserviceonline</code></dfn>
   945               </td>
   946               <td>
   947                 <a href="#event-serviceonline"><code>serviceonline</code></a>
   948               </td>
   949             </tr>
   950             <tr>
   951               <td>
   952                 <dfn id="dom-networkservice-onserviceoffline"
   953                     title="dom-NetworkService-onserviceoffline"><code>onserviceoffline</code></dfn>
   954               </td>
   955               <td>
   956                 <a href="#event-serviceoffline"><code>serviceoffline</code></a>
   957               </td>
   958             </tr>
   959           </tbody>
   960         </table>
   961       </section>
   962     </section>
   963     <section>
   964       <h2>
   965         Service Discovery
   966       </h2>
   967       <p>
   968         A <a>user agent</a> conforming to this specification MAY implement <abbr title=
   969         "Simple Service Discovery Protocol">SSDP</abbr> [[!UPNP-DEVICEARCH11]], Zeroconf [[!DNS-SD]] + [[!MDNS]] and/or
   970         <abbr title="Discovery and Launch Protocol">DIAL</abbr> [<a href=
   971         "https://sites.google.com/a/dial-multiscreen.org/dial/dial-protocol-specification">DIAL</a>] <dfn>service
   972         discovery mechanisms</dfn> - the requirements detailed in this section of the specification - to enable Web
   973         pages to request and connect with HTTP services running on networked devices, discovered via any of these
   974         mechanisms, through this API. When a <a>user agent</a> implements any of these <a>service discovery
   975         mechanisms</a>, then it MUST conform to the corresponding algorithms provided in this section of the
   976         specification.
   977       </p>
   978       <p>
   979         This section presents how the results of these <a>service discovery mechanisms</a> will be matched to requested
   980         service types, how the user agent stores available and active services and how their properties are applied to
   981         any resulting <a href="#networkservice"><code>NetworkService</code></a> objects.
   982       </p>
   983       <p>
   984         It is expected that user agents will perform these <a>service discovery mechanisms</a> asynchronously and
   985         periodically update the <a>list of available service records</a> as required. The timing of any <a>service
   986         discovery mechanisms</a> is an implementation detail left to the discretion of the implementer (e.g. by
   987         continuously monitoring the network as a background process or on invocation of this API from a Web page).
   988       </p>
   989       <p>
   990         The <dfn>list of available service records</dfn> is a single dynamic internal lookup table within user agents
   991         that is used to track all the services that have been discovered and are available in the current network at
   992         the current time. At any point during the running of either of the two <a>service discovery mechanisms</a> then
   993         existing entries within this table can be updated, entries can be added and entries can be removed as the
   994         status of networked services changes according to the rules defined in this specification.
   995       </p>
   996       <p>
   997         The <dfn>list of active service managers</dfn> is an internal list within user agents that is used to track all
   998         <a href="#networkservices"><code>NetworkServices</code></a> objects currently being shared with any web pages
   999         at the current time within the user agent. Each <a href="#networkservices"><code>NetworkServices</code></a>
  1000         object in the <a>list of active service managers</a> represents a collection of zero or more <a href=
  1001         "#networkservice"><code>NetworkService</code></a> objects - known as its <dfn>indexed properties</dfn>.
  1002         <a href="#networkservice"><code>NetworkService</code></a> objects are attached as the <a>indexed properties</a>
  1003         of a <a href="#networkservices"><code>NetworkServices</code></a> object as part of the <a href=
  1004         "#dom-navigator-getnetworkservices"><code>getNetworkServices()</code></a> algorithm.
  1005       </p>
  1006       <p>
  1007         The rule for <dfn>adding an available service</dfn> is the process of adding a <a>new service</a> or updating
  1008         an <a>existing service</a> that is generally available on the user's current network in the <a>list of
  1009         available service records</a>. This rule takes one argument, <var>network service record</var>, and consists of
  1010         running the following steps:
  1011       </p>
  1012       <ol class="rule">
  1013         <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1014         the following sub-steps:
  1015           <ol class="rule">
  1016             <li>If the <var>existing service record</var>'s <code>id</code> property does not equal <var>network
  1017             service record</var>'s <code>id</code> property then abort any remaining sub-steps and continue at the next
  1018             available <var>existing service record</var>.
  1019             </li>
  1020             <li>Replace the value of <var>existing service record</var> in the current <a>list of available service
  1021             records</a> with the value of <var>network service record</var>, aborting any remaining steps in this
  1022             algorithm and return.
  1023             </li>
  1024           </ol>
  1025         </li>
  1026         <li>Add <var>network service record</var> to the <a>list of available service records</a> as a new item.
  1027         </li>
  1028         <li>For each <var>service manager</var> in the <a>list of active service managers</a> run the following steps:
  1029           <ol class="rule">
  1030             <li>For each <var>active service</var> in <var>service manager</var> run the following steps:
  1031               <ol class="rule">
  1032                 <li>If the <var>network service record</var>'s <code>id</code> property equals the <var>active
  1033                 service</var>'s <code>id</code> attribute and <var>active service</var>'s <code>online</code> attribute
  1034                 is currently set to <code>false</code> then set <var>active service</var>'s <a href=
  1035                 "#dom-networkservice-online"><code>online</code></a> attribute to <code>true</code> and then <a href=
  1036                 "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1037                       class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1038                       "#event-serviceonline"><code>serviceonline</code></a> that uses the <a href=
  1039                       "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1040                       class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable,
  1041                       and has no default action, at the current <var>active service</var> object.
  1042                 </li>
  1043               </ol>
  1044             </li>
  1045             <li>Let <var>'service type in current service manager' flag</var> be <code>false</code>.
  1046             </li>
  1047             <li>For each <var>requested control type</var> of the <var>requested control types</var> in <var>service
  1048             manager</var> run the following steps:
  1049               <ol class="rule">
  1050                 <li>If <var>network service record</var>'s <code>type</code> property does not equal <var>requested
  1051                 control type</var> then abort any remaining sub-steps and continue at the next available <var>requested
  1052                 control type</var>.
  1053                 </li>
  1054                 <li>Set the <var>'service type in current service manager' flag</var> to <code>true</code>, abort any
  1055                 remaining sub-steps and continue.
  1056                 </li>
  1057               </ol>
  1058             </li>
  1059             <li>If the <var>'service type in current service manager' flag</var> is set to <code>true</code> then
  1060             increment <var>service manager</var>'s <a href=
  1061             "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute by <code>1</code> and
  1062             then <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1063                   class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1064                   "#event-serviceavailable"><code>serviceavailable</code></a> that uses the <a href=
  1065                   "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1066                   class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable, and
  1067                   has no default action, at the current <var>service manager</var> object.
  1068             </li>
  1069           </ol>
  1070         </li>
  1071       </ol>
  1072       <p>
  1073         The rule for <dfn>removing an available service</dfn> is the general process of removing an <a>existing
  1074         service</a> from the <a>list of available service records</a> that has left the user's current network or has
  1075         otherwise expired. This rule takes one argument, <var>service identifier</var>, and consists of running the
  1076         following steps:
  1077       </p>
  1078       <ol class="rule">
  1079         <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1080         the following sub-steps:
  1081           <ol class="rule">
  1082             <li>If the <var>existing service record</var>'s <code>id</code> property does not match <var>service
  1083             identifier</var> then skip any remaining sub-steps for the current <var>existing service record</var> and
  1084             continue at the next available <var>existing service record</var>.
  1085             </li>
  1086             <li>Let <var>'service type in use' flag</var> be <code>false</code>.
  1087             </li>
  1088             <li>For each <var>service manager</var> in the <a>list of active service managers</a> run the following
  1089             steps:
  1090               <ol class="rule">
  1091                 <li>Let <var>'service type in current service manager' flag</var> be <code>false</code>.
  1092                 </li>
  1093                 <li>For each <var>active service</var> in <var>service manager</var> run the following steps:
  1094                   <ol class="rule">
  1095                     <li>If <var>existing service record</var>'s <code>id</code> property equals the <var>active
  1096                     service</var>'s <code>id</code> attribute and <var>active service</var>'s <a href=
  1097                     "#dom-networkservice-online"><code>online</code></a> attribute is currently set to
  1098                     <code>true</code> then set <var>active service</var>'s <a href="#dom-networkservice-online"><code>
  1099                       online</code></a> attribute to <code>false</code> and then <a href=
  1100                       "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1101                           class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1102                           "#event-serviceoffline"><code>serviceoffline</code></a> that uses the <a href=
  1103                           "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1104                           class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not
  1105                           cancellable, and has no default action, at the current <var>active service</var>.
  1106                     </li>
  1107                   </ol>
  1108                 </li>
  1109                 <li>For each <var>requested control type</var> of the <var>requested control types</var> in
  1110                 <var>service manager</var> run the following steps:
  1111                   <ol class="rule">
  1112                     <li>If <var>existing service record</var>'s <code>type</code> property does not equal
  1113                     <var>requested control type</var> then abort any remaining sub-steps and continue at the next
  1114                     available <var>requested control type</var>.
  1115                     </li>
  1116                     <li>Set the <var>'service type in current service manager' flag</var> to <code>true</code> and the
  1117                     <var>'service type in use' flag</var> to <code>true</code>, abort any remaining sub-steps and
  1118                     continue.
  1119                     </li>
  1120                   </ol>
  1121                 </li>
  1122                 <li>If the <var>'service type in current service manager' flag</var> is set to <code>true</code> then
  1123                 decrement <var>service manager</var>'s <a href=
  1124                 "#dom-networkservices-servicesavailable"><code>servicesAvailable</code></a> attribute by <code>1</code>
  1125                 and then <a href=
  1126                 "http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1127                       class="externalDFN">queue a task</a> to dispatch a newly created event with the name <a href=
  1128                       "#event-serviceunavailable"><code>serviceunavailable</code></a> that uses the <a href=
  1129                       "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1130                       class="externalDFN"><code>Event</code></a> interface, which does not bubble, is not cancellable,
  1131                       and has no default action, at the current <var>service manager</var> object.
  1132                 </li>
  1133               </ol>
  1134             </li>
  1135             <li>If the <var>'service type in use' flag</var> is <code>false</code> and the <var>existing service
  1136             record</var>'s <code>type</code> property begins with the DOMString "<code>upnp:</code>" and <var>existing
  1137             service record</var>'s <code>eventsURL</code> property is set then run the rule to <a>terminate an existing
  1138             UPnP Events Subscription</a>, if one is currently active (as a result of having previously called <a>setup
  1139             a UPnP Events Subscription</a> against the current <var>existing service record</var>).
  1140             </li>
  1141             <li>Remove <var>existing service record</var> from the current <a>list of available service records</a>.
  1142             </li>
  1143           </ol>
  1144         </li>
  1145       </ol>
  1146       <p>
  1147         User agents SHOULD expire a service record from the <a>list of available service records</a> when its
  1148         <code>expiryTimestamp</code> attribute exceeds the current UTC timestamp. When this condition is met the
  1149         <a>user agent</a> SHOULD run the rule for <a>removing an available service</a>, passing in the expired service
  1150         record's <code>id</code> attribute as the only argument.
  1151       </p>
  1152       <section>
  1153         <h4>
  1154           Zeroconf (<abbr title="Multicast DNS">mDNS</abbr> + <abbr title="Domain Name System">DNS</abbr>-<abbr title=
  1155           "Service Discovery">SD</abbr>)
  1156         </h4>
  1157         <p>
  1158           For each DNS response received from a user-agent-initiated Multicast DNS Browse for <abbr title=
  1159           "DNS Pointer Record">PTR</abbr> records with the name <code>_services._dns-sd._udp</code> on the resolved
  1160           recommended automatic browsing domain [[!MDNS]], the <a>user agent</a> MUST run the following steps:
  1161         </p>
  1162         <ol class="rule">
  1163           <li>Let <var>service mDNS responses</var> be an array of PTR records received by issuing a Multicast DNS
  1164           Browse for PTR records with the name of the current discovered service type.
  1165           </li>
  1166           <li>For each Object <var>service mDNS response</var> in <var>service mDNS responses</var>, run the following
  1167           steps:
  1168             <ol>
  1169               <li>Let <var>network service record</var> be an Object consisting of the following empty properties:
  1170               <code>id</code>, <code>name</code>, <code>type</code>, <code>url</code>, <code>config</code>,
  1171               <code>expiryTimestamp</code>.
  1172               </li>
  1173               <li>Set <var>network service record</var>'s <code>id</code> property to the value of the full PTR Service
  1174               Instance Name [[!MDNS]].
  1175               </li>
  1176               <li>Set <var>network service record</var>'s <code>name</code> property to the value of the PTR Service
  1177               Instance Name's <var>Instance</var> component [[!MDNS]].
  1178               </li>
  1179               <li>Set <var>network service record</var>'s <code>type</code> property to the concatenation of the string
  1180               <code>zeroconf:</code> followed be the value of the PTR Service Instance Name's <var>Service</var>
  1181               component [[!MDNS]].
  1182               </li>
  1183               <li>Set <var>network service record</var>'s <code>url</code> property to the resolvable Service URL
  1184               obtained from performing an DNS-SD Lookup [[!DNS-SD]] of the current service from the PTR record provided
  1185               [[!MDNS]].
  1186               </li>
  1187               <li>Set <var>network service record</var>'s <code>config</code> property to the string value of the
  1188               contents of the first DNS-SD TXT record associated with the <var>service mDNS response</var> as defined
  1189               in [[!DNS-SD]].
  1190               </li>
  1191               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1192               current date, in UTC timestamp format, plus a value of <code>120</code> seconds.
  1193               </li>
  1194               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1195               service record</var> as the only argument.
  1196               </li>
  1197             </ol>
  1198           </li>
  1199         </ol>
  1200       </section>
  1201       <section>
  1202         <h5>
  1203           Simple Service Discovery Protocol (<abbr title="Simple Service Discovery Protocol">SSDP</abbr>)
  1204         </h5>
  1205         <p>
  1206           A user agent that implements UPnP service discovery MUST issue a <dfn>search request for UPnP root
  1207           devices</dfn> against the user's current local network according to the full normative text and timing
  1208           provided in 'Section 1.3.2: Search request with M-SEARCH' detailed in [[!UPNP-DEVICEARCH11]].
  1209         </p>
  1210         <p>
  1211           The user agent MUST issue all <a title="search request for UPnP root devices">search requests for UPnP root
  1212           devices</a> with a HTTP request line equal to <code>M-SEARCH * HTTP/1.1</code>, with a HOST header equal to
  1213           the reserved multicast address and port of <code>239.255.255.250:1900</code> and a MAN header equal to
  1214           <code>ssdp:discover</code>. The <a>user agent</a> must also send an ST header with this HTTP request equal to
  1215           the String value of <code>ssdp:all</code> or <code>upnp:rootdevice</code> or a single <a>valid service
  1216           type</a> token beginning with the String value <code>upnp:</code>. If a single <a>valid service type</a>
  1217           token beginning with the String value <code>upnp:</code> is to be used, the user agent MUST strip the leading
  1218           String <code>upnp:</code> before using this value in this HTTP request. The user-agent MUST also send an MX
  1219           header equal to a <dfn>maximum UPnP advertisement response wait time</dfn> value between <code>1</code> and
  1220           <code>5</code> seconds with this HTTP request.
  1221         </p>
  1222         <p>
  1223           The user agent MUST listen for any incoming responses to any <a>search request for UPnP root devices</a>.
  1224         </p>
  1225         <p>
  1226           For each <dfn>HTTP Response</dfn> following an initial <a>search request for UPnP root devices</a> sent on a
  1227           <a>standard UPnP address and port</a> the user agent MUST run the following steps:
  1228         </p>
  1229         <ol class="rule">
  1230           <li>If the <a>HTTP Response</a> is not a HTTP 200 OK response then this response is invalid and the user
  1231           agent MUST discard this response, abort any remaining steps and return. The user agent MAY issue a new
  1232           <a>search request for UPnP root devices</a> as a result of this error occurring.
  1233           </li>
  1234           <li>If the <a>maximum UPnP advertisement response wait time</a> has been exceeded since the initial <a>search
  1235           request for UPnP root devices</a> was sent then the <a>HTTP Response</a> is invalid and the user agent MUST
  1236           discard this response, abort any remaining steps and return. The user agent MAY stop listening for responses
  1237           from the current <a>search request for UPnP root devices</a> as a result of this error occurring. Equally,
  1238           the user agent MAY issue a new <a>search request for UPnP root devices</a> as a result of this error
  1239           occurring.
  1240           </li>
  1241           <li>Let <var>ssdp device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1242           Response</a>, with each key being the name of a HTTP response header and each value being that HTTP response
  1243           header's value.
  1244           </li>
  1245           <li>If <var>ssdp device</var> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one
  1246           <var>USN</var> entry, at least one <var>ST</var> entry and at least one <var>LOCATION</var> entry then the
  1247           <a>HTTP Response</a> is invalid and the <a>user agent</a> MUST discard this response, abort any remaining
  1248           steps and return.
  1249           </li>
  1250           <li>The user agent MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first
  1251           occurrence of <var>LOCATION</var> from <var>ssdp device</var> as the <var>device descriptor URL</var>
  1252           argument and the first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device
  1253           identifier</var> argument and the first occurrence of <var>CACHE-CONTROL</var> from <var>ssdp device</var>
  1254           (minus the leading string of <code>max-age=</code>) as the <var>device expiry</var> argument.
  1255           </li>
  1256         </ol>
  1257         <p>
  1258           The user agent MUST listen for incoming requests on the <dfn>standard UPnP address and port</dfn> on all
  1259           current local network interface addresses with the port <code>1900</code>.
  1260         </p>
  1261         <p>
  1262           For each <dfn>HTTP Request</dfn> received on a <a>standard UPnP address and port</a> the user agent MUST run
  1263           the following steps:
  1264         </p>
  1265         <ol class="rule">
  1266           <li>If the <a>HTTP Request</a> is not a HTTP NOTIFY request then it is not a valid UPnP Request and the user
  1267           agent MUST discard this request, abort any remaining steps and return.
  1268           </li>
  1269           <li>Let <var>ssdp device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1270           Request</a>, with each key being the name of a HTTP header and each value being that HTTP header's value.
  1271           </li>
  1272           <li>If <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:alive</code> and the <a>HTTP
  1273           Request</a> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one <var>USN</var> entry,
  1274           at least one <var>NT</var> entry, at least one <var>NTS</var> entry and at least one <var>LOCATION</var>
  1275           entry, then the <a>user agent</a> MUST discard this request, abort any remaining steps and return.
  1276           </li>
  1277           <li>If <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:alive</code> then the user agent
  1278           MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first occurrence of
  1279           <var>LOCATION</var> from <var>ssdp device</var> as the <var>device descriptor URL</var> argument and the
  1280           first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device identifier</var> argument
  1281           and the first occurrence of <var>CACHE-CONTROL</var> from <var>ssdp device</var> (minus the leading string of
  1282           <code>max-age=</code>) as the <var>device expiry</var>.<br>
  1283             <br>
  1284             Otherwise, if <var>ssdp device</var>'s <var>NTS</var> entry is equal to <code>ssdp:byebye</code> then the
  1285             user agent MUST run the rule for <a>removing all services from a registered UPnP Device</a> passing in the
  1286             first occurrence of <var>USN</var> from <var>ssdp device</var> as the <var>device identifier</var>
  1287             argument.
  1288           </li>
  1289         </ol>
  1290         <p>
  1291           The rule for <dfn>obtaining a UPnP Device Description File</dfn> is the process of obtaining the contents of
  1292           a standard UPnP Device Description [[!UPNP-DEVICEARCH11]] from a URL-based resource. This rule takes three
  1293           arguments - <var>device descriptor URL</var>, <var>device identifier</var> and <var>device expiry</var> - and
  1294           when called the user agent MUST run the following steps:
  1295         </p>
  1296         <ol class="rule">
  1297           <li>Let <var>device descriptor file</var> contain the contents of the file located at the URL provided in
  1298           <var>device descriptor URL</var> obtained according to the rules defined in 'Section 2.11: Retrieving a
  1299           description using HTTP' in [[!UPNP-DEVICEARCH11]].
  1300           </li>
  1301           <li>If the value provided in <var>device descriptor URL</var> cannot be resolved as a reachable URL on the
  1302           current network or the <var>device descriptor file</var> remains empty then it is invalid and the <a>user
  1303           agent</a> MUST abort any remaining steps and return.
  1304           </li>
  1305           <li>Run the rule for <a>processing a UPnP Device Description File</a>, passing in the current <var>device
  1306           descriptor file</var>, <var>device identifier</var> and <var>device expiry</var> arguments.
  1307           </li>
  1308         </ol>
  1309         <p>
  1310           The rule for <dfn>processing a UPnP Device Description File</dfn> is the process of parsing the contents of a
  1311           standard UPnP Device Description [[!UPNP-DEVICEARCH11]] and registering the UPnP services contained therein
  1312           within the <a>list of available service records</a>.
  1313         </p>
  1314         <p>
  1315           The rule for <a>processing a UPnP Device Description File</a> takes three arguments - <var>device descriptor
  1316           file</var>, <var>device identifier</var> and <var>device expiry</var> - and when called the user agent MUST
  1317           run the following steps:
  1318         </p>
  1319         <ol class="rule">
  1320           <li>Let <var>advertised services</var> be a list of all advertised services obtained from the <var>device
  1321           descriptor file</var> containing the value of the first occurrence of the <code>&lt;serviceList&gt;</code>
  1322           element as it is defined in 'Section 2.3: Device Description' in [[!UPNP-DEVICEARCH11]].
  1323           </li>
  1324           <li>For each <code>&lt;service&gt;</code> element - known as an <var>advertised service</var> - in
  1325           <var>advertised services</var> run the following steps:
  1326             <ol class="rule">
  1327               <li>Let <var>network service record</var> be a new Object consisting of the following empty properties:
  1328               <code>id</code>, <code>deviceId</code>, <code>name</code>, <code>type</code>, <code>url</code>,
  1329               <code>eventsUrl</code>, <code>config</code>, <code>expiryTimestamp</code>.
  1330               </li>
  1331               <li>Set <var>network service record</var>'s <code>id</code> property to the concatenated string value of
  1332               the first occurrence of the <code>&lt;UDN&gt;</code> element in the <var>device descriptor file</var>
  1333               with the <var>advertised service</var>'s <code>&lt;serviceId&gt;</code> sub-element.
  1334               </li>
  1335               <li>Set <var>network service record</var>'s <code>deviceId</code> property to the value of <var>device
  1336               identifier</var>.
  1337               </li>
  1338               <li>Set <var>network service record</var>'s <code>name</code> property to the string value of the first
  1339               occurrence of the <var>advertised service</var>'s <code>&lt;serviceId&gt;</code> sub-element.
  1340               </li>
  1341               <li>Set <var>network service record</var>'s <code>type</code> property to the concatenation of the string
  1342               <code>upnp:</code> followed by the string value of the first occurrence of the <var>advertised
  1343               service</var>'s <code>&lt;serviceType&gt;</code> sub-element.
  1344               </li>
  1345               <li>Set <var>network service record</var>'s <code>url</code> property to the string value of the first
  1346               occurrence of the <var>advertised service</var>'s <code>&lt;controlURL&gt;</code> sub-element.
  1347               </li>
  1348               <li>Set <var>network service record</var>'s <code>config</code> property to the string value of the
  1349               contents of the first occurrence of the <code>&lt;device&gt;</code> element in the <var>device descriptor
  1350               file</var>.
  1351               </li>
  1352               <li>If <var>advertised service</var>'s <code>&lt;eventSubURL&gt;</code> sub-element is not empty, then
  1353               set <var>network service record</var>'s <code>eventsUrl</code> property to the string value of the first
  1354               occurrence of the <var>advertised service</var>'s <code>&lt;eventSubURL&gt;</code> sub-element.
  1355               Otherwise, do not set <var>network service record</var>'s <code>eventsUrl</code> property.
  1356               </li>
  1357               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1358               current date, in UTC timestamp format, plus the value of <var>device expiry</var>.
  1359               </li>
  1360               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1361               service record</var> as the only argument.
  1362               </li>
  1363             </ol>
  1364           </li>
  1365           <li>If <var>device descriptor file</var> contains a <code>&lt;deviceList&gt;</code> element then for each
  1366           <code>&lt;device&gt;</code> element within <code>&lt;deviceList&gt;</code> - herein known as an <var>embedded
  1367           device descriptor file</var> - the user agent MUST run the rule for <a>processing a UPnP Device Description
  1368           File</a>, passing in the current <var>embedded device descriptor file</var> as the <var>device descriptor
  1369           file</var> argument, along with the current <var>device identifier</var> and <var>device expiry</var>
  1370           arguments.
  1371           </li>
  1372         </ol>
  1373         <p>
  1374           The rule for <dfn>removing all services from a registered UPnP Device</dfn> is the process of removing all
  1375           services associated with a device from the <a>list of available service records</a> that has left the user's
  1376           current network or has otherwise timed out or expired. This rule takes one argument, <var>device
  1377           identifier</var>, and consists of running the following steps:
  1378         </p>
  1379         <ol class="rule">
  1380           <li>For each <var>existing service record</var> in the current <a>list of available service records</a>, run
  1381           the following sub-steps:
  1382             <ol class="rule">
  1383               <li>If the <var>existing service record</var>'s <code>deviceId</code> property does not match <var>device
  1384               identifier</var> then skip any remaining sub-steps for the current <var>existing service record</var> and
  1385               continue at the next available <var>existing service record</var>.
  1386               </li>
  1387               <li>Run the general rule for <a>removing an available service</a> passing in <var>existing service
  1388               record</var>'s <code>id</code> property as the only argument.
  1389               </li>
  1390             </ol>
  1391           </li>
  1392         </ol>
  1393         <p>
  1394           When the <a>user agent</a> is to <dfn>setup a UPnP Events Subscription</dfn>, it is to run the following
  1395           steps with the current <var>network service record</var> object as defined in 'Section 4.1.2: SUBSCRIBE with
  1396           NT and CALLBACK' in [[!UPNP-DEVICEARCH11]]:
  1397         </p>
  1398         <ol class="rule">
  1399           <li>If <var>network service record</var>'s <code>eventsUrl</code> property is empty then the <a>user
  1400           agent</a> MUST abort these steps.
  1401           </li>
  1402           <li>Let <var>callback URL</var> be the value of creating a new <a>user-agent generated callback url</a>.
  1403           </li>
  1404           <li>Send a HTTP SUBSCRIBE request with a <em>NT</em> header with a string value of <code>upnp:event</code>, a
  1405           <em>TIMEOUT</em> header with a user-agent defined timeout value (in the form <code>Second-XX</code> where
  1406           <code>XX</code> is the user-agent defined timeout value in seconds) and a <em>CALLBACK</em> header with a
  1407           string value of <var>callback URL</var> towards the <var>network service record</var>'s
  1408           <code>eventsUrl</code> property.
  1409           </li>
  1410           <li>If a non-200 OK response is received from the HTTP SUBSCRIBE request then the <a>user agent</a> MUST
  1411           abort these steps.
  1412           </li>
  1413           <li>On receiving a valid 200 OK response, run the following steps:
  1414             <ol class="rule">
  1415               <li>Let <var>callback ID</var> equal the string value of the first included <em>SID</em> header, if it
  1416               exists.
  1417               </li>
  1418               <li>Let <var>timeout date</var> equal the sum of the current UTC date value plus the integer value of the
  1419               first included <em>TIMEOUT</em> header (minus the leading string of <code>Second-</code>), if it exists.
  1420               </li>
  1421               <li>Run the following steps asynchronously and continue to the step labeled <em>listen</em> below.
  1422               </li>
  1423               <li>
  1424                 <em>Refresh Subscription</em>: Run the following steps at a set interval (X) within the <a>user
  1425                 agent</a>:
  1426                 <ol class="rule">
  1427                   <li>Let <var>current date</var> equal the current UTC date.
  1428                   </li>
  1429                   <li>If <var>current date</var> is less than the <var>timeout date</var> then continue to the step
  1430                   labeled <em>refresh subscription</em> above.
  1431                   </li>
  1432                   <li>Send a HTTP SUBSCRIBE request with a <em>SID</em> header with the string value of <var>callback
  1433                   ID</var> and a user-agent defined <em>TIMEOUT</em> header (in the form <code>Second-XX</code> where
  1434                   <code>XX</code> is the user-agent defined timeout value in seconds) towards the <var>network service
  1435                   record</var>'s <code>eventsUrl</code> property.
  1436                   </li>
  1437                   <li>On receiving a valid 200 OK, update <var>callback ID</var> with the string value of the first
  1438                   included <em>SID</em> header and set <var>timeout date</var> to the sum of the current UTC date value
  1439                   plus the integer value of the first included <em>TIMEOUT</em> header (minus the leading string of
  1440                   <code>Second-</code>), if it exists. If the current date is greater than or equal to <var>timeout
  1441                   date</var> then the <a>user agent</a> SHOULD continue from the step labeled <em>refresh
  1442                   subscription</em> above. For all non 200 OK responses the <a>user agent</a> SHOULD continue from the
  1443                   step labeled <em>refresh subscription</em> above.
  1444                   </li>
  1445                 </ol>
  1446               </li>
  1447               <li>
  1448                 <em>Listen</em>: For each HTTP NOTIFY request received at the <var>callback URL</var> the <a>user
  1449                 agent</a> is to run the following steps:
  1450                 <ol class="rule">
  1451                   <li>Let <var>content clone</var> be the result of obtaining the message body of the HTTP NOTIFY
  1452                   request. If <var>content clone</var> is empty, then the <a>user agent</a> MUST abort these steps.
  1453                   </li>
  1454                   <li>Let <var>notification event</var> be a new simple event that uses the <a href=
  1455                   "http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1456                         class="externalDFN"><code>Event</code></a> interface with the name <a href=
  1457                         "#event-notify"><code>notify</code></a>, which does not bubble, is not cancellable, and has no
  1458                         default action.
  1459                   </li>
  1460                   <li>Let the <code>data</code> attribute of <var>notification event</var> have the DOMString value of
  1461                   <var>content clone</var>.
  1462                   </li>
  1463                   <li>
  1464                     <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/webappapis.html#queue-a-task"
  1465                         class="externalDFN">Queue a task</a> to dispatch <var>notification event</var> at the current
  1466                         <a><code>NetworkService</code></a> object.
  1467                   </li>
  1468                   <li>Return a HTTP 200 OK response to the sender of the HTTP NOTIFY request.
  1469                   </li>
  1470                 </ol>
  1471               </li>
  1472             </ol>
  1473           </li>
  1474         </ol>
  1475         <p>
  1476           A <a>user agent</a> can <dfn>terminate an existing UPnP Events Subscription</dfn> at any time for a
  1477           <var>network service record</var> by sending an HTTP UNSUBSCRIBE request - as defined in 'Section 4.1.4:
  1478           Cancelling a subscription with UNSUBSCRIBE' in [[!UPNP-DEVICEARCH11]] - with a HOST header set to that
  1479           <var>active service</var>'s <code>eventsUrl</code> property and a SID header set to the <var>callback
  1480           ID</var> obtained when the initial <a>setup a UPnP Events Subscription</a> action occurred.
  1481         </p>
  1482       </section>
  1483       <section>
  1484         <h5>
  1485           Discovery and Launch Protocol (<abbr title="Discovery and Launch Protocol">DIAL</abbr>)
  1486         </h5>
  1487         <p>
  1488           A user agent that implements DIAL service discovery MUST issue a <dfn>search request for DIAL-enabled
  1489           devices</dfn> against the user's current local network according to the full normative text and timing
  1490           provided in 'Section 1.3.2: Search request with M-SEARCH' detailed in [[!UPNP-DEVICEARCH11]].
  1491         </p>
  1492         <p>
  1493           Let <var>dial version</var> be the version number specified in the <a>valid service type</a> token. Let
  1494           <var>dial search target</var> be the concatentation of the
  1495           <code>urn:dial-multiscreen-org:service:dial:</code> string constant with the <var>dial version</var>
  1496           (currently, <var>dial version</var> can only be <code>1</code>)
  1497         </p>
  1498         <p>
  1499           The user agent MUST issue all <a title="search request for DIAL devices">search requests for DIAL devices</a>
  1500           with a HTTP request line equal to <code>M-SEARCH * HTTP/1.1</code>, with a HOST header equal to the reserved
  1501           multicast address and port of <code>239.255.255.250:1900</code>, a MAN header equal to
  1502           <code>ssdp:discover</code>, an ST header equal to <var>dial search target</var> and a user-agent defined MX
  1503           header equal to a <dfn>maximum DIAL advertisement response wait time</dfn> value between <code>1</code> and
  1504           <code>5</code> seconds.
  1505         </p>
  1506         <p>
  1507           The user agent MUST listen for any incoming responses to a <a>search request for DIAL devices</a>.
  1508         </p>
  1509         <p>
  1510           For each HTTP Response following an initial <a>search request for DIAL devices</a> sent on a <a>standard UPnP
  1511           address and port</a> the user agent MUST run the following steps:
  1512         </p>
  1513         <ol class="rule">
  1514           <li>If the HTTP Response is not a HTTP 200 OK response then this response is invalid and the user agent MUST
  1515           discard this response, abort any remaining steps and return. The user agent MAY issue a new <a>search request
  1516           for DIAL devices</a> as a result of this error occurring.
  1517           </li>
  1518           <li>If the <a>maximum DIAL advertisement response wait time</a> has been exceeded since the initial <a>search
  1519           request for DIAL devices</a> was sent then the <a>HTTP Response</a> is invalid and the user agent MUST
  1520           discard this response, abort any remaining steps and return. The user agent MAY stop listening for responses
  1521           from the current <a>search request for DIAL devices</a> as a result of this error occurring. Equally, the
  1522           user agent MAY issue a new <a>search request for DIAL devices</a> as a result of this error occurring.
  1523           </li>
  1524           <li>Let <var>dial device</var> be an Object with a property for each HTTP header received in the <a>HTTP
  1525           Response</a>, with each key being the name of a HTTP response header and each value being that HTTP response
  1526           header's value.
  1527           </li>
  1528           <li>If <var>dial device</var> does not contain at least one <var>CACHE-CONTROL</var> entry, at least one
  1529           <var>USN</var> entry, at least one <var>ST</var> entry and at least one <var>LOCATION</var> entry or the
  1530           value of its <var>ST</var> entry is not <var>dial search target</var>, then the <a>HTTP Response</a> is
  1531           invalid and the <a>user agent</a> MUST discard this response, abort any remaining steps and return.
  1532           </li>
  1533           <li>The user agent MUST run the rule for <a>obtaining a UPnP Device Description File</a> passing in the first
  1534           occurrence of <var>LOCATION</var> from <var>dial device</var> as the <var>device descriptor URL</var>
  1535           argument and the first occurrence of <var>USN</var> from <var>dial device</var> as the <var>device
  1536           identifier</var> argument and the first occurrence of <var>CACHE-CONTROL</var> from <var>dial device</var>
  1537           (minus the leading string of <code>max-age=</code>) as the <var>device expiry</var> argument.
  1538           </li>
  1539         </ol>
  1540         <p>
  1541           The rule for <dfn>obtaining a DIAL Device Description File</dfn> is the process of obtaining the contents of
  1542           a standard UPnP Device Description [[!UPNP-DEVICEARCH11]] from a URL-based resource. This rule takes three
  1543           arguments - <var>device descriptor URL</var>, <var>device identifier</var> and <var>device expiry</var> - and
  1544           when called the user agent MUST run the following steps:
  1545         </p>
  1546         <ol class="rule">
  1547           <li>Let <var>device descriptor file</var> contain the contents of the file located at the URL provided in
  1548           <var>device descriptor URL</var> obtained according to the rules defined in 'Section 2.11: Retrieving a
  1549           description using HTTP' in [[!UPNP-DEVICEARCH11]].
  1550           </li>
  1551           <li>Let <var>application url</var> be the value of the first occurrence of the <code>Application-URL</code>
  1552           response header field obtained according to the rules defined in 'Section 5.4: Device Description Response'
  1553           in [<a href="https://sites.google.com/a/dial-multiscreen.org/dial/dial-protocol-specification">DIAL</a>]
  1554           </li>
  1555           <li>If the value provided in <var>device descriptor URL</var> cannot be resolved as a reachable URL on the
  1556           current network or the <var>device descriptor file</var> remains empty or <var>application url</var> is
  1557           undefined then it is invalid and the <a>user agent</a> MUST abort any remaining steps and return.
  1558           </li>
  1559           <li>Run the following steps to add the newly discovered DIAL service:
  1560             <ol class="rule">
  1561               <li>Let <var>network service record</var> be a new Object consisting of the following empty properties:
  1562               <code>id</code>, <code>deviceId</code>, <code>name</code>, <code>type</code>, <code>url</code>,
  1563               <code>expiryTimestamp</code>.
  1564               </li>
  1565               <li>Set <var>network service record</var>'s <code>id</code> property to the first occurrence of the
  1566               <code>&lt;UDN&gt;</code> element in the <var>descriptor file</var> prefixed with the <code>dial:</code>
  1567               string constant
  1568               </li>
  1569               <li>Set <var>network service record</var>'s <code>deviceId</code> property to the value of <var>device
  1570               identifier</var>.
  1571               </li>
  1572               <li>Set <var>network service record</var>'s <code>name</code> property to the string value of the first
  1573               occurrence of the <code>&lt;friendlyName&gt;</code> element in the <var>descriptor file</var>.
  1574               </li>
  1575               <li>Set <var>network service record</var>'s <code>type</code> property to <var>dial search target</var>.
  1576               </li>
  1577               <li>Set <var>network service record</var>'s <code>url</code> property to the string value of the
  1578               <var>application url</var>.
  1579               </li>
  1580               <li>Set <var>network service record</var>'s <code>expiryTimestamp</code> property to the value of the
  1581               current date, in UTC timestamp format, plus the value of <var>device expiry</var>.
  1582               </li>
  1583               <li>Run the general rule for <a>adding an available service</a>, passing in the current <var>network
  1584               service record</var> as the only argument.
  1585               </li>
  1586             </ol>
  1587           </li>
  1588         </ol>
  1589       </section>
  1590       <section>
  1591         <h3>
  1592           Network Topology Monitoring
  1593         </h3>
  1594         <div>
  1595           <p>
  1596             When the <a>user agent</a> detects that the user has dropped from a connected network then, for each
  1597             <var>existing service record</var> in the <a>list of available service records</a> discovered via that
  1598             network connection, the <a>user agent</a> MUST run the general rule for <a>removing an available
  1599             service</a> passing in each <var>existing service record</var>'s <code>id</code> property as the only
  1600             argument for each call.
  1601           </p>
  1602           <p>
  1603             When the <a>user agent</a> detects that the user has connected to a new network or reconnected to an
  1604             existing network, then it SHOULD restart its discovery mechanisms as defined in the <a href=
  1605             "#service-discovery">Service Discovery</a> section of this specification, maintaining the existing <a>list
  1606             of active service managers</a> currently in use.
  1607           </p>
  1608         </div>
  1609       </section>
  1610     </section>
  1611     <section>
  1612       <h3>
  1613         Events Summary
  1614       </h3>
  1615       <p>
  1616         The following events are dispatched on the <a href="#networkservices"><code>NetworkServices</code></a> and/or
  1617         <a href="#networkservice"><code>NetworkService</code></a> objects:
  1618       </p>
  1619       <table border="1">
  1620         <thead>
  1621           <tr>
  1622             <th>
  1623               <span>Event name</span>
  1624             </th>
  1625             <th>
  1626               <span>Interface</span>
  1627             </th>
  1628             <th>
  1629               <span>Dispatched when...</span>
  1630             </th>
  1631           </tr>
  1632         </thead>
  1633         <tbody>
  1634           <tr>
  1635             <td>
  1636               <dfn id="event-serviceavailable"><code>serviceavailable</code></dfn>
  1637             </td>
  1638             <td>
  1639               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1640                   class="externalDFN"><code>Event</code></a>
  1641             </td>
  1642             <td>
  1643               When a <a>new service</a> that matches one of the <a>requested type tokens</a> is found in the current
  1644               network.
  1645             </td>
  1646           </tr>
  1647           <tr>
  1648             <td>
  1649               <dfn id="event-serviceunavailable"><code>serviceunavailable</code></dfn>
  1650             </td>
  1651             <td>
  1652               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1653                   class="externalDFN"><code>Event</code></a>
  1654             </td>
  1655             <td>
  1656               When an <a>existing service</a> that matches one of the <a>requested type tokens</a> gracefully leaves or
  1657               expires from the current network.
  1658             </td>
  1659           </tr>
  1660           <tr>
  1661             <td>
  1662               <dfn id="event-serviceonline"><code>serviceonline</code></dfn>
  1663             </td>
  1664             <td>
  1665               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1666                   class="externalDFN"><code>Event</code></a>
  1667             </td>
  1668             <td>
  1669               When a <a>current service</a> renews its service registration within the current network.
  1670             </td>
  1671           </tr>
  1672           <tr>
  1673             <td>
  1674               <dfn id="event-serviceoffline"><code>serviceoffline</code></dfn>
  1675             </td>
  1676             <td>
  1677               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1678                   class="externalDFN"><code>Event</code></a>
  1679             </td>
  1680             <td>
  1681               When a <a>current service</a> gracefully leaves or otherwise expires from the current network.
  1682             </td>
  1683           </tr>
  1684           <tr>
  1685             <td>
  1686               <dfn id="event-notify"><code>notify</code></dfn>
  1687             </td>
  1688             <td>
  1689               <a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event"
  1690                   class="externalDFN"><code>Event</code></a>
  1691             </td>
  1692             <td>
  1693               When a valid UPnP Events Subscription Message is received on a <a>user-agent generated callback url</a>
  1694               for a <a>current service</a>. This event never fires for Zeroconf-based services.
  1695             </td>
  1696           </tr>
  1697         </tbody>
  1698       </table>
  1699     </section>
  1700     <section>
  1701       <h3>
  1702         Garbage collection
  1703       </h3>
  1704       <p>
  1705         A user agent MUST only garbage collect a <a><code>NetworkServices</code></a> object and remove its entry from
  1706         the <a>list of active service managers</a> when the user has navigated away from the <a href=
  1707         "http://www.whatwg.org/specs/web-apps/current-work/complete/browsers.html#entry-script"
  1708            class="externalDFN">entry script</a>'s <a href=
  1709            "http://www.whatwg.org/specs/web-apps/current-work/complete/origin-0.html#origin"
  1710            class="externalDFN">origin</a> in which the current <a><code>NetworkServices</code></a> object was provided.
  1711       </p>
  1712       <p>
  1713         A user agent MUST NOT garbage collect individual <a><code>NetworkService</code></a> objects until their parent
  1714         <a><code>NetworkServices</code></a> object has been garbage collected.
  1715       </p>
  1716       <p>
  1717         A user agent MUST garbage collect the <a><code>NetworkService</code></a> <a>indexed properties</a> of a
  1718         <a><code>NetworkServices</code></a> object, passing each indexed property's <code>id</code> attribute as the
  1719         only argument to the rule for <a>removing an available service<a>, when that <a><code>NetworkServices</code></a> object itself has been
  1720         garbage-collected.
  1721       </p>
  1722     </section>
  1723     <section>
  1724       <h3>
  1725         Use Cases and Requirements
  1726       </h3>
  1727       <p>
  1728         This section covers what the requirements are for this API, as well as illustrates some use cases.
  1729       </p>
  1730       <ul class="rule">
  1731         <li>Once a user has given permission, user agents should provide the ability for Web pages to communicate
  1732         directly with a Local-networked Service.
  1733           <ul class="rule">
  1734             <li>Example: A web-based TV remote control. A Web page wants to control the current user's TV, changing the
  1735             programming shown or increasing/decreasing/muting the volume of the Local-networked Device. The Web page
  1736             requests a service type that is known to be implemented by television sets to which it has the application
  1737             logic to communicate. Local devices providing the request service types are discovered and presented to the
  1738             user for authorization. The user selects one or more of the discovered television sets to be accessible to
  1739             the current Web page and then clicks 'Share'. The Web page can now communicate directly with the
  1740             user-authorized Local-networked services.
  1741             </li>
  1742           </ul>
  1743         </li>
  1744         <li>Web pages should be able to communicate with Local-networked Services using the messaging channel supported
  1745         by those Devices.
  1746           <ul class="rule">
  1747             <li>Example: A Web page advertises that it is capable of controlling multiple Home Media Servers. The user
  1748             can select their Home Media Server type from a drop-down list, at which point the Web page sends a request
  1749             to the user agent to connect with the associated service type of the Home Media Server. The Media Server
  1750             selected implements a Web Socket channel for bi-directional service communication and so the Web page opens
  1751             a web socket to the requested Media Server and can communicate as required via that appropriate channel.
  1752             </li>
  1753           </ul>
  1754         </li>
  1755         <li>Web pages should be able to communicate with Local-networked Services using the messaging format supported
  1756         by those Devices.
  1757           <ul class="rule">
  1758             <li>Example: A Web page advertises that it is capable of interacting with and controlling multiple types of
  1759             Home Media Server. The user can select their Home Media Server type from a drop-down list or known Media
  1760             Servers, at which point the Web page sends a request to the user agent to connect with the associated
  1761             service type (and, optionally, the associated event type) of the Home Media Server. The communication
  1762             protocols supported by Home Media Servers typically vary between UPnP, JSON-RPC, Protocol Buffers or other
  1763             messaging formats depending on the Home Media Server requested. The Web page is able to communicate with
  1764             the user-selected Home Media Server in the messaging format supported by that Device, which, in this
  1765             example is a simple key/value pair text format.
  1766             </li>
  1767           </ul>
  1768         </li>
  1769         <li>Web pages should not be able to communicate with Local-networked Services that have not been authorized by
  1770         the user thereby maintaining the user's privacy.
  1771           <ul class="rule">
  1772             <li>Example: A Web page requests access to one type of Local-networked service. The user authorizes access
  1773             to that particular service. Other services running on that same device, and on other devices within the
  1774             network, should not be accessible to the current Web page.
  1775             </li>
  1776           </ul>
  1777         </li>
  1778         <li>A user should be able to share one or more Local-networked Services based on a particular service type
  1779         request from a Web page.
  1780           <ul class="rule">
  1781             <li>Example: A Web page is capable of interacting with a specific profile of Local-networked Service. As
  1782             such, it makes a request to the user agent to access those services, of which multiple matches are found.
  1783             The user is capable of selecting one or more of the discovered services to share with the Web page. The Web
  1784             page can then implement a drag-and-drop interface for the user to drag specific actions on to one or more
  1785             of the authorized Local-networked Services.
  1786             </li>
  1787           </ul>
  1788         </li>
  1789         <li>User agents should provide an API exposed to script that exposes the features above. The user is notified
  1790         by UI anytime interaction with Local-networked Services is requested, giving the user full ability to cancel or
  1791         abort the transaction. The user selects the Local-networked Services to be connected to the current Web page,
  1792         and can cancel these at any time. No invocations to these APIs occur silently without user intervention.
  1793         </li>
  1794       </ul>
  1795     </section>
  1796     <section class="informative appendix">
  1797       <h3>
  1798         Examples
  1799       </h3>
  1800       <div class="example">
  1801         <p>
  1802           This sample code exposes a button. When clicked, this button is disabled and the user is prompted to offer a
  1803           network service. The user may also select multiple network services. When the user has authorized a network
  1804           service to be connected to the web page then the web page issues a simple command to get a list of all the
  1805           albums stored on the connected media player service.
  1806         </p>
  1807         <p>
  1808           The button is re-enabled only when the connected network service disconnects for whatever reason (the service
  1809           becomes unavailable on the network, the user disconnects from their current network or the user revokes
  1810           access to the service from the current web page). At this point the user can re-click the button to select a
  1811           new network service to connect to the web page and the above steps are repeated.
  1812         </p>
  1813         <p>
  1814           The provided service type identifier and service interaction used in this example is based on the
  1815           well-defined service type and messaging format supported by the <a href="http://xbmc.org/about/">XBMC Media
  1816           Server</a>.
  1817         </p>
  1818         <hr>
  1819         <pre class="highlight">
  1820 &lt;input type="button" value="Start" onclick="start()" id="startBtn"/&gt;
  1821 &lt;div id="debugconsole"&gt;&lt;/div&gt;
  1822 
  1823 &lt;script&gt;
  1824  var startBtn = document.getElementById('startBtn'),
  1825      debug = document.getElementById('debugconsole');
  1826 
  1827  function start() {
  1828    if(navigator.getNetworkServices) {
  1829       navigator.getNetworkServices('zeroconf:_xbmc-jsonrpc._tcp', gotXBMCService, error);
  1830       startBtn.disabled = true;
  1831    } else {
  1832       debug.innerHTML += "&lt;br&gt;Service Discovery not supported!";
  1833    }
  1834  }
  1835 
  1836  function gotXBMCService(services) {
  1837 
  1838 // Listen for service disconnect messages
  1839 
  1840    services[0].addEventListener('serviceoffline', function ( e ) {
  1841        debug.innerHTML += "&lt;br&gt;" + services[0].name + " disconnected.";
  1842        startBtn.disabled = false;
  1843    }, false);
  1844 
  1845 // Send a service message to get albums list (and process the service response)
  1846 
  1847    var svcXhr = new XMLHttpRequest();
  1848    svcXhr.open("POST", services[0].url + "/getAlbums"); // services[0].url and its sub-resources have been
  1849                                                         // whitelisted for cross-site XHR use in this
  1850                                                         // current browsing context.
  1851 
  1852    svcXhr.setRequestHeader('Content-Type', 'application/json-rpc');
  1853 
  1854    svcXhr.addEventListener('readystatechange', function ( response ) {
  1855      if( response.readyState != 4 || response.status != 200 )
  1856         return;
  1857      debug.innerHTML += "&lt;br&gt;" + services[0].name + " response received: ";
  1858      debug.textContent += JSON.parse(response.responseText);
  1859    }, false);
  1860 
  1861    var svcMsg = [
  1862      { "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "genreid": -1,
  1863          "artistid": -1, "start": -1, "end": -1 }, "id": "1" }
  1864    ];
  1865 
  1866    svcXhr.send(JSON.stringify(svcMsg));
  1867    debug.innerHTML += "&lt;br&gt;" + services[0].name + " request sent: ";
  1868    debug.textContent += JSON.stringify(svcMsg);
  1869 
  1870  }
  1871 
  1872  function error( err ) {
  1873    debug.innerHTML += "&lt;br&gt;An error occurred obtaining a local network service.";
  1874    startBtn.disabled = false;
  1875  }
  1876 &lt;/script&gt;
  1877 </pre>
  1878       </div>
  1879       <div class="example">
  1880         <p>
  1881           This sample exposes a drop-down list containing a number of common Home-based audio devices. When the user
  1882           selects an audio device from the list provided, they are prompted to authorize a network service based on the
  1883           service type requested. The user may also select multiple network services matching the selected service
  1884           type. In this example, the user selects their make as being <var>Sony</var> and their model as being
  1885           <var>Bravia S1000</var> from which the Web page can derive a service type
  1886           (<var>urn:schemas-upnp-org:service:RenderingControl:1</var>).<br>
  1887           <br>
  1888           Once the user has authorized the device, the web page sends a simple mute command according to the messaging
  1889           format supported by the device.
  1890         </p>
  1891         <hr>
  1892         <pre class="highlight">
  1893 &lt;select name="make" id="make"&gt;
  1894   &lt;option selected="selected" disabled="disabled"&gt;Select make&lt;/option&gt;
  1895   &lt;option&gt;Sony&lt;/option&gt;
  1896   &lt;option&gt;Philips&lt;/option&gt;
  1897   &lt;option&gt;Alba&lt;/option&gt;
  1898 &lt;/select&gt;
  1899 &lt;select name="model" id="model"&gt;&lt;/select&gt;
  1900 &lt;div id="debugconsole"&gt;&lt;/div&gt;
  1901 
  1902 &lt;script&gt;
  1903   var debug = document.getElementById('debugconsole');
  1904 
  1905   var models = {
  1906     "Sony": [
  1907       {"name": "Bravia TV S1000", "type": "upnp", "service": "urn:schemas-upnp-org:service:RenderingControl:1" },
  1908       {"name": "Bravia TV S2000", "type": "zeroconf", "service": "_mediarenderer._http._tcp" },
  1909       {"name": "HiFi WD10", "type": "upnp", "service": "urn:schemas-upnp-org:service:RenderingControl:1" }
  1910     ],
  1911     "Philips": [ /* ... */ ],
  1912     "Alba": [ /* ... */ ]
  1913   };
  1914 
  1915   var makeEl = document.getElementById("make"),
  1916       modelEl = document.getElementById("model");
  1917 
  1918   makeEl.addEventListener('change', function() {
  1919     modelEl.innerHTML = ""; // reset
  1920     var defaultOption = document.createElement("option");
  1921     defaultOption.textContent = "Select model";
  1922     defaultOption.setAttribute("disabled", "disabled");
  1923     defaultOption.setAttribute("selected", "selected");
  1924     modelEl.appendChild(defaultOption);
  1925     for(var i = 0, l = models[makeEl.value].length; i &lt; l; i++) {
  1926       var option = document.createElement("option");
  1927       option.textContent = models[makeEl.value][i]["name"];
  1928       option.setAttribute("value", models[makeEl.value][i]["type"] + ":" + models[makeEl.value][i]["service"]);
  1929       modelEl.appendChild(option);
  1930     }
  1931   }, false);
  1932 
  1933   modelEl.addEventListener('change', function() {
  1934     if(navigator.getNetworkServices &amp;&amp;
  1935          modelEl.value == "upnp:urn:schemas-upnp-org:service:RenderingControl:1") {
  1936       navigator.getNetworkServices(modelEl.value, successCallback, errorCallback);
  1937     } else if (modelEl.value == "zeroconf:_mediarenderer._http._tcp") {
  1938       debug.innerHTML += "&lt;br&gt;Service type is not implemented by this application.";
  1939     } else {
  1940       debug.innerHTML += "&lt;br&gt;Service Discovery is not supported!";
  1941     }
  1942   }, false);
  1943 &lt;/script&gt;
  1944 
  1945 &lt;script&gt;
  1946   function successCallback( services ) {
  1947 
  1948   // Listen for service push notification messages
  1949 
  1950     services[0].addEventListener('notify', function ( msg ) {
  1951          debug.innerHTML += "&lt;br&gt;" + services[0].name + " event received: ";
  1952          debug.textContent += msg.data;
  1953     }, false);
  1954 
  1955  // Send a control signal to mute the service audio
  1956 
  1957     var svcXhr = new XMLHttpRequest();
  1958     svcXhr.open("POST", services[0].url); // services[0].url and its
  1959                                           // sub-resources have been whitelisted for
  1960                                           // cross-site XHR use in this current
  1961                                           // browsing context.
  1962 
  1963     svcXhr.setRequestHeader('SOAPAction', 'urn:schemas-upnp-org:service:RenderingControl:1#SetMute');
  1964     svcXhr.setRequestHeader('Content-Type', 'text/xml; charset="utf-8";');
  1965 
  1966     svcXhr.onreadystatechange = function ( response ) {
  1967       if( response.readyState != 4 || response.status != 200 )
  1968         return;
  1969       debug.innerHTML += "&lt;br&gt;" + services[0].name + " response received: ";
  1970       debug.textContent += response.responseXML;
  1971     }
  1972 
  1973     // Service messaging to mute the provided service
  1974     var svcMsg = '&lt;?xml version="1.0" encoding="utf-8"?&gt;' +
  1975                  '&lt;s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ' +
  1976                    'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;' +
  1977                    '&lt;s:Body&gt;' +
  1978                      '&lt;u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"&gt;' +
  1979                        '&lt;InstanceID&gt;0&lt;/InstanceID&gt;' +
  1980                        '&lt;Channel&gt;Master&lt;/Channel&gt;' +
  1981                        '&lt;DesiredMute&gt;true&lt;/DesiredMute&gt;' +
  1982                      '&lt;/u:SetMute&gt;' +
  1983                    '&lt;/s:Body&gt;' +
  1984                  '&lt;/s:Envelope&gt;';
  1985 
  1986     svcXhr.send(svcMsg);
  1987     debug.innerHTML += "&lt;br&gt;" + services[0].name + " request sent: ";
  1988     debug.textContent += svcMsg;
  1989   }
  1990 
  1991   function errorCallback( error ) {
  1992     debug.innerHTML += "&lt;br&gt;An error occurred: " + error.code;
  1993   }
  1994 &lt;/script&gt;
  1995 </pre>
  1996       </div>
  1997     </section>
  1998     <section>
  1999       <h3>
  2000         Acknowledgements
  2001       </h3>
  2002       <p>
  2003         Thanks are expressed by the editor to the following individuals for their feedback on this specification to
  2004         date (in alphabetical order):<br>
  2005         <br>
  2006         Gar Bergstedt, Lars-Erik Bolstad, Cathy Chan, Hari G Kumar, Bob Lund, Giuseppe Pascale, Marcin Simonides,
  2007         Clarke Stevens, Christian Söderström, Mark Vickers.
  2008       </p>
  2009       <p>
  2010         Thanks are also expressed by the editor to the following organizations and groups for their support in
  2011         producing this specification to date (in alphabetical order):<br>
  2012         <br>
  2013         CableLabs, Opera Software ASA, W3C Device APIs Working Group, W3C Web and TV Interest Group.
  2014       </p>
  2015     </section>
  2016   </body>
  2017 </html>