getOnlineUserCount static method
Future<int?>
getOnlineUserCount({
- required dynamic onSuccess(
- int count
- required dynamic onError(
- CometChatException excep
get the total count of online users for your app
Get the count of online users.
Migration Note: Migrated from platform channels to native Dart implementation. Uses PresenceRepository for getting online user count. Behavior and signature remain identical for backward compatibility.
Android Reference: UsersRequest.getOnlineUserCount(CallbackListener<Integer>)
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<int?> getOnlineUserCount(
{required Function(int count)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart presence repository
final count = await sdk.presence.getOnlineUserCount();
// Call success callback
if (onSuccess != null) onSuccess(count);
return count;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}