Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A dart-lang version of the SIP UA stack, ported from [JsSIP](https://github.com/
- SIP over WebSocket (use real SIP in your flutter mobile, [desktop](https://flutter.dev/desktop), [web](https://flutter.dev/web) apps)
- Audio/video calls ([flutter-webrtc](https://github.com/cloudwebrtc/flutter-webrtc)) and instant messaging
- Support with standard SIP servers such as OpenSIPS, Kamailio, Asterisk and FreeSWITCH.
- RFC8599 Push Notification Support using Contact Params - https://tools.ietf.org/html/rfc8599#section-4

## Currently supported platforms
- [X] iOS
Expand Down
16 changes: 16 additions & 0 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Settings {
// Registration parameters.
var register = true;
var register_expires = 600;
var register_extra_headers = null;
var register_extra_contact_params = null;
var registrar_server = null;

// Connection options.
Expand Down Expand Up @@ -211,6 +213,20 @@ class Checks {
dst.register_expires = register_expires;
}
},
'register_extra_headers': (src, dst) {
var register_extra_headers = src.register_extra_headers;
if (register_extra_headers == null) return;
if (register_extra_headers is List<String>) {
dst.register_extra_headers = register_extra_headers;
}
},
'register_extra_contact_params': (src, dst) {
var register_extra_contact_params = src.register_extra_contact_params;
if (register_extra_contact_params == null) return;
if (register_extra_contact_params is Map<String, dynamic>) {
dst.register_extra_contact_params = register_extra_contact_params;
}
},
'registrar_server': (src, dst) {
var registrar_server = src.registrar_server;
if (registrar_server == null) return;
Expand Down
16 changes: 10 additions & 6 deletions lib/src/registrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class Registrator {
this._contact += ';+sip.ice';

// Custom headers for REGISTER and un-REGISTER.
this._extraHeaders = [];
this.setExtraHeaders(ua.configuration.register_extra_headers);

// Custom Contact header params for REGISTER and un-REGISTER.
this._extraContactParams = '';
this.setExtraContactParams(ua.configuration.register_extra_contact_params);

if (reg_id != null) {
this._contact += ';reg-id=${reg_id}';
Expand Down Expand Up @@ -111,7 +111,7 @@ class Registrator {
return;
}

var extraHeaders = _extraHeaders ?? [];
var extraHeaders = this._extraHeaders ?? [];

extraHeaders.add(
'Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}');
Expand All @@ -133,11 +133,15 @@ class Registrator {
EventManager localEventHandlers = EventManager();
localEventHandlers.on(EventOnRequestTimeout(),
(EventOnRequestTimeout value) {
this._registrationFailure(UnHandledResponse(408, DartSIP_C.causes.REQUEST_TIMEOUT), DartSIP_C.causes.REQUEST_TIMEOUT);
this._registrationFailure(
UnHandledResponse(408, DartSIP_C.causes.REQUEST_TIMEOUT),
DartSIP_C.causes.REQUEST_TIMEOUT);
});
localEventHandlers.on(EventOnTransportError(),
(EventOnTransportError value) {
this._registrationFailure(UnHandledResponse(500, DartSIP_C.causes.CONNECTION_ERROR), DartSIP_C.causes.CONNECTION_ERROR);
this._registrationFailure(
UnHandledResponse(500, DartSIP_C.causes.CONNECTION_ERROR),
DartSIP_C.causes.CONNECTION_ERROR);
});
localEventHandlers.on(EventOnAuthenticated(), (EventOnAuthenticated value) {
this._cseq += 1;
Expand Down Expand Up @@ -274,7 +278,7 @@ class Registrator {
this._registrationTimer = null;
}

var extraHeaders = _extraHeaders ?? [];
var extraHeaders = this._extraHeaders ?? [];

if (unregister_all) {
extraHeaders.add('Contact: *${this._extraContactParams}');
Expand Down
14 changes: 14 additions & 0 deletions lib/src/sip_ua_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class SIPUAHelper extends EventManager {
_settings.display_name = uaSettings.displayName;
_settings.authorization_user = uaSettings.authorizationUser;
_settings.user_agent = uaSettings.userAgent ?? DartSIP_C.USER_AGENT;
_settings.register_extra_headers = uaSettings.registerParams.extraHeaders;
_settings.register_extra_contact_params =
uaSettings.registerParams.extraContactParams;

try {
_ua = UA(_settings);
Expand Down Expand Up @@ -528,10 +531,21 @@ class WebSocketSettings {
bool allowBadCertificate = false;
}

class RegisterParams {
/// Allow extra headers and Contact Params to be sent on REGISTER
/// Mainly used for RFC8599 Support
/// https://github.com/cloudwebrtc/dart-sip-ua/issues/89
Map<String, dynamic> extraHeaders = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Settings.register_extera_headers type is List<String>, here the extraHeaders type should also be List<String>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, spotted that after. Reason to be a list?

Map<String, dynamic> extraContactParams = {};
}

class UaSettings {
String webSocketUrl;
WebSocketSettings webSocketSettings = WebSocketSettings();

/// Mainly used for RFC8599 Push Notification Support
RegisterParams registerParams = RegisterParams();

/// `User Agent` field for sip message.
String userAgent;
String uri;
Expand Down