Move sound into browser

This commit is contained in:
Daniel Imms
2019-07-04 12:31:21 -07:00
parent f235d70f30
commit 47164d2f68
4 changed files with 18 additions and 17 deletions
+5 -5
View File
@@ -34,7 +34,7 @@ import { SelectionService } from './browser/services/SelectionService';
import * as Browser from 'common/Platform';
import { addDisposableDomListener } from 'browser/Lifecycle';
import * as Strings from './browser/LocalizableStrings';
import { SoundManager } from './SoundManager';
import { SoundService } from 'browser/services/SoundService';
import { MouseZoneManager } from './MouseZoneManager';
import { AccessibilityManager } from './AccessibilityManager';
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
@@ -49,7 +49,7 @@ import { ColorManager } from 'browser/ColorManager';
import { RenderService } from 'browser/services/RenderService';
import { IOptionsService, IBufferService, ICoreService } from 'common/services/Services';
import { OptionsService } from 'common/services/OptionsService';
import { ICharSizeService, IRenderService, IMouseService, ISelectionService } from 'browser/services/Services';
import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService } from 'browser/services/Services';
import { CharSizeService } from 'browser/services/CharSizeService';
import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService';
import { Disposable } from 'common/Lifecycle';
@@ -116,6 +116,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _mouseService: IMouseService;
private _renderService: IRenderService;
private _selectionService: ISelectionService;
private _soundService: ISoundService;
// modes
public applicationKeypad: boolean;
@@ -174,7 +175,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _userScrolling: boolean;
private _inputHandler: InputHandler;
public soundManager: SoundManager;
public linkifier: ILinkifier;
public viewport: IViewport;
private _compositionHelper: ICompositionHelper;
@@ -304,7 +304,6 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._selectionService = this._selectionService || null;
this.linkifier = this.linkifier || new Linkifier(this);
this._mouseZoneManager = this._mouseZoneManager || null;
this.soundManager = this.soundManager || new SoundManager(this);
if (this.options.windowsMode) {
this._windowsMode = applyWindowsMode(this);
@@ -619,6 +618,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._renderService.onRender(e => this._onRender.fire(e));
this.onResize(e => this._renderService.resize(e.cols, e.rows));
this._soundService = new SoundService(this.optionsService);
this._mouseService = new MouseService(this._renderService, this._charSizeService);
this._mouseZoneManager = new MouseZoneManager(this, this._mouseService);
@@ -1676,7 +1676,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
*/
public bell(): void {
if (this._soundBell()) {
this.soundManager.playBellSound();
this._soundService.playBellSound();
}
if (this._visualBell()) {
-4
View File
@@ -346,10 +346,6 @@ export interface IBrowser {
isWindows: boolean;
}
export interface ISoundManager {
playBellSound(): void;
}
export interface IMouseZoneManager extends IDisposable {
add(zone: IMouseZone): void;
clearAll(start?: number, end?: number): void;
+4
View File
@@ -72,3 +72,7 @@ export interface ISelectionService {
refresh(isLinuxMouseSelection?: boolean): void;
onMouseDown(event: MouseEvent): void;
}
export interface ISoundService {
playBellSound(): void;
}
@@ -3,35 +3,36 @@
* @license MIT
*/
import { ITerminal, ISoundManager } from './Types';
import { IOptionsService } from 'common/services/Services';
import { ISoundService } from 'browser/services/Services';
export class SoundManager implements ISoundManager {
export class SoundService implements ISoundService {
private static _audioContext: AudioContext;
static get audioContext(): AudioContext | null {
if (!SoundManager._audioContext) {
if (!SoundService._audioContext) {
const audioContextCtor: typeof AudioContext = (<any>window).AudioContext || (<any>window).webkitAudioContext;
if (!audioContextCtor) {
console.warn('Web Audio API is not supported by this browser. Consider upgrading to the latest version');
return null;
}
SoundManager._audioContext = new audioContextCtor();
SoundService._audioContext = new audioContextCtor();
}
return SoundManager._audioContext;
return SoundService._audioContext;
}
constructor(
private _terminal: ITerminal
private _optionsService: IOptionsService
) {
}
public playBellSound(): void {
const ctx = SoundManager.audioContext;
const ctx = SoundService.audioContext;
if (!ctx) {
return;
}
const bellAudioSource = ctx.createBufferSource();
ctx.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._terminal.options.bellSound)), (buffer) => {
ctx.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._optionsService.options.bellSound)), (buffer) => {
bellAudioSource.buffer = buffer;
bellAudioSource.connect(ctx.destination);
bellAudioSource.start(0);