Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: ui/file_manager/video_player/js/cast/caster.js

Issue 410043003: Video Player: Use Google Cast API extension instead of deprecated way (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/video_player/js/cast/caster.js
diff --git a/ui/file_manager/video_player/js/cast/caster.js b/ui/file_manager/video_player/js/cast/caster.js
index 6ff0831c63a3b11b60dddca5fa81ccc6cd21002a..6b436d6c79e6e35da17facc0cbcf60716ac8203e 100644
--- a/ui/file_manager/video_player/js/cast/caster.js
+++ b/ui/file_manager/video_player/js/cast/caster.js
@@ -4,11 +4,11 @@
'use strict';
-/**
- * The instance of cast api.
- * @type {cast.ExtensionApi}
- */
-var castApi = null;
+// This hack prevents a bug on the cast extension.
+// TODO(yoshiki): Remove this once the cast extension supports Chrome apps.
+// Although localStorage in Chrome app is not supported, but it's used in the
+// cast extension. This line prevents an exception on using localStorage.
+window.__defineGetter__('localStorage', function() { return {}; });
/**
* @type {string}
@@ -16,37 +16,78 @@ var castApi = null;
*/
var CAST_COMMAND_LINE_FLAG = 'enable-video-player-chromecast-support';
+// THIS IS A TEST APP.
+// TODO(yoshiki): Fix this before launch.
+var APPLICATION_ID = '214CC863';
+
chrome.commandLinePrivate.hasSwitch(CAST_COMMAND_LINE_FLAG, function(result) {
if (!result)
return;
- CastExtensionDiscoverer.findInstalledExtension(onCastExtensionFound);
+ ensureLoad(initializeApi);
});
-function onCastExtensionFound(extensionId) {
- if (!extensionId) {
- console.info('Cast extention is not found.');
- return;
+/**
+ * Executes the given callback after the cast extension is initialized.
+ * @param {function} callback Callback (executed asynchronously).
+ */
+function ensureLoad(callback) {
+ if(!chrome.cast || !chrome.cast.isAvailable) {
+ var checkTimer = setTimeout(function() {
+ console.error('Either "Google Cast API" or "Google Cast" extension ' +
+ 'seems not to be installed?');
+ }, 5000);
+
+ window['__onGCastApiAvailable'] = function(loaded, errorInfo) {
+ if (loaded) {
+ callback();
+ clearTimeout(chcekTimer);
+ } else {
+ console.error(errorInfo);
+ }
+ }
+ } else {
+ setTimeout(callback); // Runs asynchronously.
}
+}
- var api = document.createElement('script');
- api.src = 'chrome-extension://' + extensionId + '/api_script.js';
- api.onload = function() {
- initializeCast(extensionId);
+/**
+ * Initialize Cast API.
+ */
+function initializeApi() {
+ var onSession = function() {
+ // TODO(yoshiki): Implement this.
};
- api.onerror = function() {
- console.error('api_script.js load failed.');
+
+ var onInitSuccess = function() {
+ // TODO(yoshiki): Implement this.
};
- document.body.appendChild(api);
-};
-function initializeCast(extensionId) {
- loadCastExtensionApi();
+ /**
+ * @param {chrome.cast.Error} error
+ */
+ var onError = function(error) {
+ console.error('Error on Cast initialization.', error);
+ };
- castApi = new cast.ExtensionApi(extensionId);
- castApi.addReceiverListener('ChromeCast', onReceiverUpdate);
+ var sessionRequest = new chrome.cast.SessionRequest(APPLICATION_ID);
+ var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
+ onSession,
+ onReceiver);
+ chrome.cast.initialize(apiConfig, onInitSuccess, onError);
}
-function onReceiverUpdate(receivers) {
- player.setCastList(receivers);
+/**
+ * @param {chrome.cast.ReceiverAvailability} availability Availability of casts.
+ * @param {Array.<Object>} receivers List of casts.
+ */
+function onReceiver(availability, receivers) {
+ if (availability === chrome.cast.ReceiverAvailability.AVAILABLE) {
+ player.setCastList(receivers);
+ } else if (availability == chrome.cast.ReceiverAvailability.UNAVAILABLE) {
+ player.setCastList([]);
+ } else {
+ console.error('Unexpected response in onReceiver.', arguments);
+ player.setCastList([]);
+ }
}
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698