<!--
Copyright 2013 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<script>
var extensionId = "knldjmfmopnpolahpmmgbagdohdnhkik";
function onMediaStreamError(mediaStreamError) {
console.log(mediaStreamError.message);
return false;
}
function requestStreamId() {
return new Promise(resolve => {
function onResponse(response) {
if (chrome.runtime.lastError) {
throw new Error("Failure");
}
id = response["id"];
resolve(id);
};
chrome.runtime.sendMessage(
extensionId, ["getStream"], onResponse);
});
}
function getStream() {
return requestStreamId()
.then((id) => {
if (!id) {
return false;
}
return new Promise((resolve, reject) => {
navigator.webkitGetUserMedia({
audio:false,
video: { mandatory: { chromeMediaSource: "desktop",
chromeMediaSourceId: id } },
}, resolve, reject);
});
})
.then(() => true, onMediaStreamError);
}
function getStreamWithInvalidId() {
return requestStreamId()
.then((id) => {
if (!id) {
return false;
}
return new Promise((resolve, reject) => {
navigator.webkitGetUserMedia({
audio:false,
video: { mandatory: { chromeMediaSource: "desktop",
chromeMediaSourceId: id + "x" } }
}, resolve, reject);
});
})
.then(() => false, () => true);
}
function openPickerDialogAndReturn() {
return new Promise(resolve => {
chrome.runtime.sendMessage(
extensionId, ["getStreamNoWait"], function(message) {
// Once the picker is shown request to close the tab. The picker should
// be destroyed as result.
resolve(true);
});
});
}
</script>