-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
45 changed files
with
1,699 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
import { tap, throttleTime } from 'rxjs/operators'; | ||
import { AudioFile } from './audio'; | ||
|
||
interface AudioPlayEvent { | ||
file: AudioFile; | ||
volume: number; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AudioService { | ||
private readonly audio: HTMLAudioElement; | ||
private readonly queue$ = new Subject<AudioPlayEvent>(); | ||
|
||
constructor() { | ||
this.audio = document.createElement('audio'); | ||
this.init(); | ||
} | ||
|
||
public play(file: AudioFile, volume: number = 1): void { | ||
this.queue$.next({ file, volume }); | ||
} | ||
|
||
private init(): void { | ||
this.queue$.pipe( | ||
throttleTime(500), | ||
tap(event => { | ||
this.audio.pause(); | ||
this.audio.src = event.file; | ||
this.audio.currentTime = 0; | ||
this.audio.volume = event.volume; | ||
this.audio.play(); | ||
}) | ||
).subscribe(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum AudioFile { | ||
Notification = '/dist/poe-overlay-overwolf/assets/audio/notification.wav' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './audio'; | ||
export * from './audio.service'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Observable } from 'rxjs'; | ||
import { flatMap, shareReplay, delay } from 'rxjs/operators'; | ||
import { OWAudio } from './ow-audio'; | ||
|
||
export class OWAudioFile { | ||
private id$: Observable<string>; | ||
|
||
constructor(private readonly url: string) { } | ||
|
||
public play(): Observable<void> { | ||
return this.ensure().pipe( | ||
flatMap(id => OWAudio.play(id)) | ||
); | ||
} | ||
|
||
public resume(): Observable<void> { | ||
return this.ensure().pipe( | ||
flatMap(id => OWAudio.resume(id)) | ||
); | ||
} | ||
|
||
public stop(): Observable<void> { | ||
return this.ensure().pipe( | ||
flatMap(id => OWAudio.stop(id)) | ||
); | ||
} | ||
|
||
public setVolume(volume: number): Observable<void> { | ||
return this.ensure().pipe( | ||
flatMap(() => OWAudio.setVolume(volume)) | ||
); | ||
} | ||
|
||
private ensure(): Observable<string> { | ||
if (!this.id$) { | ||
this.id$ = OWAudio.create(this.url).pipe( | ||
shareReplay(1) | ||
); | ||
} | ||
return this.id$; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { from, Observable } from 'rxjs'; | ||
|
||
export class OWAudio { | ||
|
||
public static create(url: string): Observable<string> { | ||
const promise = new Promise<string>((resolve, reject) => { | ||
overwolf.media.audio.create(url, result => { | ||
console.log(result); | ||
if (result.success) { | ||
resolve(result.id); | ||
} else { | ||
reject(result.error); | ||
} | ||
}); | ||
}); | ||
return from(promise); | ||
} | ||
|
||
public static play(id: string): Observable<void> { | ||
const promise = new Promise<void>((resolve, reject) => { | ||
overwolf.media.audio.play(id, result => { | ||
console.log(result); | ||
if (result.success) { | ||
resolve(); | ||
} else { | ||
reject(result.error); | ||
} | ||
}); | ||
}); | ||
return from(promise); | ||
} | ||
|
||
public static stop(id: string): Observable<void> { | ||
const promise = new Promise<void>((resolve, reject) => { | ||
overwolf.media.audio.stopById(id, result => { | ||
console.log(result); | ||
if (result.success) { | ||
resolve(); | ||
} else { | ||
reject(result.error); | ||
} | ||
}); | ||
}); | ||
return from(promise); | ||
} | ||
|
||
public static resume(id: string): Observable<void> { | ||
const promise = new Promise<void>((resolve, reject) => { | ||
overwolf.media.audio.resumeById(id, result => { | ||
console.log(result); | ||
if (result.success) { | ||
resolve(); | ||
} else { | ||
reject(result.error); | ||
} | ||
}); | ||
}); | ||
return from(promise); | ||
} | ||
|
||
public static setVolume(volume: number): Observable<void> { | ||
const promise = new Promise<void>((resolve, reject) => { | ||
overwolf.media.audio.setVolume(volume, result => { | ||
console.log(result); | ||
if (result.success) { | ||
resolve(); | ||
} else { | ||
reject(result.error); | ||
} | ||
}); | ||
}); | ||
return from(promise); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.