@@ -151,9 +151,7 @@ class SIPUAHelper extends EventManager {
151151 _settings.sockets = < SIPUASocketInterface > [];
152152
153153 if (uaSettings.transportType == TransportType .TCP ) {
154- SIPUATcpSocket socket = SIPUATcpSocket (
155- uaSettings.host ?? '0.0.0.0' , uaSettings.port ?? '5060' ,
156- messageDelay: 1 );
154+ SIPUATcpSocket socket = SIPUATcpSocket (uaSettings.uri, messageDelay: 1 );
157155 _settings.sockets! .add (socket);
158156 }
159157
@@ -166,7 +164,7 @@ class SIPUAHelper extends EventManager {
166164 }
167165
168166 _settings.transportType = uaSettings.transportType! ;
169- _settings.uri = uaSettings.uri != null ? URI . parse (uaSettings.uri ! ) : null ;
167+ _settings.uri = uaSettings.uri;
170168 _settings.sip_message_delay = uaSettings.sip_message_delay;
171169 _settings.realm = uaSettings.realm;
172170 _settings.password = uaSettings.password;
@@ -186,9 +184,7 @@ class SIPUAHelper extends EventManager {
186184 uaSettings.sessionTimersRefreshMethod;
187185 _settings.instance_id = uaSettings.instanceId;
188186 _settings.registrar_server = uaSettings.registrarServer;
189- _settings.contact_uri = uaSettings.contact_uri != null
190- ? URI .parse (uaSettings.contact_uri! )
191- : null ;
187+ _settings.contact_uri = uaSettings.contact_uri;
192188 _settings.connection_recovery_max_interval =
193189 uaSettings.connectionRecoveryMaxInterval;
194190 _settings.connection_recovery_min_interval =
@@ -853,6 +849,50 @@ extension _IceTransportPolicyEncoding on IceTransportPolicy {
853849}
854850
855851class UaSettings {
852+ UaSettings ({
853+ required this .uri,
854+ this .register,
855+ this .register_expires,
856+ this .userAgent,
857+ this .webSocketUrl,
858+ this .realm,
859+ this .authorizationUser,
860+ this .password,
861+ this .ha1,
862+ this .displayName,
863+ this .instanceId,
864+ this .registrarServer,
865+ this .contact_uri,
866+ this .transportType,
867+ this .dtmfMode = DtmfMode .INFO ,
868+ this .sessionTimers = true ,
869+ this .iceGatheringTimeout = 500 ,
870+ this .connectionRecoveryMaxInterval = 30 ,
871+ this .connectionRecoveryMinInterval = 2 ,
872+ this .terminateOnMediaPortZero = false ,
873+ this .sip_message_delay = 0 ,
874+ this .iceServers = const < Map <String , String >> [
875+ < String , String > {'urls' : 'stun:stun.l.google.com:19302' },
876+ ],
877+ this .iceTransportPolicy,
878+ this .sessionTimersRefreshMethod = DartSIP_C .SipMethod .UPDATE ,
879+ }) {
880+ _validateUri (uri);
881+ }
882+ // Validate the URI (host, port, scheme) without assigning it
883+ static void _validateUri (URI uri) {
884+ if (uri.host == null || uri.host.isEmpty) {
885+ throw ArgumentError ('Invalid URI: Missing host' );
886+ }
887+ if (uri.port == null ) {
888+ throw ArgumentError ('Invalid URI: Missing port' );
889+ }
890+ if (uri.scheme == null || uri.scheme.isEmpty) {
891+ print ('URI: Missing scheme, adding sip' );
892+ uri.scheme = DartSIP_C .SIP ;
893+ }
894+ }
895+
856896 WebSocketSettings webSocketSettings = WebSocketSettings ();
857897 TcpSocketSettings tcpSocketSettings = TcpSocketSettings ();
858898
@@ -867,10 +907,8 @@ class UaSettings {
867907 RegisterParams registerParams = RegisterParams ();
868908
869909 /// `User Agent` field for sip message.
910+ final URI uri;
870911 String ? userAgent;
871- String ? host;
872- String ? port;
873- String ? uri;
874912 String ? webSocketUrl;
875913 String ? realm;
876914 String ? authorizationUser;
@@ -879,7 +917,7 @@ class UaSettings {
879917 String ? displayName;
880918 String ? instanceId;
881919 String ? registrarServer;
882- String ? contact_uri;
920+ URI ? contact_uri;
883921
884922 TransportType ? transportType;
885923
0 commit comments