@cometchat/calls-sdk-react-native 4.1.0 → 4.2.0

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.
@@ -53,7 +53,7 @@ class AudioDeviceHandlerGeneric implements
53
53
  @Override
54
54
  public void run() {
55
55
  Set<String> devices = new HashSet<>();
56
- AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
56
+ AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
57
57
 
58
58
  for (AudioDeviceInfo info: deviceInfos) {
59
59
  switch (info.getType()) {
@@ -1,6 +1,7 @@
1
1
 
2
2
  package com.CometChatCalls;
3
3
 
4
+ import android.Manifest;
4
5
  import android.bluetooth.BluetoothAdapter;
5
6
  import android.bluetooth.BluetoothHeadset;
6
7
  import android.bluetooth.BluetoothProfile;
@@ -8,9 +9,13 @@ import android.content.BroadcastReceiver;
8
9
  import android.content.Context;
9
10
  import android.content.Intent;
10
11
  import android.content.IntentFilter;
12
+ import android.content.pm.PackageManager;
11
13
  import android.media.AudioManager;
14
+ import android.os.Build;
12
15
  import android.util.Log;
13
16
 
17
+ import androidx.core.app.ActivityCompat;
18
+
14
19
  /**
15
20
  * Helper class to detect and handle Bluetooth device changes. It monitors
16
21
  * Bluetooth headsets being connected / disconnected and notifies the module
@@ -123,7 +128,11 @@ class BluetoothHeadsetMonitor {
123
128
  filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
124
129
  filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
125
130
 
126
- context.registerReceiver(receiver, filter);
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
+ }
127
136
  }
128
137
 
129
138
  /**
@@ -131,6 +140,10 @@ class BluetoothHeadsetMonitor {
131
140
  * {@link Listener} registered event.
132
141
  */
133
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
+ }
134
147
  boolean headsetAvailable = (headset != null) && !headset.getConnectedDevices().isEmpty();
135
148
  listener.onBluetoothDeviceChange(headsetAvailable);
136
149
  }
@@ -39,7 +39,7 @@ public class CallNotificationServiceModule extends ReactContextBaseJavaModule {
39
39
  }
40
40
 
41
41
  @ReactMethod
42
- public static void stopService() {
42
+ public void stopService() {
43
43
  Intent serviceIntent = new Intent(reactContext, CallNotificationService.class);
44
44
  reactContext.stopService(serviceIntent);
45
45
  CallNotificationService.resetStartingTime();
@@ -38,6 +38,7 @@ public class CometChatCallsPackage implements ReactPackage {
38
38
  modules.add(new AudioModeModule(reactContext));
39
39
  modules.add(new CallNotificationServiceModule(reactContext));
40
40
  modules.add(new PictureInPictureModule(reactContext));
41
+ modules.add(new CometChatCommonModule(reactContext));
41
42
  return modules;
42
43
  }
43
44
 
@@ -0,0 +1,48 @@
1
+ package com.CometChatCalls;
2
+
3
+ import android.annotation.SuppressLint;
4
+ import android.app.Activity;
5
+ import android.content.Context;
6
+ import android.content.pm.ActivityInfo;
7
+
8
+ import androidx.annotation.NonNull;
9
+
10
+ import com.facebook.react.bridge.Promise;
11
+ import com.facebook.react.bridge.ReactApplicationContext;
12
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
13
+ import com.facebook.react.bridge.ReactMethod;
14
+
15
+ public class CometChatCommonModule extends ReactContextBaseJavaModule {
16
+ public static final String NAME = "CometChatCommonModule";
17
+ public static final String TAG = NAME;
18
+ private final ReactApplicationContext mReactContext;
19
+
20
+ public int appOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
21
+
22
+ public CometChatCommonModule(@NonNull ReactApplicationContext reactContext) {
23
+ super(reactContext);
24
+ mReactContext = reactContext;
25
+ }
26
+
27
+ @NonNull
28
+ @Override
29
+ public String getName() {
30
+ return NAME;
31
+ }
32
+
33
+ @SuppressLint("SourceLockedOrientationActivity")
34
+ @ReactMethod
35
+ public void lockToPortrait() {
36
+ Activity currentActivity = getCurrentActivity();
37
+ if (currentActivity == null) return;
38
+ this.appOrientation = currentActivity.getRequestedOrientation();
39
+ currentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
40
+ }
41
+
42
+ @ReactMethod
43
+ public void unlockAllOrientations() {
44
+ Activity currentActivity = getCurrentActivity();
45
+ if (currentActivity == null) return;
46
+ currentActivity.setRequestedOrientation(this.appOrientation);
47
+ }
48
+ }