Permission Requests
Different call participants can have different capabilities and permissions. Depending on your app's requirements, some users might be able to request additional permissions during a call. More details about permissions here.
Consider the following custom implementation of CallViewModel that manages permision requests:
final class CustomCallViewModel: CallViewModel {
var permissionRequest: PermissionRequestEvent?
@Published var permissionPopupShown = false
func subscribeForPermissionsRequests() {
guard let call = call else { return }
Task {
for await request in call.subscribe(for: PermissionRequestEvent.self) {
self.permissionRequest = request
self.permissionPopupShown = true
}
}
}
func grantUserPermissions() async throws {
guard let request = permissionRequest else { return }
let permissionRequests = request.permissions.map { PermissionRequest(permission: $0, user: request.user.toUser, requestedAt: request.createdAt) }
for permissionRequest in permissionRequests {
try await call?.grant(request: permissionRequest)
}
}
}When a user asks for additional capabilities, the hosts of the call receive an event that they can react to (approve or deny the request). You can listen to these events by subscribing to the subscribe(for:) async stream:
func subscribeForPermissionsRequests() {
guard let call = call else { return }
Task {
for await request in call.subscribe(for: PermissionRequestEvent.self) {
self.permissionRequest = request
self.permissionPopupShown = true
}
}
}Call subscribeForPermissionsRequests() once the user has joined the call (for example, when the view model's callingState changes to .inCall), so that call is set. Each new request also sets permissionPopupShown to true, which presents the alert below.
The simplest way to present these is via alerts in SwiftUI, with two buttons for approving or denying the permission request.
struct CustomView: View {
@ObservedObject var viewModel: CustomCallViewModel
var body: some View {
YourHostView()
.alert(isPresented: $viewModel.permissionPopupShown) {
Alert(
title: Text("Permission request"),
message: Text("\(viewModel.permissionRequest?.user.name ?? "Someone") raised their hand to speak."),
primaryButton: .default(Text("Allow")) {
Task {
try await viewModel.grantUserPermissions()
}
},
secondaryButton: .cancel()
)
}
}
}Depending on your app's UI, you can also easily build a more customized version of this view.