OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 /** |
| 8 * The instance of cast api. |
| 9 * @type {cast.ExtensionApi} |
| 10 */ |
| 11 var castApi = null; |
| 12 |
| 13 /** |
| 14 * @type {string} |
| 15 * @const |
| 16 */ |
| 17 var CAST_COMMAND_LINE_FLAG = 'enable-video-player-chromecast-support'; |
| 18 |
| 19 chrome.commandLinePrivate.hasSwitch(CAST_COMMAND_LINE_FLAG, function(result) { |
| 20 if (!result) |
| 21 return; |
| 22 |
| 23 CastExtensionDiscoverer.findInstalledExtension(onCastExtensionFound); |
| 24 }); |
| 25 |
| 26 function onCastExtensionFound(extensionId) { |
| 27 if (!extensionId) { |
| 28 console.info('Cast extention is not found.'); |
| 29 return; |
| 30 } |
| 31 |
| 32 var api = document.createElement('script'); |
| 33 api.src = 'chrome-extension://' + extensionId + '/api_script.js'; |
| 34 api.onload = function() { |
| 35 initializeCast(extensionId); |
| 36 }; |
| 37 api.onerror = function() { |
| 38 console.error('api_script.js load failed.'); |
| 39 }; |
| 40 document.body.appendChild(api); |
| 41 }; |
| 42 |
| 43 function initializeCast(extensionId) { |
| 44 loadCastExtensionApi(); |
| 45 |
| 46 castApi = new cast.ExtensionApi(extensionId); |
| 47 castApi.addReceiverListener('ChromeCast', onReceiverUpdate); |
| 48 } |
| 49 |
| 50 function onReceiverUpdate(receivers) { |
| 51 player.setCastList(receivers); |
| 52 } |
OLD | NEW |