/
index.html
2189 lines (2153 loc) · 90.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>
Presentation API
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c-common" async
class="remove">
</script>
<script class="remove">
var respecConfig = {
specStatus: 'ED',
edDraftURI: 'https://w3c.github.io/presentation-api/',
shortName: 'presentation-api',
editors: [
{
w3cid: 68454,
name: 'Mark Foltz',
company: 'Google',
mailto: 'mfoltz@google.com'
},
{
w3cid: 63802,
name: 'Dominik Röttsches',
company: 'Intel',
note: 'until April 2015'
}
],
previousMaturity: 'WD',
previousPublishDate: '2015-07-01',
otherLinks: [
{
key: 'Version history',
data: [
{
value: 'GitHub w3c/presentation-api/commits',
href: 'https://github.com/w3c/presentation-api/commits/'
}
]
},
{
key: 'Participate',
data: [
{
value: 'GitHub w3c/presentation-api',
href: 'https://github.com/w3c/presentation-api/'
},
{
value: 'File an issue',
href: 'https://github.com/w3c/presentation-api/issues/new'
},
{
value: 'Open issues',
href: 'https://github.com/w3c/presentation-api/issues/'
},
{
value: 'Mailing-list (public-secondscreen@w3.org)',
href: 'https://lists.w3.org/Archives/Public/public-secondscreen/'
}
]
}
],
wg: 'Second Screen Presentation Working Group',
wgURI: 'http://www.w3.org/2014/secondscreen/',
wgPublicList: 'public-secondscreen',
wgPatentURI: 'http://www.w3.org/2004/01/pp-impl/74168/status',
localBiblio: {
PROMGUIDE: {
title: 'Writing Promise-Using Specifications',
href: 'http://www.w3.org/2001/tag/doc/promises-guide',
authors: [
'Domenic Denicola'
],
status: 'finding',
publisher: 'W3C'
}
},
issueBase: "https://www.github.com/w3c/presentation-api/issues/",
// TODO: Uncomment when https://github.com/w3c/presentation-api/issues/228 is fixed
// githubAPI: "https://api.github.com/repos/w3c/presentation-api",
// Temp fix for ReSpec issue #483:
// https://github.com/w3c/respec/issues/483
afterEnd: function () {
Array.prototype.forEach.call(
document.querySelectorAll("[for],[dfn-for],[link-for]"),
function (element) {
element.removeAttribute('for');
element.removeAttribute('dfn-for');
element.removeAttribute('link-for');
}
);
}
};
</script>
<style>
/* Note formatting taken from HTML5 spec */
.note { border-left-style: solid; border-left-width: 0.25em; background: none repeat scroll 0 0 #E9FBE9; border-color: #52E052; }
.note em, .warning em, .note i, .warning i { font-style: normal; }
p.note, div.note { padding: 0.5em 2em; }
span.note { padding: 0 2em; }
.note p:first-child { margin-top: 0; }
.note p:last-child { margin-bottom: 0; }
p.note:before { content: 'NOTE: '; }
.non-normative { border-left-style: solid; border-left-width: 0.25em; background: none repeat scroll 0 0 #E9FBE9; border-color: #52E052; }
p.non-normative:before { content: 'Non-normative: '; font-weight: bolder;}
p.non-normative, div.non-normative { padding: 0.5em 2em; }
/* Pre.idl formatting taken from HTML5 spec */
pre.idl { border: solid thin #d3d3d3; background: #FCFCFC; color: black; padding: 0.5em 1em; position: relative; }
pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
pre.idl::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 }
/* .example idl formatting taken from HTML5 nightly spec */
.example {
display: block;
color: #222222;
background: #FCFCFC;
border-left-style: solid;
border-color: #c0c0c0;
border-left-width: 0.25em;
margin-left: 1em;
padding-left: 1em;
padding-bottom: 0.5em;
}
.algorithm li {
margin-bottom: 0.5em;
}
.interface dd, .parameters dt {
margin-bottom: 0.5em;
}
code { color: orangered; }
table { border-collapse: collapse; border-style: hidden hidden none hidden; }
table thead, table tbody { border-bottom: solid; }
table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
dfn { font-weight: bolder; font-style: normal; }
.copyright { font-size: small; }
.issue[id^='issue-'] > *:not([role='heading']) { display: none; }
</style>
</head>
<body>
<section id="abstract">
<p>
This specification defines an API to enable web content to access
external presentation-type displays and use them for presenting web
content.
</p>
</section>
<section id="sotd">
<p>
This document is a <b>work in progress</b> and is subject to change.
Some sections are still incomplete or underspecified. <a href=
"#security-and-privacy-considerations">Security and privacy
considerations</a> need to be adjusted based on feedback and
experience. Some open issues are noted inline; please check the group's
<a href="https://github.com/w3c/presentation-api/issues">issue
tracker</a> on GitHub for all open issues. Feedback from early
experimentations is encouraged to allow the Second Screen Presentation
Working Group to evolve the specification based on implementation
issues.
</p>
</section>
<section class="informative">
<h2>
Introduction
</h2>
<p>
This specification aims to make <a>presentation displays</a> such as
projectors or connected TVs, available to the Web and takes into
account displays that are attached using wired (HDMI, DVI, or similar)
and wireless technologies (Miracast, Chromecast, DLNA, AirPlay, or
similar).
</p>
<p>
Devices with limited screen size lack the ability to show content to a
larger audience, for example, a group of colleagues in a conference
room, or friends and family at home. Showing content on an external
large <a>presentation display</a> helps to improve the perceived
quality and impact of the presented content.
</p>
<p>
At its core, this specification enables an exchange of messages between
a page that acts as the <a>controller</a> and another page that
represents the <a data-lt="receiving browsing context">presentation</a>
shown in the <a>presentation display</a>. How the messages are
transmitted is left to the UA in order to allow the use of
<a>presentation display</a> devices that can be attached in a wide
variety of ways. For example, when a <a>presentation display</a> device
is attached using HDMI or Miracast, the same UA that acts as the
<a>controller</a> renders the <a data-lt=
"receiving browsing context">presentation</a>. Instead of displaying
the <a data-lt="receiving browsing context">presentation</a> in another
window on the same device, however, it can use whatever means the
operating system provides for using the external <a>presentation
displays</a>. In such a case, both the <a>controller</a> and
<a data-lt="receiving browsing context">presentation</a> run on the
same UA and the operating system is used to route the <a>presentation
display</a> output to the <a>presentation display</a>. This is commonly
referred to as the <dfn><b id="1-ua">1-UA</b></dfn> case. This
specification imposes no requirements on the <a>presentation
display</a> devices connected in such a manner.
</p>
<p>
If the <a>presentation display</a> is able to render HTML documents and
communicate with the <a>controller</a>, the <a>controller</a> does not
need to render the <a data-lt=
"receiving browsing context">presentation</a>. In this case, the UA
acts as a proxy that requests the <a>presentation display</a> to show
and render the <a data-lt="receiving browsing context">presentation</a>
itself. This is commonly referred to as the <b id="2-ua">2-UA</b> case.
This way of attaching to displays could be enhanced in the future by
defining a standard protocol for delivering these types of messages
that display devices could choose to implement.
</p>
<p>
The API defined here is intended to be used with UAs that attach to
<a>presentation display</a> devices through any of the above means.
</p>
</section>
<section id="use-cases-and-requirements">
<h2>
Use cases and requirements
</h2>
<p>
Use cases and requirements are captured in a separate <a href=
"https://github.com/w3c/presentation-api/blob/gh-pages/uc-req.md">Presentation
API Use Cases and Requirements</a> document.
</p>
</section>
<section id="conformance">
<p>
Requirements phrased in the imperative as part of algorithms (such as
"strip any leading space characters" or "return false and terminate
these steps") are to be interpreted with the meaning of the key word
("MUST", "SHOULD", "MAY", etc.) used in introducing the algorithm.
</p>
<p>
Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the result is equivalent. (In
particular, the algorithms defined in this specification are intended
to be easy to follow, and not intended to be performant.)
</p>
<section>
<h3>
Conformance Classes
</h3>
<p>
This specification describes the conformance criteria for two classes
of user agents.
</p>
<dl>
<dt>
<dfn>Controlling user agent</dfn>
</dt>
<dd>
<p>
Web browsers that conform to the specifications of a
<a>controlling user agent</a> must be able to start and control
presentations by providing a <a>controlling browsing context</a>
as described in this specification. This context implements the
<a><code>Presentation</code></a>,
<a><code>PresentationConnection</code></a>,
<a><code>PresentationConnectionAvailableEvent</code></a>, and
<a><code>PresentationRequest</code></a> interfaces.
</p>
</dd>
<dt>
<dfn>Receiving user agent</dfn>
</dt>
<dd>
<p>
Web browsers that conform to the specifications of a <a>receiving
user agent</a> must be able to render presentations by providing
a <a>receiving browsing context</a> as described in this
specification. This context implements the
<a><code>Presentation</code></a>,
<a><code>PresentationConnection</code></a>,
<a><code>PresentationConnectionAvailableEvent</code></a>, and
<a><code>PresentationReceiver</code></a> interfaces.
</p>
</dd>
</dl>
<p>
One user agent may act both as a <a>controlling user agent</a> and as
a <a>receiving user agent</a>, if it provides both browsing contexts
and implements all of their required interfaces. This can happen when
the same user agent is able to host the <a>controlling browsing
context</a> and the <a>receiving browsing context</a> for a
presentation, as in the <a>1-UA</a> implementation of the API.
</p>
</section>
</section>
<section>
<h2>
Terminology
</h2>
<p>
The terms <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#browsing-context">browsing
context</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/webappapis.html#event-handlers">event
handler</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/webappapis.html#event-handler-event-type">event
handler event type</a></dfn>, <dfn data-lt="fire|fires"><a href=
"http://www.w3.org/TR/html5/infrastructure.html#concept-event-fire">firing
an event</a></dfn>, <dfn data-lt="fire a simple event"><a href=
"http://www.w3.org/TR/html5/webappapis.html#fire-a-simple-event">firing
a simple event</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#navigate">navigate</a></dfn>,
<dfn><a href=
"http://www.w3.org/TR/html5/webappapis.html#queue-a-task">queue a
task</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/infrastructure.html#concept-events-trusted">
trusted event</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#allowed-to-show-a-popup">allowed
to show a popup</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#top-level-browsing-context">top-level
browsing context</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#session-history">session
history</a></dfn>, <dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#sandboxed-auxiliary-navigation-browsing-context-flag">
sandboxed auxiliary navigation browsing context flag</a></dfn>, and
<dfn><a href=
"http://www.w3.org/TR/html5/browsers.html#sandboxed-top-level-navigation-browsing-context-flag">
sandboxed top-level navigation browsing context flag</a></dfn> are
defined in [[!HTML5]].
</p>
<p>
The term <dfn><a href=
"http://www.w3.org/TR/html51/infrastructure.html#in-parallel">in
parallel</a></dfn> is defined in [[!HTML51]].
</p>
<p>
This document provides interface definitions using the Web IDL standard
([[!WEBIDL]]). The terms <dfn><a href=
"https://heycam.github.io/webidl/#idl-promise">Promise</a></dfn>,
<dfn><a href=
"http://heycam.github.io/webidl/#idl-ArrayBuffer">ArrayBuffer</a></dfn>,
<dfn><a href=
"http://heycam.github.io/webidl/#idl-ArrayBufferView">ArrayBufferView</a></dfn>
are defined in [[!WEBIDL]].
</p>
<p>
The <dfn>term</dfn> throw in this specification is used as defined in
[[!WEBIDL]]. The following exception names are defined by WebIDL and
used by this specification:
</p>
<ul>
<li>
<dfn><code>AbortError</code></dfn>
</li>
<li>
<dfn><code>InvalidAccessError</code></dfn>
</li>
<li>
<dfn><code>NotFoundError</code></dfn>
</li>
<li>
<dfn><code>NotSupportedError</code></dfn>
</li>
<li>
<dfn><code>OperationError</code></dfn>
</li>
<li>
<dfn><code>SyntaxError</code></dfn>
</li>
</ul>
<p>
The terms <dfn data-lt="resolve"><a href=
"http://www.w3.org/2001/tag/doc/promises-guide#resolve-promise">resolving
a Promise</a></dfn>, and <dfn data-lt="reject"><a href=
"http://www.w3.org/2001/tag/doc/promises-guide#reject-promise">rejecting
a Promise</a></dfn> are used as explained in [[!PROMGUIDE]].
</p>
<p>
The term <dfn><a href="https://url.spec.whatwg.org/#url">URL</a></dfn>
is defined in the WHATWG URL standard [[!URL]].
</p>
<p>
The term <dfn><a href=
"http://dev.w3.org/2006/webapi/FileAPI/#blob">Blob</a></dfn> is defined
in the File API specification [[!FILEAPI]].
</p>
<p>
The term <dfn><a href=
"http://w3c.github.io/webrtc-pc/#idl-def-RTCDataChannel">RTCDataChannel</a></dfn>
is defined in the WebRTC API specification [[WEBRTC]].
</p>
<p>
The term <dfn><a href=
"http://tools.ietf.org/html/rfc6265#section-4.2">cookie store</a></dfn>
is defined in RFC 6265 [[COOKIES]].
</p>
<p>
The terms <dfn data-lt="permission|permissions"><a href=
"https://w3c.github.io/permissions/#idl-def-Permission">permission</a></dfn>
and <dfn><a href=
"https://w3c.github.io/permissions/#idl-def-PermissionState">permission
state</a></dfn> are defined in [[PERMISSIONS]].
</p>
<p>
The term <dfn data-lt="database|databases"><a href=
"http://www.w3.org/TR/IndexedDB/#database-concept">database</a></dfn>
is defined in [[INDEXEDDB]].
</p>
<p>
The terms <dfn><a href=
"http://www.w3.org/TR/webstorage/#the-localstorage-attribute"><code>localStorage</code></a></dfn>
and <dfn><a href=
"http://www.w3.org/TR/webstorage/#the-sessionstorage-attribute"><code>sessionStorage</code></a></dfn>
are defined in [[WEBSTORAGE]].
</p>
</section>
<section>
<h2>
Examples
</h2>
<p>
This section shows example codes that highlight the usage of main
features of the Presentation API. In these examples,
<code>controller.html</code> implements the controller and
<code>presentation.html</code> implements the presentation. Both pages
are served from the domain <code>http://example.org</code>
(<code>http://example.org/controller.html</code> and
<code>http://example.org/presentation.html</code>). These examples
assume that the controlling page is managing one presentation at a
time. Please refer to the comments in the code examples for further
details.
</p>
<section>
<h3>
Monitor availability of presentation displays example
</h3>
<pre class="example highlight">
<!-- controller.html -->
<button id="presentBtn" style="display: none;">Present</button>
<script>
// The Present button is visible if at least one presentation display is available
var presentBtn = document.getElementById("presentBtn");
// It is also possible to use relative presentation URL e.g. "presentation.html"
var presUrl = "http://example.com/presentation.html";
// show or hide present button depending on display availability
var handleAvailabilityChange = function(available) {
presentBtn.style.display = available ? "inline" : "none";
};
// Promise is resolved as soon as the presentation display availability is
// known.
var request = new PresentationRequest(presUrl);
request.getAvailability().then(function(availability) {
// availability.value may be kept up-to-date by the controlling UA as long
// as the availability object is alive. It is advised for the web developers
// to discard the object as soon as it's not needed.
handleAvailabilityChange(availability.value);
availability.onchange = function() { handleAvailabilityChange(this.value); };
}).catch(function() {
// Availability monitoring is not supported by the platform, so discovery of
// presentation displays will happen only after request.start() is called.
// Pretend the devices are available for simplicity; or, one could implement
// a third state for the button.
handleAvailabilityChange(true);
});
</script>
</pre>
</section>
<section>
<h3>
Starting a new presentation example
</h3>
<pre class="example highlight">
<!-- controller.html -->
<script>
presentBtn.onclick = function () {
// Start new presentation.
request.start()
// The connection to the presentation will be passed to setConnection on
// success.
.then(setConnection);
// Otherwise, the user canceled the selection dialog or no screens were
// found.
};
</script>
</pre>
</section>
<section>
<h3>
Reconnect to a presentation example
</h3>
<pre class="example highlight">
<!-- controller.html -->
<button id="reconnectBtn" style="display: none;">Reconnect</button>
<script>
var reconnect = function () {
// read presId from localStorage if exists
var presId = localStorage["presId"];
// presId is mandatory when reconnecting to a presentation.
if (!!presId) {
request.reconnect(presId)
// The new connection to the presentation will be passed to
// setConnection on success.
.then(setConnection);
// No connection found for presUrl and presId, or an error occurred.
}
};
// On navigation of the controller, reconnect automatically.
document.addEventListener("DOMContentLoaded", reconnect);
// Or allow manual reconnection.
reconnectBtn.onclick = reconnect;
</script>
</pre>
</section>
<section>
<h3>
Presentation initation by the controlling UA example
</h3>
<pre class="example highlight">
<!-- controller.html -->
<!-- Setting presentation.defaultRequest allows the page to specify the
PresentationRequest to use when the controlling UA initiates a
presentation. -->
<script>
navigator.presentation.defaultRequest = new PresentationRequest(defaultUrl);
navigator.presentation.defaultRequest.onconnectionavailable = function(evt) {
setConnection(evt.connection);
};
</script>
</pre>
</section>
<section>
<h3>
Monitor connection's state and exchange data example
</h3>
<pre class="example highlight">
<!-- controller.html -->
<button id="disconnectBtn" style="display: none;">Disconnect</button>
<button id="terminateBtn" style="display: none;">Stop</button>
<script>
var connection;
// The Disconnect and Stop buttons are visible if there is a connected presentation
var disconnectBtn = document.getElementById("disconnectBtn");
var stopBtn = document.getElementById("stopBtn");
stopBtn.onclick = function () { connection && connection.terminate(); };
var setConnection = function (theConnection) {
// Disconnect from existing presentation, if any
close();
// Set the new connection and save the presentation ID
connection = theConnection;
localStorage["presId"] = connection.id;
// monitor connection's state
connection.onconnected = function () {
// Allow the user to disconnect from or terminate the presentation
disconnectBtn.style.display = "inline";
stopBtn.style.display = "inline";
reconnectBtn.style.display = "none";
// register message handler
this.onmessage = function (message) {
console.log("receive message", message.data);
};
// send initial message to presentation page
this.send("say hello");
};
connection.onclosed = reset;
connection.onterminated = function () {
// remove presId from localStorage if exists
delete localStorage["presId"];
// Reset the UI
reset();
};
};
var reset = function () {
connection = null;
disconnectBtn.style.display = "none";
stopBtn.style.display = "none";
reconnectBtn.style.display = localStorage["presId"] ? "inline" : "none";
};
var close = function () { connection && connection.close(); };
disconnectBtn.onclick = close;
</script>
</pre>
</section>
<section>
<h3>
Monitor available connection(s) and say hello
</h3>
<pre class="example highlight">
<!-- receiver.html -->
<script>
var addConnection = function(connection) {
connection.onconnected = function () {
this.onmessage = function (message) {
if (message.data == "say hello")
this.send("hello");
};
};
};
navigator.presentation.receiver.connectionList.then(function (list) {
list.connections.map(function (connection) {
addConnection(connection);
});
list.connections.onconnectionavailable = function (connections) {
addConnection(connections[connections.length - 1]);
};
});
</script>
</pre>
</section>
</section>
<section>
<h2>
API
</h2>
<section>
<h3>
Common idioms
</h3>
<p>
A <dfn lt="presentation display|presentation displays">presentation
display</dfn> refers to an external screen available to the user
agent via an implementation specific connection technology.
</p>
<p>
A <dfn lt=
"presentation connection|presentation connections">presentation
connection</dfn> is an object relating a <a>controlling browsing
context</a> to its <a>receiving browsing context</a> and enables
two-way-messaging between them. Each <a>presentation connection</a>
has a <dfn>presentation connection state</dfn>, a <dfn lt=
"presentation identifier|presentation identifiers">presentation
identifier</dfn> to distinguish it from other <a>presentation</a>s,
and a <dfn>presentation URL</dfn> that is a <a>URL</a> used to create
or resume the <a>presentation</a>. A <dfn>valid presentation
identifier</dfn> consists of alphanumeric ASCII characters only, is
at least 16 characters long, and is unique within the <a>set of
presentations</a>.
</p>
<p>
A <dfn lt=
"controlling browsing context|controlling browsing contexts">controlling
browsing context</dfn> (or <dfn>controller</dfn> for short) is a
<a>browsing context</a> that has connected to a <a>presentation</a>
by calling <code><a for="PresentationRequest">start</a>()</code> or
<code><a for="PresentationRequest">reconnect</a>()</code>, or
received a <a>presentation connection</a> via a
<code>connectionavailable</code> event.
</p>
<p>
The <dfn data-lt=
"receiving browsing context|receiving browsing contexts">receiving
browsing context</dfn> (or <a data-lt=
"receiving browsing context">presentation</a> for short) is the
browsing context responsible for rendering to a <a>presentation
display</a>. A <a>receiving browsing context</a> can reside in the
same user agent as the <a>controlling browsing context</a> or a
different one. A <a>receiving browsing context</a> is created by
following the steps to <a>create a receiving browsing context</a>.
</p>
<p>
The <dfn>set of presentations</dfn>, initially empty, contains the
<a>presentation</a>s created by the <a>controlling browsing
contexts</a> for the controlling user agent (or a specific user
profile within that user agent). The <a>set of presentations</a> is
represented by a list of tuples, where each tuple consists of a
<a>presentation URL</a>, a <a>presentation identifier</a>, and the
<a>presentation connection</a> itself. The <a>presentation URL</a>
and <a>presentation identifier</a> uniquely identify the
<a>presentation</a>.
</p>
</section>
<section>
<h3>
Interface <code>Presentation</code>
</h3>
<pre class="idl">
partial interface Navigator {
[SameObject] readonly attribute Presentation presentation;
};
interface Presentation {
attribute PresentationRequest? defaultRequest;
[SameObject] readonly attribute PresentationReceiver? receiver;
};
</pre>
<p>
The <dfn for="Navigator"><code>presentation</code></dfn> attribute is
used to retrieve an instance of the <a>Presentation</a> interface.
</p>
<section>
<h4>
Controlling user agent
</h4>
<p>
In a <a>controlling user agent</a>, the <dfn for=
"Presentation"><code>defaultRequest</code></dfn> MUST return the
<a>default presentation request</a> if any, <code>null</code>
otherwise.
</p>
<p>
If set by the <a>controller</a>, the <a for=
"Presentation">defaultRequest</a> SHOULD be used by the
<a>controlling user agent</a> as the <dfn>default presentation
request</dfn> for that controller. When the <a>controlling user
agent</a> wishes to initiate a <a>PresentationConnection</a> on the
controller's behalf, it MUST <a>start a presentation</a> using the
<a>default presentation request</a> for the <a>controller</a> (as
if the controller had called <code>defaultRequest.start()</code>).
</p>
<p>
The <a>controlling user agent</a> SHOULD initiate presentation
using the <a>default presentation request</a> only when the user
has expressed an intention to do so, for example by clicking a
button in the browser.
</p>
<div class="note">
Not all user agents may support initiation of a presentation
connection outside of the content area. In this case setting
<code>defaultRequest</code> has no effect.
</div>
<div class="issue">
It should be clear that user-intiated presentation via the user
agent may have pre-selected the presentation display. In this case
step 6 of <a>start a presentation</a> is optional. It may be
cleaner to define a separate set of steps for initiating a default
presentation.
</div>
</section>
<section>
<h4>
Receiving user agent
</h4>
<p>
In a <a>receiving user agent</a>, <dfn for=
"Presentation"><code>receiver</code></dfn> MUST return
<a><code>PresentationReceiver</code></a> instance in a <a>receiving
browsing context</a>. In any other <a>browsing context</a>, it MUST
return <code>null</code>.
</p>
</section>
</section>
<section>
<h3>
Interface <a><code>PresentationRequest</code></a>
</h3>
<pre class="idl">
[Constructor(DOMString url)]
interface PresentationRequest : EventTarget {
Promise<PresentationConnection> start();
Promise<PresentationConnection> reconnect(DOMString presentationId);
Promise<PresentationAvailability> getAvailability();
attribute EventHandler onconnectionavailable;
};
</pre>
<p>
A <a><code>PresentationRequest</code></a> object is associated with a
request to initiate or reconnect to a presentation made by a
<a>controlling browsing context</a>. The
<a><code>PresentationRequest</code></a> object MUST be implemented in
a <a>controlling browsing context</a> provided by a <a>controlling
user agent</a>.
</p>
<p>
When a <a><code>PresentationRequest</code></a> is constructed, the
given <code>url</code> MUST be used as the <dfn>presentation request
URL</dfn> which is the <a>presentation URL</a> for the
<a><code>PresentationRequest</code></a> instance.
</p>
<section>
<h4>
Constructing a <code>PresentationRequest</code>
</h4>
<p>
When the <code>PresentationRequest</code> constructor is called,
the <a>controlling user agent</a> MUST run these steps:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>url</code>, the <a>presentation request URL</a>
</dd>
<dt>
Output
</dt>
<dd>
A <code>PresentationRequest</code> object
</dd>
</dl>
<ol>
<li>Resolve <em>url</em> relative to the API base URL specified by
the entry settings object, and let <em>presentationUrl</em> be the
resulting absolute URL, if any.
</li>
<li>If the resolve a URL algorithm failed, then throw a
<a>SyntaxError</a> exception and abort the remaining steps.
</li>
<li>Construct a new <code>PresentationRequest</code> object with
<em>presentationUrl</em> as the constructor argument and return it.
</li>
</ol>
</section>
<section>
<h4>
Starting a presentation
</h4>
<p>
When the <code><dfn for="PresentationRequest">start</dfn></code>
method is called, the user agent MUST run the following steps to
<dfn>start a presentation</dfn>:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>presentationRequest</code>, the
<code>PresentationRequest</code> object
</dd>
<dd>
<code>presentationUrl</code>, the <a>presentation request URL</a>
</dd>
<dt>
Output
</dt>
<dd>
<em>P</em>, a <a>Promise</a>
</dd>
</dl>
<ol>
<li>If the algorithm isn't <a>allowed to show a popup</a>, return a
<a>Promise</a> rejected with an <a>InvalidAccessError</a> exception
and abort these steps.
</li>
<li>If there is already an unsettled <a>Promise</a> from a previous
call to <code>start</code> for the same <a>controlling browsing
context</a>, return a <a>Promise</a> rejected with an
<a>OperationError</a> exception and abort all remaining steps.
</li>
<li>Let <em>P</em> be a new <a>Promise</a>.
</li>
<li>Return <em>P</em>, but continue running these steps in
parallel.
</li>
<li>If the user agent is not <a data-lt=
"monitor the list of available presentation displays">monitoring
the list of available presentation displays</a>, run the steps to
<a>monitor the list of available presentation displays</a> <a>in
parallel</a>.
</li>
<li>Request user permission for the use of a <a>presentation
display</a> and selection of one presentation display.
</li>
<li>If either of the following is true:
<ol>
<li>The <a>list of available presentation displays</a> is empty
and will remain so before the request for user permission is
completed.
</li>
<li>No member in the <a>list of available presentation
displays</a> is a <a>compatible presentation display</a> for
<code>presentationUrl</code>.
</li>
</ol>Then run the following steps:
<ol>
<li>
<a>Reject</a> <em>P</em> with a <a>NotFoundError</a>
exception.
</li>
<li>Abort all remaining steps.
</li>
</ol>
</li>
<li>If the user <em>denied permission</em> to use a display, reject
<em>P</em> with an <a>AbortError</a> exception, and abort all
remaining steps.
</li>
<li>Otherwise, the user <em>granted permission</em> to use a
display; let <em>D</em> be that display.
</li>
<li>Let <var>I</var> be a new <a>valid presentation identifier</a>
unique among all <a>presentation identifiers</a> for known
presentations in the <a>set of presentations</a>.
</li>
<li>Create a new <a>PresentationConnection</a> <em>S</em>.
</li>
<li>Set the <a>presentation identifier</a> of <var>S</var> to <var>
I</var>, and set the <a>presentation connection state</a> of
<var>S</var> to <code>connecting</code>.
</li>
<li>Add the tuple {<em>presentationUrl</em>, <em>S.id</em>,
<em>S</em>} to the <a>set of presentations</a>.
</li>
<li>
<a>Resolve</a> <em>P</em> with <em>S</em>.
</li>
<li>
<a>Queue a task</a> to <a>fire</a> a <a>trusted event</a> with
the name <code>connectionavailable</code>, that uses the
<a>PresentationConnectionAvailableEvent</a> interface, with the
<a for="PresentationConnectionAvailableEvent">connection</a>
attribute initialized to <em>S</em>, at
<code>presentationRequest</code>. The event must not bubble, must
not be cancelable, and has no default action.
</li>
<li>If any of the following steps fails, abort all remaining steps
and <a>queue a task</a> to <a data-lt="close-algorithm">close the
presentation connection</a> with <var>S</var> as
<code>presentationConnection</code>, <code>error</code> as
<code>closeReason</code>, and a human readable message describing
the failure as <code>closeMessage</code>.
</li>
<li>
<a>Create a receiving browsing context</a> on <em>D</em> and let
<em>R</em> be the result.
</li>
<li>
<a>Navigate</a> <em>R</em> to <code>presentationUrl</code>.
</li>
<li>
<a>Establish a presentation connection</a> with <em>S</em>.
</li>
</ol>
<div class="note">
The details of implementing the permission request and display
selection are left to the user agent; for example it may show the
user a dialog and allow the user to select an available display
(granting permission), or cancel the selection (denying
permission).
</div>
<div class="note">
The <code>presentationUrl</code> should name a resource accessible
to the local or a remote user agent. This specification defines
behavior for <code>presentationUrl</code> using the
<code>http</code> or <code>https</code> schemes; behavior for other
schemes is not defined by this specification.
</div>
<div class="issue">
Do we want to distinguish the permission-denied outcome from the
no-screens-available outcome? Developers would be able to infer it
anyway from <code>getAvailability()</code>.
</div>
</section>
<section>
<h4>
Reconnecting to a presentation
</h4>
<p>
When the <code><dfn for=
"PresentationRequest">reconnect</dfn>(presentationId)</code> method
is called on a <code>PresentationRequest</code>
<em>presentationRequest</em>, the user agent MUST run the following
steps to <dfn>reconnect to a presentation</dfn>:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>presentationRequest</code>, the
<code>PresentationRequest</code> object that
<code>reconnect()</code> was called on.
</dd>
<dd>
<code>presentationId</code>, a <a>presentation identifier</a>
</dd>
<dt>
Output
</dt>
<dd>
<em>P</em>, a <a>Promise</a>
</dd>
</dl>
<ol>
<li>Let <em>P</em> be a new <a>Promise</a>.
</li>
<li>Return <em>P</em>, but continue running these steps in
parallel.
</li>
<li>For each <var>known connection</var> in the <a>set of
presentations</a>,
<div style="margin-left: 2em">
If <a>presentation connection state</a> of <var>known