updatePermissionConfig function

Future<void> updatePermissionConfig(
  1. UpdatePermissionConfigOptions options
)

Updates the permission configuration for the room. Only hosts (islevel === "2") can update the configuration.

Example:

await updatePermissionConfig(UpdatePermissionConfigOptions(
  socket: socket,
  config: PermissionConfig(
    level0: PermissionCapabilities(useMic: "disallow", useCamera: "disallow", useScreen: "disallow", useChat: "allow"),
    level1: PermissionCapabilities(useMic: "allow", useCamera: "allow", useScreen: "allow", useChat: "allow"),
  ),
  member: "currentUser",
  islevel: "2",
  roomName: "room123",
  showAlert: (alert) => print(alert.message),
));

Implementation

Future<void> updatePermissionConfig(
    UpdatePermissionConfigOptions options) async {
  // Only hosts can update permission config
  if (options.islevel != "2") {
    options.showAlert?.call(
      message: "Only the host can update permission configuration",
      type: "danger",
      duration: 3000,
    );
    return;
  }

  final completer = Completer<void>();

  options.socket.emitWithAck("updatePermissionConfig", {
    'config': options.config.toJson(),
    'roomName': options.roomName,
  }, ack: (response) {
    if (response == null || response['success'] != true) {
      final reason = response?['reason'] ?? 'Unknown error';
      debugPrint('updatePermissionConfig failed: $reason');
      options.showAlert?.call(
        message: reason,
        type: "danger",
        duration: 3000,
      );
    } else {
      options.showAlert?.call(
        message: "Permission configuration updated",
        type: "success",
        duration: 3000,
      );
    }
    completer.complete();
  });

  return completer.future;
}