@@ -151,9 +151,7 @@ class SIPUAHelper extends EventManager {
151
151
_settings.sockets = < SIPUASocketInterface > [];
152
152
153
153
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 );
157
155
_settings.sockets! .add (socket);
158
156
}
159
157
@@ -166,7 +164,7 @@ class SIPUAHelper extends EventManager {
166
164
}
167
165
168
166
_settings.transportType = uaSettings.transportType! ;
169
- _settings.uri = uaSettings.uri != null ? URI . parse (uaSettings.uri ! ) : null ;
167
+ _settings.uri = uaSettings.uri;
170
168
_settings.sip_message_delay = uaSettings.sip_message_delay;
171
169
_settings.realm = uaSettings.realm;
172
170
_settings.password = uaSettings.password;
@@ -186,9 +184,7 @@ class SIPUAHelper extends EventManager {
186
184
uaSettings.sessionTimersRefreshMethod;
187
185
_settings.instance_id = uaSettings.instanceId;
188
186
_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;
192
188
_settings.connection_recovery_max_interval =
193
189
uaSettings.connectionRecoveryMaxInterval;
194
190
_settings.connection_recovery_min_interval =
@@ -853,6 +849,50 @@ extension _IceTransportPolicyEncoding on IceTransportPolicy {
853
849
}
854
850
855
851
class 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
+
856
896
WebSocketSettings webSocketSettings = WebSocketSettings ();
857
897
TcpSocketSettings tcpSocketSettings = TcpSocketSettings ();
858
898
@@ -867,10 +907,8 @@ class UaSettings {
867
907
RegisterParams registerParams = RegisterParams ();
868
908
869
909
/// `User Agent` field for sip message.
910
+ final URI uri;
870
911
String ? userAgent;
871
- String ? host;
872
- String ? port;
873
- String ? uri;
874
912
String ? webSocketUrl;
875
913
String ? realm;
876
914
String ? authorizationUser;
@@ -879,7 +917,7 @@ class UaSettings {
879
917
String ? displayName;
880
918
String ? instanceId;
881
919
String ? registrarServer;
882
- String ? contact_uri;
920
+ URI ? contact_uri;
883
921
884
922
TransportType ? transportType;
885
923
0 commit comments