init method
Khởi tạo SDK với appKey, domain, và tự xác định platform
Implementation
Future<void> init({
required String appKey,
required String domain,
}) async {
if (_initialized) {
throw Exception('MiChat SDK has already been initialized.');
}
final platform = _detectPlatform();
final response = await _authenticateWithServer(appKey, domain, platform);
final success = response['success'] == true;
final code = response['code'] ?? 'unknown';
final type = response['type'] ?? 'Unknown';
final error = response['error'] ?? 'Unknown error';
if (!success) {
throw Exception(
'[$code - $type] Authentication failed: $error',
);
}
_appKey = appKey;
_domain = domain;
_platform = platform;
_chatUrl = response["url"].toString();
_initialized = true;
print('[MiChat] Init success on platform=${platform}. Url: ${chatUrl}.');
}