1 // Copyright 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.
6 * @fileoverview A class for keeping track of the details of a player.
9 var PlayerInfo
= (function() {
13 * A class that keeps track of properties on a media player.
14 * @param id A unique id that can be used to identify this player.
16 function PlayerInfo(id
) {
18 // The current value of the properties for this player.
20 // All of the past (and present) values of the properties.
23 // Every single event in the order in which they were received.
25 this.lastRendered
= 0;
27 this.firstTimestamp_
= -1;
30 PlayerInfo
.prototype = {
32 * Adds or set a property on this player.
33 * This is the default logging method as it keeps track of old values.
34 * @param timestamp The time in milliseconds since the Epoch.
35 * @param key A String key that describes the property.
36 * @param value The value of the property.
38 addProperty: function(timestamp
, key
, value
) {
39 // The first timestamp that we get will be recorded.
40 // Then, all future timestamps are deltas of that.
41 if (this.firstTimestamp_
=== -1) {
42 this.firstTimestamp_
= timestamp
;
45 if (typeof key
!== 'string') {
46 throw new Error(typeof key
+ ' is not a valid key type');
49 this.properties
[key
] = value
;
51 if (!this.pastValues
[key
]) {
52 this.pastValues
[key
] = [];
56 time
: timestamp
- this.firstTimestamp_
,
61 this.pastValues
[key
].push(recordValue
);
62 this.allEvents
.push(recordValue
);
66 * Adds or set a property on this player.
67 * Does not keep track of old values. This is better for
68 * values that get spammed repeatedly.
69 * @param timestamp The time in milliseconds since the Epoch.
70 * @param key A String key that describes the property.
71 * @param value The value of the property.
73 addPropertyNoRecord: function(timestamp
, key
, value
) {
74 this.addProperty(timestamp
, key
, value
);