Skip to content

Commit

Permalink
Merge pull request #1780 from nextcloud/check-microphone-permission-i…
Browse files Browse the repository at this point in the history
…n-call

Disable UI when microphone permission is missing
  • Loading branch information
SystemKeeper authored Aug 24, 2024
2 parents 416f844 + c51c4c8 commit a9f4fe7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion NextcloudTalk/CallViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2043,12 +2043,20 @@ - (void)callControllerDidDrawFirstLocalFrame:(NCCallController *)callController

- (void)callController:(NCCallController *)callController userPermissionsChanged:(NSInteger)permissions
{
[self setAudioMuteButtonEnabled:(permissions & NCPermissionCanPublishAudio)];
[self setAudioMuteButtonEnabled:(permissions & NCPermissionCanPublishAudio) && [callController isMicrophoneAccessAvailable]];
[self setVideoDisableButtonEnabled:((permissions & NCPermissionCanPublishVideo) && [callController isCameraAccessAvailable])];
}

- (void)callController:(NCCallController *)callController didCreateLocalAudioTrack:(RTCAudioTrack *)audioTrack
{
if (!audioTrack) {
// No audio track was created, probably because there are no publishing rights or microphone access was denied
[self setAudioMuteButtonEnabled:NO];
[self setAudioMuteButtonActive:NO];

return;
}

[self setAudioMuteButtonActive:audioTrack.isEnabled];
}

Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCCallController.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef void (^GetAudioEnabledStateCompletionBlock)(BOOL isEnabled);
- (void)enableBackgroundBlur:(BOOL)enable;
- (void)stopCapturing;
- (BOOL)isCameraAccessAvailable;
- (BOOL)isMicrophoneAccessAvailable;

- (void)willSwitchToCall:(NSString *)token;

Expand Down
10 changes: 9 additions & 1 deletion NextcloudTalk/NCCallController.m
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ - (BOOL)isCameraAccessAvailable {
return (authStatus == AVAuthorizationStatusAuthorized);
}

- (BOOL)isMicrophoneAccessAvailable
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
return (authStatus == AVAuthorizationStatusAuthorized);
}

- (void)stopCapturing
{
[self.cameraController stopAVCaptureSession];
Expand Down Expand Up @@ -864,7 +870,9 @@ - (void)createLocalMedia
self->_localAudioTrack = nil;
self->_localVideoTrack = nil;

if ((self->_userPermissions & NCPermissionCanPublishAudio) != 0 || !self->_serverSupportsConversationPermissions) {
BOOL hasPublishAudioPermission = ((self->_userPermissions & NCPermissionCanPublishAudio) != 0 || !self->_serverSupportsConversationPermissions);

if (hasPublishAudioPermission && [self isMicrophoneAccessAvailable]) {
[self createLocalAudioTrack];
} else {
[self.delegate callController:self didCreateLocalAudioTrack:nil];
Expand Down

0 comments on commit a9f4fe7

Please sign in to comment.