// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import '../../ui/legacy/legacy.js'; import * as Common from '../../core/common/common.js'; import * as i18n from '../../core/i18n/i18n.js'; import type * as Platform from '../../core/platform/platform.js'; import * as SDK from '../../core/sdk/sdk.js'; import type * as Protocol from '../../generated/protocol.js'; import * as UI from '../../ui/legacy/legacy.js'; import {html, render} from '../../ui/lit/lit.js'; import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; import webAudioStyles from './webAudio.css.js'; import {Events as ModelEvents, WebAudioModel} from './WebAudioModel.js'; const {widgetConfig} = UI.Widget; const {bindToAction} = UI.UIUtils; const UIStrings = { /** * @description Text in Web Audio View if there is nothing to show. * Web Audio API is an API for controlling audio on the web. */ noWebAudio: 'No Web Audio API usage detected', /** * @description Text in Web Audio View */ openAPageThatUsesWebAudioApiTo: 'Open a page that uses Web Audio API to start monitoring.', /** * @description Text that shows there is no recording */ noRecordings: '(no recordings)', /** * @description Label prefix for an audio context selection * @example {realtime (1e03ec)} PH1 */ audioContextS: 'Audio context: {PH1}', /** * @description The current state of an item */ state: 'State', /** * @description Text in Web Audio View */ sampleRate: 'Sample Rate', /** * @description Text in Web Audio View */ callbackBufferSize: 'Callback Buffer Size', /** * @description Label in the Web Audio View for the maximum number of output channels * that this Audio Context has. */ maxOutputChannels: 'Max Output Channels', /** * @description Text in Web Audio View */ currentTime: 'Current Time', /** * @description Text in Web Audio View */ callbackInterval: 'Callback Interval', /** * @description Text in Web Audio View */ renderCapacity: 'Render Capacity', } as const; const str_ = i18n.i18n.registerUIStrings('panels/web_audio/WebAudioView.ts', UIStrings); const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); const WEBAUDIO_EXPLANATION_URL = 'https://developer.chrome.com/docs/devtools/webaudio' as Platform.DevToolsPath.UrlString; interface ViewInput { contexts: Protocol.WebAudio.BaseAudioContext[]; selectedContextIndex: number; onContextSelectorSelectionChanged: (contextId: string) => void; contextRealtimeData: Protocol.WebAudio.ContextRealtimeData|null; } type View = (input: ViewInput, output: object, target: HTMLElement) => void; export const DEFAULT_VIEW: View = (input, _output, target) => { const { contexts, selectedContextIndex, onContextSelectorSelectionChanged, contextRealtimeData, } = input; const selectedContext = selectedContextIndex > -1 ? contexts[selectedContextIndex] : null; const titleForContext = (context: Protocol.WebAudio.BaseAudioContext): string => context.contextType + ' (' + context.contextId.substr(-6) + ')'; const selectorTitle = i18nString( UIStrings.audioContextS, {PH1: selectedContext ? titleForContext(selectedContext) : i18nString(UIStrings.noRecordings)}); // clang-format off render(html`