Skip to content

Commit 9ffdd6f

Browse files
committed
ios: Add helper methods to access RTCAudioSession.audioSessionDidActivate and deactivate
1 parent 1121257 commit 9ffdd6f

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

Documentation/iOSInstallation.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@ Navigate to `<ProjectFolder>/ios/<ProjectName>/` and edit `Info.plist`, add the
2626
<string>Microphone permission description</string>
2727
```
2828

29+
## CallKit
30+
31+
If your app uses a CallKit integration to handle incoming calls, then your
32+
CXProviderDelegate should call through to `RTCAudioSession.sharedInstance.audioSessionDidActivate/Deactivate` accordingly.
33+
34+
```
35+
#import <WebRTC/RTCAudioSession.h>
36+
37+
- (void) provider:(CXProvider *) provider didActivateAudioSession:(AVAudioSession *) audioSession {
38+
[[RTCAudioSession sharedInstance] audioSessionDidActivate:[AVAudioSession sharedInstance]];
39+
}
40+
41+
- (void) provider:(CXProvider *) provider didDeactivateAudioSession:(AVAudioSession *) audioSession {
42+
[[RTCAudioSession sharedInstance] audioSessionDidDeactivate:[AVAudioSession sharedInstance]];
43+
}
44+
```
45+
46+
Javascript methods are also provided to call these methods:
47+
48+
```
49+
import { RTCAudioSession } from '@livekit/react-native-webrtc'
50+
51+
// Call as needed.
52+
RTCAudioSession.audioSessionDidActivate();
53+
RTCAudioSession.audioSessionDidDeactivate();
54+
```
55+
2956
## Library not loaded/Code signature invalid
3057

3158
This is an issue with iOS 13.3.1.

ios/RCTWebRTC.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
4EE3A8D425B841DD00FAA24A /* ScreenCapturer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EE3A8CD25B841DD00FAA24A /* ScreenCapturer.m */; };
2525
D3FF699919D2664B25C9D458 /* Pods_RCTWebRTC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A20F721AD842563B66292D5B /* Pods_RCTWebRTC.framework */; };
2626
D74EF94829652169000742E1 /* TrackCapturerEventsEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = D74EF94629652169000742E1 /* TrackCapturerEventsEmitter.m */; };
27+
D7F0711E2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m in Sources */ = {isa = PBXBuildFile; fileRef = D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */; };
2728
DEC96577264176C10052DB35 /* DataChannelWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = DEC96576264176C10052DB35 /* DataChannelWrapper.m */; };
2829
/* End PBXBuildFile section */
2930

@@ -75,6 +76,7 @@
7576
D74EF94529652148000742E1 /* CapturerEventsDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CapturerEventsDelegate.h; path = RCTWebRTC/CapturerEventsDelegate.h; sourceTree = SOURCE_ROOT; };
7677
D74EF94629652169000742E1 /* TrackCapturerEventsEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TrackCapturerEventsEmitter.m; path = RCTWebRTC/TrackCapturerEventsEmitter.m; sourceTree = SOURCE_ROOT; };
7778
D74EF94729652169000742E1 /* TrackCapturerEventsEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TrackCapturerEventsEmitter.h; path = RCTWebRTC/TrackCapturerEventsEmitter.h; sourceTree = SOURCE_ROOT; };
79+
D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "WebRTCModule+RTCAudioSession.m"; path = "RCTWebRTC/WebRTCModule+RTCAudioSession.m"; sourceTree = SOURCE_ROOT; };
7880
D7F99C122938F4E0000A2450 /* WebRTCModule+RTCMediaStream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "WebRTCModule+RTCMediaStream.h"; path = "RCTWebRTC/WebRTCModule+RTCMediaStream.h"; sourceTree = SOURCE_ROOT; };
7981
DEC96576264176C10052DB35 /* DataChannelWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = DataChannelWrapper.m; path = RCTWebRTC/DataChannelWrapper.m; sourceTree = "<group>"; };
8082
DEC96579264176DF0052DB35 /* DataChannelWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DataChannelWrapper.h; path = RCTWebRTC/DataChannelWrapper.h; sourceTree = "<group>"; };
@@ -131,6 +133,7 @@
131133
4EE3A8AF25B8413200FAA24A /* VideoCaptureController.h */,
132134
0BDDA6DF20C18B6B00B38B45 /* VideoCaptureController.m */,
133135
4EE3A8B525B8414A00FAA24A /* WebRTCModule+Permissions.m */,
136+
D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */,
134137
4EE3A8B825B8415900FAA24A /* WebRTCModule+RTCDataChannel.h */,
135138
4EE3A8B925B8415900FAA24A /* WebRTCModule+RTCDataChannel.m */,
136139
D7F99C122938F4E0000A2450 /* WebRTCModule+RTCMediaStream.h */,
@@ -262,6 +265,7 @@
262265
4EC498BC25B8777F00E76218 /* ScreenCapturePickerViewManager.m in Sources */,
263266
4EE3A8B225B8414000FAA24A /* WebRTCModule.m in Sources */,
264267
4EE3A8D225B841DD00FAA24A /* CaptureController.m in Sources */,
268+
D7F0711E2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m in Sources */,
265269
D74EF94829652169000742E1 /* TrackCapturerEventsEmitter.m in Sources */,
266270
4EE3A8D125B841DD00FAA24A /* SocketConnection.m in Sources */,
267271
4EE3A8BD25B8416500FAA24A /* WebRTCModule+RTCMediaStream.m in Sources */,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#import <objc/runtime.h>
2+
3+
#import <React/RCTBridge.h>
4+
#import <React/RCTBridgeModule.h>
5+
6+
#import "WebRTCModule.h"
7+
8+
@implementation WebRTCModule (RTCAudioSession)
9+
10+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidActivate) {
11+
[[RTCAudioSession sharedInstance] audioSessionDidActivate:[AVAudioSession sharedInstance]];
12+
return nil;
13+
}
14+
15+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidDeactivate) {
16+
[[RTCAudioSession sharedInstance] audioSessionDidDeactivate:[AVAudioSession sharedInstance]];
17+
return nil;
18+
}
19+
20+
@end

src/RTCAudioSession.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NativeModules, Platform } from 'react-native';
2+
3+
const { WebRTCModule } = NativeModules;
4+
5+
export default class RTCAudioSession {
6+
/**
7+
* To be called when CallKit activates the audio session.
8+
*/
9+
static audioSessionDidActivate() {
10+
// Only valid for iOS
11+
if (Platform.OS === "ios") {
12+
WebRTCModule.audioSessionDidActivate()
13+
}
14+
}
15+
16+
/**
17+
* To be called when CallKit deactivates the audio session.
18+
*/
19+
static audioSessionDidDeactivate() {
20+
// Only valid for iOS
21+
if (Platform.OS === "ios") {
22+
WebRTCModule.audioSessionDidDeactivate()
23+
}
24+
}
25+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import MediaStream from './MediaStream';
1515
import MediaStreamTrack from './MediaStreamTrack';
1616
import MediaStreamTrackEvent from './MediaStreamTrackEvent';
1717
import permissions from './Permissions';
18+
import RTCAudioSession from './RTCAudioSession';
1819
import RTCErrorEvent from './RTCErrorEvent';
1920
import RTCIceCandidate from './RTCIceCandidate';
2021
import RTCPeerConnection from './RTCPeerConnection';
@@ -40,6 +41,7 @@ export {
4041
RTCRtpReceiver,
4142
RTCRtpSender,
4243
RTCErrorEvent,
44+
RTCAudioSession,
4345
MediaStream,
4446
MediaStreamTrack,
4547
mediaDevices,

0 commit comments

Comments
 (0)