register static method
Register with SIP server
Example:
await VoipPlugin.register(
domain: 'sip.example.com',
username: '1001',
password: 'password123',
realm: 'wss://ws.example.com',
callerId: 'John Doe',
);
Implementation
static Future<bool> register({
required String domain,
required String username,
required String password,
String? realm,
String? callerId,
String? displayName,
int port = 5060,
bool useWebSocket = false,
}) async {
if (!_initialized) {
await initialize();
}
try {
debugPrint('═══════════════════════════════════════');
debugPrint('📝 VoIP PLUGIN: REGISTERING');
debugPrint('═══════════════════════════════════════');
debugPrint('Domain: $domain');
debugPrint('Username: $username');
debugPrint('Realm: ${realm ?? "Not set"}');
debugPrint('═══════════════════════════════════════');
// Auto-detect WebSocket if realm is provided
final isWebSocket = useWebSocket || (realm != null &&
(realm.startsWith('ws://') || realm.startsWith('wss://')));
final success = await SipService.register(
username: username,
password: password,
domain: domain,
realm: realm,
displayName: displayName ?? callerId,
callerId: callerId,
sendAs: callerId,
useWebSocket: isWebSocket,
wsUrl: isWebSocket ? realm : null,
);
if (success) {
debugPrint('✅ Registration initiated');
} else {
debugPrint('❌ Registration failed');
}
return success;
} catch (e, stackTrace) {
debugPrint('❌ Registration error: $e');
debugPrint('Stack trace: $stackTrace');
return false;
}
}