| OLD | NEW |
| (Empty) | |
| 1 /** |
| 2 * @fileoverview A class for keeping track of the details of a player. |
| 3 */ |
| 4 |
| 5 var PlayerInfo = (function () { |
| 6 "use strict"; |
| 7 |
| 8 /** |
| 9 * A class that keeps track of properties on a media player. |
| 10 * @param id A unique id that can be used to identify this player. |
| 11 * @constructor |
| 12 */ |
| 13 function PlayerInfo(id) { |
| 14 this.id = id; |
| 15 // The current value of the properties for this player |
| 16 this.properties = {}; |
| 17 // All of the past (and present) values of the properties |
| 18 this.pastValues = {}; |
| 19 |
| 20 // Every single event in the order in which they were received |
| 21 this.allEvents = []; |
| 22 this.lastRendered = 0; |
| 23 |
| 24 this.firstTimestamp = -1; |
| 25 } |
| 26 |
| 27 |
| 28 /** |
| 29 * Adds or set a property on this player. |
| 30 * This is the default logging method as it keeps track of old values |
| 31 * @param timestamp The time in milliseconds since the Epoch |
| 32 * @param key A String key that describes the property |
| 33 * @param value The value of the property. |
| 34 */ |
| 35 PlayerInfo.prototype.addProperty = function (timestamp, key, value) { |
| 36 // The first timestamp that we get will be recorded. |
| 37 // Then, all future timestamps are deltas of that. |
| 38 if (this.firstTimestamp === -1) { |
| 39 this.firstTimestamp = timestamp; |
| 40 } |
| 41 |
| 42 if (typeof key !== 'string') { |
| 43 throw new Error(typeof key + " is not a valid key type"); |
| 44 } |
| 45 |
| 46 this.properties[key] = value; |
| 47 |
| 48 if (!this.pastValues[key]) { |
| 49 // Preallocate for performance |
| 50 this.pastValues[key] = new Array(512); |
| 51 } |
| 52 |
| 53 var recordValue = { |
| 54 time: timestamp - this.firstTimestamp, |
| 55 key: key, |
| 56 value: value |
| 57 }; |
| 58 |
| 59 this.pastValues[key].push(recordValue); |
| 60 this.allEvents.push(recordValue); |
| 61 }; |
| 62 |
| 63 |
| 64 /** |
| 65 * Adds or set a property on this player. |
| 66 * Does not keep track of old values. This is better for |
| 67 * values that get spammed repeatedly. |
| 68 * @param timestamp The time in milliseconds since the Epoch |
| 69 * @param key A String key that describes the property |
| 70 * @param value The value of the property. |
| 71 */ |
| 72 PlayerInfo.prototype.addPropertyNoRecord = |
| 73 function (timestamp, key, value) { |
| 74 this.addProperty(timestamp, key, value); |
| 75 this.allEvents.pop(); |
| 76 this.pastValues[key] = [this.pastValues[key].pop()]; |
| 77 }; |
| 78 |
| 79 return PlayerInfo; |
| 80 }()); |
| OLD | NEW |