The cordova-plugin-audioroute alternative for Capacitor iOS apps is @capgo/capacitor-audio-session. The Capgo plugin is a port of saghul/cordova-plugin-audioroute and exposes currentOutputs(), overrideOutput(), and Capacitor listeners for route changes and audio session interruptions instead of cordova.plugins.audioroute callbacks and DOM events. This guide covers maintenance facts, install steps, a short example, and an API mapping table.
Why migrate off cordova-plugin-audioroute
cordova-plugin-audioroute on npm is version 0.1.2. The registry modified date is 13 June 2022, and the package homepage points to saghul/cordova-plugin-audioroute. The repository’s latest commit is from April 2017.
The Cordova API is small but dated for Capacitor:
- Methods live under
cordova.plugins.audioroutewith success and error callbacks. - Route updates use a
document.addEventListener('audioroute-changed', ...)hook with a stringreason. - Installation uses
cordova plugin add cordova-plugin-audioroute.
@capgo/capacitor-audio-session keeps the same iOS-only scope and adds addListener('interruption', ...) for phone calls and other AVAudioSession interruptions. Capgo maintains the v8 line for Capacitor 8 with the same open source workflow where a human still reviews, tests and merges 50+ pull requests daily.
Install
bun add @capgo/capacitor-audio-session
bunx cap sync
No extra Info.plist keys are required beyond what your VoIP or media stack already uses, but you should configure AVAudioSession category and options in your native audio or WebRTC plugin before calling routing helpers. Rebuild iOS after adding the Capacitor plugin.
Usage example
import { AudioSession } from '@capgo/capacitor-audio-session';
export async function enableSpeakerForCall() {
const routeListener = await AudioSession.addListener('routeChanged', (event) => {
console.log('Route reason', event.reason);
});
await AudioSession.overrideOutput('speaker');
const outputs = await AudioSession.currentOutputs();
console.log('Active ports', outputs);
}
Call AudioSession.overrideOutput('default') when the user ends the call so Bluetooth or the receiver can take over again.
Migrating from Cordova to Capacitor
Remove cordova.plugins.audioroute and the audioroute-changed document listener. Import AudioSession and use promises plus Capacitor listeners.
API mapping table
| cordova-plugin-audioroute | @capgo/capacitor-audio-session |
|---|---|
cordova.plugins.audioroute.currentOutputs(success, error) |
AudioSession.currentOutputs() |
cordova.plugins.audioroute.overrideOutput(output, success, error) |
AudioSession.overrideOutput(type) with speaker or default |
document.addEventListener('audioroute-changed', fn) |
addListener('routeChanged', fn) |
Event reason strings (new-device-available, override, …) |
routeChanged payload reason |
| No Cordova API for interruptions | addListener('interruption', fn) |
| iOS only | iOS only (empty arrays on Android and web) |
Port output type strings directly: Cordova accepts default and speaker, which match Capgo OutputOverrideType.
Links and next steps
- Plugin docs: https://capgo.app/docs/plugins/audiosession/
- Marketing page: /plugins/capacitor-audiosession/
- npm: https://www.npmjs.com/package/@capgo/capacitor-audio-session
- GitHub: https://github.com/Cap-go/capacitor-audiosession/
- Cordova upstream: https://github.com/saghul/cordova-plugin-audioroute
Pair this plugin with your media or VoIP stack, ship native builds through Capgo Build, and iterate call UI with Capgo live updates. Broader migration: migrating Cordova to Capacitor.