forked from w3c/presentation-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1736 lines (1716 loc) · 70.2 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: 'http://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: '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/'
}
]
}
],
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',
issueBase: 'https://www.github.com/w3c/presentation-api/issues/',
localBiblio: {
PROMGUIDE: {
title: 'Writing Promise-Using Specifications',
href: 'http://www.w3.org/2001/tag/doc/promises-guide',
authors: [
'Domenic Denicola'
],
status: 'finding',
publisher: 'W3C'
}
},
issueBase: "https://www.github.com/w3c/presentation-api/issues/",
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; }
/* 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>
<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>
This document is a <b>work in progress</b> and is subject to change.
Some sections are still incomplete or underspecified. <a href=
"#security-and-privacy-considerations">Security and privacy
considerations</a> need to be adjusted based on feedback and
experience. Some 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 all open issues. Feedback from early
experimentations is encouraged to allow the Second Screen Presentation
Working Group to evolve the specification based on implementation
issues.
</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 title="presenting 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 title=
"presenting browsing context">presentation</a>. Instead of displaying
the <a title="presenting 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 title=
"presenting 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 <b>1-UA</b> 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 title=
"presenting 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 title="presenting browsing context">presentation</a>
itself. This is commonly referred to as the <b>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>
<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=
"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 title="fire"><a href=
"http://www.w3.org/TR/html5/infrastructure.html#concept-event-fire">firing
an 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</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> are defined in [[!HTML5]].
</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>
and <dfn><a href=
"http://heycam.github.io/webidl/#idl-DOMException">DOMException</a></dfn>
are defined in [[!WEBIDL]].
</p>
<p>
The terms <dfn title="resolve"><a href=
"http://www.w3.org/2001/tag/doc/promises-guide#resolve-promise">resolving
a Promise</a></dfn>, and <dfn title="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 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>
</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>). 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="castBtn" style="display: none;">Cast</button>
<script>
// it is also possible to use relative presentation URL e.g. "presentation.html"
var presUrl = "http://example.com/presentation.html";
// 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.
var request = new PresentationRequest(presUrl);
request.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, so discovery of presentation
// displays will happen only after request.start() is called. Pretend the
// devices are available for simplicity; or, 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 highlight">
<!-- controller.html -->
<script>
// Start new session.
request.start()
// 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 highlight">
<!-- controller.html -->
<script>
// read presId from localStorage if exists
var presId = localStorage && localStorage["presId"] || null;
// presId is mandatory when joining a session.
if (presId) {
request.join(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 highlight">
<!-- controller.html -->
<head>
<!-- Setting presentation.defaultRequest allows the page to specify the
PresentationRequest to use when the UA initiates a presentation session. -->
</head>
<script>
navigator.presentation.defaultRequest = new PresentationRequest(defaultUrl);
navigator.presentation.defaultRequest.onsessionconnect = function(evt) {
setSession(evt.session);
};
</script>
</pre>
</section>
<section>
<h3>
Monitor session's state and exchange data example
</h3>
<pre class="example highlight">
<!-- 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 highlight">
<!-- presentation.html -->
<script>
var addSession = function(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");
}
});
navigator.presentation.getSession().then(addSession);
navigator.presentation.onsessionavailable = function(evt) {
navigator.presentation.getSessions().then(function(sessions) {
addSession(sessions[sessions.length-1]);
});
};
</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 session|presentation sessions">presentation
session</dfn> is an object relating a <a>controlling browsing
context</a> to its <a>presenting browsing context</a> and enables
two-way-messaging between them. Each <a>presentation session</a> has
a <dfn>presentation session state</dfn>, a <dfn lt=
"presentation session identifier|presentation session identifiers">presentation
session identifier</dfn> to distinguish it from other <a>presentation
sessions</a>, and a <dfn>presentation session URL</dfn> that is a
<a>URL</a> used to create or resume the <a>presentation session</a>.
A <dfn>valid presentation session identifier</dfn> consists of
alphanumeric ASCII characters only, is at least 16 characters long,
and is unique within the <a>set of presentations</a>.
</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
session</a> by calling <code><a for=
"PresentationRequest">start</a>()</code> or <code><a for=
"PresentationRequest">join</a>()</code>, or received a
<a>presentation session</a> via a <code>sessionconnect</code> event.
</p>
<p>
The <dfn>presenting browsing context</dfn> (or <dfn title=
"presentation context">presentation</dfn> for short) is the browsing
context responsible for rendering to a <a>presentation display</a>. A
<a>presenting browsing context</a> can reside in the same user agent
as the <a>controlling browsing context</a> or a different one.
</p>
<p>
The <dfn>set of presentations</dfn>, initially empty, contains the
<a>presentation session</a>s created by the <a>controlling browsing
contexts</a> for the user agent (or a specific user profile within
the user agent). The <a>set of presentations</a> is represented by a
list of tuples, where each tuple consists of a <a>presentation
session URL</a>, a <a>presentation session identifier</a>, and the
<a>presentation session</a> itself. The <a>presentation session
URL</a> and <a>presentation session identifier</a> uniquely identify
the <a>presentation session</a>.
</p>
</section>
<section>
<h3>
Interface <code>PresentationSession</code>
</h3>
<p>
Each <a>presentation session</a> is represented by a
<a>PresentationSession</a> object.
</p>
<pre class="idl">
enum PresentationSessionState { "connected", "disconnected" /*, "resumed" */ };
enum BinaryType { "blob", "arraybuffer" };
interface PresentationSession : EventTarget {
readonly attribute DOMString? id;
readonly attribute PresentationSessionState state;
void close();
attribute EventHandler onstatechange;
// Communication
attribute BinaryType binaryType;
attribute EventHandler onmessage;
void send (DOMString message);
void send (Blob data);
void send (ArrayBuffer data);
void send (ArrayBufferView data);
};
</pre>
<div dfn-for="PresentationSession" link-for="PresentationSession">
<p>
The <dfn><code>id</code></dfn> attribute specifies the
<a>presentation session</a>'s <a>presentation session
identifier</a>.
</p>
<p>
The <dfn><code>state</code></dfn> attribute represents the
<a>presentation session</a>'s current state. It can take one of the
values of <a>PresentationSessionState</a> depending on connection
state.
</p>
<p>
When the <code><dfn>send</dfn>()</code> method is called on a
<a>PresentationSession</a> object with a <code>message</code>, the
user agent MUST run the algorithm to <a title="algorithm-send">send
a message through a <code>PresentationSession</code></a>.
</p>
<p>
When the <code><dfn>close</dfn>()</code> method is called on a
<a>PresentationSession</a>, the user agent MUST run the algorithm
to <a title="close-algorithm">close a presentation session</a> with
<a>PresentationSession</a>.
</p>
</div>
<section>
<h4>
Sending a message through <code>PresentationSession</code>
</h4>
<div class="note">
No specific transport for the connection between the <a>controlling
browsing context</a> and the <a>presenting browsing context</a> is
mandated, except that for multiple calls to <code><a for=
"PresentationSession">send</a>()</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
<a><code>RTCDataChannel</code></a> in reliable mode.
</div>
<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 link-for="PresentationSession">
<li>If the <a>state</a> property of <a>PresentationSession</a> is
<code>"disconnected"</code>, throw an
<code>InvalidStateError</code> exception.
</li>
<li>Let <a>presentation message type</a> <em>messageType</em> be
<code>binary</code> if <code>data</code> is one of
<code>ArrayBuffer</code>, <code>ArrayBufferView</code>, or
<code>Blob</code>. Let <em>messageType</em> be <code>text</code> if
<code>data</code> is of type <code>DOMString</code>)
</li>
<li>Assign the <dfn>destination browsing context</dfn> as follows:
<ol>
<li>Let the <a>destination browsing context</a> be the
<a>controlling browsing context</a> if
<code><a>send</a>()</code> is called in the <a>presenting
browsing context</a>.
</li>
<li>Let <a>destination browsing context</a> be the
<a>presenting browsing context</a> if
<code><a>send</a>()</code> is called from the <a>controlling
browsing context</a>.
</li>
</ol>
</li>
<li>Using an implementation specific mechanism, transmit the
contents of the <code>data</code> argument as <a>presentation
message data</a> and <a>presentation message type</a>
<em>messageType</em> to the <a>destination browsing context</a>
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 <a>presentation message data</a> and
<a>presentation message type</a>, it MUST run the following steps:
</p>
<ol link-for="PresentationSession">
<li>If the <a>state</a> property of <a>PresentationSession</a> is
<code>"disconnected"</code>, abort these steps.
</li>
<li>Let <em>event</em> be a newly created <a>trusted event</a> that
uses the <code>MessageEvent</code> interface, with the event type
<code>message</code>, which does not bubble, is not cancelable, and
has no default action.
</li>
<li>Initialize the <em>event's</em> data attribute as follows:
<ol>
<li>If the <a>presentation message type</a> is
<code>text</code>, then initialize <em>event's</em>
<code>data</code> attribute to the contents of <a>presentation
message data</a> of type <code>DOMString</code>.
</li>
<li>If the <a>presentation message type</a> is
<code>binary</code>, and <a>binaryType</a> is set to
<code>blob</code>, then initialise <em>event</em>'s
<code>data</code> attribute to a new <code>Blob</code> object
that represents <a>presentation message data</a> as its raw
data.
</li>
<li>If the <a>presentation message type</a> is
<code>binary</code>, and <a>binaryType</a> is set to
<code>arraybuffer</code>, then initialise <em>event</em>'s
<code>data</code> attribute to a new <code>ArrayBuffer</code>
object whose contents are <a>presentation message data</a>.
</li>
</ol>
</li>
<li>
<a>Queue a task</a> to <a>fire</a> <em>event</em> at
<a><code>PresentationSession</code></a>.
</li>
</ol>
</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 <a>presentation session state</a> of <em>session</em> is not
<code>connected</code>, then abort these steps.
</li>
<li>Set <a>presentation session state</a> of <em>session</em> to
<code>disconnected</code>.
</li>
<li>
<a>Queue a task</a> to run the following steps in order:
<ol>
<li>For each <em>known session</em> in the <a>set of
presentations</a>:
<ol>
<li>If the <a>presentation session identifier</a> of
<em>known session</em> and <em>session</em> are equal, run
the following steps:
<ol>
<li>
<a>Queue a task</a> to <a>fire</a> an event named
<code>statechange</code> at <em>session</em>.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<div class="issue" data-number="35"></div>
</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 <a>PresentationSession</a>
interface:
</p>
<table dfn-for="PresentationSession">
<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>PresentationAvailability</code>
</h3>
<pre class="idl">
interface PresentationAvailability : EventTarget {
readonly attribute boolean value;
attribute EventHandler onchange;
};
</pre>
<p>
A <a><code>PresentationAvailability</code></a> object is associated
with a <a>presentation display</a> and represents its
<dfn>presentation display availability</dfn>.
</p>
<p>
The <dfn for="PresentationAvailability">value</dfn> attribute MUST
return the last value it was set to. The value is updated by the
<a>monitor the list of available presentation displays</a> algorithm.
</p>
<p>
The <dfn for="PresentationAvailability">onchange</dfn> attribute is
an <a>event handler</a> whose corresponding <a>event handler event
type</a> is <code>change</code>.
</p>
<section>
<h4>
The set of availability objects
</h4>
<p>
The user agent MUST keep track of the <dfn>set of availability
objects</dfn> requested through the <code><a for=
"PresentationRequest">getAvailability</a>()</code> method. The
<a>set of availability objects</a> is represented as a set of
tuples <em>(A, availabilityUrl, P)</em>, initially empty, where:
</p>
<ol>
<li>
<em>A</em> is a live <a>PresentationAvailability</a> object;
</li>
<li>
<em>availabilityUrl</em> is the <code>availabilityUrl</code>
passed to <code><a for=
"PresentationRequest">getAvailability</a>()</code> to create A.
</li>
<li>
<em>P</em> is the <a>Promise</a> that was returned by
<code><a for="PresentationRequest">getAvailability</a>()</code>
when <em>A</em> was created.
</li>
</ol>
</section>
<section>
<h4>
The list of available presentation displays
</h4>
<p>
The user agent MUST keep a <dfn>list of available presentation
displays</dfn>. This current list of <a>presentation displays</a>
may be used for starting new presentations, and is populated based
on an implementation specific discovery mechanism. It is set to the
most recent result of the algorithm to <a>monitor the list of
available presentation displays</a>.
</p>
<p>
While there are live <a>PresentationAvailability</a> objects, the
user agent MAY <a>monitor the list of available presentation
displays</a> continuously, so that pages can use the <a for=
"PresentationAvailability">value</a> property of an
<a>PresentationAvailability</a> object to offer presentation only
when there are available displays. However, the user agent may not
support continuous availability monitoring; for example, because of
platform or power consumption restrictions. In this case the
<a>Promise</a> returned by <code>getAvailability()</code> is
<a title="reject">rejected</a> and the algorithm to <a>monitor the
list of available presentation displays</a> will only run as part
of the <a for="PresentationRequest" title="start">start a
presentation session</a> algorithm.
</p>
<p>
When there are no live <a>PresentationAvailability</a> objects
(that is, the <a>set of availability objects</a> is empty), user
agents SHOULD NOT <a>monitor the list of available presentation
displays</a> to satisfy the <a href=
"https://github.com/w3c/presentation-api/blob/gh-pages/uc-req.md#nf-req01-power-saving-friendly">
power saving non-functional requirement</a>. To further save power,
the user agent MAY also keep track of whether the page holding a
<a>PresentationAvailability</a> object is in the foreground. Using
this information, implementation specific discovery of
<a>presentation displays</a> can be resumed or suspended.
</p>
<p>
Some <a>presentation displays</a> may only be able to display a
subset of Web content because of functional, security or hardware
limitations. Examples are set-top boxes, smart TVs or networked
speakers capable of rendering only audio. We say that such a
display is a <dfn>compatible presentation display</dfn> for a
<dfn>display availability URL</dfn> if the user agent can
reasonably guarantee that the presentation of the URL on that
display will succeed.
</p>
</section>
<section>
<h4>
Monitor the list of available presentation displays
</h4>
<p>
If <a>set of availability objects</a> is non-empty, or there is a
pending request to <a for="PresentationRequest" title="start">start
a presentation session</a>, the user agent MUST <dfn>monitor the
list of available presentation displays</dfn> by running the
following steps.
</p>
<ol link-for="PresentationAvailability">
<li>
<a>Queue a task</a> to retrieve available presentation displays
(using an implementation specific mechanism) and let
<em>newDisplays</em> be this list.
</li>
<li>Wait for the completion of that task.
</li>
<li>For each member <em>(A, availabilityUrl, P)</em> of the <a>set
of availability objects</a>:
<ol>
<li>Set <em>previousAvailability</em> to the value of
<em>A</em>'s <a>value</a> property.
</li>
<li>Let <em>newAvailability</em> be <code>true</code> if
<em>newDisplays</em> is not empty and at least one display in
<em>newDisplays</em> is a <a>compatible presentation
display</a> for <em>availabilityUrl</em>. Otherwise, set
<em>newAvailability</em> to <code>false</code>.
</li>
<li>If <em>previousAvailability</em> is not equal to
<em>newAvailability</em>, then <a>queue a task</a> to run the
following steps:
<ol>
<li>Set <em>A</em>'s <a>value</a> property to
<em>newAvailability</em>.
</li>
<li>If <em>P</em> is settled, then <a>fire</a> an event
named <code>change</code> at <em>A</em>.
</li>
<li>If <em>P</em> is not settled, then <a>resolve</a> <em>
P</em> with <em>A</em>.
</li>
</ol>
</li>
</ol>
</li>
<li>Set the <a>list of available presentation displays</a> to the
value of <em>newDisplays</em>.
</li>
</ol>
<p>
When a <a>PresentationAvailability</a> object is no longer alive
(i.e., is eligible for garbage collection), the user agent SHOULD
run the following steps:
</p>
<ol>
<li>Find and remove any entry <em>(A, availabilityUrl, P)</em> in
the <a>set of availability objects</a> for the newly deceased <em>
A</em>.
</li>
<li>If the <a>set of availability objects</a> is now empty and
there is no pending request to <a for="PresentationRequest"
title="start">start a presentation session</a>, cancel any
pending task to <a>monitor the list of available presentation
displays</a> for power saving purposes.
</li>
</ol>
<div class="note">
The mechanism used to monitor <a>presentation displays</a>
availability and determine the compatibility of a <a>presentation
display</a> with a given URL is left to the user agent.
</div>
</section>
</section>
<section>
<h3>
Interface <a><code>PresentationRequest</code></a>
</h3>
<pre class="idl">
[Constructor(DOMString url)]
interface PresentationRequest : EventTarget {
Promise<PresentationSession> start();
Promise<PresentationSession> join(DOMString presentationId);
Promise<PresentationAvailability> getAvailability();
attribute EventHandler onsessionconnect;
};
</pre>
<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 session URL</a> for the
<a><code>PresentationRequest</code></a> instance.
</p>
<section>
<h4>
Starting a presentation session
</h4>
<p>
When the <code><dfn for="PresentationRequest">start</dfn></code>
method is called, the user agent MUST run the following steps to
<dfn>start a presentation session</dfn>:
</p>
<dl>
<dt>
Input
</dt>
<dd>
<code>presentationRequest</code>, the
<code>PresentationRequest</code> object
</dd>
<dd>
<code>presentationUrl</code>, the <a>presentation request URL</a>
</dd>
<dt>
Output
</dt>
<dd>
<em>P</em>, 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 a <a>DOMException</a> named
<code>"InvalidAccessError"</code> and abort these steps.
</li>
<li>Let <em>P</em> be a new <a>Promise</a>.
</li>
<li>Return <em>P</em>.
</li>
<li>Run the following steps:
<ol>
<li>
<a>Monitor the list of available presentation displays</a>.
</li>
<li>Wait until the algorithm completes.
</li>
</ol>
</li>
<li>If either of the following is true:
<ol>
<li>The <a>list of available presentation displays</a> is
empty;
</li>