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