-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefaultsessionstart.html
1648 lines (1621 loc) · 82.3 KB
/
defaultsessionstart.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="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css">
<style type="text/css">
/* 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; }
#use-cases-and-requirements dd { margin-top: 0.5em; margin-bottom: 1em; }
.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-14-may-2015">
Editor's Draft 14 May 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>
<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/">public-secondscreen@w3.org</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>
<a href="mailto:mfoltz@google.com">Mark Foltz</a>, Google
</dd>
<dd>
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 an Editor's Draft. If you wish to make comments
regarding this document, please send them to <a href="mailto:public-secondscreen@w3.org">public-secondscreen@w3.org</a>
(<a href="mailto:public-secondscreen-request@w3.org?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. It
builds on the <a href="http://www.w3.org/2014/secondscreen/presentation-api/20141118/" title="Presentation API W3C Community Group Final Report">final report</a>
(dated 18 November 2014) produced by the Second Screen Presentation
Community Group. Algorithms have been drafted in particular. Most
sections are still incomplete or underspecified. Privacy and security
considerations are missing. A few 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 First Public Working Draft does not imply endorsement
by the <abbr title="World Wide Web Consortium">W3C</abbr> Membership.
This draft document 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
<abbr title="World Wide Web Consortium">W3C</abbr> Patent Policy</a>.
<abbr title="World Wide Web Consortium">W3C</abbr> 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 that 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 <abbr title="World Wide Web Consortium">W3C</abbr> 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>
<ol>
<li><a href="#use-cases-0"><span class="secno">2.1 </span>
Use cases
</a></li>
<li><a href="#requirements-0"><span class="secno">2.2 </span>
Requirements
</a>
<ol>
<li><a href="#functional-requirements"><span class="secno">2.2.1 </span>
Functional requirements
</a></li>
<li><a href="#non-functional-requirements"><span class="secno">2.2.2 </span>
Non-functional requirements
</a></ol></ol></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="#common-definitions"><span class="secno">6.2 </span>
Common definitions
</a></li>
<li><a href="#interface-presentationsession"><span class="secno">6.3 </span>
Interface <code>PresentationSession</code>
</a>
<ol>
<li><a href="#sending-a-message-through-presentationsession"><span class="secno">6.3.1 </span>
Sending a message through <code>PresentationSession</code>
</a></li>
<li><a href="#receiving-a-message-through-presentationsession"><span class="secno">6.3.2 </span>
Receiving a message through <code>PresentationSession</code>
</a></li>
<li><a href="#closing-a-presentationsession"><span class="secno">6.3.3 </span>
Closing a <code>PresentationSession</code>
</a></li>
<li><a href="#event-handlers"><span class="secno">6.3.4 </span>
Event Handlers
</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="#the-onavailablechange-eventhandler"><span class="secno">6.4.4 </span>
The <code>onavailablechange</code> EventHandler
</a>
<ol>
<li><a href="#adding-an-eventhandler-to-onavailablechange"><span class="secno">6.4.4.1 </span>
Adding an <code>EventHandler</code> to
<code>onavailablechange</code>
</a></li>
<li><a href="#removing-an-eventhandler"><span class="secno">6.4.4.2 </span>
Removing an <code>EventHandler</code>
</a></li>
<li><a href="#monitoring-the-list-of-available-presentation-displays"><span class="secno">6.4.4.3 </span>
Monitoring the list of available presentation displays
</a></ol></ol></li>
<li><a href="#interface-availablechangeevent"><span class="secno">6.5 </span>
<span>Interface <code>AvailableChangeEvent</code></span>
</a></li>
<li><a href="#interface-defaultsessionstart"><span class="secno">6.6 </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></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>
<section id="use-cases">
<h3 id="use-cases-0"><span class="secno">2.1 </span>
Use cases
</h3>
<dl>
<dt>
Presentations
</dt>
<dd>
A user is preparing a set of slides for a talk. Using a web-based
service, she is editing her slides and speaker notes on the primary
screen while the secondary larger screen shows a preview of the
current slide. When the slides are done, her mobile phone allows
her to access them from an online service while on the go. Coming
to the conference, using wireless display technology, she would
like to present her slides on the stage screen from her mobile
phone. The phone's touch screen helps her to navigate slides and
presents a slide preview while the projector shows her slides to
the audience.
</dd>
<dt>
Video and image sharing
</dt>
<dd>
Using an online video or image sharing service, a user would like
to show memorable moments to her friends. Using a device with a
small screen, however, a user cannot show the content to a large
group of people. Connecting an external TV screen or projector to
her device - with a cable or wirelessly - the online sharing
service now makes use of the connected display, allowing a wider
audience to enjoy the content. The web page shows UI elements that
allow the user to trigger displaying content on the secondary
display (e.g., a "send to second screen" ) only if there is at
least one secondary screen available.
</dd>
<dt>
Multiplayer gaming
</dt>
<dd>
Splitting the gaming experience into a near screen controller and a
large screen visual experience can create new gaming experiences.
Accessing the local display on the small screen device and an
external larger display allows for richer web-based gaming
experiences.
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/27">ISSUE
27: Define a multiplayer gaming use case</a>
</p>
</dd>
<dt>
Media flinging to multiple screens
</dt>
<dd>
Alice enters a video sharing site using a browser on her tablet.
Next, Alice picks her favorite video from the site, and the video
starts to play on her tablet. While the video is playing Alice
clicks a button "Share on different screen". The browser provides a
user interface that lists all the screens Alice has at her home,
asking her to select one. The screens are identified by names that
are familiar to Alice. Alice picks one screen from the list,
"Alice's big TV", and the video playback continues seamlessly on
the selected screen. Next she decides to switch the playback to a
different screen. She clicks the same button "Share on different
screen" provided by the site, and the browser presents the user
interface that lists all the screens. Alice picks another screen
from the list, "Alice's kitchen TV", and the playback resumes on
that screen. Video site also provides a feature to see the action
(Alice is watching a soccer game) from a different angle. Alice
clicks a button "Select screen for additional angle", and the
browser asks Alice similarly to select the screen for playback.
Alice picks "Alice's Projector" and the soccer game is shown on the
projector from a different angle, in parallel to the content being
played back on "Alice's kitchen TV".
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/40">ISSUE
40: Screen availability mechanism for multiple sessions</a>
</p>
</dd>
</dl>
</section>
<section id="requirements">
<h3 id="requirements-0"><span class="secno">2.2 </span>
Requirements
</h3>
<p>
The requirements enumerated in this section are derived from the
<a href="#use-cases">use cases</a>.
</p>
<section>
<h4 id="functional-requirements"><span class="secno">2.2.1 </span>
Functional requirements
</h4>
<dl>
<dt>
Discovery & availability
</dt>
<dd>
The UA must provide a way to find out whether at least one
secondary screen is available.
</dd>
<dt>
Launching presentation
</dt>
<dd>
The UA must provide a way to start sending content to the
secondary screen. This may occur at the request of the page or at
the request of the UA.
</dd>
<dt>
Resuming presentation
</dt>
<dd>
The UA must be able to resume an existing session with the
content being displayed on the secondary screen.
</dd>
<dt>
Communication
</dt>
<dd>
The UA must enable exchanging data between the primary and the
secondary screen in order to have a control channel between the
primary and secondary page. The UA must not make assumptions
about the execution locality of the UA of the remote page it
communicates with (i.e. the secondary page might run on a remote
UA, and thus the link between these two pages must be loosely
coupled).
</dd>
<dt>
Signaling disconnection
</dt>
<dd>
The UA must signal disconnection from the presentation page to
the primary page and vice versa.
</dd>
</dl>
<p class="note">
Multi-screen enumeration and named identification requirement was
removed after <a class="external free" href="http://lists.w3.org/Archives/Public/public-webscreens/2014Feb/0021.html" rel="nofollow">
discussion on the mailing list</a>.
</p>
</section>
<section>
<h4 id="non-functional-requirements"><span class="secno">2.2.2 </span>
Non-functional requirements
</h4>
<dl>
<dt>
Power saving friendly
</dt>
<dd>
All API design decisions must be analyzed from a power efficiency
point of view. Especially when using wireless display
technologies or querying availability over a radio channel, care
needs to be taken to design the API in a way that does not pose
obstacles to using radio resources in an efficient way. For
example, powering up the wireless display detection only when
needed.
</dd>
</dl>
</section>
</section>
</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>
The term <a class="external" data-anolis-spec="es6" href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects" title="promise-objects">Promise</a> is defined in <a href="#refsES6">[ES6]</a>. 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 terms <a class="external" data-anolis-spec="typedarray" href="http://www.khronos.org/registry/typedarray/specs/latest/#5">ArrayBuffer</a>,
<a class="external" data-anolis-spec="typedarray" href="http://www.khronos.org/registry/typedarray/specs/latest/#6">ArrayBufferView</a> are defined
in the Typed Array specification: <a href="#refsTYPEDARRAY">[TYPEDARRAY]</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>
This document provides interface definitions using the
<a href="#refsWEBIDL">[WEBIDL]</a> standard.
</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> represents the controlling page that runs
in the opener UA and <code>presentation.html</code> represents the
presenting page that runs in the presenting UA. 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");
// availablechange event is fired when the presentation display availability changes
navigator.presentation.onavailablechange = function (evt) {
// show or hide cast button depending on display availability
castBtn.style.display = evt.available ? "inline" : "none";
};
</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";
// create random presId
var presId = Math.random().toFixed(6).substr(2);
// Start new session. presId is optional.
navigator.presentation.startSession(presUrl, presId)
// 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" id="ABCD1234" >
</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="concept-presentation" title="concept-presentation">presentation</dfn> is an active
connection between a user agent and a <a href="#presentation-display">presentation
display</a> for displaying web content on the latter at the
request of the former.
</p>
<p>
A <dfn id="concept-presentation-session" title="concept-presentation-session">presentation
session</dfn> is an object relating an <a href="#opening-browsing-context">opening browsing
context</a> to its <a href="#presentation-display">presentation display</a> and enabling
two-way-messaging between them. Each such object has a
<dfn id="presentation-session-state">presentation session state</dfn> and a <dfn id="presentation-session-identifier">presentation session
identifier</dfn> to distinguish it from other <a href="#concept-presentation-session" title="concept-presentation-session">presentation sessions</a>.
</p>
<p>
An <dfn id="opening-browsing-context">opening browsing context</dfn> 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
<span>presentation session</span> by calling
<code><a href="#startsession">startSession</a>()</code> or
<code><a href="#joinsession">joinSession</a>()</code> or received a
<span>presentation session</span> via
<code><span>ondefaultsessionstart</span></code> event.
</p>
<p>
The <dfn id="presenting-browsing-context">presenting browsing context</dfn> 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="#opening-browsing-context">opening browsing context</a> or a different
one.
</p>
</section>
<section>
<h3 id="common-definitions"><span class="secno">6.2 </span>
Common definitions
</h3>
<p>
Let <em>D</em> be the set of presentations that are currently known
to the user agent (regardles of their state). <em>D</em> is
represented as a set of tuples <em>(U, I, S)</em> where <em>U</em> is
the <a class="external" data-anolis-spec="url" href="https://url.spec.whatwg.org/#url">URL</a> that is being presented;
<em>I</em> is an alphanumeric identifier for the presentation; and
<em>S</em> is the user agent's <a href="#presentationsession"><code>PresentationSession</code></a> for
the presentation. <em>U</em> and <em>I</em> together uniquely
identify the <a href="#presentationsession"><code>PresentationSession</code></a> of the corresponding
presentation.
</p>
</section>
<section>
<h3 id="interface-presentationsession"><span class="secno">6.3 </span>
Interface <a href="#presentationsession"><code>PresentationSession</code></a>
</h3>
<p>
Each <a href="#concept-presentation-session" title="concept-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="http://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="http://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="typedarray" href="http://www.khronos.org/registry/typedarray/specs/latest/#5">ArrayBuffer</a> data);
void <dfn id="send-arraybufferview" title="send-arraybufferview">send</dfn> (<a class="external" data-anolis-spec="typedarray" href="http://www.khronos.org/registry/typedarray/specs/latest/#6">ArrayBufferView</a> data);
};
</pre>
<p>
The <dfn id="id"><code>id</code></dfn> attribute holds the alphanumeric
<a href="#presentation-session-identifier">presentation session identifier</a>.
</p>
<p>
The <dfn id="state"><code>state</code></dfn> attribute represents the
<span>presentation session</span>'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>.
</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>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/46">ISSUE
46: Define send behavior</a>
</p>
<h4 id="sending-a-message-through-presentationsession"><span class="secno">6.3.1 </span>
Sending a message through <a href="#presentationsession"><code>PresentationSession</code></a>
</h4>
<p class="note">
Presentation API does not mandate a specific protocol for the
connection between the <a href="#opening-browsing-context">opening 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 in sequence.
</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>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="#opening-browsing-context">opening 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 <a href="#opening-browsing-context">opening browsing context</a>.
</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.3.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 <em>event's</em> <code>origin</code> attribute to
the Unicode serialization of the URL that the <a href="#opening-browsing-context">opening
browsing context</a> and the <a href="#presenting-browsing-context">presenting browsing
context</a> have in common.
<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>
</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>
</section>
<section>
<h4 id="closing-a-presentationsession"><span class="secno">6.3.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 S</dfn>, it must run the following steps:
</p>
<ol>
<li>If <em>S.state</em> is not <code>connected</code>, then:
<ol>
<li>Abort these steps.
</li>
</ol>
</li>
<li>Set <em>S.state</em> to <code>disconnected</code>.
</li>
<li>Let <em>D</em> be the set of presentations known by the user
agent.