Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use web audio api for bell sound #1200

Merged
merged 7 commits into from
Feb 21, 2018
Merged

Use web audio api for bell sound #1200

merged 7 commits into from
Feb 21, 2018

Conversation

bmf-ribeiro
Copy link
Contributor

Implementation of the feature requested in #1181

Feedback on what to change is welcome! 馃槃

Btw: the typings aren't recognizing AudioContext || webkitAudioContext

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good 馃憤

For the types I'd try updating typescript to 2.6 to see if they've been added to lib.dom.d.ts (I think that's where it will be defined)

@@ -7,4 +7,4 @@
// This sound is released under the Creative Commons Attribution 3.0 Unported
// (CC BY 3.0) license. It was created by 'altemark'. No modifications have been
// made, apart from the conversion to base64.
export const BellSound = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
export const BellSound = 'UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need ti handle the data uri case otherwise this represents an API change and would need to wait for v4

src/Terminal.ts Outdated
@@ -1797,7 +1794,19 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
*/
public bell(): void {
this.emit('bell');
if (this.soundBell()) this.bellAudioElement.play();
if (this.soundBell()) {
if (!this.audioContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need feature detection just in case. Browser support seems pretty good so I'm fine with dropping the DOM-based sound loading https://caniuse.com/#feat=audio-api

@@ -1797,7 +1794,19 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
*/
public bell(): void {
this.emit('bell');
if (this.soundBell()) this.bellAudioElement.play();
if (this.soundBell()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to move all the sound-related code (including base64ToArrayBuffer) into it's own file now that the DOM interactions are gone.

@bmf-ribeiro
Copy link
Contributor Author

I refactored the code a bit.

For the feature detection, it's only printing a message to the console, should i do something else?

As for the typings, even after updating the ts version, they still don't seem to be working.. I'll try a few more things when i have more time 馃槈

@Tyriar
Copy link
Member

Tyriar commented Feb 21, 2018

@dgriffen FYI this PR will drop terminal bell support for IE11, I don't think you're even using it yet 馃槂

@Tyriar
Copy link
Member

Tyriar commented Feb 21, 2018

@nikonso I merged from master resolving the conflicts and then fixed some lint/style problems. Could you give this a once over to make sure everything looks good before I merge this in?

@Tyriar Tyriar added this to the 3.2.0 milestone Feb 21, 2018
@Tyriar Tyriar self-assigned this Feb 21, 2018
@bmf-ribeiro
Copy link
Contributor Author

@Tyriar Everything seems to be Ok 馃憤 Except there are a bunch of changes in the package-lock.json, are they Ok to merge in?

@Tyriar
Copy link
Member

Tyriar commented Feb 21, 2018

Yeah I think I accidentally added that, I think we need to add the file to .gitignore or something. Need to do some reading on best practices.

@Tyriar Tyriar merged commit 94bbc4e into xtermjs:master Feb 21, 2018
@bmf-ribeiro bmf-ribeiro deleted the 1181 branch February 21, 2018 23:36
@Tyriar Tyriar changed the title WIP: Use web audio api Use web audio api for bell sound Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants