Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous casting fixes #287

Merged
merged 3 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/assets/native-10.7/chrome.cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/assets/native-10.7/nativeshell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/jellyfin/mobile/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/jellyfin/mobile/utils/WebAppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down