forked from romgere/romgerebox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route to restore audioContext (if suspended on safari or other?)
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 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
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 Route from '@ember/routing/route'; | ||
import { inject as service } from '@ember/service'; | ||
/** | ||
* https://www.mattmontag.com/web/unlock-web-audio-in-safari-for-ios-and-macos | ||
*/ | ||
export default Route.extend({ | ||
|
||
audioService: service('audio'), | ||
events : ['touchstart','touchend', 'mousedown','keydown'], | ||
|
||
handleEvent: function(){ | ||
this.unlock(); | ||
}, | ||
|
||
afterModel(model, transition) { | ||
this._super(model, transition); | ||
|
||
const b = document.body; | ||
this.get('events').forEach((e) => { | ||
b.addEventListener(e, this, false); | ||
}); | ||
}, | ||
|
||
unlock: function(){ | ||
|
||
this.get('audioService.audioContext').resume().then(() => { | ||
|
||
//Remove touch/click event | ||
this.clean(); | ||
|
||
//Replay previous transition | ||
this.send('replayInitialeTransition'); | ||
}); | ||
}, | ||
|
||
clean: function(){ | ||
const b = document.body; | ||
this.get('events').forEach((e) => { | ||
b.removeEventListener(e, this, false); | ||
}); | ||
}, | ||
}); |
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 @@ | ||
Votre navigateur a suspendu l'accès audio, veuillez cliquez/toucher l'écran pour débloquer l'audio et utiliser l'application. |
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,11 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
|
||
moduleFor('route:unlock-audio', 'Unit | Route | unlock audio', { | ||
// Specify the other units that are required for this test. | ||
// needs: ['controller:foo'] | ||
}); | ||
|
||
test('it exists', function(assert) { | ||
let route = this.subject(); | ||
assert.ok(route); | ||
}); |