| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 <include src="media_router_data.js"> | 5 <include src="media_router_data.js"> |
| 6 <include src="media_router_ui_interface.js"> | 6 <include src="media_router_ui_interface.js"> |
| 7 | 7 |
| 8 // Handles user events for the Media Router UI. | 8 // Handles user events for the Media Router UI. |
| 9 cr.define('media_router', function() { | 9 cr.define('media_router', function() { |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 // The media-router-container element. Initialized after polymer is ready. | 12 // The media-router-container element. Initialized after polymer is ready. |
| 13 var container = null; | 13 var container = null; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Initializes the Media Router WebUI and requests initial media | 16 * Initializes the Media Router WebUI and requests initial media |
| 17 * router content, such as the media sink and media route lists. | 17 * router content, such as the media sink and media route lists. |
| 18 */ | 18 */ |
| 19 function initialize() { | 19 function initialize() { |
| 20 media_router.browserApi.requestInitialData(); | 20 media_router.browserApi.requestInitialData(); |
| 21 | 21 |
| 22 container = $('media-router-container'); | 22 container = $('media-router-container'); |
| 23 media_router.ui.setContainer(container); | 23 media_router.ui.setContainer(container); |
| 24 | 24 |
| 25 container.addEventListener('close-button-click', onCloseDialogEvent); | 25 container.addEventListener('close-button-click', onCloseDialogEvent); |
| 26 container.addEventListener('close-dialog', onCloseDialogEvent); | 26 container.addEventListener('close-dialog', onCloseDialogEvent); |
| 27 container.addEventListener('close-route-click', onCloseRouteClick); | 27 container.addEventListener('close-route-click', onCloseRouteClick); |
| 28 container.addEventListener('join-route-click', onJoinRouteClick); |
| 28 container.addEventListener('create-route', onCreateRoute); | 29 container.addEventListener('create-route', onCreateRoute); |
| 29 container.addEventListener('issue-action-click', onIssueActionClick); | 30 container.addEventListener('issue-action-click', onIssueActionClick); |
| 30 container.addEventListener('report-sink-count', onSinkCountReported); | 31 container.addEventListener('report-sink-count', onSinkCountReported); |
| 31 } | 32 } |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Closes the dialog. | 35 * Closes the dialog. |
| 35 * Called when the user clicks the close button on the dialog. | 36 * Called when the user clicks the close button on the dialog. |
| 36 */ | 37 */ |
| 37 function onCloseDialogEvent() { | 38 function onCloseDialogEvent() { media_router.browserApi.closeDialog(); } |
| 38 media_router.browserApi.closeDialog(); | |
| 39 } | |
| 40 | 39 |
| 41 /** | 40 /** |
| 42 * Acts on an issue and dismisses it from the UI. | 41 * Acts on an issue and dismisses it from the UI. |
| 43 * Called when the user performs an action on an issue. | 42 * Called when the user performs an action on an issue. |
| 44 * | 43 * |
| 45 * @param {{detail: {id: string, actionType: number, helpPageId: number}}} | 44 * @param {{detail: {id: string, actionType: number, helpPageId: number}}} |
| 46 * data | 45 * data |
| 47 * Parameters in |data|.detail: | 46 * Parameters in |data|.detail: |
| 48 * id - issue ID. | 47 * id - issue ID. |
| 49 * actionType - type of action performed by the user. | 48 * actionType - type of action performed by the user. |
| 50 * helpPageId - the numeric help center ID. | 49 * helpPageId - the numeric help center ID. |
| 51 */ | 50 */ |
| 52 function onIssueActionClick(data) { | 51 function onIssueActionClick(data) { |
| 53 media_router.browserApi.actOnIssue(data.detail.id, | 52 media_router.browserApi.actOnIssue( |
| 54 data.detail.actionType, | 53 data.detail.id, data.detail.actionType, data.detail.helpPageId); |
| 55 data.detail.helpPageId); | |
| 56 container.issue = null; | 54 container.issue = null; |
| 57 } | 55 } |
| 58 | 56 |
| 59 /** | 57 /** |
| 60 * Creates a media route. | 58 * Creates a media route. |
| 61 * Called when the user requests to create a media route. | 59 * Called when the user requests to create a media route. |
| 62 * | 60 * |
| 63 * @param {{detail: {sinkId: string, selectedCastModeValue: number}}} data | 61 * @param {{detail: {sinkId: string, selectedCastModeValue: number}}} data |
| 64 * Parameters in |data|.detail: | 62 * Parameters in |data|.detail: |
| 65 * sinkId - sink ID selected by the user. | 63 * sinkId - sink ID selected by the user. |
| 66 * selectedCastModeValue - cast mode selected by the user. | 64 * selectedCastModeValue - cast mode selected by the user. |
| 67 */ | 65 */ |
| 68 function onCreateRoute(data) { | 66 function onCreateRoute(data) { |
| 69 media_router.browserApi.requestRoute(data.detail.sinkId, | 67 media_router.browserApi.requestRoute( |
| 70 data.detail.selectedCastModeValue); | 68 data.detail.sinkId, data.detail.selectedCastModeValue); |
| 71 } | 69 } |
| 72 | 70 |
| 73 /** | 71 /** |
| 74 * Stops a route. | 72 * Stops a route. |
| 75 * Called when the user requests to stop a media route. | 73 * Called when the user requests to stop a media route. |
| 76 * | 74 * |
| 77 * @param {{detail: {route: string}}} data | 75 * @param {{detail: {route: string}}} data |
| 78 * Parameters in |data|.detail: | 76 * Parameters in |data|.detail: |
| 79 * route - route ID. | 77 * route - route ID. |
| 80 */ | 78 */ |
| 81 function onCloseRouteClick(data) { | 79 function onCloseRouteClick(data) { |
| 82 media_router.browserApi.closeRoute(data.detail.route); | 80 media_router.browserApi.closeRoute(data.detail.route); |
| 83 } | 81 } |
| 84 | 82 |
| 85 /** | 83 /** |
| 84 * Joins a route. |
| 85 * Called when the user requests to join a media route. |
| 86 * |
| 87 * @param {{detail: {route: string}}} data |
| 88 * Parameters in |data|.detail: |
| 89 * route - route ID. |
| 90 */ |
| 91 function onJoinRouteClick(data) { |
| 92 console.log('media router ui join clicked: ' + JSON.stringify(data.detail)); |
| 93 media_router.browserApi.joinRoute(data.detail.route); |
| 94 } |
| 95 |
| 96 /** |
| 86 * Reports the current sink count. | 97 * Reports the current sink count. |
| 87 * Called 3 seconds after the dialog is initially opened. | 98 * Called 3 seconds after the dialog is initially opened. |
| 88 * | 99 * |
| 89 * @param {{detail: {sinkCount: number}}} data | 100 * @param {{detail: {sinkCount: number}}} data |
| 90 * Parameters in |data|.detail: | 101 * Parameters in |data|.detail: |
| 91 * sinkCount - the number of sinks. | 102 * sinkCount - the number of sinks. |
| 92 */ | 103 */ |
| 93 function onSinkCountReported(data) { | 104 function onSinkCountReported(data) { |
| 94 media_router.browserApi.reportSinkCount(data.detail.sinkCount); | 105 media_router.browserApi.reportSinkCount(data.detail.sinkCount); |
| 95 } | 106 } |
| 96 | 107 |
| 97 return { | 108 return { |
| 98 initialize: initialize, | 109 initialize: initialize, |
| 99 }; | 110 }; |
| 100 }); | 111 }); |
| 101 | 112 |
| 102 window.addEventListener('load', media_router.initialize); | 113 window.addEventListener('load', media_router.initialize); |
| OLD | NEW |