@cometchat/calls-sdk-react-native 5.0.0 → 5.0.2-beta.1

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.
@@ -20,7 +20,35 @@
20
20
 
21
21
  @interface CometChatAudioSession : NSObject
22
22
 
23
+ /**
24
+ * Enables or disables manual audio session management, for use with CallKit.
25
+ *
26
+ * When enabled, WebRTC no longer activates the audio session on its own:
27
+ * audio stays disabled (`isAudioEnabled == NO`) until the system activates
28
+ * the audio session and `activateWithAudioSession:` is called from
29
+ * `CXProviderDelegate`'s `provider:didActivateAudioSession:`.
30
+ *
31
+ * Enable this before reporting the call to CallKit (before requesting the
32
+ * `CXStartCallAction`/`CXAnswerCallAction`), and disable it when the call
33
+ * ends so that non-CallKit calls keep working.
34
+ */
35
+ + (void)setUseManualAudio:(BOOL)useManualAudio;
36
+
37
+ /**
38
+ * Whether manual audio session management is currently enabled.
39
+ */
40
+ + (BOOL)useManualAudio;
41
+
42
+ /**
43
+ * Call from `CXProviderDelegate`'s `provider:didActivateAudioSession:`.
44
+ * Hands the CallKit-activated session over to WebRTC and enables audio.
45
+ */
23
46
  + (void)activateWithAudioSession:(AVAudioSession *)session;
47
+
48
+ /**
49
+ * Call from `CXProviderDelegate`'s `provider:didDeactivateAudioSession:`.
50
+ * Disables audio and notifies WebRTC that the session was deactivated.
51
+ */
24
52
  + (void)deactivateWithAudioSession:(AVAudioSession *)session;
25
53
 
26
54
  @end
@@ -24,12 +24,37 @@
24
24
  return [RTCAudioSession sharedInstance];
25
25
  }
26
26
 
27
+ + (void)setUseManualAudio:(BOOL)useManualAudio {
28
+ RTCAudioSession *rtcAudioSession = self.rtcAudioSession;
29
+ rtcAudioSession.useManualAudio = useManualAudio;
30
+ // Audio stays disabled until the session is activated by the system
31
+ // and handed over via activateWithAudioSession:.
32
+ rtcAudioSession.isAudioEnabled = NO;
33
+ }
34
+
35
+ + (BOOL)useManualAudio {
36
+ return self.rtcAudioSession.useManualAudio;
37
+ }
38
+
27
39
  + (void)activateWithAudioSession:(AVAudioSession *)session {
28
- [self.rtcAudioSession audioSessionDidActivate:session];
40
+ RTCAudioSession *rtcAudioSession = self.rtcAudioSession;
41
+ // In manual audio mode WebRTC no longer configures the session itself,
42
+ // so apply its configuration to the CallKit-activated session here.
43
+ // It must be WebRTC's own configuration object: configuring the session
44
+ // any other way (or anywhere earlier, e.g. before requesting the
45
+ // CXStartCallAction) desyncs the CallKit UI's audio route button.
46
+ RTCAudioSessionConfiguration *config = [RTCAudioSessionConfiguration webRTCConfiguration];
47
+ [rtcAudioSession lockForConfiguration];
48
+ [rtcAudioSession setConfiguration:config error:nil];
49
+ [rtcAudioSession unlockForConfiguration];
50
+ [rtcAudioSession audioSessionDidActivate:session];
51
+ rtcAudioSession.isAudioEnabled = YES;
29
52
  }
30
53
 
31
54
  + (void)deactivateWithAudioSession:(AVAudioSession *)session {
32
- [self.rtcAudioSession audioSessionDidDeactivate:session];
55
+ RTCAudioSession *rtcAudioSession = self.rtcAudioSession;
56
+ rtcAudioSession.isAudioEnabled = NO;
57
+ [rtcAudioSession audioSessionDidDeactivate:session];
33
58
  }
34
59
 
35
60
  @end
@@ -95,14 +95,25 @@ RCT_EXPORT_MODULE();
95
95
 
96
96
  audioCallConfig = [[RTCAudioSessionConfiguration alloc] init];
97
97
  audioCallConfig.category = AVAudioSessionCategoryPlayAndRecord;
98
- audioCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionDefaultToSpeaker;
98
+ audioCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
99
99
  audioCallConfig.mode = AVAudioSessionModeVoiceChat;
100
100
 
101
101
  videoCallConfig = [[RTCAudioSessionConfiguration alloc] init];
102
102
  videoCallConfig.category = AVAudioSessionCategoryPlayAndRecord;
103
- videoCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth;
103
+ videoCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
104
104
  videoCallConfig.mode = AVAudioSessionModeVideoChat;
105
105
 
106
+ // Keep WebRTC's own configuration in sync with the audio-call
107
+ // profile. WebRTC (re)applies this object whenever it configures the
108
+ // session internally, and CometChatAudioSession applies it on CallKit
109
+ // activation; if it drifted from the configs above, every internal
110
+ // reconfiguration would change the category options on a live
111
+ // session and desync the CallKit UI's audio route button.
112
+ RTCAudioSessionConfiguration *webRTCConfig = [RTCAudioSessionConfiguration webRTCConfiguration];
113
+ webRTCConfig.category = AVAudioSessionCategoryPlayAndRecord;
114
+ webRTCConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
115
+ webRTCConfig.mode = AVAudioSessionModeVoiceChat;
116
+
106
117
  // Manually routing audio to the earpiece doesn't quite work unless one disables BT (weird, I know).
107
118
  earpieceConfig = [[RTCAudioSessionConfiguration alloc] init];
108
119
  earpieceConfig.category = AVAudioSessionCategoryPlayAndRecord;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/calls-sdk-react-native",
3
- "version": "5.0.0",
3
+ "version": "5.0.2-beta.1",
4
4
  "description": "CometChat Calls SDK for React Native provides voice and video calling capabilities for React Native applications.",
5
5
  "private": false,
6
6
  "main": "dist/index.js",