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

VoIP: Use Tracks Instead of Transceivers #969

Merged
merged 8 commits into from
Dec 9, 2020
Merged
Changes from 2 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
40 changes: 32 additions & 8 deletions MatrixSDKExtensions/VoIP/Jingle/MXJingleCallStackCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "MXJingleCameraCaptureController.h"
#import <WebRTC/WebRTC.h>

NSString *const kMXJingleCallWebRTCMainStreamID = @"ARDAMS";
NSString *const kMXJingleCallWebRTCMainStreamID = @"userMedia";

@interface MXJingleCallStackCall () <RTCPeerConnectionDelegate>
{
Expand Down Expand Up @@ -312,6 +312,9 @@ - (void)createAnswer:(void (^)(NSString *))success failure:(void (^)(NSError *))

});

// check we can consider this call as held, after setting local description
[self checkTheCallIsOnHold];

}];
}
else
Expand Down Expand Up @@ -415,12 +418,6 @@ - (void)peerConnection:(RTCPeerConnection *)peerConnection
didRemoveStream:(RTCMediaStream *)stream
{
NSLog(@"[MXJingleCallStackCall] didRemoveStream");

// TODO: Check this stream has the main stream ID (kMXJingleCallWebRTCMainStreamID) after all platforms decided to use the same stream id.

dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate callStackCallDidHold:self];
});
}

- (void)peerConnection:(RTCPeerConnection *)peerConnection didAddReceiver:(RTCRtpReceiver *)rtpReceiver streams:(NSArray<RTCMediaStream *> *)mediaStreams
Expand Down Expand Up @@ -602,7 +599,34 @@ - (void)setCameraPosition:(AVCaptureDevicePosition)theCameraPosition

#pragma mark - Private methods

// Not used for now, will be in future
- (void)checkTheCallIsOnHold
{
NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *activeReceivers = [self->peerConnection.transceivers filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver, NSDictionary<NSString *,id> * _Nullable bindings) {

RTCRtpTransceiverDirection direction = RTCRtpTransceiverDirectionStopped;
if ([transceiver currentDirection:&direction])
{
if (direction == RTCRtpTransceiverDirectionInactive ||
direction == RTCRtpTransceiverDirectionSendOnly ||
direction == RTCRtpTransceiverDirectionStopped)
{
return NO;
}
}

return YES;
}]];

// if there is no active receivers left, we can say this call is holded
if (activeReceivers.count == 0)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate callStackCallDidHold:self];
ismailgulek marked this conversation as resolved.
Show resolved Hide resolved
});
}
}

// Not used for now, may be in future
- (BOOL)isHoldOffer:(NSString *)sdpOffer
{
NSUInteger numberOfAudioTracks = [self numberOfMatchesOfKeyword:@"m=audio" inString:sdpOffer];
Expand Down