[EME] Clean up promise chains and reject paths in examples.
--- a/encrypted-media/encrypted-media.html Thu Apr 17 13:11:20 2014 -0700
+++ b/encrypted-media/encrypted-media.html Mon Apr 21 14:12:31 2014 -0700
@@ -98,7 +98,7 @@
<div class="head">
<p><a href="http://www.w3.org/"><img src="https://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48"></a></p>
<h1>Encrypted Media Extensions</h1>
- <h2 id="draft-date">W3C Editor's Draft 17 April 2014</h2>
+ <h2 id="draft-date">W3C Editor's Draft 21 April 2014</h2>
<dl>
<dt>This Version:</dt>
<dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html">http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html</a></dd>
@@ -1255,21 +1255,27 @@
var video = document.getElementById("video");
if (!video.<a href="#dom-attrmediakeys">mediaKeys</a>) {
- <a href="#dom-mediakeys">MediaKeys</a>.<a href="#dom-create">create</a>("org.w3.clearkey").then(
+ var promise = <a href="#dom-mediakeys">MediaKeys</a>.<a href="#dom-create">create</a>("org.w3.clearkey");
+ promise.catch(
+ console.error.bind(console, "Unable to create MediaKeys")
+ );
+ promise.then(
function(createdMediaKeys) {
return video.<a href="#dom-setmediakeys">setMediaKeys</a>(createdMediaKeys);
- },
- console.error.bind(console, "Unable to create MediaKeys")
- ).then(
- function() {
+ }
+ ).catch(
+ console.error.bind(console, "Unable to set MediaKeys")
+ );
+ promise.then(
+ function(createdMediaKeys) {
var initData = new Uint8Array([ ... ]);
- return video.<a href="#dom-attrmediakeys">mediaKeys</a>.<a href="#dom-createsession">createSession</a>("webm", initData);
- },
- console.error.bind(console, "Unable to set MediaKeys")
+ return createdMediaKeys.<a href="#dom-createsession">createSession</a>("webm", initData);
+ }
).then(
function(keySession) {
keySession.addEventListener("<a href="#dom-eventmessage">message</a>", handleMessage, false);
- },
+ }
+ ).catch(
console.error.bind(console, "Unable to create key session")
);
}
@@ -1329,10 +1335,9 @@
video.pendingSessionData = [];
return video.<a href="#dom-setmediakeys">setMediaKeys</a>(createdMediaKeys);
- },
- console.error.bind(console, "Unable to create MediaKeys")
+ }
).catch(
- console.error.bind(console, "Unable to set MediaKeys")
+ console.error.bind(console, "Unable to create or use new MediaKeys")
);
}
addSession(video, event.<a href="#dom-initdatatype">initDataType</a>, event.<a href="#dom-initdata">initData</a>);
@@ -1350,8 +1355,9 @@
mediaKeys.<a href="#dom-createsession">createSession</a>(initDataType, initData).then(
function(keySession) {
keySession.addEventListener("<a href="#dom-eventmessage">message</a>", licenseRequestReady, false);
- },
- console.error.bind(console, "Unable to create key session")
+ }
+ ).catch(
+ console.error.bind(console, "Unable to create or initialize key session")
);
}
@@ -1400,8 +1406,9 @@
keySession.close.then(
console.log.bind(console, "Session closed")
);
- },
- console.error.bind(console, "Unable to create key session")
+ }
+ ).catch(
+ console.error.bind(console, "Unable to create or initialize key session")
);
}
--- a/encrypted-media/encrypted-media.xml Thu Apr 17 13:11:20 2014 -0700
+++ b/encrypted-media/encrypted-media.xml Mon Apr 21 14:12:31 2014 -0700
@@ -97,7 +97,7 @@
<div class="head">
<p><a href="http://www.w3.org/"><img src="https://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48" /></a></p>
<h1>Encrypted Media Extensions</h1>
- <h2 id="draft-date">W3C Editor's Draft 17 April 2014</h2>
+ <h2 id="draft-date">W3C Editor's Draft 21 April 2014</h2>
<dl>
<dt>This Version:</dt>
<dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html">http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html</a></dd>
@@ -1198,21 +1198,27 @@
var video = document.getElementById("video");
if (!video.<precoderef prefix="attr">mediaKeys</precoderef>) {
- <precoderef>MediaKeys</precoderef>.<premethodref>create</premethodref>("org.w3.clearkey").then(
+ var promise = <precoderef>MediaKeys</precoderef>.<premethodref>create</premethodref>("org.w3.clearkey");
+ promise.catch(
+ console.error.bind(console, "Unable to create MediaKeys")
+ );
+ promise.then(
function(createdMediaKeys) {
return video.<premethodref>setMediaKeys</premethodref>(createdMediaKeys);
- },
- console.error.bind(console, "Unable to create MediaKeys")
- ).then(
- function() {
+ }
+ ).catch(
+ console.error.bind(console, "Unable to set MediaKeys")
+ );
+ promise.then(
+ function(createdMediaKeys) {
var initData = new Uint8Array([ ... ]);
- return video.<precoderef prefix="attr">mediaKeys</precoderef>.<premethodref>createSession</premethodref>("webm", initData);
- },
- console.error.bind(console, "Unable to set MediaKeys")
+ return createdMediaKeys.<premethodref>createSession</premethodref>("webm", initData);
+ }
).then(
function(keySession) {
keySession.addEventListener("<precoderef prefix="event">message</precoderef>", handleMessage, false);
- },
+ }
+ ).catch(
console.error.bind(console, "Unable to create key session")
);
}
@@ -1272,10 +1278,9 @@
video.pendingSessionData = [];
return video.<premethodref>setMediaKeys</premethodref>(createdMediaKeys);
- },
- console.error.bind(console, "Unable to create MediaKeys")
+ }
).catch(
- console.error.bind(console, "Unable to set MediaKeys")
+ console.error.bind(console, "Unable to create or use new MediaKeys")
);
}
addSession(video, event.<precoderef>initDataType</precoderef>, event.<precoderef>initData</precoderef>);
@@ -1293,8 +1298,9 @@
mediaKeys.<premethodref>createSession</premethodref>(initDataType, initData).then(
function(keySession) {
keySession.addEventListener("<precoderef prefix="event">message</precoderef>", licenseRequestReady, false);
- },
- console.error.bind(console, "Unable to create key session")
+ }
+ ).catch(
+ console.error.bind(console, "Unable to create or initialize key session")
);
}
@@ -1343,8 +1349,9 @@
keySession.close.then(
console.log.bind(console, "Session closed")
);
- },
- console.error.bind(console, "Unable to create key session")
+ }
+ ).catch(
+ console.error.bind(console, "Unable to create or initialize key session")
);
}