1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96

content / browser / resources / media / main.js [blame]

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {objectForEach} from './util.js';

let manager = null;

window.media = window.media || {};

/**
 * Users of |media| must call initialize prior to calling other methods.
 */
export function initialize(theManager) {
  manager = theManager;

  // |chrome| is not defined during tests.
  if (window.chrome && window.chrome.send) {
    chrome.send('getEverything');
  }
}

// Exporting initialize on |window| for tests.
window.initialize = initialize;

// Adding the functions below on |window| since they are called from C++.
window.media.updateGeneralAudioInformation = function(audioInfo) {
  manager.updateGeneralAudioInformation(audioInfo);
};

window.media.onReceiveAudioStreamData = function(audioStreamData) {
  for (const component in audioStreamData) {
    window.media.updateAudioComponent(audioStreamData[component]);
  }
};

window.media.onReceiveVideoCaptureCapabilities = function(
    videoCaptureCapabilities) {
  manager.updateVideoCaptureCapabilities(videoCaptureCapabilities);
};

window.media.onReceiveAudioFocusState = function(audioFocusState) {
  if (!audioFocusState) {
    return;
  }

  manager.updateAudioFocusSessions(audioFocusState.sessions);
};

window.media.updateRegisteredCdms = function(cdms) {
  if (!cdms) {
    return;
  }

  manager.updateRegisteredCdms(cdms);
};

window.media.updateAudioComponent = function(component) {
  const uniqueComponentId = component.owner_id + ':' + component.component_id;
  switch (component.status) {
    case 'closed':
      manager.removeAudioComponent(component.component_type, uniqueComponentId);
      break;
    default:
      manager.updateAudioComponent(
          component.component_type, uniqueComponentId, component);
      break;
  }
};

window.media.onPlayerOpen = function(id, timestamp) {
  manager.addPlayer(id, timestamp);
};

window.media.onMediaEvent = function(event) {
  const source = event.renderer + ':' + event.player;

  // Although this gets called on every event, there is nothing we can do
  // because there is no onOpen event.
  media.onPlayerOpen(source);
  manager.updatePlayerInfoNoRecord(
      source, event.ticksMillis, 'render_id', event.renderer);
  manager.updatePlayerInfoNoRecord(
      source, event.ticksMillis, 'player_id', event.player);

  let propertyCount = 0;
  objectForEach(event.params, function(value, key) {
    key = key.trim();
    manager.updatePlayerInfo(source, event.ticksMillis, key, value);
    propertyCount += 1;
  });

  if (propertyCount === 0) {
    manager.updatePlayerInfo(source, event.ticksMillis, 'event', event.type);
  }
};