зеркало из https://github.com/GoogleChrome/kino.git
Only return the casting button when there are devices to cast to.
This commit is contained in:
Родитель
cd26b29d6c
Коммит
b02f5aa780
28
src/index.js
28
src/index.js
|
@ -170,20 +170,40 @@ window.kinoInitGoogleCast = (function kinoInitGoogleCastIIFE() {
|
|||
return () => {
|
||||
if (!castButtonPromise) {
|
||||
castButtonPromise = new Promise((resolve) => {
|
||||
const initCastApi = () => {
|
||||
window.cast.framework.CastContext.getInstance().setOptions({
|
||||
receiverApplicationId: window.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
|
||||
});
|
||||
let resolved = false;
|
||||
|
||||
const resolveWithButton = () => {
|
||||
const castButton = document.createElement('button');
|
||||
const castCustomElement = document.createElement('google-cast-launcher');
|
||||
|
||||
castButton.setAttribute('aria-label', 'Cast this video');
|
||||
castButton.appendChild(castCustomElement);
|
||||
|
||||
resolved = true;
|
||||
resolve(castButton);
|
||||
};
|
||||
|
||||
const checkCastState = () => {
|
||||
const castState = window.cast.framework.CastContext.getInstance().getCastState();
|
||||
|
||||
if (castState !== 'NO_DEVICES_AVAILABLE' && !resolved) {
|
||||
resolveWithButton();
|
||||
}
|
||||
};
|
||||
|
||||
const initCastApi = () => {
|
||||
window.cast.framework.CastContext.getInstance().setOptions({
|
||||
receiverApplicationId: window.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
|
||||
});
|
||||
|
||||
checkCastState();
|
||||
|
||||
window.cast.framework.CastContext.getInstance().addEventListener(
|
||||
window.cast.framework.CastContextEventType.CAST_STATE_CHANGED,
|
||||
checkCastState,
|
||||
);
|
||||
};
|
||||
|
||||
window.__onGCastApiAvailable = (isAvailable) => {
|
||||
if (isAvailable) {
|
||||
initCastApi();
|
||||
|
|
Загрузка…
Ссылка в новой задаче