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