register static method

Future<bool> register({
  1. required String domain,
  2. required String username,
  3. required String password,
  4. String? realm,
  5. String? callerId,
  6. String? displayName,
  7. int port = 5060,
  8. bool useWebSocket = false,
})

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;
  }
}