Skip to content

Commit

Permalink
Merge pull request #503 from andrewvmail/cutting-other-app-music
Browse files Browse the repository at this point in the history
pull out initAudioDevices from the constructor into its own api
  • Loading branch information
hthetiot authored Jun 2, 2020
2 parents 15402b1 + 1782e4f commit b068041
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/iosrtc.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ cordova.plugins.iosrtc.requestPermission(needMic, needCamera, function (permissi
})
```

### `iosrtc.initAudioDevices`

Initialize the audio session, specifically setting the session's category and activating the session.
This is to avoid cutting the audio of other applications on app boot.

To use this install plugin using
```bash
cordova plugin add cordova-plugin-iosrtc --variable MANUAL_INIT_AUDIO_DEVICE=TRUE
```

```javascript
cordova.plugins.iosrtc.initAudioDevices();
```

## Others


Expand Down
1 change: 1 addition & 0 deletions extra/renderer-and-libwebrtc-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (cordova && cordova.plugins && cordova.plugins.iosrtc) {
cordova.plugins.iosrtc.registerGlobals();
//cordova.plugins.iosrtc.debug.disable('*', true);
//cordova.plugins.iosrtc.debug.enable('*', true);
cordova.plugins.iosrtc.initAudioDevices();
cordova.plugins.iosrtc.turnOnSpeaker(true);
cordova.plugins.iosrtc.requestPermission(true, true, function (result) {
console.log('requestPermission.result', result);
Expand Down
9 changes: 9 additions & 0 deletions js/iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module.exports = {
// Checking permision (audio and camera)
requestPermission: requestPermission,

// Expose a function to initAudioDevices if needed, sets the audio session active
initAudioDevices: initAudioDevices,

// Expose a function to pollute window and naigator namespaces.
registerGlobals: registerGlobals,

Expand Down Expand Up @@ -121,6 +124,12 @@ function requestPermission(needMic, needCamera, callback) {
exec(ok, error, 'iosrtcPlugin', "RTCRequestPermission", [needMic, needCamera]);
}

function initAudioDevices() {
debug('initAudioDevices()');

exec(null, null, 'iosrtcPlugin', "initAudioDevices", []);
}

function callbackifyMethod(originalMethod) {
return function (arg) { // jshint ignore:line
var success, failure,
Expand Down
6 changes: 6 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
</feature>
</config-file>

<preference name="MANUAL_INIT_AUDIO_DEVICE" default="FALSE"/>

<config-file target="*-Info.plist" parent="ManualInitAudioDevice">
<string>$MANUAL_INIT_AUDIO_DEVICE</string>
</config-file>

<!-- Permission notes -->
<config-file parent="NSCameraUsageDescription" target="*-Info.plist">
<string>This Application uses your camera to make video calls.</string>
Expand Down
7 changes: 5 additions & 2 deletions src/PluginRTCAudioController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ class PluginRTCAudioController {
static private var speakerEnabled: Bool = false

init() {

PluginRTCAudioController.initAudioDevices()
let shouldManualInit = Bundle.main.object(forInfoDictionaryKey: "ManualInitAudioDevice") as? String

if(shouldManualInit == "FALSE") {
PluginRTCAudioController.initAudioDevices()
}

NotificationCenter.default.addObserver(
self,
Expand Down
6 changes: 6 additions & 0 deletions src/iosrtcPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,12 @@ class iosrtcPlugin : CDVPlugin {
}
}

@objc(initAudioDevices:) func initAudioDevices(_ command: CDVInvokedUrlCommand) {
NSLog("iosrtcPlugin#initAudioDevices()")

PluginRTCAudioController.initAudioDevices()
}

@objc(RTCTurnOnSpeaker:) func RTCTurnOnSpeaker(_ command: CDVInvokedUrlCommand) {
DispatchQueue.main.async {
let isTurnOn: Bool = CBool(command.arguments[0] as! Bool)
Expand Down

0 comments on commit b068041

Please sign in to comment.