koel/resources/assets/js/utils/supports.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

import isMobile from 'ismobilejs';
2016-06-25 05:24:55 +00:00
import Vue from 'vue'
/**
* Check if AudioContext is supported by the current browser.
*
* @return {Boolean}
*/
export function isAudioContextSupported() {
2016-06-25 16:05:24 +00:00
// Apple device just doesn't love AudioContext that much.
if (isMobile.apple.device) {
return false;
}
2016-06-25 16:05:24 +00:00
const AudioContext = (window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext);
2016-06-25 16:05:24 +00:00
if (!AudioContext) {
return false;
}
2016-06-25 16:05:24 +00:00
// Safari (MacOS & iOS alike) has webkitAudioContext, but is buggy.
// @link http://caniuse.com/#search=audiocontext
if (!(new AudioContext()).createMediaElementSource) {
return false;
}
2016-06-25 16:05:24 +00:00
return true;
};
2016-06-25 05:24:55 +00:00
const event = {
2016-06-25 16:05:24 +00:00
bus: null,
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
init() {
if (!this.bus) {
this.bus = new Vue();
}
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
return this;
},
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
emit(name, ...args) {
this.bus.$emit(name, ...args);
return this;
},
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
on() {
if (arguments.length === 2) {
this.bus.$on(arguments[0], arguments[1]);
} else {
Object.keys(arguments[0]).forEach(key => {
this.bus.$on(key, arguments[0][key]);
});
}
2016-06-25 05:24:55 +00:00
2016-06-25 16:05:24 +00:00
return this;
},
2016-06-25 05:24:55 +00:00
}
export { event };