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