forked from w3c/presentation-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Overview.src.html
executable file
·1426 lines (1411 loc) · 58.2 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" type="text/css" href=
"http://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
<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; }
.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-->http://w3c.github.io/presentation-api/
<!--end-link-->
</dd>
<dt>
Latest published version:
</dt>
<dd>
<!--begin-link-->http://www.w3.org/TR/presentation-api/
<!--end-link-->
</dd>
<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/">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">
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 id=
"sotd_patent" rel="w3p:patentRules" href=
"http://www.w3.org/Consortium/Patent-Policy-20040205/">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 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>
The term <span data-anolis-spec="es6" title=
"promise-objects">Promise</span> is defined in <span data-anolis-ref=
"">ES6</span>. 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 terms <span data-anolis-spec="typedarray">ArrayBuffer</span>,
<span data-anolis-spec="typedarray">ArrayBufferView</span> are defined
in the Typed Array specification: <span data-anolis-ref=
"typedarray">TYPEDARRAY</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>
This document provides interface definitions using the
<span data-anolis-ref="webidl">WEBIDL</span> standard.
</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");
// 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>
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>
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" id="ABCD1234" >
</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 presentation session has a <dfn>presentation session state</dfn>
and a <dfn>presentation session identifier</dfn> to distinguish it
from other <span>presentation sessions</span>.
</p>
<p>
An <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>
</section>
<section>
<h3>
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 <span data-anolis-spec="url">URL</span> that is being presented;
<em>I</em> is an alphanumeric identifier for the presentation; and
<em>S</em> is the user agent's <code>PresentationSession</code> for
the presentation. <em>U</em> and <em>I</em> together uniquely
identify the <code>PresentationSession</code> of the corresponding
presentation.
</p>
</section>
<section>
<h3>
Interface <code>PresentationSession</code>
</h3>
<p>
Each <span title="concept-presentation-session">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=
"typedarray">ArrayBuffer</span> data);
void <dfn title="send-arraybufferview">send</dfn> (<span data-anolis-spec=
"typedarray">ArrayBufferView</span> data);
};
</pre>
<p>
The <dfn><code>id</code></dfn> attribute holds the alphanumeric
<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>.
</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>
Sending a message through <code>PresentationSession</code>
</h4>
<p class="note">
Presentation API does not mandate a specific protocol 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 in sequence.
</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 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.
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span> <em>T</em>
to run the following steps in order:
<ol>
<li>For each presentation <em>(U, I, S')</em> in <em>D</em>,
<ol>
<li>Let <em>u</em> equal <em>U</em>, <em>i</em> equal <em>
I</em>, and <em>s</em> equal <em>S'</em>.
</li>
<li>If <em>u</em> is equal to <em>S.url</em> and <em>i</em>
is equal to <em>S.id</em>, 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>s</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>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, DOMString? presentationId);
Promise<<span>PresentationSession</span>> <span>joinSession</span>(DOMString url, DOMString? presentationId);
attribute <span data-anolis-spec=
"w3c-html">EventHandler</span> <span>onavailablechange</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,
presentationId)</code> method is called, the user agent must run
the following steps:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>presentationUrl</code>, the <span data-anolis-spec=
"url">URL</span> of the document to be presented
</dd>
<dd>
<code>presentationId</code>, an optional identifier for the
presentation
</dd>
<dt>
Output
</dt>
<dd>
<em>P</em>, a <span data-anolis-spec="es6" title=
"promise-objects">Promise</span>
</dd>
</dl>
<ol>
<li>Let <em>P</em> be a new <span data-anolis-spec="es6" title=
"promise-objects">Promise</span>.
</li>
<li>Return <em>P</em>.
</li>
<li>If the user agent does not <span>monitor presentation display
availability</span>, run the following steps:
<ol>
<li>
<span>Monitor presentation display availability</span>.
</li>
<li>Wait until the algorithm completes.
</li>
</ol>
</li>
<li>If the <span>list of available presentation displays</span> is
empty, then:
<ol>
<li>
<span data-anolis-spec="promguide" title=
"resolve-reject">Reject</span> <em>P</em> with a
<span data-anolis-spec="dom" title=
"domexception">DOMException</span> named
<code>"NotFoundError"</code>.
</li>
<li>Abort all remaining steps.
</li>
</ol>
</li>
<li>Queue a task <em>T</em> to request user permission for the use
of a <span data-anolis-ref="presentation">presentation
display</span> and selection of one presentation display.
<ol>
<li>If <em>T</em> completes with the user <em>granting
permission</em> to use a display, run the following steps:
<ol>
<li>If <code>presentationId</code> is not
<em>undefined</em>, assign <em>I</em> to that that
<code>presentationId</code>.
</li>
<li>If <code>presentationId</code> is
<code>undefined</code>, let <em>I</em> be a random
alphanumeric value of at least 16 characters drawn from the
characters <code>[A-Za-z0-9]</code>.
</li>
<li>Create a new <code>PresentationSession</code>
<em>S</em>.
</li>
<li>Set <code>S.url</code> to <code>presentationUrl</code>,
set <code>S.id</code> to <em>I</em>, and set
<code>S.state</code> to <code>disconnected</code>.
</li>
<li>
<span data-anolis-spec="w3c-html">Queue a task</span>
<em>C</em> to create a new <span data-anolis-spec=
"w3c-html">browsing context</span> on the user-selected
<span>presentation display</span> and
<span data-anolis-spec="w3c-html">navigate</span> to
<code>presentationUrl</code> in it.
<ol>
<li>If <em>C</em> completes successfully, run the
following steps:
<ol>
<li>Add <em>(S.url, S.id, S)</em> to <em>D</em>.
</li>
<li>
<span data-anolis-spec="promguide" title=
"resolve-reject">Resolve</span> <em>P</em> with
<em>S</em>.
</li>
<li>
<span>Establish a presentation connection</span>
with <em>S</em>.
</li>
</ol>
</li>
<li>If <em>C</em> fails, run the following steps:
<ol>
<li>
<span data-anolis-spec="promguide" title=
"resolve-reject">Reject</span> P with a
<span data-anolis-spec="dom" title=
"domexception">DOMException</span> named
<code>"OperationError"</code>.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li>If <em>T</em> completes with the user <em>denying
permission</em>, run the following steps:
<ol>
<li>
<span data-anolis-spec="promguide" title=
"resolve-reject">Reject</span> <em>P</em> with a
<span data-anolis-spec="dom" title=
"domexception">DOMException</span> named
<code>"AbortError"</code>.
</li>
</ol>
</li>
</ol>
</li>