forked from w3c/presentation-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1599 lines (1577 loc) · 82 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>
<style>
@media print {
[data-anolis-spec]::after { content:"[" attr(data-anolis-spec) "]"; font-size:.6em; vertical-align:super; text-transform:uppercase }
}
</style>
<link href="https://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet">
<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: '; }
.open-issue { border-left-style: solid; border-left-width: 0.25em; background: none repeat scroll 0 0 #fbfbe9; border-color: #faf9a5; }
.open-issue em, .warning em, .open-issue i, .warning i { font-style: normal; }
p.open-issue, div.open-issue { padding: 0.5em 2em; }
span.open-issue { padding: 0 2em; }
.open-issue p:first-child { margin-top: 0; }
.open-issue p:last-child { margin-bottom: 0; }
.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; }
</style>
</head>
<body>
<div class="head">
<!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="https://www.w3.org/Icons/w3c_home" width="72"></a></p>
<!--end-logo-->
<h1>
Presentation API
</h1>
<h2 class="no-num no-toc" id="editor's-draft-12-june-2015">
Editor's Draft 12 June 2015
</h2>
<dl>
<dt>
This version:
</dt>
<dd>
<!--begin-link--><a href="http://w3c.github.io/presentation-api/">http://w3c.github.io/presentation-api/</a><!--end-link-->
</dd>
<dt>
Latest published version:
</dt>
<dd>
<!--begin-link--><a href="http://www.w3.org/TR/presentation-api/">http://www.w3.org/TR/presentation-api/</a><!--end-link-->
</dd><!--previous-version-->
<dt>
Latest editor's draft:
</dt>
<dd>
<!--begin-link--><a href="http://w3c.github.io/presentation-api/
">http://w3c.github.io/presentation-api/
</a><!--end-link-->
</dd>
<dt>
Version history:
</dt>
<dd>
<!--begin-link--><a href="https://github.com/w3c/presentation-api/commits/
">https://github.com/w3c/presentation-api/commits/
</a><!--end-link-->
</dd>
<dt>
Participate:
</dt>
<dd>
Send feedback to <a href="https://lists.w3.org/Archives/Public/public-secondscreen/">[email protected]</a>
or <a href="https://github.com/w3c/presentation-api/issues/new">open
a new issue</a> (<a href="https://github.com/w3c/presentation-api/issues/">open issues</a>)
</dd>
<dt>
Editors:
</dt>
<dd data-editor-id="68454">
<a href="mailto:[email protected]">Mark Foltz</a>, Google
</dd>
<dd data-editor-id="63802">
Dominik Röttsches, Intel (until April 2015)
</dd>
</dl>
<p class="copyright">
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
© 2015 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.
</p>
<hr>
</div>
<section>
<h2 class="no-num no-toc" id="abstract">
Abstract
</h2>
<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>
<h2 class="no-num no-toc" id="sotd">
Status of This Document
</h2>
<p>
<em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical
report can be found in the <a href="http://www.w3.org/TR/">W3C
technical reports index</a> at http://www.w3.org/TR/.</em>
</p>
<p>
This document was published by the <a href="http://www.w3.org/2014/secondscreen/">Second Screen Presentation
Working Group</a> as a Working Draft. If you wish to make comments
regarding this document, please send them to <a href="mailto:[email protected]">[email protected]</a>
(<a href="mailto:[email protected]?subject=subscribe">subscribe</a>,
<a href="http://lists.w3.org/Archives/Public/public-secondscreen/">archives</a>).
All comments are welcome.
</p>
<p>
This document is a <b>work in progress</b> and is subject to change.
Some sections are still incomplete or underspecified. Privacy and
security considerations need to be adjusted based on feedback and
experience. 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 an accurate list. Feedback from early
experimentations is encouraged to allow the Second Screen Presentation
Working Group to evolve the specification based on implementation
issues.
</p>
<p>
Publication as a Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite
this document as other than work in progress.
</p>
<p>
This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/" id="sotd_patent" rel="w3p:patentRules">5 February 2004
W3C Patent Policy</a>. W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/74168/status" rel="disclosure">public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.
</p>
<p>
This document is governed by the <a href="http://www.w3.org/2014/Process-20140801/" id="w3c_process_revision">1 August 2014 <abbr title="World Wide Web Consortium">W3C</abbr> Process Document</a>.
</p>
</section>
<section>
<h2 class="no-num no-toc" id="table-of-contents">
Table of Contents
</h2>
<!--begin-toc-->
<ol class="toc">
<li><a href="#introduction"><span class="secno">1 </span>
Introduction
</a></li>
<li><a href="#use-cases-and-requirements-0"><span class="secno">2 </span>
Use cases and requirements
</a></li>
<li><a href="#conformance"><span class="secno">3 </span>
Conformance
</a></li>
<li><a href="#terminology"><span class="secno">4 </span>
Terminology
</a></li>
<li><a href="#examples"><span class="secno">5 </span>
Examples
</a>
<ol>
<li><a href="#monitor-availability-of-presentation-displays-example"><span class="secno">5.1 </span>
Monitor availability of presentation displays example
</a></li>
<li><a href="#starting-a-new-presentation-session-example"><span class="secno">5.2 </span>
Starting a new presentation session example
</a></li>
<li><a href="#joining-a-presentation-session-example"><span class="secno">5.3 </span>
Joining a presentation session example
</a></li>
<li><a href="#handling-an-event-for-a-ua-initiated-presentation-session-example"><span class="secno">5.4 </span>
Handling an event for a UA initiated presentation session example
</a></li>
<li><a href="#monitor-session's-state-and-exchange-data-example"><span class="secno">5.5 </span>
Monitor session's state and exchange data example
</a></ol></li>
<li><a href="#api"><span class="secno">6 </span>
API
</a>
<ol>
<li><a href="#common-idioms"><span class="secno">6.1 </span>
Common idioms
</a></li>
<li><a href="#interface-presentationsession"><span class="secno">6.2 </span>
Interface <code>PresentationSession</code>
</a>
<ol>
<li><a href="#sending-a-message-through-presentationsession"><span class="secno">6.2.1 </span>
Sending a message through <code>PresentationSession</code>
</a></li>
<li><a href="#receiving-a-message-through-presentationsession"><span class="secno">6.2.2 </span>
Receiving a message through <code>PresentationSession</code>
</a></li>
<li><a href="#closing-a-presentationsession"><span class="secno">6.2.3 </span>
Closing a <code>PresentationSession</code>
</a></li>
<li><a href="#event-handlers"><span class="secno">6.2.4 </span>
Event Handlers
</a></ol></li>
<li><a href="#interface-availability"><span class="secno">6.3 </span>
Interface <code>Availability</code>
</a>
<ol>
<li><a href="#monitoring-the-list-of-available-presentation-displays"><span class="secno">6.3.1 </span>
Monitoring the list of available presentation displays
</a></ol></li>
<li><a href="#interface-navigatorpresentation"><span class="secno">6.4 </span>
Interface <code>NavigatorPresentation</code>
</a>
<ol>
<li><a href="#starting-a-presentation-session"><span class="secno">6.4.1 </span>
Starting a presentation session
</a></li>
<li><a href="#joining-a-presentation-session"><span class="secno">6.4.2 </span>
Joining a presentation session
</a></li>
<li><a href="#establishing-a-presentation-connection"><span class="secno">6.4.3 </span>
Establishing a presentation connection
</a></li>
<li><a href="#getting-the-presentation-displays-availability-information"><span class="secno">6.4.4 </span>
Getting the <span>presentation displays</span> availability
information
</a></li>
<li><a href="#event-handlers-0"><span class="secno">6.4.5 </span>
Event Handlers
</a></ol></li>
<li><a href="#interface-defaultsessionstart"><span class="secno">6.5 </span>
<span>Interface <code>DefaultSessionStart</code></span>
</a></ol></li>
<li><a href="#security-and-privacy-considerations"><span class="secno">7 </span>
Security and privacy considerations
</a>
<ol>
<li><a href="#personally-identifiable-information"><span class="secno">7.1 </span>
Personally identifiable information
</a></li>
<li><a href="#cross-origin-access"><span class="secno">7.2 </span>
Cross-origin access
</a></li>
<li><a href="#device-access"><span class="secno">7.3 </span>
Device Access
</a></li>
<li><a href="#temporary-identifiers-and-browser-state"><span class="secno">7.4 </span>
Temporary identifiers and browser state
</a></li>
<li><a href="#incognito-mode-and-clearing-of-browsing-data"><span class="secno">7.5 </span>
Incognito mode and clearing of browsing data
</a></li>
<li><a href="#messaging-between-presentation-sessions"><span class="secno">7.6 </span>
Messaging between presentation sessions
</a></ol></li>
<li><a href="#references"><span class="secno">8 </span>
References
</a></li>
<li><a href="#acknowledgments"><span class="secno">9 </span>
Acknowledgments
</a></ol>
<!--end-toc-->
</section>
<section>
<h2 id="introduction"><span class="secno">1 </span>
Introduction
</h2><em>This section is non-normative.</em>
<p>
This specification aims to make secondary displays such as a projector
or a connected TV 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 display 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 requesting page and a presentation page shown in the secondary
display. How those messages are transmitted is left to the UA in order
to allow for the use of display devices that can be attached to a wide
variety of ways. For example, when a display device is attached using
HDMI or MiraCast, the UA on the requesting device can render the
requested presentation page in that same UA. Instead of displaying in a
window on that same device, however, it can use whatever means the
operating system provides for using those external displays. In that
case, both the requesting page and the presentation page run on the
requesting device and the operating system is used to route the
presentation display output to the other display device. The second
display device doesn't need to know anything about this spec or that
the content involves HTML5.
</p>
<p>
Alternately, some types of external displays may be able to render
HTML5 themselves and may have defined their way to send messages to
that content. In that case, the UA on the requesting device would not
need to render the presentation page itself. Instead, the UA could act
as a proxy translating the request to show a page and the messages into
the form understood by the display device.
</p>
<p>
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
display devices through any of the above means.
</p>
</section>
<section id="use-cases-and-requirements">
<h2 id="use-cases-and-requirements-0"><span class="secno">2 </span>
Use cases and requirements
</h2>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.
</section>
<section>
<h2 id="conformance"><span class="secno">3 </span>
Conformance
</h2>
<p>
All diagrams, examples, and notes in this specification are
non-normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative.
</p>
<p>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in RFC
2119. For readability, these words do not appear in all uppercase
letters in this specification. <a href="#refsRFC2119">[RFC2119]</a>
</p>
<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>
<section>
<h2 id="terminology"><span class="secno">4 </span>
Terminology
</h2>
<p>
The terms <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/browsers.html#browsing-context">browsing context</a>,
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#event-handlers">event handlers</a>, <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#event-handler-event-type" title="event handler event type">event handler
event types</a>, <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-event-fire" title="concept-event-fire">firing an event</a>, <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/browsers.html#navigate">navigate</a>, <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task" title="queue a task">queing a task</a> are defined in
<a href="#refsHTML5">[HTML5]</a>.
</p>
<p>
The term <a class="external" data-anolis-spec="dom" href="https://dom.spec.whatwg.org/#domexception" title="domexception">DOMException</a> is defined in <a href="#refsDOM">[DOM]</a>.
</p>
<p>
This document provides interface definitions using the
<a href="#refsWEBIDL">[WEBIDL]</a> standard. The terms
<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#idl-promise">Promise</a>, <a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#idl-ArrayBuffer">ArrayBuffer</a>, and <a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#common-ArrayBufferView">ArrayBufferView</a> are defined in <a href="#refsWEBIDL">[WEBIDL]</a>.
</p>
<p>
The terms <a class="external" data-anolis-spec="promguide" href="http://www.w3.org/2001/tag/doc/promises-guide#shorthand-manipulating" title="resolve-reject">resolving a Promise, and rejecting a Promise</a>
are used as explained in <a href="#refsPROMGUIDE">[PROMGUIDE]</a>.
</p>
<p>
The term <a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#url">URL</a> is defined in the
WHATWG URL standard: <a href="#refsURL">[URL]</a>.
</p>
<p>
The term <a class="external" data-anolis-spec="fileapi" href="http://dev.w3.org/2006/webapi/FileAPI/#blob">Blob</a> is defined in the
File API specification: <a href="#refsFILEAPI">[FILEAPI]</a>.
</p>
<p>
The term <dfn id="rtcdatachannel">RTCDataChannel</dfn> is defined in the WebRTC API
specification: <a href="http://w3c.github.io/webrtc-pc/#widl-RTCDataChannel-protocol">WEBRTC</a>.
</p>
</section>
<section>
<h2 id="examples"><span class="secno">5 </span>
Examples
</h2>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/42">ISSUE 42:
Make the Example section more concise</a>
</p>
<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>). Please refer to the
comments in the code examples for further details.
</p>
<section>
<h3 id="monitor-availability-of-presentation-displays-example"><span class="secno">5.1 </span>
Monitor availability of presentation displays example
</h3>
<pre class="example"><!-- controller.html -->
<button id="castBtn" style="display: none;">Cast</button>
<script>
// the cast button is visible if at least one presentation display is available
var castBtn = document.getElementById("castBtn");
// show or hide cast button depending on display availability
var handleAvailabilityChange = function(available) {
castBtn.style.display = available ? "inline" : "none";
};
// Promise is resolved as soon as the presentation display availability is known.
navigator.presentation.getAvailability().then(function(availability) {
// availability.value may be kept up-to-date by the 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, discovery of presentation
// displays will happen only after startSession() call. Pretend the devices are
// available for simplicity (one could implement the third state for the button).
handleAvailabilityChange(true);
});
</script>
</pre>
</section>
<section>
<h3 id="starting-a-new-presentation-session-example"><span class="secno">5.2 </span>
Starting a new presentation session example
</h3>
<pre class="example"><!-- controller.html -->
<script>
// it is also possible to use relative presentation URL e.g. "presentation.html"
var presUrl = "http://example.com/presentation.html";
// Start new session.
navigator.presentation.startSession(presUrl)
// the new started session will be passed to setSession on success
.then(setSession)
// user cancels the selection dialog or an error is occurred
.catch(endSession);
</script>
</pre>
</section>
<section>
<h3 id="joining-a-presentation-session-example"><span class="secno">5.3 </span>
Joining a presentation session example
</h3>
<pre class="example"><!-- controller.html -->
<script>
// read presId from localStorage if exists
var presId = localStorage && localStorage["presId"] || null;
// presId is mandatory for joinSession.
presId && navigator.presentation.joinSession(presUrl, presId)
// The joined session will be passed to setSession on success
.then(setSession)
// no session found for presUrl and presId or an error is occurred
.catch(endSession);
</script>
</pre>
</section>
<section>
<h3 id="handling-an-event-for-a-ua-initiated-presentation-session-example"><span class="secno">5.4 </span>
Handling an event for a UA initiated presentation session example
</h3>
<pre class="example"><!-- controller.html -->
<head>
<!-- the link element with rel='default-presentation' allows the page to specify -->
<!-- the presentation URL and id for when the UA initiates a presentation session -->
<link href="http://example.com/presentation.html" rel="default-presentation" >
</head>
<script>
navigator.presentation.ondefaultsessionstart = function (evt) {
setSession(evt.session);
};
</script>
</pre>
</section>
<section>
<h3 id="monitor-session's-state-and-exchange-data-example"><span class="secno">5.5 </span>
Monitor session's state and exchange data example
</h3>
<pre class="example"><!-- controller.html -->
<script>
var session;
var setSession = function (theSession) {
// end existing session, if any
endSession();
// set the new session
session = theSession;
if (session) {
// save presId in localStorage
localStorage && (localStorage["presId"] = session.id);
// monitor session's state
session.onstatechange = function () {
if (this == session && this.state == "disconnected")
endSession();
};
// register message handler
session.onmessage = function (evt) {
console.log("receive message", evt.data);
};
// send message to presentation page
session.send("say hello");
}
};
var endSession = function () {
// close old session if exists
session && session.close();
// remove old presId from localStorage if exists
localStorage && delete localStorage["presId"];
};
</script>
</pre>
<pre class="example"><!-- presentation.html -->
<script>
var session = navigator.presentation.session;
session.onstatechange = function () {
// session.state is either 'connected' or 'disconnected'
console.log("session's state is now", session.state);
};
session.onmessage = function (evt) {
if (evt.data == "say hello")
session.send("hello");
};
</script>
</pre>
</section>
</section>
<section>
<h2 id="api"><span class="secno">6 </span>
API
</h2>
<section>
<h3 id="common-idioms"><span class="secno">6.1 </span>
Common idioms
</h3>
<p>
A <dfn id="presentation-display">presentation display</dfn> refers to an external screen
available to the user agent via an implementation specific connection
technology.
</p>
<p>
A <dfn id="presentation-session">presentation session</dfn> is an object relating an
<a href="#controlling-browsing-context">controlling browsing context</a> to its <a href="#presenting-browsing-context">presenting
browsing context</a> and enables two-way-messaging between them.
Each <a href="#presentation-session">presentation session</a> has a <dfn id="presentation-session-state">presentation
session state</dfn>, a <dfn id="presentation-session-identifier">presentation session identifier</dfn> to
distinguish it from other <span>presentation sessions</span>, and a
<dfn id="presentation-session-url">presentation session URL</dfn> that is a <a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#url">URL</a> used to create or resume the <a href="#presentation-session">presentation
session</a>. A <dfn id="valid-presentation-session-identifier">valid presentation session identifier</dfn>
consists of alphanumeric ASCII characters only, is at least 16
characters long, and is unique within the <a href="#set-of-presentations">set of
presentations</a>.
</p>
<p>
A <dfn id="controlling-browsing-context">controlling browsing context</dfn> (or <em>controller</em> for
short) is a <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/browsers.html#browsing-context">browsing context</a>
that has initiated or resumed a <a href="#presentation-session">presentation session</a> by
calling <code><a href="#startsession">startSession</a>()</code> or
<code><a href="#joinsession">joinSession</a>()</code> or received a
<a href="#presentation-session">presentation session</a> via
<a href="#ondefaultsessionstart"><code><span>ondefaultsessionstart</span></code></a> event.
</p>
<p>
The <dfn id="presenting-browsing-context">presenting browsing context</dfn> (or <em>presentation</em>
for short) is the browsing context responsible for rendering to a
<a href="#presentation-display">presentation display</a>. A <a href="#presenting-browsing-context">presenting browsing
context</a> can reside in the same user agent as the
<a href="#controlling-browsing-context">controlling browsing context</a> or a different one.
</p>
<p>
The <dfn id="set-of-presentations">set of presentations</dfn>, initially empty, contains the
<a href="#presentation-session">presentation session</a>s created by the <a href="#controlling-browsing-context">controlling
browsing context</a>s for the user agent (or a specific user
profile within the user agent). The <a href="#set-of-presentations">set of presentations</a>
is represented by a list of tuples, where each tuple consists of a
<a href="#presentation-session-url">presentation session URL</a>, a <a href="#presentation-session-identifier">presentation session
identifier</a>, and the <a href="#presentation-session">presentation session</a> itself.
The <a href="#presentation-session-url">presentation session URL</a> and <a href="#presentation-session-identifier">presentation
session identifier</a> uniquely identify the <a href="#presentation-session">presentation
session</a>.
</p>
</section>
<section>
<h3 id="interface-presentationsession"><span class="secno">6.2 </span>
Interface <a href="#presentationsession"><code>PresentationSession</code></a>
</h3>
<p>
Each <a href="#presentation-session">presentation session</a> is represented by a
<a href="#presentationsession"><code>PresentationSession</code></a> object.
</p>
<pre class="idl">enum <dfn id="presentationsessionstate">PresentationSessionState</dfn> { "connected", "disconnected" /*, "resumed" */ };
enum <dfn id="binarytype">BinaryType</dfn> { "blob", "arraybuffer" };
interface <dfn id="presentationsession">PresentationSession</dfn> : EventTarget {
readonly <a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>? <a href="#id">id</a>;
readonly attribute <a href="#presentationsessionstate">PresentationSessionState</a> <a href="#state">state</a>;
void <a href="#close">close</a>();
attribute <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#eventhandler">EventHandler</a> <a href="#onstatechange">onstatechange</a>;
// Communication
attribute BinaryType <dfn id="binarytype-attribute" title="binarytype-attribute">binaryType</dfn>;
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#eventhandler">EventHandler</a> <dfn id="presentation-onmessage" title="presentation-onmessage">onmessage</dfn>;
void <dfn id="send">send</dfn> (<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a> message);
void <dfn id="send-blob" title="send-blob">send</dfn> (<a class="external" data-anolis-spec="fileapi" href="http://dev.w3.org/2006/webapi/FileAPI/#blob">Blob</a> data);
void <dfn id="send-arraybuffer" title="send-arraybuffer">send</dfn> (<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#idl-ArrayBuffer">ArrayBuffer</a> data);
void <dfn id="send-arraybufferview" title="send-arraybufferview">send</dfn> (<a class="external" data-anolis-spec="webidl" href="https://heycam.github.io/webidl/#common-ArrayBufferView">ArrayBufferView</a> data);
};
</pre>
<p>
The <dfn id="id"><code>id</code></dfn> attribute specifies the
<a href="#presentation-session">presentation session</a>'s <a href="#presentation-session-identifier">presentation session
identifier</a>.
</p>
<p>
The <dfn id="state"><code>state</code></dfn> attribute represents the
<a href="#presentation-session">presentation session</a>'s current state. It can take one of
the values of <a href="#presentationsessionstate"><code>PresentationSessionState</code></a>
depending on connection state.
</p>
<p>
When the <code><a href="#send">send</a>()</code> method is called on a
<a href="#presentationsession"><code>PresentationSession</code></a> object with a <code>message</code>,
the user agent must run the algorithm to <a href="#algorithm-send" title="algorithm-send">send a message through a
<span><code>PresentationSession</code></span></a>.
</p>
<p>
When the <code><dfn id="close">close</dfn>()</code> method is called on a
<a href="#presentationsession"><code>PresentationSession</code></a>, the user agent must run the
algorithm to <a href="#close-algorithm" title="close-algorithm">close a presentation
session</a> with <a href="#presentationsession"><code>PresentationSession</code></a>.
</p>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/34">ISSUE 34:
Specify the presentation initialization algorithm</a>
</p>
<section>
<h4 id="sending-a-message-through-presentationsession"><span class="secno">6.2.1 </span>
Sending a message through <a href="#presentationsession"><code>PresentationSession</code></a>
</h4>
<p class="note">
Presentation API does not mandate a specific transport for the
connection between the <a href="#controlling-browsing-context">controlling browsing context</a>
and the <a href="#presenting-browsing-context">presenting browsing context</a>, except that for
multiple calls to <a href="#send"><code>send</code></a> it has to be ensured that
messages are delivered to the other end reliably and in sequence.
The transport should function equivalently to an
<a href="#rtcdatachannel">RTCDataChannel</a> in reliable mode.
</p>
<p>
Let <dfn id="presentation-message-data">presentation message data</dfn> be the payload data to be
transmitted between two browsing contexts. Let <dfn id="presentation-message-type">presentation
message type</dfn> be the type of that data, one of
<code>text</code> and <code>binary</code>.
</p>
<p>
When the user agent is to <dfn id="algorithm-send" title="algorithm-send">send a
message through a <code>PresentationSession</code> S</dfn>, it must
run the following steps:
</p>
<ol>
<li>If the <a href="#state"><code>state</code></a> property of
<a href="#presentationsession"><code>PresentationSession</code></a> is <code>"disconnected"</code>,
throw an <code>InvalidStateError</code> exception.
</li>
<li>Let <a href="#presentation-message-type">presentation message type</a> <em>messageType</em>
be <code>binary</code> if <code>data</code> is one of
<code>ArrayBuffer</code> or <code>ArrayBufferView</code> or <code>Blob</code>. Let
<em>messageType</em> be <code>text</code> if <code>data</code> is
of type <code>DOMString</code>)
</li>
<li>Assign the <dfn id="destination-browsing-context">destination browsing context</dfn> as follows:
<ol>
<li>Let the the <a href="#destination-browsing-context">destination browsing context</a> be
the <a href="#controlling-browsing-context">controlling browsing context</a> if
<a href="#send">send</a> is called in the <a href="#presenting-browsing-context">presenting browsing
context</a>.
</li>
<li>Let <a href="#destination-browsing-context">destination browsing context</a> be the <a href="#presenting-browsing-context">
presenting browsing context</a> if <a href="#send">send</a> is
called from the <span>opening browsing context</span>.
</li>
</ol>
</li>
<li>Using an implementation specific mechanism, transmit the
contents of the <code>data</code> argument as <a href="#presentation-message-data">presentation
message data</a> and <a href="#presentation-message-type">presentation message type</a> <em>
messageType</em> to the <a href="#destination-browsing-context">destination browsing context</a>
side.
</li>
</ol>
</section>
<section>
<h4 id="receiving-a-message-through-presentationsession"><span class="secno">6.2.2 </span>
Receiving a message through <a href="#presentationsession"><code>PresentationSession</code></a>
</h4>
<p>
When the user agent has received a transmission from the remote
side consisting of <a href="#presentation-message-data">presentation message data</a> and
<a href="#presentation-message-type">presentation message type</a>, it must run the following
steps:
</p>
<ol>
<li>If the <a href="#state"><code>state</code></a> property of
<a href="#presentationsession"><code>PresentationSession</code></a> is <code>"disconnected"</code>,
abort these steps.
</li>
<li>Let <em>event</em> be a newly created <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-events-trusted" title="concept-events-trusted">trusted event</a> that
uses the <code>MessageEvent</code> interface, with the event type
<code>message</code>, which does not bubble, is not cancelable, and
has no default action.
</li>
<li>Initialize the <em>event's</em> data attribute as follows:
<ol>
<li>If the <a href="#presentation-message-type">presentation message type</a> is
<code>text</code>, then initialize <em>event's</em>
<code>data</code> attribute to the contents of
<a href="#presentation-message-data">presentation message data</a> of type
<code>DOMString</code>.
</li>
<li>If the <a href="#presentation-message-type">presentation message type</a> is
<code>binary</code>, and <a href="#binarytype"><code>binaryType</code></a> is set to
<code>blob</code>, then initialise <em>event</em>'s
<code>data</code> attribute to a new <code>Blob</code> object
that represents <a href="#presentation-message-data">presentation message data</a> as its
raw data.
</li>
<li>If the <a href="#presentation-message-type">presentation message type</a> is
<code>binary</code>, and <a href="#binarytype"><code>binaryType</code></a> is set to
<code>arraybuffer</code>, then initialise <em>event</em>'s
<code>data</code> attribute to a new <code>ArrayBuffer</code>
object whose contents are <a href="#presentation-message-data">presentation message
data</a>.
</li>
</ol>
</li>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a> to
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-event-fire" title="concept-event-fire">fire
<em>event</em></a> at
<a href="#presentationsession"><code>PresentationSession</code></a>.
</li>
</ol>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/63">ISSUE
63: Define (cross) origin relationship between opener and
presenting page</a>
</p>
</section>
<section>
<h4 id="closing-a-presentationsession"><span class="secno">6.2.3 </span>
Closing a <a href="#presentationsession"><code>PresentationSession</code></a>
</h4>
<p>
When the user agent is to <dfn id="close-algorithm" title="close-algorithm">close a
presentation session</dfn> using <em>session</em>, it must run the
following steps:
</p>
<ol>
<li>If <a href="#presentation-session-state">presentation session state</a> of <em>session</em>
is not <code>connected</code>, then abort these steps.
</li>
<li>Set <a href="#presentation-session-state">presentation session state</a> of <em>session</em>
to <code>disconnected</code>.
</li>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a> to run the
following steps in order:
<ol>
<li>For each <em>known session</em> in the <a href="#set-of-presentations">set of
presentations</a>:
<ol>
<li>If the <a href="#presentation-session-identifier">presentation session identifier</a> of
<em>known session</em> and <em>session</em> are equal, run
the following steps:
<ol>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a>
to <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-event-fire" title="concept-event-fire">fire an event</a> named
<code>statechange</code> at <em>session</em>.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/35">ISSUE
35: Refine how to do session teardown/disconnect/closing</a>
</p>
</section>
<section>
<h4 id="event-handlers"><span class="secno">6.2.4 </span>
Event Handlers
</h4>
<p>
The following are the event handlers (and their corresponding event
handler event types) that must be supported, as event handler IDL
attributes, by objects implementing the
<a href="#presentationsession"><code>PresentationSession</code></a> interface:
</p>
<table>
<thead>
<tr>
<th>
Event handler
</th>
<th>
Event handler event type
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn id="onmessage"><code>onmessage</code></dfn>
</td>
<td>
<code>message</code>
</td>
</tr>
<tr>
<td>
<dfn id="onstatechange"><code>onstatechange</code></dfn>
</td>
<td>
<code>statechange</code>
</td>
</tr>
</tbody>
</table>
</section>
</section>
<section>
<h3 id="interface-availability"><span class="secno">6.3 </span>
Interface <a href="#availability"><code>Availability</code></a>
</h3>
<pre class="idl">interface <dfn id="availability">Availability</dfn> : EventTarget {
readonly attribute boolean value;
attribute <a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#eventhandler">EventHandler</a> <span>onchange</span>;
};
</pre>
<p>
The <code>change</code> event is fired during the execution of the
<a href="#monitor-the-list-of-available-presentation-displays">monitor the list of available presentation displays</a>
algorithm when the <dfn id="presentation-display-availability">presentation display availability</dfn>
changes. It is fired at the <a href="#availability"><code>Availability</code></a>
object, using the <code>ChangeEvent</code> interface. The
<a href="#availability"><code>Availability</code></a> object's <code>value</code> attribute is
updated to the boolean value that the algorithm determined.
</p>
<p>
In order to satisfy the <a href="https://github.com/w3c/presentation-api/blob/gh-pages/uc-req.md#req08-power-saving-friendly">
power saving non-functional requirement</a>, the user agent must keep
track of the number of <a href="#availability"><code>Availability</code></a> objects requested
through the <code>getAvailability()</code> method. The UA may also
keep track of whether the page holding the <a href="#availability"><code>Availability</code></a>
object is in the foreground. Using this information, implementation
specific discovery of <span title="presentation-display">presentation
displays</span> can be resumed or suspended, in order to save power.
</p>
<p>
The user agent must keep a <dfn id="list-of-available-presentation-displays">list of available presentation
displays</dfn>. According to the number of alive
<a href="#availability"><code>Availability</code></a> objects, the user agent must also keep the
list up to date by running the algorithm to <a href="#monitor-the-list-of-available-presentation-displays">monitor the list of
available presentation displays</a>.
</p>
<p>
The user agent might not support continuous availability monitoring
due to platform or power consumption restrictions, for example. In
this case the <span>Promise</span> returned by
<code>getAvailability()</code> is <a class="external" data-anolis-spec="promguide" href="http://www.w3.org/2001/tag/doc/promises-guide#shorthand-manipulating" title="resolve-reject">rejected</a> and the algorithm to
<a href="#monitor-the-list-of-available-presentation-displays">monitor the list of available presentation displays</a> will
only run as part of the <a href="#startsession" title="startSession">session
start</a> algorithm.
</p>
<section>
<h5 id="monitoring-the-list-of-available-presentation-displays"><span class="secno">6.3.1 </span>
Monitoring the list of available presentation displays
</h5>
<p>
When the user agent is to <dfn id="monitor-the-list-of-available-presentation-displays">monitor the list of available
presentation displays</dfn>, it must run the following steps:
</p>
<p>
While there are alive <a href="#availability"><code><span>Availability</span></code></a>
objects, the user agent should continuously keep track of the
<a href="#list-of-available-presentation-displays">list of available presentation displays</a> and repeat the
following steps:
</p>
<ol>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a> to retrieve
the list of currently available <a href="#presentation-display">presentation displays</a> and let <a id="newdisplays"><em>newDisplays</em></a> be this list.
</li>
<li>Wait for the completion of that task.
</li>
<li>If the <a href="#list-of-available-presentation-displays">list of available presentation displays</a> is
empty and <a href="#newdisplays">newDisplays</a> is not empty, then
for each alive <a href="#availability"><code>Availability</code></a> object:
<ol>
<li>Set the object's <code>value</code> property to
<code>true</code>.
</li>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a> to
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-event-fire" title="concept-event-fire">fire an event</a> named
<code>change</code> at the object.
</li>
</ol>
</li>
<li>If the <a href="#list-of-available-presentation-displays">list of available presentation displays</a> is
not empty and <a href="#newdisplays">newDisplays</a> is empty, then
for each alive <a href="#availability"><code>Availability</code></a> object:
<ol>
<li>Set the object's <code>value</code> property to
<code>false</code>.
</li>
<li>
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/webappapis.html#queue-a-task">Queue a task</a> to
<a class="external" data-anolis-spec="w3c-html" href="http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#concept-event-fire" title="concept-event-fire">fire an event</a> named
<code>change</code> at the object.
</li>
</ol>
</li>
<li>Set the <a href="#list-of-available-presentation-displays">list of available presentation displays</a> to
the value of <a href="#newdisplays">newDisplays</a>.
</li>
</ol>
<p class="note">
The mechanism used to monitor <a href="#presentation-display">presention displays</a> availability is
left to the user agent. The UA may choose to monitor the
availability of presentation displays even when there are no
<a href="#availability"><code>Availability</code></a> objects.
</p>
<p>