diff --git a/src/Terminal.ts b/src/Terminal.ts index f836011779..902c6d5162 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -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()) { diff --git a/src/Types.d.ts b/src/Types.d.ts index eaf6196b46..a54606a84a 100644 --- a/src/Types.d.ts +++ b/src/Types.d.ts @@ -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; diff --git a/src/browser/services/Services.d.ts b/src/browser/services/Services.d.ts index b22a0b3799..603d4109ff 100644 --- a/src/browser/services/Services.d.ts +++ b/src/browser/services/Services.d.ts @@ -72,3 +72,7 @@ export interface ISelectionService { refresh(isLinuxMouseSelection?: boolean): void; onMouseDown(event: MouseEvent): void; } + +export interface ISoundService { + playBellSound(): void; +} diff --git a/src/SoundManager.ts b/src/browser/services/SoundService.ts similarity index 74% rename from src/SoundManager.ts rename to src/browser/services/SoundService.ts index 6bff444f4d..31380031d7 100644 --- a/src/SoundManager.ts +++ b/src/browser/services/SoundService.ts @@ -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 = (window).AudioContext || (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);