addPanelist function
- AddPanelistOptions options
Adds a participant to the panelist list. Respects the maximum panelist limit.
Returns true if added successfully, false otherwise.
Example:
final success = await addPanelist(AddPanelistOptions(
socket: socket,
participant: Participant(id: "123", name: "John"),
currentPanelists: [],
maxPanelists: 10,
roomName: "room123",
member: "currentUser",
islevel: "2",
showAlert: (alert) => print(alert.message),
));
Implementation
Future<bool> addPanelist(AddPanelistOptions options) async {
// Only hosts can add panelists
if (options.islevel != "2") {
options.showAlert?.call(
message: "Only the host can add panelists",
type: "danger",
duration: 3000,
);
return false;
}
// Check if already a panelist
if (options.currentPanelists.any((p) => p.id == options.participant.id)) {
options.showAlert?.call(
message: "${options.participant.name} is already a panelist",
type: "info",
duration: 3000,
);
return false;
}
// Check max limit
if (options.currentPanelists.length >= options.maxPanelists) {
options.showAlert?.call(
message: "Maximum panelist limit (${options.maxPanelists}) reached",
type: "danger",
duration: 3000,
);
return false;
}
final completer = Completer<bool>();
options.socket.emitWithAck("addPanelist", {
'participantId': options.participant.id,
'participantName': options.participant.name,
'roomName': options.roomName,
}, ack: (response) {
if (response == null || response['success'] != true) {
final reason = response?['reason'] ?? 'Unknown error';
debugPrint('addPanelist failed: $reason');
options.showAlert?.call(
message: reason,
type: "danger",
duration: 3000,
);
completer.complete(false);
} else {
completer.complete(true);
}
});
return completer.future;
}