@odion-cloud/capacitor-volume-control
Version:
Capacitor plugin for advanced volume control with native Android and iOS implementations
89 lines (81 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var core = require('@capacitor/core');
exports.VolumeType = void 0;
(function (VolumeType) {
VolumeType["VOICE_CALL"] = "voice_call";
VolumeType["SYSTEM"] = "system";
VolumeType["RING"] = "ring";
VolumeType["DEFAULT"] = "default";
VolumeType["MUSIC"] = "music";
VolumeType["ALARM"] = "alarm";
VolumeType["NOTIFICATION"] = "notification";
VolumeType["DTMF"] = "dtmf";
})(exports.VolumeType || (exports.VolumeType = {}));
const VolumeControl = core.registerPlugin('VolumeControl', {
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.VolumeControlWeb()),
});
class VolumeControlWeb extends core.WebPlugin {
constructor() {
super(...arguments);
this.isWatchingVolume = false;
this.mockVolume = 0.5;
}
async getVolumeLevel(options) {
console.log('getVolumeLevel called with options:', options);
// Web implementation - limited to what's available in browsers
// Most browsers don't expose system volume, so we return a mock value
return { value: this.mockVolume };
}
async setVolumeLevel(options) {
console.log('setVolumeLevel called with options:', options);
// Validate input
if (options.value < 0 || options.value > 1) {
throw new Error('Volume value must be between 0.0 and 1.0');
}
// Update mock volume
this.mockVolume = options.value;
// Web implementation - browsers don't allow setting system volume
// This would typically show a warning or throw an error
console.warn('Setting system volume is not supported in web browsers');
return { value: options.value };
}
async watchVolume(options, callback) {
console.log('watchVolume called with options:', options);
if (this.isWatchingVolume) {
throw new Error('Volume buttons has already been watched');
}
this.watchCallback = callback;
this.isWatchingVolume = true;
// Web implementation - limited volume change detection
// We can't reliably detect hardware volume button presses in browsers
console.warn('Volume watching has limited functionality in web browsers');
// Simulate volume changes for testing (remove in production)
if (process.env.NODE_ENV === 'development') {
setTimeout(() => {
if (this.isWatchingVolume && this.watchCallback) {
this.watchCallback({ direction: 'up' });
}
}, 3000);
}
// Return a callback ID (mock)
return 'web-volume-watch-1';
}
async clearWatch() {
console.log('clearWatch called');
if (!this.isWatchingVolume) {
throw new Error('Volume buttons has not been watched');
}
this.watchCallback = undefined;
this.isWatchingVolume = false;
}
async isWatching() {
return { value: this.isWatchingVolume };
}
}
var web = /*#__PURE__*/Object.freeze({
__proto__: null,
VolumeControlWeb: VolumeControlWeb
});
exports.VolumeControl = VolumeControl;
//# sourceMappingURL=plugin.cjs.js.map