@cometchat/calls-sdk-react-native 4.4.2-beta.1 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -19
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +13 -12
- package/android/src/main/AndroidManifest.xml +15 -6
- package/android/src/main/java/com/callingv5/AudioDeviceHandlerConnectionService.java +185 -0
- package/android/src/main/java/com/callingv5/AudioDeviceHandlerGeneric.java +254 -0
- package/android/src/main/java/com/{CometChatCalls → callingv5}/AudioModeModule.java +93 -56
- package/android/src/main/java/com/callingv5/ConnectionService.java +451 -0
- package/android/src/main/java/com/callingv5/KeepAwakeModule.java +53 -0
- package/android/src/main/java/com/callingv5/MyAppPackage.java +35 -0
- package/android/src/main/java/com/callingv5/RNConnectionService.java +244 -0
- package/android/src/main/java/com/callingv5/ToastModule.java +29 -0
- package/android/src/main/java/com/callingv5/utils/CometChatLogger.java +88 -0
- package/cometchat-calls-sdk-react-native.podspec +9 -10
- package/dist/index.d.mts +4066 -0
- package/dist/index.d.ts +4066 -9
- package/dist/index.js +11116 -132
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11085 -0
- package/dist/index.mjs.map +1 -0
- package/dist/polyfills/RTCPeerConnection.js +19 -0
- package/dist/polyfills/Storage.js +192 -0
- package/dist/polyfills/browser.js +337 -0
- package/dist/polyfills/index.js +1 -0
- package/dist/polyfills/ipv6utils.js +197 -0
- package/dist/polyfills/webrtc.js +11 -0
- package/ios/{JitsiAudioSession+Private.h → Audio/CometChatAudioSession+Private.h} +2 -3
- package/ios/{LogUtils.h → Audio/CometChatAudioSession.h} +9 -6
- package/ios/{JitsiAudioSession.m → Audio/CometChatAudioSession.m} +4 -3
- package/ios/{AudioMode.m → Modules/AudioMode.m} +15 -49
- package/ios/Modules/KeepAwake.h +4 -0
- package/ios/Modules/KeepAwake.m +29 -0
- package/package.json +24 -110
- package/LICENSE.md +0 -3
- package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerGeneric.java +0 -213
- package/android/src/main/java/com/CometChatCalls/AudioDeviceHandlerLegacy.java +0 -213
- package/android/src/main/java/com/CometChatCalls/BluetoothHeadsetMonitor.java +0 -187
- package/android/src/main/java/com/CometChatCalls/CallNotificationService.java +0 -93
- package/android/src/main/java/com/CometChatCalls/CallNotificationServiceModule.java +0 -48
- package/android/src/main/java/com/CometChatCalls/CometChatCallsPackage.java +0 -56
- package/android/src/main/java/com/CometChatCalls/CometChatCommonModule.java +0 -48
- package/android/src/main/java/com/CometChatCalls/PictureInPictureModule.java +0 -133
- package/android/src/main/res/drawable-mdpi/callingcomponent_icons_headphones_pluged.png +0 -0
- package/dist/CometChatErrorConstants.d.ts +0 -124
- package/dist/Constants.d.ts +0 -724
- package/dist/Helper copy.d.ts +0 -1
- package/dist/Helper.d.ts +0 -7
- package/dist/api/APIHandler.d.ts +0 -42
- package/dist/api/endpoints.d.ts +0 -7
- package/dist/api/helper.d.ts +0 -69
- package/dist/api/index.d.ts +0 -2
- package/dist/constants/CallConstants.d.ts +0 -136
- package/dist/constants/index.d.ts +0 -1
- package/dist/defaultCallsettings.d.ts +0 -2
- package/dist/models/CallAppSettings.d.ts +0 -42
- package/dist/models/CallGroup.d.ts +0 -14
- package/dist/models/CallLog.d.ts +0 -276
- package/dist/models/CallLogFilterParams.d.ts +0 -97
- package/dist/models/CallSettings.d.ts +0 -330
- package/dist/models/CallUser.d.ts +0 -14
- package/dist/models/CometChatCallLogs.d.ts +0 -193
- package/dist/models/CometChatCalls.d.ts +0 -110
- package/dist/models/CometChatCallsComponent.d.ts +0 -13
- package/dist/models/CometChatCallsComponentCore.d.ts +0 -18
- package/dist/models/CometChatCallsException.d.ts +0 -7
- package/dist/models/CometChatPresenterComponent.d.ts +0 -13
- package/dist/models/ErrorModel.d.ts +0 -11
- package/dist/models/Listner.d.ts +0 -69
- package/dist/models/ListnerHandler.d.ts +0 -10
- package/dist/models/MessageComponent.d.ts +0 -7
- package/dist/models/Participant.d.ts +0 -184
- package/dist/models/PresenterSettings.d.ts +0 -208
- package/dist/models/RTCUser.d.ts +0 -18
- package/dist/models/Recording.d.ts +0 -86
- package/dist/models/index.d.ts +0 -9
- package/dist/types/ICallAppSettings.d.ts +0 -6
- package/dist/types/ICallSettings.d.ts +0 -61
- package/dist/types/RTCUser.d.ts +0 -6
- package/dist/types/callEvents.d.ts +0 -54
- package/dist/types/common.d.ts +0 -18
- package/dist/types/index.d.ts +0 -2
- package/ios/AudioMode.h +0 -11
- package/ios/CometChatCommonModule.h +0 -6
- package/ios/CometChatCommonModule.m +0 -29
- package/ios/JitsiAudioSession.h +0 -17
- package/ios/react-native-calls2.xcodeproj/project.pbxproj +0 -269
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
package com.CometChatCalls;
|
|
2
|
-
import android.annotation.TargetApi;
|
|
3
|
-
import android.media.AudioDeviceInfo;
|
|
4
|
-
import android.media.AudioManager;
|
|
5
|
-
import android.os.Build;
|
|
6
|
-
import android.util.Log;
|
|
7
|
-
|
|
8
|
-
import java.util.HashSet;
|
|
9
|
-
import java.util.Set;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* {@link AudioModeModule.AudioDeviceHandlerInterface} module implementing device handling for
|
|
15
|
-
* all post-M Android versions. This handler can be used on any Android versions >= M, but by
|
|
16
|
-
* default it's only used on versions < O, since versions >= O use ConnectionService, but it
|
|
17
|
-
* can be disabled.
|
|
18
|
-
*/
|
|
19
|
-
@TargetApi(Build.VERSION_CODES.M)
|
|
20
|
-
class AudioDeviceHandlerGeneric implements
|
|
21
|
-
AudioModeModule.AudioDeviceHandlerInterface,
|
|
22
|
-
AudioManager.OnAudioFocusChangeListener {
|
|
23
|
-
|
|
24
|
-
private final static String TAG = AudioDeviceHandlerGeneric.class.getSimpleName();
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Reference to the main {@code AudioModeModule}.
|
|
28
|
-
*/
|
|
29
|
-
private AudioModeModule module;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Constant defining a USB headset. Only available on API level >= 26.
|
|
33
|
-
* The value of: AudioDeviceInfo.TYPE_USB_HEADSET
|
|
34
|
-
*/
|
|
35
|
-
private static final int TYPE_USB_HEADSET = 22;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Indicator that we have lost audio focus.
|
|
39
|
-
*/
|
|
40
|
-
private boolean audioFocusLost = false;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* {@link AudioManager} instance used to interact with the Android audio
|
|
44
|
-
* subsystem.
|
|
45
|
-
*/
|
|
46
|
-
private AudioManager audioManager;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* {@link Runnable} for running audio device detection the main thread.
|
|
50
|
-
* This is only used on Android >= M.
|
|
51
|
-
*/
|
|
52
|
-
private final Runnable onAudioDeviceChangeRunner = new Runnable() {
|
|
53
|
-
@Override
|
|
54
|
-
public void run() {
|
|
55
|
-
Set<String> devices = new HashSet<>();
|
|
56
|
-
AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
|
|
57
|
-
|
|
58
|
-
for (AudioDeviceInfo info: deviceInfos) {
|
|
59
|
-
switch (info.getType()) {
|
|
60
|
-
case AudioDeviceInfo.TYPE_BLUETOOTH_SCO:
|
|
61
|
-
devices.add(AudioModeModule.DEVICE_BLUETOOTH);
|
|
62
|
-
break;
|
|
63
|
-
case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
|
|
64
|
-
devices.add(AudioModeModule.DEVICE_EARPIECE);
|
|
65
|
-
break;
|
|
66
|
-
case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
|
|
67
|
-
devices.add(AudioModeModule.DEVICE_SPEAKER);
|
|
68
|
-
break;
|
|
69
|
-
case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
|
|
70
|
-
case AudioDeviceInfo.TYPE_WIRED_HEADSET:
|
|
71
|
-
case TYPE_USB_HEADSET:
|
|
72
|
-
devices.add(AudioModeModule.DEVICE_HEADPHONES);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.replaceDevices(devices);
|
|
78
|
-
|
|
79
|
-
Log.i(TAG , " Available audio devices: " + devices.toString());
|
|
80
|
-
|
|
81
|
-
module.updateAudioRoute();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
private final android.media.AudioDeviceCallback audioDeviceCallback =
|
|
86
|
-
new android.media.AudioDeviceCallback() {
|
|
87
|
-
@Override
|
|
88
|
-
public void onAudioDevicesAdded(
|
|
89
|
-
AudioDeviceInfo[] addedDevices) {
|
|
90
|
-
Log.d(TAG , " Audio devices added");
|
|
91
|
-
onAudioDeviceChange();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@Override
|
|
95
|
-
public void onAudioDevicesRemoved(
|
|
96
|
-
AudioDeviceInfo[] removedDevices) {
|
|
97
|
-
Log.d(TAG , " Audio devices removed");
|
|
98
|
-
onAudioDeviceChange();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
public AudioDeviceHandlerGeneric(AudioManager audioManager) {
|
|
103
|
-
this.audioManager = audioManager;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Helper method to trigger an audio route update when devices change. It
|
|
108
|
-
* makes sure the operation is performed on the audio thread.
|
|
109
|
-
*/
|
|
110
|
-
private void onAudioDeviceChange() {
|
|
111
|
-
module.runInAudioThread(onAudioDeviceChangeRunner);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* {@link AudioManager.OnAudioFocusChangeListener} interface method. Called
|
|
116
|
-
* when the audio focus of the system is updated.
|
|
117
|
-
*
|
|
118
|
-
* @param focusChange - The type of focus change.
|
|
119
|
-
*/
|
|
120
|
-
@Override
|
|
121
|
-
public void onAudioFocusChange(final int focusChange) {
|
|
122
|
-
module.runInAudioThread(new Runnable() {
|
|
123
|
-
@Override
|
|
124
|
-
public void run() {
|
|
125
|
-
switch (focusChange) {
|
|
126
|
-
case AudioManager.AUDIOFOCUS_GAIN: {
|
|
127
|
-
Log.d(TAG , " Audio focus gained");
|
|
128
|
-
// Some other application potentially stole our audio focus
|
|
129
|
-
// temporarily. Restore our mode.
|
|
130
|
-
if (audioFocusLost) {
|
|
131
|
-
module.updateAudioRoute();
|
|
132
|
-
}
|
|
133
|
-
audioFocusLost = false;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case AudioManager.AUDIOFOCUS_LOSS:
|
|
137
|
-
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
|
138
|
-
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
|
|
139
|
-
Log.d(TAG , " Audio focus lost");
|
|
140
|
-
audioFocusLost = true;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Helper method to set the output route to a Bluetooth device.
|
|
150
|
-
*
|
|
151
|
-
* @param enabled true if Bluetooth should use used, false otherwise.
|
|
152
|
-
*/
|
|
153
|
-
private void setBluetoothAudioRoute(boolean enabled) {
|
|
154
|
-
if (enabled) {
|
|
155
|
-
audioManager.startBluetoothSco();
|
|
156
|
-
audioManager.setBluetoothScoOn(true);
|
|
157
|
-
} else {
|
|
158
|
-
audioManager.setBluetoothScoOn(false);
|
|
159
|
-
audioManager.stopBluetoothSco();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
@Override
|
|
164
|
-
public void start(AudioModeModule audioModeModule) {
|
|
165
|
-
Log.i("Using " , TAG + " as the audio device handler");
|
|
166
|
-
|
|
167
|
-
module = audioModeModule;
|
|
168
|
-
|
|
169
|
-
// Setup runtime device change detection.
|
|
170
|
-
audioManager.registerAudioDeviceCallback(audioDeviceCallback, null);
|
|
171
|
-
|
|
172
|
-
// Do an initial detection.
|
|
173
|
-
onAudioDeviceChange();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
@Override
|
|
177
|
-
public void stop() {
|
|
178
|
-
audioManager.unregisterAudioDeviceCallback(audioDeviceCallback);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
@Override
|
|
182
|
-
public void setAudioRoute(String device) {
|
|
183
|
-
// Turn speaker on / off
|
|
184
|
-
audioManager.setSpeakerphoneOn(device.equals(AudioModeModule.DEVICE_SPEAKER));
|
|
185
|
-
|
|
186
|
-
// Turn bluetooth on / off
|
|
187
|
-
setBluetoothAudioRoute(device.equals(AudioModeModule.DEVICE_BLUETOOTH));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@Override
|
|
191
|
-
public boolean setMode(int mode) {
|
|
192
|
-
if (mode == AudioModeModule.DEFAULT) {
|
|
193
|
-
audioFocusLost = false;
|
|
194
|
-
audioManager.setMode(AudioManager.MODE_NORMAL);
|
|
195
|
-
audioManager.abandonAudioFocus(this);
|
|
196
|
-
audioManager.setSpeakerphoneOn(false);
|
|
197
|
-
setBluetoothAudioRoute(false);
|
|
198
|
-
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
|
203
|
-
audioManager.setMicrophoneMute(false);
|
|
204
|
-
|
|
205
|
-
if (audioManager.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN)
|
|
206
|
-
== AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
|
|
207
|
-
Log.w(TAG , " Audio focus request failed");
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
package com.CometChatCalls;
|
|
2
|
-
|
|
3
|
-
import android.content.BroadcastReceiver;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.content.Intent;
|
|
6
|
-
import android.content.IntentFilter;
|
|
7
|
-
import android.content.pm.PackageManager;
|
|
8
|
-
import android.media.AudioManager;
|
|
9
|
-
import android.util.Log;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* {@link AudioModeModule.AudioDeviceHandlerInterface} module implementing device handling for
|
|
14
|
-
* legacy (pre-M) Android versions.
|
|
15
|
-
*/
|
|
16
|
-
class AudioDeviceHandlerLegacy implements
|
|
17
|
-
AudioModeModule.AudioDeviceHandlerInterface,
|
|
18
|
-
AudioManager.OnAudioFocusChangeListener,
|
|
19
|
-
BluetoothHeadsetMonitor.Listener {
|
|
20
|
-
|
|
21
|
-
private final static String TAG = AudioDeviceHandlerLegacy.class.getSimpleName();
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Reference to the main {@code AudioModeModule}.
|
|
25
|
-
*/
|
|
26
|
-
private AudioModeModule module;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Indicator that we have lost audio focus.
|
|
30
|
-
*/
|
|
31
|
-
private boolean audioFocusLost = false;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* {@link AudioManager} instance used to interact with the Android audio
|
|
35
|
-
* subsystem.
|
|
36
|
-
*/
|
|
37
|
-
private AudioManager audioManager;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* {@link BluetoothHeadsetMonitor} for detecting Bluetooth device changes in
|
|
41
|
-
* old (< M) Android versions.
|
|
42
|
-
*/
|
|
43
|
-
private BluetoothHeadsetMonitor bluetoothHeadsetMonitor;
|
|
44
|
-
|
|
45
|
-
public AudioDeviceHandlerLegacy(AudioManager audioManager) {
|
|
46
|
-
this.audioManager = audioManager;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Helper method to trigger an audio route update when Bluetooth devices are
|
|
51
|
-
* connected / disconnected.
|
|
52
|
-
*/
|
|
53
|
-
@Override
|
|
54
|
-
public void onBluetoothDeviceChange(final boolean deviceAvailable) {
|
|
55
|
-
module.runInAudioThread(new Runnable() {
|
|
56
|
-
@Override
|
|
57
|
-
public void run() {
|
|
58
|
-
if (deviceAvailable) {
|
|
59
|
-
module.addDevice(AudioModeModule.DEVICE_BLUETOOTH);
|
|
60
|
-
} else {
|
|
61
|
-
module.removeDevice(AudioModeModule.DEVICE_BLUETOOTH);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.updateAudioRoute();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Helper method to trigger an audio route update when a headset is plugged
|
|
71
|
-
* or unplugged.
|
|
72
|
-
*/
|
|
73
|
-
private void onHeadsetDeviceChange() {
|
|
74
|
-
module.runInAudioThread(new Runnable() {
|
|
75
|
-
@Override
|
|
76
|
-
public void run() {
|
|
77
|
-
// XXX: isWiredHeadsetOn is not deprecated when used just for
|
|
78
|
-
// knowing if there is a wired headset connected, regardless of
|
|
79
|
-
// audio being routed to it.
|
|
80
|
-
//noinspection deprecation
|
|
81
|
-
if (audioManager.isWiredHeadsetOn()) {
|
|
82
|
-
module.addDevice(AudioModeModule.DEVICE_HEADPHONES);
|
|
83
|
-
} else {
|
|
84
|
-
module.removeDevice(AudioModeModule.DEVICE_HEADPHONES);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.updateAudioRoute();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* {@link AudioManager.OnAudioFocusChangeListener} interface method. Called
|
|
94
|
-
* when the audio focus of the system is updated.
|
|
95
|
-
*
|
|
96
|
-
* @param focusChange - The type of focus change.
|
|
97
|
-
*/
|
|
98
|
-
@Override
|
|
99
|
-
public void onAudioFocusChange(final int focusChange) {
|
|
100
|
-
module.runInAudioThread(new Runnable() {
|
|
101
|
-
@Override
|
|
102
|
-
public void run() {
|
|
103
|
-
switch (focusChange) {
|
|
104
|
-
case AudioManager.AUDIOFOCUS_GAIN: {
|
|
105
|
-
Log.d(TAG , " Audio focus gained");
|
|
106
|
-
// Some other application potentially stole our audio focus
|
|
107
|
-
// temporarily. Restore our mode.
|
|
108
|
-
if (audioFocusLost) {
|
|
109
|
-
module.updateAudioRoute();
|
|
110
|
-
}
|
|
111
|
-
audioFocusLost = false;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case AudioManager.AUDIOFOCUS_LOSS:
|
|
115
|
-
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
|
116
|
-
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: {
|
|
117
|
-
Log.d(TAG , " Audio focus lost");
|
|
118
|
-
audioFocusLost = true;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Helper method to set the output route to a Bluetooth device.
|
|
128
|
-
*
|
|
129
|
-
* @param enabled true if Bluetooth should use used, false otherwise.
|
|
130
|
-
*/
|
|
131
|
-
private void setBluetoothAudioRoute(boolean enabled) {
|
|
132
|
-
if (enabled) {
|
|
133
|
-
audioManager.startBluetoothSco();
|
|
134
|
-
audioManager.setBluetoothScoOn(true);
|
|
135
|
-
} else {
|
|
136
|
-
audioManager.setBluetoothScoOn(false);
|
|
137
|
-
audioManager.stopBluetoothSco();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
@Override
|
|
142
|
-
public void start(AudioModeModule audioModeModule) {
|
|
143
|
-
Log.i( TAG , " as the audio device handler");
|
|
144
|
-
|
|
145
|
-
module = audioModeModule;
|
|
146
|
-
Context context = module.getContext();
|
|
147
|
-
|
|
148
|
-
// Setup runtime device change detection.
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
// Detect changes in wired headset connections.
|
|
152
|
-
IntentFilter wiredHeadSetFilter = new IntentFilter(AudioManager.ACTION_HEADSET_PLUG);
|
|
153
|
-
BroadcastReceiver wiredHeadsetReceiver = new BroadcastReceiver() {
|
|
154
|
-
@Override
|
|
155
|
-
public void onReceive(Context context, Intent intent) {
|
|
156
|
-
Log.d(TAG , " Wired headset added / removed");
|
|
157
|
-
onHeadsetDeviceChange();
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
context.registerReceiver(wiredHeadsetReceiver, wiredHeadSetFilter);
|
|
161
|
-
|
|
162
|
-
// Detect Bluetooth device changes.
|
|
163
|
-
bluetoothHeadsetMonitor = new BluetoothHeadsetMonitor(context, this);
|
|
164
|
-
|
|
165
|
-
// On Android < M, detect if we have an earpiece.
|
|
166
|
-
PackageManager pm = context.getPackageManager();
|
|
167
|
-
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
|
|
168
|
-
module.addDevice(AudioModeModule.DEVICE_EARPIECE);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Always assume there is a speaker.
|
|
172
|
-
module.addDevice(AudioModeModule.DEVICE_SPEAKER);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
@Override
|
|
176
|
-
public void stop() {
|
|
177
|
-
bluetoothHeadsetMonitor.stop();
|
|
178
|
-
bluetoothHeadsetMonitor = null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
@Override
|
|
182
|
-
public void setAudioRoute(String device) {
|
|
183
|
-
// Turn speaker on / off
|
|
184
|
-
audioManager.setSpeakerphoneOn(device.equals(AudioModeModule.DEVICE_SPEAKER));
|
|
185
|
-
|
|
186
|
-
// Turn bluetooth on / off
|
|
187
|
-
setBluetoothAudioRoute(device.equals(AudioModeModule.DEVICE_BLUETOOTH));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@Override
|
|
191
|
-
public boolean setMode(int mode) {
|
|
192
|
-
if (mode == AudioModeModule.DEFAULT) {
|
|
193
|
-
audioFocusLost = false;
|
|
194
|
-
audioManager.setMode(AudioManager.MODE_NORMAL);
|
|
195
|
-
audioManager.abandonAudioFocus(this);
|
|
196
|
-
audioManager.setSpeakerphoneOn(false);
|
|
197
|
-
setBluetoothAudioRoute(false);
|
|
198
|
-
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
|
203
|
-
audioManager.setMicrophoneMute(false);
|
|
204
|
-
|
|
205
|
-
if (audioManager.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN)
|
|
206
|
-
== AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
|
|
207
|
-
Log.w(TAG , " Audio focus request failed");
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
package com.CometChatCalls;
|
|
3
|
-
|
|
4
|
-
import android.Manifest;
|
|
5
|
-
import android.bluetooth.BluetoothAdapter;
|
|
6
|
-
import android.bluetooth.BluetoothHeadset;
|
|
7
|
-
import android.bluetooth.BluetoothProfile;
|
|
8
|
-
import android.content.BroadcastReceiver;
|
|
9
|
-
import android.content.Context;
|
|
10
|
-
import android.content.Intent;
|
|
11
|
-
import android.content.IntentFilter;
|
|
12
|
-
import android.content.pm.PackageManager;
|
|
13
|
-
import android.media.AudioManager;
|
|
14
|
-
import android.os.Build;
|
|
15
|
-
import android.util.Log;
|
|
16
|
-
|
|
17
|
-
import androidx.core.app.ActivityCompat;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Helper class to detect and handle Bluetooth device changes. It monitors
|
|
21
|
-
* Bluetooth headsets being connected / disconnected and notifies the module
|
|
22
|
-
* about device changes when this occurs.
|
|
23
|
-
*/
|
|
24
|
-
class BluetoothHeadsetMonitor {
|
|
25
|
-
private final static String TAG = BluetoothHeadsetMonitor.class.getSimpleName();
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The {@link Context} in which this module executes.
|
|
29
|
-
*/
|
|
30
|
-
private final Context context;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Reference to the {@link BluetoothAdapter} object, used to access Bluetooth functionality.
|
|
34
|
-
*/
|
|
35
|
-
private BluetoothAdapter adapter;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Reference to a proxy object which allows us to query connected devices.
|
|
39
|
-
*/
|
|
40
|
-
private BluetoothHeadset headset;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* receiver registered for receiving Bluetooth connection state changes.
|
|
44
|
-
*/
|
|
45
|
-
private BroadcastReceiver receiver;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Listener for receiving Bluetooth device change events.
|
|
49
|
-
*/
|
|
50
|
-
private Listener listener;
|
|
51
|
-
|
|
52
|
-
public BluetoothHeadsetMonitor(Context context, Listener listener) {
|
|
53
|
-
this.context = context;
|
|
54
|
-
this.listener = listener;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private boolean getBluetoothHeadsetProfileProxy() {
|
|
58
|
-
adapter = BluetoothAdapter.getDefaultAdapter();
|
|
59
|
-
|
|
60
|
-
if (adapter == null) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// XXX: The profile listener listens for system services of the given
|
|
65
|
-
// type being available to the application. That is, if our Bluetooth
|
|
66
|
-
// adapter has the "headset" profile.
|
|
67
|
-
BluetoothProfile.ServiceListener listener
|
|
68
|
-
= new BluetoothProfile.ServiceListener() {
|
|
69
|
-
@Override
|
|
70
|
-
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
|
71
|
-
if (profile == BluetoothProfile.HEADSET) {
|
|
72
|
-
headset = (BluetoothHeadset) proxy;
|
|
73
|
-
updateDevices();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@Override
|
|
78
|
-
public void onServiceDisconnected(int profile) {
|
|
79
|
-
// The logic is the same as the logic of onServiceConnected.
|
|
80
|
-
onServiceConnected(profile, /* proxy */ null);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return adapter.getProfileProxy(context, listener, BluetoothProfile.HEADSET);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private void onBluetoothReceiverReceive(Context context, Intent intent) {
|
|
88
|
-
final String action = intent.getAction();
|
|
89
|
-
|
|
90
|
-
if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
|
|
91
|
-
// XXX: This action will be fired when a Bluetooth headset is
|
|
92
|
-
// connected or disconnected to the system. This is not related to
|
|
93
|
-
// audio routing.
|
|
94
|
-
int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, -99);
|
|
95
|
-
|
|
96
|
-
switch (state) {
|
|
97
|
-
case BluetoothHeadset.STATE_CONNECTED:
|
|
98
|
-
case BluetoothHeadset.STATE_DISCONNECTED:
|
|
99
|
-
Log.d(TAG , " BT headset connection state changed: " + state);
|
|
100
|
-
updateDevices();
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
} else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)) {
|
|
104
|
-
// XXX: This action will be fired when the connection established
|
|
105
|
-
// with a Bluetooth headset (called a SCO connection) changes state.
|
|
106
|
-
// When the SCO connection is active we route audio to it.
|
|
107
|
-
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -99);
|
|
108
|
-
|
|
109
|
-
switch (state) {
|
|
110
|
-
case AudioManager.SCO_AUDIO_STATE_CONNECTED:
|
|
111
|
-
case AudioManager.SCO_AUDIO_STATE_DISCONNECTED:
|
|
112
|
-
Log.d(TAG , " BT SCO connection state changed: " + state);
|
|
113
|
-
updateDevices();
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private void registerBluetoothReceiver() {
|
|
120
|
-
receiver = new BroadcastReceiver() {
|
|
121
|
-
@Override
|
|
122
|
-
public void onReceive(Context context, Intent intent) {
|
|
123
|
-
onBluetoothReceiverReceive(context, intent);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
IntentFilter filter = new IntentFilter();
|
|
128
|
-
filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
|
|
129
|
-
filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
|
|
130
|
-
|
|
131
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
132
|
-
context.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
|
|
133
|
-
} else {
|
|
134
|
-
context.registerReceiver(receiver, filter);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Detects if there are new devices connected / disconnected and fires the
|
|
140
|
-
* {@link Listener} registered event.
|
|
141
|
-
*/
|
|
142
|
-
private void updateDevices() {
|
|
143
|
-
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
|
|
144
|
-
Log.w(TAG, "BLUETOOTH_CONNECT permission not granted. Unable to update Bluetooth devices.");
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
boolean headsetAvailable = (headset != null) && !headset.getConnectedDevices().isEmpty();
|
|
148
|
-
listener.onBluetoothDeviceChange(headsetAvailable);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public void start() {
|
|
152
|
-
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
153
|
-
|
|
154
|
-
if (!audioManager.isBluetoothScoAvailableOffCall()) {
|
|
155
|
-
Log.w(TAG , " Bluetooth SCO is not available");
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!getBluetoothHeadsetProfileProxy()) {
|
|
160
|
-
Log.w(TAG , " Couldn't get BT profile proxy");
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
registerBluetoothReceiver();
|
|
165
|
-
|
|
166
|
-
// Initial detection.
|
|
167
|
-
updateDevices();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public void stop() {
|
|
171
|
-
if (receiver != null) {
|
|
172
|
-
context.unregisterReceiver(receiver);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (adapter != null && headset != null) {
|
|
176
|
-
adapter.closeProfileProxy(BluetoothProfile.HEADSET, headset);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
receiver = null;
|
|
180
|
-
headset = null;
|
|
181
|
-
adapter = null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
interface Listener {
|
|
185
|
-
void onBluetoothDeviceChange(boolean deviceAvailable);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
package com.CometChatCalls;
|
|
2
|
-
|
|
3
|
-
import android.app.Notification;
|
|
4
|
-
import android.app.NotificationChannel;
|
|
5
|
-
import android.app.NotificationManager;
|
|
6
|
-
import android.app.PendingIntent;
|
|
7
|
-
import android.app.Service;
|
|
8
|
-
import android.content.Intent;
|
|
9
|
-
import android.content.pm.ServiceInfo;
|
|
10
|
-
import android.os.Build;
|
|
11
|
-
import android.os.IBinder;
|
|
12
|
-
import android.util.Log;
|
|
13
|
-
|
|
14
|
-
import androidx.annotation.Nullable;
|
|
15
|
-
import androidx.annotation.RequiresApi;
|
|
16
|
-
import androidx.core.app.NotificationCompat;
|
|
17
|
-
|
|
18
|
-
public class CallNotificationService extends Service {
|
|
19
|
-
|
|
20
|
-
private static final String CHANNEL_ID = "CALL_NOTIFICATION_CHANNEL";
|
|
21
|
-
private static final int NOTIFICATION_ID = 1;
|
|
22
|
-
private static long startingTime = 0;
|
|
23
|
-
|
|
24
|
-
@Override
|
|
25
|
-
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
26
|
-
createNotificationChannel();
|
|
27
|
-
Intent notificationIntent = new Intent(this, CallNotificationService.class);
|
|
28
|
-
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
29
|
-
if (startingTime == 0) {
|
|
30
|
-
startingTime = System.currentTimeMillis();
|
|
31
|
-
}
|
|
32
|
-
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
|
|
33
|
-
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
34
|
-
.setContentTitle("Ongoing Call")
|
|
35
|
-
.setContentText("Tap to return to the call")
|
|
36
|
-
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
37
|
-
.setSmallIcon(R.drawable.callingcomponent_icons_headphones_pluged)
|
|
38
|
-
.setContentIntent(pendingIntent)
|
|
39
|
-
.setOngoing(true)
|
|
40
|
-
.setWhen(startingTime)
|
|
41
|
-
.setUsesChronometer(true)
|
|
42
|
-
.setAutoCancel(false)
|
|
43
|
-
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
44
|
-
.setOnlyAlertOnce(true)
|
|
45
|
-
.build();
|
|
46
|
-
|
|
47
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
48
|
-
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
|
|
49
|
-
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
|
50
|
-
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
|
|
51
|
-
} else {
|
|
52
|
-
startForeground(NOTIFICATION_ID, notification);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return START_NOT_STICKY;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@Override
|
|
59
|
-
public void onDestroy() {
|
|
60
|
-
super.onDestroy();
|
|
61
|
-
stopSelf();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
static void resetStartingTime() {
|
|
66
|
-
startingTime = 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@Override
|
|
70
|
-
public void onTaskRemoved(Intent rootIntent) {
|
|
71
|
-
super.onTaskRemoved(rootIntent);
|
|
72
|
-
stopSelf();
|
|
73
|
-
CallNotificationServiceModule.sendEvent("onTaskRemoved", "onTaskRemoved");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@Nullable
|
|
77
|
-
@Override
|
|
78
|
-
public IBinder onBind(Intent intent) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private void createNotificationChannel() {
|
|
83
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
84
|
-
NotificationChannel serviceChannel = new NotificationChannel(
|
|
85
|
-
CHANNEL_ID,
|
|
86
|
-
"Call Notification Service",
|
|
87
|
-
NotificationManager.IMPORTANCE_DEFAULT
|
|
88
|
-
);
|
|
89
|
-
NotificationManager manager = getSystemService(NotificationManager.class);
|
|
90
|
-
manager.createNotificationChannel(serviceChannel);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|