| 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 ESC key maps to keycode '27'. | 12 // The ESC key maps to keycode '27'. |
| 13 // @const {number} | 13 // @const {number} |
| 14 var KEYCODE_ESC = 27; | 14 var KEYCODE_ESC = 27; |
| 15 | 15 |
| 16 // The media-router-container element. Initialized after polymer is ready. | 16 /** |
| 17 * The media-router-container element. Initialized after polymer is ready. |
| 18 * @type {?MediaRouterContainerElement} |
| 19 */ |
| 17 var container = null; | 20 var container = null; |
| 18 | 21 |
| 19 /** | 22 /** |
| 20 * Initializes the Media Router WebUI and requests initial media | 23 * Initializes the Media Router WebUI and requests initial media |
| 21 * router content, such as the media sink and media route lists. | 24 * router content, such as the media sink and media route lists. |
| 22 */ | 25 */ |
| 23 function initialize() { | 26 function initialize() { |
| 24 media_router.browserApi.requestInitialData(); | 27 media_router.browserApi.requestInitialData(); |
| 25 | 28 |
| 26 container = $('media-router-container'); | 29 container = /** @type {!MediaRouterContainerElement} */ |
| 30 ($('media-router-container')); |
| 27 media_router.ui.setContainer(container); | 31 media_router.ui.setContainer(container); |
| 28 | 32 |
| 29 container.addEventListener('acknowledge-first-run-flow', | 33 container.addEventListener('acknowledge-first-run-flow', |
| 30 onAcknowledgeFirstRunFlow); | 34 onAcknowledgeFirstRunFlow); |
| 31 container.addEventListener('back-click', onNavigateToSinkList); | 35 container.addEventListener('back-click', onNavigateToSinkList); |
| 32 container.addEventListener('cast-mode-selected', onCastModeSelected); | 36 container.addEventListener('cast-mode-selected', onCastModeSelected); |
| 33 container.addEventListener('close-button-click', onCloseDialogEvent); | 37 container.addEventListener('close-button-click', onCloseDialogEvent); |
| 34 container.addEventListener('close-dialog', onCloseDialogEvent); | 38 container.addEventListener('close-dialog', onCloseDialogEvent); |
| 35 container.addEventListener('close-route-click', onCloseRouteClick); | 39 container.addEventListener('close-route-click', onCloseRouteClick); |
| 36 container.addEventListener('create-route', onCreateRoute); | 40 container.addEventListener('create-route', onCreateRoute); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 container.maybeReportUserFirstAction( | 59 container.maybeReportUserFirstAction( |
| 56 media_router.MediaRouterUserAction.CLOSE); | 60 media_router.MediaRouterUserAction.CLOSE); |
| 57 } | 61 } |
| 58 }); | 62 }); |
| 59 } | 63 } |
| 60 | 64 |
| 61 /** | 65 /** |
| 62 * Reports the selected cast mode. | 66 * Reports the selected cast mode. |
| 63 * Called when the user selects a cast mode from the picker. | 67 * Called when the user selects a cast mode from the picker. |
| 64 * | 68 * |
| 65 * @param {{detail: {castModeType: number}}} data | 69 * @param {!Event} event |
| 66 * Parameters in |data|.detail: | 70 * Parameters in |event|.detail: |
| 67 * castModeType - type of cast mode selected by the user. | 71 * castModeType - type of cast mode selected by the user. |
| 68 */ | 72 */ |
| 69 function onCastModeSelected(data) { | 73 function onCastModeSelected(event) { |
| 70 media_router.browserApi.reportSelectedCastMode(data.detail.castModeType); | 74 /** @type {{castModeType: number}} */ |
| 75 var detail = event.detail; |
| 76 media_router.browserApi.reportSelectedCastMode(detail.castModeType); |
| 71 } | 77 } |
| 72 | 78 |
| 73 /** | 79 /** |
| 74 * Updates the preference that the user has seen the first run flow. | 80 * Updates the preference that the user has seen the first run flow. |
| 75 * Called when the user clicks on the acknowledgement button on the first run | 81 * Called when the user clicks on the acknowledgement button on the first run |
| 76 * flow. | 82 * flow. |
| 77 */ | 83 */ |
| 78 function onAcknowledgeFirstRunFlow() { | 84 function onAcknowledgeFirstRunFlow() { |
| 79 media_router.browserApi.acknowledgeFirstRunFlow(); | 85 media_router.browserApi.acknowledgeFirstRunFlow(); |
| 80 } | 86 } |
| 81 | 87 |
| 82 /** | 88 /** |
| 83 * Closes the dialog. | 89 * Closes the dialog. |
| 84 * Called when the user clicks the close button on the dialog. | 90 * Called when the user clicks the close button on the dialog. |
| 85 */ | 91 */ |
| 86 function onCloseDialogEvent() { | 92 function onCloseDialogEvent() { |
| 87 container.maybeReportUserFirstAction( | 93 container.maybeReportUserFirstAction( |
| 88 media_router.MediaRouterUserAction.CLOSE); | 94 media_router.MediaRouterUserAction.CLOSE); |
| 89 media_router.browserApi.closeDialog(); | 95 media_router.browserApi.closeDialog(); |
| 90 } | 96 } |
| 91 | 97 |
| 92 /** | 98 /** |
| 93 * Reports the first action the user takes after opening the dialog. | 99 * Reports the first action the user takes after opening the dialog. |
| 94 * Called when the user explicitly interacts with the dialog to perform an | 100 * Called when the user explicitly interacts with the dialog to perform an |
| 95 * action. | 101 * action. |
| 96 * | 102 * |
| 97 * @param {{detail: {action: number}}} data | 103 * @param {!Event} event |
| 98 * Parameters in |data|.detail: | 104 * Parameters in |event|.detail: |
| 99 * action - the first action taken by the user. | 105 * action - the first action taken by the user. |
| 100 */ | 106 */ |
| 101 function onInitialAction(data) { | 107 function onInitialAction(event) { |
| 102 media_router.browserApi.reportInitialAction(data.detail.action); | 108 /** @type {{action: number}} */ |
| 109 var detail = event.detail; |
| 110 media_router.browserApi.reportInitialAction(detail.action); |
| 103 } | 111 } |
| 104 | 112 |
| 105 /** | 113 /** |
| 106 * Reports the time it took for the user to close the dialog if that was the | 114 * Reports the time it took for the user to close the dialog if that was the |
| 107 * first action the user took after opening the dialog. | 115 * first action the user took after opening the dialog. |
| 108 * Called when the user closes the dialog without taking any other action. | 116 * Called when the user closes the dialog without taking any other action. |
| 109 * | 117 * |
| 110 * @param {{detail: {timeMs: number}}} data | 118 * @param {!Event} event |
| 111 * Parameters in |data|.detail: | 119 * Parameters in |event|.detail: |
| 112 * timeMs - time in ms for the user to close the dialog. | 120 * timeMs - time in ms for the user to close the dialog. |
| 113 */ | 121 */ |
| 114 function onInitialActionClose(data) { | 122 function onInitialActionClose(event) { |
| 115 media_router.browserApi.reportTimeToInitialActionClose(data.detail.timeMs); | 123 /** @type {{timeMs: number}} */ |
| 124 var detail = event.detail; |
| 125 media_router.browserApi.reportTimeToInitialActionClose(detail.timeMs); |
| 116 } | 126 } |
| 117 | 127 |
| 118 /** | 128 /** |
| 119 * Acts on an issue and dismisses it from the UI. | 129 * Acts on an issue and dismisses it from the UI. |
| 120 * Called when the user performs an action on an issue. | 130 * Called when the user performs an action on an issue. |
| 121 * | 131 * |
| 122 * @param {{detail: {id: string, actionType: number, helpPageId: number}}} | 132 * @param {!Event} event |
| 123 * data | 133 * Parameters in |event|.detail: |
| 124 * Parameters in |data|.detail: | |
| 125 * id - issue ID. | 134 * id - issue ID. |
| 126 * actionType - type of action performed by the user. | 135 * actionType - type of action performed by the user. |
| 127 * helpPageId - the numeric help center ID. | 136 * helpPageId - the numeric help center ID. |
| 128 */ | 137 */ |
| 129 function onIssueActionClick(data) { | 138 function onIssueActionClick(event) { |
| 130 media_router.browserApi.actOnIssue(data.detail.id, | 139 /** @type {{id: string, actionType: number, helpPageId: number}} */ |
| 131 data.detail.actionType, | 140 var detail = event.detail; |
| 132 data.detail.helpPageId); | 141 media_router.browserApi.actOnIssue(detail.id, |
| 142 detail.actionType, |
| 143 detail.helpPageId); |
| 133 container.issue = null; | 144 container.issue = null; |
| 134 } | 145 } |
| 135 | 146 |
| 136 /** | 147 /** |
| 137 * Creates a media route. | 148 * Creates a media route. |
| 138 * Called when the user requests to create a media route. | 149 * Called when the user requests to create a media route. |
| 139 * | 150 * |
| 140 * @param {{detail: {sinkId: string, selectedCastModeValue: number}}} data | 151 * @param {!Event} event |
| 141 * Parameters in |data|.detail: | 152 * Parameters in |event|.detail: |
| 142 * sinkId - sink ID selected by the user. | 153 * sinkId - sink ID selected by the user. |
| 143 * selectedCastModeValue - cast mode selected by the user. | 154 * selectedCastModeValue - cast mode selected by the user. |
| 144 */ | 155 */ |
| 145 function onCreateRoute(data) { | 156 function onCreateRoute(event) { |
| 146 media_router.browserApi.requestRoute(data.detail.sinkId, | 157 /** @type {{sinkId: string, selectedCastModeValue, number}} */ |
| 147 data.detail.selectedCastModeValue); | 158 var detail = event.detail; |
| 159 media_router.browserApi.requestRoute(detail.sinkId, |
| 160 detail.selectedCastModeValue); |
| 148 } | 161 } |
| 149 | 162 |
| 150 /** | 163 /** |
| 151 * Stops a route. | 164 * Stops a route. |
| 152 * Called when the user requests to stop a media route. | 165 * Called when the user requests to stop a media route. |
| 153 * | 166 * |
| 154 * @param {{detail: {route: media_router.Route}}} data | 167 * @param {!Event} event |
| 155 * Parameters in |data|.detail: | 168 * Parameters in |event|.detail: |
| 156 * route - route to close. | 169 * route - The route to close. |
| 157 */ | 170 */ |
| 158 function onCloseRouteClick(data) { | 171 function onCloseRouteClick(event) { |
| 159 media_router.browserApi.closeRoute(data.detail.route); | 172 /** @type {{route: !media_router.Route}} */ |
| 173 var detail = event.detail; |
| 174 media_router.browserApi.closeRoute(detail.route); |
| 160 } | 175 } |
| 161 | 176 |
| 162 /** | 177 /** |
| 163 * Joins a route. | 178 * Joins a route. |
| 164 * Called when the user requests to join a media route. | 179 * Called when the user requests to join a media route. |
| 165 * | 180 * |
| 166 * @param {{detail: {route: media_router.Route}}} data | 181 * @param {!Event} event |
| 167 * Parameters in |data|.detail: | 182 * Parameters in |event|.detail: |
| 168 * route - route to join. | 183 * route - route to join. |
| 169 */ | 184 */ |
| 170 function onJoinRouteClick(data) { | 185 function onJoinRouteClick(event) { |
| 171 media_router.browserApi.joinRoute(data.detail.route); | 186 /** @type {{route: !media_router.Route}} */ |
| 187 var detail = event.detail; |
| 188 media_router.browserApi.joinRoute(detail.route); |
| 172 } | 189 } |
| 173 | 190 |
| 174 /** | 191 /** |
| 175 * Reports the index of the sink that was clicked. | |
| 176 * Called when the user selects a sink on the sink list. | |
| 177 * | |
| 178 * @param {{detail: {index: number}}} data | |
| 179 * Paramters in |data|.detail: | |
| 180 * index - the index of the clicked sink. | |
| 181 */ | |
| 182 function onSinkClick(data) { | |
| 183 media_router.browserApi.reportClickedSinkIndex(data.detail.index); | |
| 184 } | |
| 185 | |
| 186 /** | |
| 187 * Reports the user navigation to the cast mode view. | 192 * Reports the user navigation to the cast mode view. |
| 188 * Called when the user clicks the drop arrow to navigate to the cast mode | 193 * Called when the user clicks the drop arrow to navigate to the cast mode |
| 189 * view on the dialog. | 194 * view on the dialog. |
| 190 */ | 195 */ |
| 191 function onNavigateToCastMode() { | 196 function onNavigateToCastMode() { |
| 192 media_router.browserApi.reportNavigateToView( | 197 media_router.browserApi.reportNavigateToView( |
| 193 media_router.MediaRouterView.CAST_MODE_LIST); | 198 media_router.MediaRouterView.CAST_MODE_LIST); |
| 194 } | 199 } |
| 195 | 200 |
| 196 /** | 201 /** |
| 197 * Reports the user navigation the route details view. | 202 * Reports the user navigation the route details view. |
| 198 * Called when the user clicks on a sink to navigate to the route details | 203 * Called when the user clicks on a sink to navigate to the route details |
| 199 * view. | 204 * view. |
| 200 */ | 205 */ |
| 201 function onNavigateToDetails() { | 206 function onNavigateToDetails() { |
| 202 media_router.browserApi.reportNavigateToView( | 207 media_router.browserApi.reportNavigateToView( |
| 203 media_router.MediaRouterView.ROUTE_DETAILS); | 208 media_router.MediaRouterView.ROUTE_DETAILS); |
| 204 } | 209 } |
| 205 | 210 |
| 206 /** | 211 /** |
| 207 * Reports the user navigation the sink list view. | 212 * Reports the user navigation the sink list view. |
| 208 * Called when the user clicks on the back button from the route details view | 213 * Called when the user clicks on the back button from the route details view |
| 209 * to the sink list view. | 214 * to the sink list view. |
| 210 */ | 215 */ |
| 211 function onNavigateToSinkList() { | 216 function onNavigateToSinkList() { |
| 212 media_router.browserApi.reportNavigateToView( | 217 media_router.browserApi.reportNavigateToView( |
| 213 media_router.MediaRouterView.SINK_LIST); | 218 media_router.MediaRouterView.SINK_LIST); |
| 214 } | 219 } |
| 215 | 220 |
| 216 /* | 221 /** |
| 217 * Reports the initial state of the dialog after it is opened. | 222 * Reports the initial state of the dialog after it is opened. |
| 218 * Called after initial data is populated. | 223 * Called after initial data is populated. |
| 219 * | 224 * |
| 220 * @param {{detail: {currentView: string}}} data | 225 * @param {!Event} event |
| 221 * Parameters in |data|.detail: | 226 * Parameters in |event|.detail: |
| 222 * currentView - the current dialog's current view. | 227 * currentView - the current dialog's current view. |
| 223 */ | 228 */ |
| 224 function onShowInitialState(data) { | 229 function onShowInitialState(event) { |
| 225 media_router.browserApi.reportInitialState(data.detail.currentView); | 230 /** @type {{currentView: string}} */ |
| 231 var detail = event.detail; |
| 232 media_router.browserApi.reportInitialState(detail.currentView); |
| 226 } | 233 } |
| 227 | 234 |
| 228 /** | 235 /** |
| 229 * Reports the index of the sink that was clicked. | 236 * Reports the index of the sink that was clicked. |
| 230 * Called when the user selects a sink on the sink list. | 237 * Called when the user selects a sink on the sink list. |
| 231 * | 238 * |
| 232 * @param {{detail: {index: number}}} data | 239 * @param {!Event} event |
| 233 * Paramters in |data|.detail: | 240 * Paramters in |event|.detail: |
| 234 * index - the index of the clicked sink. | 241 * index - the index of the clicked sink. |
| 235 */ | 242 */ |
| 236 function onSinkClick(data) { | 243 function onSinkClick(event) { |
| 237 media_router.browserApi.reportClickedSinkIndex(data.detail.index); | 244 /** @type {{index: number}} */ |
| 245 var detail = event.detail; |
| 246 media_router.browserApi.reportClickedSinkIndex(detail.index); |
| 238 } | 247 } |
| 239 | 248 |
| 240 /** | 249 /** |
| 241 * Reports the time it took for the user to select a sink to create a route | 250 * Reports the time it took for the user to select a sink to create a route |
| 242 * after the list was popuated and shown. | 251 * after the list was popuated and shown. |
| 243 * | 252 * |
| 244 * @param {{detail: {timeMs: number}}} data | 253 * @param {!Event} event |
| 245 * Paramters in |data|.detail: | 254 * Paramters in |event|.detail: |
| 246 * timeMs - the time it took for the user to select a sink. | 255 * timeMs - the time it took for the user to select a sink. |
| 247 */ | 256 */ |
| 248 function onSinkClickTimeReported(data) { | 257 function onSinkClickTimeReported(event) { |
| 249 media_router.browserApi.reportTimeToClickSink(data.detail.timeMs); | 258 /** @type {{timeMs: number}} */ |
| 259 var detail = event.detail; |
| 260 media_router.browserApi.reportTimeToClickSink(detail.timeMs); |
| 250 } | 261 } |
| 251 | 262 |
| 252 /** | 263 /** |
| 253 * Reports the current sink count. | 264 * Reports the current sink count. |
| 254 * Called 3 seconds after the dialog is initially opened. | 265 * Called 3 seconds after the dialog is initially opened. |
| 255 * | 266 * |
| 256 * @param {{detail: {sinkCount: number}}} data | 267 * @param {!Event} event |
| 257 * Parameters in |data|.detail: | 268 * Parameters in |event|.detail: |
| 258 * sinkCount - the number of sinks. | 269 * sinkCount - the number of sinks. |
| 259 */ | 270 */ |
| 260 function onSinkCountReported(data) { | 271 function onSinkCountReported(event) { |
| 261 media_router.browserApi.reportSinkCount(data.detail.sinkCount); | 272 /** @type {{sinkCount: number}} */ |
| 273 var detail = event.detail; |
| 274 media_router.browserApi.reportSinkCount(detail.sinkCount); |
| 262 } | 275 } |
| 263 | 276 |
| 264 return { | 277 return { |
| 265 initialize: initialize, | 278 initialize: initialize, |
| 266 }; | 279 }; |
| 267 }); | 280 }); |
| 268 | 281 |
| 269 window.addEventListener('load', media_router.initialize); | 282 window.addEventListener('load', media_router.initialize); |
| OLD | NEW |