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