Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 /** | |
| 6 * A global object that gets used by the C++ interface. | |
| 7 */ | |
| 8 var media = (function() { | |
| 9 'use strict'; | |
| 10 | |
| 11 var doNothing = function() { | |
| 12 }; | |
| 13 var mockRenderManager = { | |
| 14 redrawList: doNothing, | |
| 15 update: doNothing, | |
| 16 select: doNothing | |
| 17 }; | |
| 18 | |
| 19 var manager = new PlayerManager((typeof RenderManager !== 'undefined') ? | |
| 20 new RenderManager : mockRenderManager); | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
this is a very subtle way of injecting a mock that
Ty Overby
2013/07/29 21:53:31
Because RenderManager depends on every "yet to be
| |
| 21 | |
| 22 /** | |
| 23 * Call to modify or add a system property | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
periods on comments here + below
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 24 */ | |
| 25 function onSystemProperty(timestamp, key, value) { | |
| 26 console.log('System properties not yet implemented'); | |
| 27 } | |
| 28 | |
| 29 /** | |
| 30 * Call to modify or add a property on a player | |
| 31 */ | |
| 32 function onPlayerProperty(id, timestamp, key, value) { | |
| 33 manager.updatePlayerInfo(id, timestamp, key, value); | |
| 34 } | |
| 35 | |
| 36 function onPlayerPropertyNoRecord(id, timestamp, key, value) { | |
| 37 manager.updatePlayerInfoNoRecord(id, timestamp, key, value); | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * Call to add a player. | |
| 42 */ | |
| 43 function onPlayerOpen(id, timestamp) { | |
| 44 manager.addPlayer(id, timestamp); | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * Call to remove a player. | |
| 49 */ | |
| 50 function onPlayerClose(id) { | |
| 51 manager.removePlayer(id); | |
| 52 } | |
| 53 | |
| 54 var media = { | |
| 55 onSystemProperty: onSystemProperty, | |
| 56 onPlayerProperty: onPlayerProperty, | |
| 57 onPlayerPropertyNoRecord: onPlayerPropertyNoRecord, | |
| 58 onPlayerOpen: onPlayerOpen, | |
| 59 onPlayerClose: onPlayerClose, | |
| 60 manager: manager | |
| 61 }; | |
| 62 | |
| 63 // Everything beyond this point is for backwards | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
try to use more chars per-line (up to 80) if you c
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 64 // compatibility reasons. It will go away when | |
| 65 // the backend is updated. | |
| 66 | |
| 67 media.onNetUpdate = function(update) { | |
| 68 // TODO(tyoverby): Implement | |
| 69 }; | |
| 70 | |
| 71 media.onRendererTerminated = function(renderId) { | |
| 72 goog.object.forEach(manager.players_, function(playerInfo, id) { | |
| 73 if (playerInfo.properties['render_id'] == renderId) { | |
| 74 media.onPlayerClose(id); | |
| 75 } | |
| 76 }); | |
| 77 }; | |
| 78 | |
| 79 // For whatever reason, addAudioStream is also called on | |
| 80 // the removal of audio streams. | |
| 81 media.addAudioStream = function(event) { | |
| 82 switch (event.status) { | |
| 83 case 'created': | |
| 84 media.onPlayerOpen(event.id); | |
| 85 // We have to simulate the timestamp since | |
| 86 // it isn't provided to us. | |
| 87 media.onPlayerProperty(event.id, (new Date()).getTime(), | |
| 88 'playing', event.playing); | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
indentation for any continued line gets either:
| |
| 89 break; | |
| 90 case 'closed': | |
| 91 media.onPlayerClose(event.id); | |
| 92 break; | |
| 93 } | |
| 94 }; | |
| 95 media.onItemDeleted = function() { | |
| 96 // This only gets called when an audio stream is removed, which | |
| 97 // for whatever reason is also handled by addAudioStream... | |
| 98 // Because it is already handled, we can safely ignore it. | |
| 99 }; | |
| 100 | |
| 101 media.onMediaEvent = function(event) { | |
| 102 var source = event.renderer + ':' + event.player; | |
| 103 | |
| 104 // Although this gets called on every event, there | |
| 105 // is nothing we can do about this because there is no onOpen event. | |
| 106 media.onPlayerOpen(source); | |
| 107 media.onPlayerPropertyNoRecord(source, event.ticksMillis, 'render_id', | |
| 108 event.renderer); | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
ditto
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 109 media.onPlayerPropertyNoRecord(source, event.ticksMillis, 'player_id', | |
| 110 event.player); | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
ditto
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 111 | |
| 112 var propertyCount = 0; | |
| 113 goog.object.forEach(event.params, function(value, key) { | |
| 114 key = key.trim(); | |
| 115 if (key === 'buffer_start' || key === 'buffer_end' || | |
| 116 key === 'buffer_current' || key === 'is_downloading_data') { | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
same style rules apply here - this should be align
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 117 media.onPlayerPropertyNoRecord(source, event.ticksMillis, key, | |
| 118 value); | |
| 119 } else { | |
| 120 media.onPlayerProperty(source, event.ticksMillis, key, value); | |
| 121 } | |
| 122 propertyCount += 1; | |
| 123 }); | |
| 124 | |
| 125 if (propertyCount === 0) { | |
| 126 media.onPlayerProperty(source, event.ticksMillis, 'EVENT', | |
| 127 event.type); | |
|
scherkus (not reviewing)
2013/07/29 20:35:54
ditto
Ty Overby
2013/07/29 21:53:31
Done.
| |
| 128 } | |
| 129 }; | |
| 130 | |
| 131 return media; | |
| 132 }()); | |
| OLD | NEW |