Skip to content

Commit ddd0ee7

Browse files
committed
change default behavior: no proximity when video
1 parent f18d939 commit ddd0ee7

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ DeviceEventEmitter.addListener('Proximity', function (data) {
7777
**on start:**
7878
* store current settings, set KeepScreenOn flag = true, and register some event listeners.
7979
* if media type is `audio`, route voice to earpiece, otherwise route to speaker.
80+
* audio will enable proximity sensor which is disabled by default if media=video
8081
* when proximity detect user closed to screen, turn off screen to avoid accident touch and route voice to earpiece.
8182
* when newly external device plugged, such as wired-headset, route audio to external device.
8283

android/src/main/java/com/zxcpoiu/incallmanager/InCallManagerModule.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void acquireProximityWakeLock() {
146146
}
147147
}
148148

149-
private void releaseProximityWakeLock(boolean waitForNoProximity) {
149+
private void releaseProximityWakeLock(final boolean waitForNoProximity) {
150150
if (!isProximityWakeLockSupported()) {
151151
return;
152152
}
@@ -509,7 +509,7 @@ public void test_deviceCallback() {
509509
// -- TODO: bluetooth support
510510
*/
511511

512-
private static void sendEvent(String eventName, @Nullable WritableMap params) {
512+
private static void sendEvent(final String eventName, @Nullable WritableMap params) {
513513
try {
514514
reactContext
515515
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -520,26 +520,21 @@ private static void sendEvent(String eventName, @Nullable WritableMap params) {
520520
}
521521

522522
@ReactMethod
523-
public void start(String media, boolean auto) {
524-
if (media == "video") {
523+
public void start(final String media, final boolean auto) {
524+
if (media.equals("video")) {
525525
defaultSpeakerOn = true;
526526
} else {
527527
defaultSpeakerOn = false;
528528
}
529529
automatic = auto;
530530
if (!audioManagerInitialized) {
531531
Log.d(TAG, "start audioRouteManager");
532-
requestAudioFocus();
533-
// TODO: even if not acquired focus, we can still play sounds. but need figure out which is better.
534532
storeOriginalAudioSetup();
533+
startEvents();
534+
// TODO: even if not acquired focus, we can still play sounds. but need figure out which is better.
535535
setMicrophoneMute(false);
536536
audioManager.setMode(defaultAudioMode);
537537
updateAudioRoute();
538-
startWiredHeadsetEvent();
539-
startNoisyAudioEvent();
540-
startMediaButtonEvent();
541-
startProximitySensor();
542-
setKeepScreenOn(true);
543538
audioManagerInitialized = true;
544539
}
545540
}
@@ -548,39 +543,45 @@ public void start(String media, boolean auto) {
548543
public void stop() {
549544
if (audioManagerInitialized) {
550545
Log.d(TAG, "stop audioRouteManager");
551-
stopWiredHeadsetEvent();
552-
stopNoisyAudioEvent();
553-
stopMediaButtonEvent();
554-
stopProximitySensor();
546+
stopEvents();
555547
restoreOriginalAudioSetup();
556-
releaseAudioFocus();
557-
setKeepScreenOn(false);
558548
audioManagerInitialized = false;
559549
}
560550
}
561551

562552
private void pause() {
563553
if (audioManagerInitialized) {
564554
Log.d(TAG, "pause audioRouteManager");
565-
releaseAudioFocus();
566-
stopWiredHeadsetEvent();
567-
stopNoisyAudioEvent();
568-
stopMediaButtonEvent();
569-
stopProximitySensor();
570-
setKeepScreenOn(false);
555+
stopEvents();
571556
}
572557
}
573558

574559
private void resume() {
575560
if (audioManagerInitialized) {
576561
Log.d(TAG, "resume audioRouteManager");
577-
requestAudioFocus();
578-
startWiredHeadsetEvent();
579-
startNoisyAudioEvent();
580-
startMediaButtonEvent();
562+
startEvents();
563+
}
564+
}
565+
566+
private void startEvents() {
567+
requestAudioFocus();
568+
startWiredHeadsetEvent();
569+
startNoisyAudioEvent();
570+
startMediaButtonEvent();
571+
if (!defaultSpeakerOn) {
572+
// video, default disable proximity
581573
startProximitySensor();
582-
setKeepScreenOn(true);
583574
}
575+
setKeepScreenOn(true);
576+
}
577+
578+
private void stopEvents() {
579+
stopWiredHeadsetEvent();
580+
stopNoisyAudioEvent();
581+
stopMediaButtonEvent();
582+
stopProximitySensor();
583+
setKeepScreenOn(false);
584+
releaseAudioFocus();
584585
}
585586

586587
private void requestAudioFocus() {
@@ -664,15 +665,15 @@ public void run() {
664665
}
665666

666667
@ReactMethod
667-
public void setSpeakerphoneOn(boolean enable) {
668+
public void setSpeakerphoneOn(final boolean enable) {
668669
if (enable != audioManager.isSpeakerphoneOn()) {
669670
Log.d(TAG, "setSpeakerphoneOn(): " + enable);
670671
audioManager.setSpeakerphoneOn(enable);
671672
}
672673
}
673674

674675
@ReactMethod
675-
public void setForceSpeakerphoneOn(boolean enable) {
676+
public void setForceSpeakerphoneOn(final boolean enable) {
676677
forceSpeakerOn = enable;
677678
if (forceSpeakerOn) {
678679
Log.d(TAG, "setForceSpeakerphoneOn()");
@@ -681,7 +682,7 @@ public void setForceSpeakerphoneOn(boolean enable) {
681682
}
682683

683684
@ReactMethod
684-
public void setMicrophoneMute(boolean enable) {
685+
public void setMicrophoneMute(final boolean enable) {
685686
if (enable != audioManager.isMicrophoneMute()) {
686687
Log.d(TAG, "setMicrophoneMute(): " + enable);
687688
audioManager.setMicrophoneMute(enable);

ios/RNInCallManager/RNInCallManager.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class RNInCallManager: NSObject {
5454
//self.audioSession.setCategory(defaultAudioCategory, options: [.DefaultToSpeaker, .AllowBluetooth])
5555
_ = try? self.audioSession.setCategory(self.defaultAudioCategory)
5656
_ = try? self.audioSession.setMode(self.defaultAudioMode)
57-
self.startProximitySensor()
57+
if media == "audio" {
58+
self.startProximitySensor()
59+
}
5860
self.setKeepScreenOn(true)
5961
self.audioSessionInitialized = true
6062
}

0 commit comments

Comments
 (0)