forked from w3c/presentation-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.src.html
executable file
·1546 lines (1534 loc) · 63.9 KB
/
Overview.src.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 rel="stylesheet" href=
"https://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
<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">
<!--logo-->
<h1>
Presentation API
</h1>
<h2 class="no-num no-toc">
[LONGSTATUS] [DATE]
</h2>
<dl>
<dt>
This version:
</dt>
<dd>
<!--begin-link-->[VERSION]<!--end-link-->
</dd>
<dt>
Latest published version:
</dt>
<dd>
<!--begin-link-->[LATEST]<!--end-link-->
</dd><!--previous-version-->
<dt>
Latest editor's draft:
</dt>
<dd>
<!--begin-link-->http://w3c.github.io/presentation-api/
<!--end-link-->
</dd>
<dt>
Version history:
</dt>
<dd>
<!--begin-link-->https://github.com/w3c/presentation-api/commits/
<!--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">
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 id=
"sotd_patent" rel="w3p:patentRules" href=
"http://www.w3.org/Consortium/Patent-Policy-20040205/">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 id="w3c_process_revision" href=
"http://www.w3.org/2014/Process-20140801/">1 August 2014 <abbr title=
"World Wide Web Consortium">W3C</abbr> Process Document</a>.
</p>
</section>
<section>
<h2 class="no-num no-toc">
Table of Contents
</h2><!--toc-->
</section>
<section>
<h2>
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>
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>
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. <span data-anolis-ref="">RFC2119</span>
</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>
Terminology
</h2>
<p>
The terms <span data-anolis-spec="w3c-html">browsing context</span>,
<span data-anolis-spec="w3c-html">event handlers</span>, <span title=
"event handler event type" data-anolis-spec="w3c-html">event handler
event types</span>, <span data-anolis-spec="w3c-html" title=
"concept-event-fire">firing an event</span>, <span data-anolis-spec=
"w3c-html">navigate</span>, <span data-anolis-spec="w3c-html" title=
"queue a task">queing a task</span> are defined in
<span data-anolis-ref="">HTML5</span>.
</p>
<p>
The term <span data-anolis-spec="dom" title=
"domexception">DOMException</span> is defined in <span data-anolis-ref=
"dom">DOM</span>.
</p>
<p>
This document provides interface definitions using the
<span data-anolis-ref="webidl">WEBIDL</span> standard. The terms
<span data-anolis-spec="webidl">Promise</span>, <span data-anolis-spec=
"webidl">ArrayBuffer</span>, and <span data-anolis-spec=
"webidl">ArrayBufferView</span> are defined in <span data-anolis-ref=
"webidl">WEBIDL</span>.
</p>
<p>
The terms <span data-anolis-spec="promguide" title=
"resolve-reject">resolving a Promise, and rejecting a Promise</span>
are used as explained in <span data-anolis-ref="">PROMGUIDE</span>.
</p>
<p>
The term <span data-anolis-spec="url">URL</span> is defined in the
WHATWG URL standard: <span data-anolis-ref="url">URL</span>.
</p>
<p>
The term <span data-anolis-spec="fileapi">Blob</span> is defined in the
File API specification: <span data-anolis-ref="fileapi">FILEAPI</span>.
</p>
<p>
The term <dfn>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>
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>
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>
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>
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>
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>
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>
API
</h2>
<section>
<h3>
Common idioms
</h3>
<p>
A <dfn>presentation display</dfn> refers to an external screen
available to the user agent via an implementation specific connection
technology.
</p>
<p>
A <dfn>presentation session</dfn> is an object relating an
<span>controlling browsing context</span> to its <span>presenting
browsing context</span> and enables two-way-messaging between them.
Each <span>presentation session</span> has a <dfn>presentation
session state</dfn>, a <dfn>presentation session identifier</dfn> to
distinguish it from other <span>presentation sessions</span>, and a
<dfn>presentation session URL</dfn> that is a <span data-anolis-spec=
"url">URL</span> used to create or resume the <span>presentation
session</span>. A <dfn>valid presentation session identifier</dfn>
consists of alphanumeric ASCII characters only, is at least 16
characters long, and is unique within the <span>set of
presentations</span>.
</p>
<p>
A <dfn>controlling browsing context</dfn> (or <em>controller</em> for
short) is a <span data-anolis-spec="w3c-html">browsing context</span>
that has initiated or resumed a <span>presentation session</span> by
calling <code><span>startSession</span>()</code> or
<code><span>joinSession</span>()</code> or received a
<span>presentation session</span> via
<code><span>ondefaultsessionstart</span></code> event.
</p>
<p>
The <dfn>presenting browsing context</dfn> (or <em>presentation</em>
for short) is the browsing context responsible for rendering to a
<span>presentation display</span>. A <span>presenting browsing
context</span> can reside in the same user agent as the
<span>controlling browsing context</span> or a different one.
</p>
<p>
The <dfn>set of presentations</dfn>, initially empty, contains the
<span>presentation session</span>s created by the <span>controlling
browsing context</span>s for the user agent (or a specific user
profile within the user agent). The <span>set of presentations</span>
is represented by a list of tuples, where each tuple consists of a
<span>presentation session URL</span>, a <span>presentation session
identifier</span>, and the <span>presentation session</span> itself.
The <span>presentation session URL</span> and <span>presentation
session identifier</span> uniquely identify the <span>presentation
session</span>.
</p>
</section>
<section>
<h3>
Interface <code>PresentationSession</code>
</h3>
<p>
Each <span>presentation session</span> is represented by a
<code>PresentationSession</code> object.
</p>
<pre class="idl">
enum <dfn>PresentationSessionState</dfn> { "connected", "disconnected" /*, "resumed" */ };
enum <dfn>BinaryType</dfn> { "blob", "arraybuffer" };
interface <dfn>PresentationSession</dfn> : EventTarget {
readonly <span data-anolis-spec="webidl">DOMString</span>? <span>id</span>;
readonly attribute <span>PresentationSessionState</span> <span>state</span>;
void <span>close</span>();
attribute <span data-anolis-spec=
"w3c-html">EventHandler</span> <span>onstatechange</span>;
// Communication
attribute BinaryType <dfn title="binarytype-attribute">binaryType</dfn>;
<span data-anolis-spec="w3c-html">EventHandler</span> <dfn title=
"presentation-onmessage">onmessage</dfn>;
void <dfn>send</dfn> (<span data-anolis-spec=
"webidl">DOMString</span> message);
void <dfn title="send-blob">send</dfn> (<span data-anolis-spec=
"fileapi">Blob</span> data);
void <dfn title="send-arraybuffer">send</dfn> (<span data-anolis-spec=
"webidl">ArrayBuffer</span> data);
void <dfn title="send-arraybufferview">send</dfn> (<span data-anolis-spec=
"webidl">ArrayBufferView</span> data);
};
</pre>
<p>
The <dfn><code>id</code></dfn> attribute specifies the
<span>presentation session</span>'s <span>presentation session
identifier</span>.
</p>
<p>
The <dfn><code>state</code></dfn> attribute represents the
<span>presentation session</span>'s current state. It can take one of
the values of <span><code>PresentationSessionState</code></span>
depending on connection state.
</p>
<p>
When the <code><span>send</span>()</code> method is called on a
<code>PresentationSession</code> object with a <code>message</code>,
the user agent must run the algorithm to <span title=
"algorithm-send">send a message through a
<span><code>PresentationSession</code></span></span>.
</p>
<p>
When the <code><dfn>close</dfn>()</code> method is called on a
<code>PresentationSession</code>, the user agent must run the
algorithm to <span title="close-algorithm">close a presentation
session</span> with <code>PresentationSession</code>.
</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>
Sending a message through <code>PresentationSession</code>
</h4>
<p class="note">
Presentation API does not mandate a specific transport for the
connection between the <span>controlling browsing context</span>
and the <span>presenting browsing context</span>, except that for
multiple calls to <code>send</code> it has to be ensured that
messages are delivered to the other end reliably and in sequence.
The transport should function equivalently to an
<span>RTCDataChannel</span> in reliable mode.
</p>
<p>
Let <dfn>presentation message data</dfn> be the payload data to be
transmitted between two browsing contexts. Let <dfn>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 title="algorithm-send">send a
message through a <code>PresentationSession</code> S</dfn>, it must
run the following steps:
</p>
<ol>
<li>If the <code>state</code> property of
<code>PresentationSession</code> is <code>"disconnected"</code>,
throw an <code>InvalidStateError</code> exception.
</li>
<li>Let <span>presentation message type</span> <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>destination browsing context</dfn> as follows:
<ol>
<li>Let the the <span>destination browsing context</span> be
the <span>controlling browsing context</span> if
<span>send</span> is called in the <span>presenting browsing
context</span>.
</li>
<li>Let <span>destination browsing context</span> be the <span>
presenting browsing context</span> if <span>send</span> 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 <span>presentation
message data</span> and <span>presentation message type</span> <em>
messageType</em> to the <span>destination browsing context</span>
side.
</li>
</ol>
</section>
<section>
<h4>
Receiving a message through <code>PresentationSession</code>
</h4>
<p>
When the user agent has received a transmission from the remote
side consisting of <span>presentation message data</span> and
<span>presentation message type</span>, it must run the following
steps:
</p>
<ol>
<li>If the <code>state</code> property of
<code>PresentationSession</code> is <code>"disconnected"</code>,
abort these steps.
</li>
<li>Let <em>event</em> be a newly created <span data-anolis-spec=
"w3c-html" title="concept-events-trusted">trusted event</span> 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 <span>presentation message type</span> is
<code>text</code>, then initialize <em>event's</em>
<code>data</code> attribute to the contents of
<span>presentation message data</span> of type
<code>DOMString</code>.
</li>
<li>If the <span>presentation message type</span> is
<code>binary</code>, and <code>binaryType</code> 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 <span>presentation message data</span> as its
raw data.
</li>
<li>If the <span>presentation message type</span> is
<code>binary</code>, and <code>binaryType</code> 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 <span>presentation message
data</span>.
</li>
</ol>
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> to
<span data-anolis-spec="w3c-html" title="concept-event-fire">fire
<em>event</em></span> at
<span><code>PresentationSession</code></span>.
</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>
Closing a <code>PresentationSession</code>
</h4>
<p>
When the user agent is to <dfn title="close-algorithm">close a
presentation session</dfn> using <em>session</em>, it must run the
following steps:
</p>
<ol>
<li>If <span>presentation session state</span> of <em>session</em>
is not <code>connected</code>, then abort these steps.
</li>
<li>Set <span>presentation session state</span> of <em>session</em>
to <code>disconnected</code>.
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> to run the
following steps in order:
<ol>
<li>For each <em>known session</em> in the <span>set of
presentations</span>:
<ol>
<li>If the <span>presentation session identifier</span> of
<em>known session</em> and <em>session</em> are equal, run
the following steps:
<ol>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span>
to <span data-anolis-spec="w3c-html" title=
"concept-event-fire">fire an event</span> 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>
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
<code>PresentationSession</code> interface:
</p>
<table>
<thead>
<tr>
<th>
Event handler
</th>
<th>
Event handler event type
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn><code>onmessage</code></dfn>
</td>
<td>
<code>message</code>
</td>
</tr>
<tr>
<td>
<dfn><code>onstatechange</code></dfn>
</td>
<td>
<code>statechange</code>
</td>
</tr>
</tbody>
</table>
</section>
</section>
<section>
<h3>
Interface <code>Availability</code>
</h3>
<pre class="idl">
interface <dfn>Availability</dfn> : EventTarget {
readonly attribute boolean value;
attribute <span data-anolis-spec=
"w3c-html">EventHandler</span> <span>onchange</span>;
};
</pre>
<p>
The <code>change</code> event is fired during the execution of the
<span>monitor the list of available presentation displays</span>
algorithm when the <dfn>presentation display availability</dfn>
changes. It is fired at the <span><code>Availability</code></span>
object, using the <code>ChangeEvent</code> interface. The
<code>Availability</code> 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 <code>Availability</code> objects requested
through the <code>getAvailability()</code> method. The UA may also
keep track of whether the page holding the <code>Availability</code>
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>list of available presentation
displays</dfn>. According to the number of alive
<code>Availability</code> objects, the user agent must also keep the
list up to date by running the algorithm to <span>monitor the list of
available presentation displays</span>.
</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 <span data-anolis-spec="promguide"
title="resolve-reject">rejected</span> and the algorithm to
<span>monitor the list of available presentation displays</span> will
only run as part of the <span title="startSession">session
start</span> algorithm.
</p>
<section>
<h5>
Monitoring the list of available presentation displays
</h5>
<p>
When the user agent is to <dfn>monitor the list of available
presentation displays</dfn>, it must run the following steps:
</p>
<p>
While there are alive <code><span>Availability</span></code>
objects, the user agent should continuously keep track of the
<span>list of available presentation displays</span> and repeat the
following steps:
</p>
<ol>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> 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 <span>list of available presentation displays</span> is
empty and <a href="#newdisplays">newDisplays</a> is not empty, then
for each alive <code>Availability</code> object:
<ol>
<li>Set the object's <code>value</code> property to
<code>true</code>.
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> to
<span data-anolis-spec="w3c-html" title=
"concept-event-fire">fire an event</span> named
<code>change</code> at the object.
</li>
</ol>
</li>
<li>If the <span>list of available presentation displays</span> is
not empty and <a href="#newdisplays">newDisplays</a> is empty, then
for each alive <code>Availability</code> object:
<ol>
<li>Set the object's <code>value</code> property to
<code>false</code>.
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> to
<span data-anolis-spec="w3c-html" title=
"concept-event-fire">fire an event</span> named
<code>change</code> at the object.
</li>
</ol>
</li>
<li>Set the <span>list of available presentation displays</span> 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
<code>Availability</code> objects.
</p>
<p>
When the user agent is to <dfn>cancel monitoring the list of
available presentation displays</dfn>, it must run the following
steps:
</p>
</section>
</section>
<section>
<h3>
Interface <code>NavigatorPresentation</code>
</h3>
<pre class="idl">
partial interface <span data-anolis-spec="w3c-html">Navigator</span> {
readonly attribute <span>NavigatorPresentation</span> <span>presentation</span>;
};
</pre>
<p>
The <dfn><code>presentation</code></dfn> attribute is used to
retrieve an instance of the <code>NavigatorPresentation</code>
interface, the main interface of Presentation API.
</p>
<pre class="idl">
interface <dfn>NavigatorPresentation</dfn> : EventTarget {
readonly attribute <span>PresentationSession</span>? <span>session</span>;
Promise<<span>PresentationSession</span>> <span>startSession</span>(DOMString url);
Promise<<span>PresentationSession</span>> <span>joinSession</span>(DOMString url, DOMString presentationId);
Promise<<span>Availability</span>> <span>getAvailability</span>();
attribute <span data-anolis-spec=
"w3c-html">EventHandler</span> <span>ondefaultsessionstart</span>;
};
</pre>
<p class="open-issue">
<a href="https://github.com/w3c/presentation-api/issues/52">ISSUE 52:
Specify the NavigatorPresentation.session attribute and its related
algorithms</a>
</p>
<section>
<h4>
Starting a presentation session
</h4>
<p>
When the <code><dfn>startSession</dfn>(presentationUrl)</code>
method is called, the user agent must run the following steps:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>presentationUrl</code>, the <span>presentation session
URL</span>
</dd>
<dt>
Output
</dt>
<dd>