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 Keeps track of all the existing PlayerInfo and
7 * audio stream objects and is the entry-point for messages from the backend.
9 * The events captured by Manager (add, remove, update) are relayed
10 * to the clientRenderer which it can choose to use to modify the UI.
12 var Manager = (function() {
15 function Manager(clientRenderer) {
17 this.audioStreams_ = {};
18 this.clientRenderer_ = clientRenderer;
23 * Adds an audio-stream to the dictionary of audio-streams to manage.
24 * @param id The unique-id of the audio-stream.
26 addAudioStream: function(id) {
27 this.audioStreams_[id] = this.audioStreams_[id] || {};
28 this.clientRenderer_.audioStreamAdded(this.audioStreams_,
29 this.audioStreams_[id]);
33 * Sets properties of an audiostream.
34 * @param id The unique-id of the audio-stream.
35 * @param properties A dictionary of properties to be added to the
38 updateAudioStream: function(id, properties) {
39 for (var key in properties) {
40 this.audioStreams_[id][key] = properties[key];
42 this.clientRenderer_.audioStreamAdded(
43 this.audioStreams_, this.audioStreams_[id]);
47 * Removes an audio-stream from the manager.
48 * @param id The unique-id of the audio-stream.
50 removeAudioStream: function(id) {
51 this.clientRenderer_.audioStreamRemoved(
52 this.audioStreams_, this.audioStreams_[id]);
53 delete this.audioStreams_[id];
58 * Adds a player to the list of players to manage.
60 addPlayer: function(id) {
61 if (this.players_[id]) {
64 // Make the PlayerProperty and add it to the mapping
65 this.players_[id] = new PlayerInfo(id);
66 this.clientRenderer_.playerAdded(this.players_, this.players_[id]);
70 * Attempts to remove a player from the UI.
71 * @param id The ID of the player to remove.
73 removePlayer: function(id) {
74 delete this.players_[id];
75 this.clientRenderer_.playerRemoved(this.players_, this.players_[id]);
78 updatePlayerInfoNoRecord: function(id, timestamp, key, value) {
79 if (!this.players_[id]) {
80 console.error('[updatePlayerInfo] Id ' + id + ' does not exist');
84 this.players_[id].addPropertyNoRecord(timestamp, key, value);
85 this.clientRenderer_.playerUpdated(this.players_,
93 * @param id The unique ID that identifies the player to be updated.
94 * @param timestamp The timestamp of when the change occured. This
95 * timestamp is *not* normalized.
96 * @param key The name of the property to be added/changed.
97 * @param value The value of the property.
99 updatePlayerInfo: function(id, timestamp, key, value) {
100 if (!this.players_[id]) {
101 console.error('[updatePlayerInfo] Id ' + id + ' does not exist');
105 this.players_[id].addProperty(timestamp, key, value);
106 this.clientRenderer_.playerUpdated(this.players_,