Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pc: handle PC initialization failures #1454

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,20 @@ private PeerConnection.RTCConfiguration parseRTCConfiguration(ReadableMap map) {
}

@ReactMethod(isBlockingSynchronousMethod = true)
public void peerConnectionInit(ReadableMap configuration, int id) {
public boolean peerConnectionInit(ReadableMap configuration, int id) {
PeerConnection.RTCConfiguration rtcConfiguration = parseRTCConfiguration(configuration);

try {
ThreadUtils
return (boolean) ThreadUtils
.submitToExecutor(() -> {
PeerConnectionObserver observer = new PeerConnectionObserver(this, id);
PeerConnection peerConnection = mFactory.createPeerConnection(rtcConfiguration, observer);
if (peerConnection == null) {
return false;
}
observer.setPeerConnection(peerConnection);
mPeerConnectionObservers.put(id, observer);
return true;
})
.get();
} catch (ExecutionException | InterruptedException e) {
Expand Down
14 changes: 10 additions & 4 deletions ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ @implementation WebRTCModule (RTCPeerConnection)
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionInit
: (RTCConfiguration *)configuration objectID
: (nonnull NSNumber *)objectID) {
__block BOOL ret = YES;

dispatch_sync(self.workerQueue, ^{
NSDictionary *optionalConstraints = @{@"DtlsSrtpKeyAgreement" : @"true"};
RTCMediaConstraints *constraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:optionalConstraints];
RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
optionalConstraints:nil];
RTCPeerConnection *peerConnection = [self.peerConnectionFactory peerConnectionWithConfiguration:configuration
constraints:constraints
delegate:self];
if (peerConnection == nil) {
ret = NO;
return;
}

peerConnection.dataChannels = [NSMutableDictionary new];
peerConnection.reactTag = objectID;
peerConnection.remoteStreams = [NSMutableDictionary new];
Expand All @@ -93,7 +99,7 @@ @implementation WebRTCModule (RTCPeerConnection)
self.peerConnections[objectID] = peerConnection;
});

return nil;
return @(ret);
}

RCT_EXPORT_METHOD(peerConnectionSetConfiguration
Expand Down
5 changes: 4 additions & 1 deletion src/RTCPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default class RTCPeerConnection extends EventTarget<RTCPeerConnectionEven
super();

this._pcId = nextPeerConnectionId++;
WebRTCModule.peerConnectionInit(configuration, this._pcId);

if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) {
throw new Error('Failed to initialize PeerConnection, check the native logs!');
}

this._transceivers = [];
this._remoteStreams = new Map();
Expand Down