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() { | |
|
scherkus (not reviewing)
2013/07/29 23:09:23
remove this -- not used
Ty Overby
2013/07/29 23:26:56
Done.
| |
| 12 }; | |
| 13 | |
| 14 // Use must call media.initialize(); | |
|
scherkus (not reviewing)
2013/07/29 23:09:23
this comment would be better served as jsdoc on in
Ty Overby
2013/07/29 23:26:56
Done.
| |
| 15 var manager = null; | |
| 16 | |
| 17 function initialize(man) { | |
| 18 manager = man; | |
| 19 } | |
| 20 | |
|
scherkus (not reviewing)
2013/07/29 23:09:23
remove extra blank line (1 blank line is always en
Ty Overby
2013/07/29 23:26:56
Done.
| |
| 21 | |
| 22 /** | |
| 23 * Call to modify or add a system property. | |
| 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 | |
| 61 initialize: initialize, | |
| 62 | |
| 63 getManager: function() { | |
|
scherkus (not reviewing)
2013/07/29 23:09:23
this doesn't appear to be used anymore -- remove
Ty Overby
2013/07/29 23:26:56
Done.
| |
| 64 return manager; | |
| 65 } | |
| 66 }; | |
| 67 | |
| 68 // Everything beyond this point is for backwards compatibility reasons. | |
| 69 // It will go away when the backend is updated. | |
| 70 | |
| 71 media.onNetUpdate = function(update) { | |
| 72 // TODO(tyoverby): Implement | |
| 73 }; | |
| 74 | |
| 75 media.onRendererTerminated = function(renderId) { | |
| 76 util.object.forEach(manager.players_, function(playerInfo, id) { | |
| 77 if (playerInfo.properties['render_id'] == renderId) { | |
| 78 media.onPlayerClose(id); | |
| 79 } | |
| 80 }); | |
| 81 }; | |
| 82 | |
| 83 // For whatever reason, addAudioStream is also called on | |
| 84 // the removal of audio streams. | |
| 85 media.addAudioStream = function(event) { | |
| 86 switch (event.status) { | |
| 87 case 'created': | |
| 88 media.onPlayerOpen(event.id); | |
| 89 // We have to simulate the timestamp since it isn't provided to us. | |
| 90 media.onPlayerProperty( | |
| 91 event.id, (new Date()).getTime(), 'playing', event.playing); | |
| 92 break; | |
| 93 case 'closed': | |
| 94 media.onPlayerClose(event.id); | |
| 95 break; | |
| 96 } | |
| 97 }; | |
| 98 media.onItemDeleted = function() { | |
| 99 // This only gets called when an audio stream is removed, which | |
| 100 // for whatever reason is also handled by addAudioStream... | |
| 101 // Because it is already handled, we can safely ignore it. | |
| 102 }; | |
| 103 | |
| 104 media.onMediaEvent = function(event) { | |
| 105 var source = event.renderer + ':' + event.player; | |
| 106 | |
| 107 // Although this gets called on every event, there is nothing we can do | |
| 108 // about this because there is no onOpen event. | |
| 109 media.onPlayerOpen(source); | |
| 110 media.onPlayerPropertyNoRecord( | |
| 111 source, event.ticksMillis, 'render_id', event.renderer); | |
| 112 media.onPlayerPropertyNoRecord( | |
| 113 source, event.ticksMillis, 'player_id', event.player); | |
| 114 | |
| 115 var propertyCount = 0; | |
| 116 util.object.forEach(event.params, function(value, key) { | |
| 117 key = key.trim(); | |
| 118 | |
| 119 // These keys get spammed *a lot*, so put them on the display | |
| 120 // but don't log list. | |
| 121 if (key === 'buffer_start' || | |
| 122 key === 'buffer_end' || | |
| 123 key === 'buffer_current' || | |
| 124 key === 'is_downloading_data') { | |
| 125 media.onPlayerPropertyNoRecord( | |
| 126 source, event.ticksMillis, key, value); | |
| 127 } else { | |
| 128 media.onPlayerProperty(source, event.ticksMillis, key, value); | |
| 129 } | |
| 130 propertyCount += 1; | |
| 131 }); | |
| 132 | |
| 133 if (propertyCount === 0) { | |
| 134 media.onPlayerProperty( | |
| 135 source, event.ticksMillis, 'EVENT', event.type); | |
| 136 } | |
| 137 }; | |
| 138 | |
| 139 return media; | |
| 140 }()); | |
| OLD | NEW |