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