Merge pull request #287 from nielsvanvelzen/cast-fixes

Miscellaneous casting fixes
This commit is contained in:
Max Rumpf
2021-01-19 10:40:03 +01:00
committed by GitHub
5 changed files with 10 additions and 3 deletions
@@ -1378,6 +1378,7 @@ execute('setup', function (err, args) {
});
window.chrome.cast = chrome.cast;
console.info('Applied custom cast interface to window');
/**
* Updates the current session with the incoming javaSession
@@ -1404,6 +1405,7 @@ function execute (action) {
throw new Error('Not initialized. Must call chrome.cast.initialize first.');
}
console.debug('execCast', action);
window.NativeShell.execCast(action, args, callback);
}
@@ -1429,6 +1431,7 @@ function handleError (err, callback) {
}
var error = new chrome.cast.Error(err, desc, {});
console.error('Encountered cast error', error);
if (callback) {
callback(error);
}
@@ -74,13 +74,13 @@ window.NativeShell = {
return plugins;
},
execCast(action, args, callback) {
async execCast(action, args, callback) {
this.castCallbacks = this.castCallbacks || {};
this.castCallbacks[action] = callback;
window.NativeInterface.execCast(action, JSON.stringify(args));
},
castCallback(action, keep, err, result) {
async castCallback(action, keep, err, result) {
const callbacks = this.castCallbacks || {};
const callback = callbacks[action];
callback && callback(err || null, result);
@@ -146,6 +146,10 @@ class WebViewFragment : Fragment() {
null // continue loading normally
}
path.contains("native") -> webView.context.loadAsset("native-${assetsVersion}/${url.lastPathSegment}")
path.endsWith(Constants.CAST_SDK_PATH) -> {
// Load the chrome.cast.js library instead
webView.context.loadAsset("native-${assetsVersion}/chrome.cast.js")
}
path.endsWith(Constants.SELECT_SERVER_PATH) -> {
runOnUiThread { onSelectServer() }
emptyResponse
@@ -11,6 +11,7 @@ object Constants {
// Webapp constants
const val APPLOADER_PATH = "scripts/apploader.js" // 10.6.4 <=
const val ANY_BUNDLE_PATH = ".bundle.js" // 10.7 >=
const val CAST_SDK_PATH = "cast_sender.js"
const val SELECT_SERVER_PATH = "selectserver.html"
const val SESSION_CAPABILITIES_PATH = "sessions/capabilities/full"
@@ -13,7 +13,6 @@ const val JS_INJECTION_CODE = """
var scripts = [
'/native/nativeshell.js',
'/native/EventEmitter.js',
'/native/chrome.cast.js',
];
scripts.forEach(function(src) {
var scriptElement = document.createElement('script');