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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ pubspec.lock
doc/api/
.DS_Store
example/lib/generated_plugin_registrant.dart

.flutter-plugins
.flutter-plugins-dependencies
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.flutter-plugins-dependencies
5 changes: 5 additions & 0 deletions example/lib/src/callscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,9 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
void onNewMessage(SIPMessageRequest msg) {
// NO OP
}

@override
void onNewNotify(Notify ntf) {
// TODO: implement onNewNotify
}
}
5 changes: 5 additions & 0 deletions example/lib/src/dialpad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,9 @@ class _MyDialPadWidget extends State<DialPadWidget>
receivedMsg = msgBody;
});
}

@override
void onNewNotify(Notify ntf) {
// TODO: implement onNewNotify
}
}
5 changes: 5 additions & 0 deletions example/lib/src/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,9 @@ class _MyRegisterWidget extends State<RegisterWidget>
void onNewMessage(SIPMessageRequest msg) {
// NO OP
}

@override
void onNewNotify(Notify ntf) {
// TODO: implement onNewNotify
}
}
2 changes: 1 addition & 1 deletion lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Map<int, String> REASON_PHRASE = <int, String>{
};

const String ALLOWED_METHODS =
'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO';
'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY';
const String ACCEPTED_BODY_TYPES = 'application/sdp, application/dtmf-relay';
const int MAX_FORWARDS = 69;
const int SESSION_EXPIRES = 90;
Expand Down
13 changes: 10 additions & 3 deletions lib/src/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Id {

// RFC 3261 12.1.
class Dialog {
Dialog(RTCSession owner, dynamic message, String type, [int? state]) {
Dialog(Owner owner, dynamic message, String type, [int? state]) {
state = state ?? DialogStatus.STATUS_CONFIRMED;
_owner = owner;
_ua = owner.ua;
Expand Down Expand Up @@ -91,7 +91,7 @@ class Dialog {
'$type dialog created with status ${_state == DialogStatus.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'}');
}

RTCSession? _owner;
Owner? _owner;
UA? _ua;
bool uac_pending_reply = false;
bool uas_pending_reply = false;
Expand All @@ -108,7 +108,7 @@ class Dialog {
UA? get ua => _ua;
Id? get id => _id;

RTCSession? get owner => _owner;
Owner? get owner => _owner;

void update(dynamic message, String type) {
_state = DialogStatus.STATUS_CONFIRMED;
Expand Down Expand Up @@ -263,3 +263,10 @@ class Dialog {
return true;
}
}

abstract class Owner {
Function(IncomingRequest) get receiveRequest;
int? get status;
int get TerminatedCode;
UA? get ua;
}
2 changes: 1 addition & 1 deletion lib/src/dialog/request_sender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DialogRequestSender {
_request.cseq = _dialog.local_seqnum!.toInt();
_reattemptTimer = setTimeout(() {
// TODO(cloudwebrtc): look at dialog state instead.
if (_dialog.owner!.status != RTCSession.C.STATUS_TERMINATED) {
if (_dialog.owner!.status != _dialog.owner!.TerminatedCode) {
_reattempt = true;
_request_sender.send();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/event_manager/internal_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ class EventOnErrorResponse extends EventType {
EventOnErrorResponse({this.response});
IncomingMessage? response;
}

class EventOnNewSubscribe extends EventType {
EventOnNewSubscribe({this.request});
IncomingRequest? request;
}
18 changes: 18 additions & 0 deletions lib/src/event_manager/notifier_events.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:sip_ua/src/sip_message.dart';

import 'events.dart';

class EventTerminated extends EventType {
EventTerminated({this.terminationCode, this.sendFinalNotify});
int? terminationCode;
bool? sendFinalNotify;
}

class EventSubscribe extends EventType {
EventSubscribe(
{this.isUnsubscribe, this.request, this.body, this.content_type});
bool? isUnsubscribe;
IncomingRequest? request;
String? body;
String? content_type;
}
23 changes: 23 additions & 0 deletions lib/src/event_manager/subscriber_events.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import '../sip_message.dart';
import 'events.dart';

class EventTerminated extends EventType {
EventTerminated({this.TerminationCode, this.reason, this.retryAfter});
int? TerminationCode;
String? reason;
int? retryAfter;
}

class EventPending extends EventType {}

class EventActive extends EventType {}

class EventNotify extends EventType {
EventNotify({this.isFinal, this.request, this.body, this.contentType});
bool? isFinal;
IncomingRequest? request;
String? body;
String? contentType;
}

class EventAccepted extends EventType {}
4 changes: 2 additions & 2 deletions lib/src/grammar_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17093,7 +17093,7 @@ class GrammarParser {
_failure(_expect85);
}
if (success) {
final $1 = $$;
final $1 = $$[2];
final $start = startPos1;
var pos0 = _startPos;
$$ = ((offset, expires) {
Expand Down Expand Up @@ -22438,7 +22438,7 @@ class GrammarParser {
if (!success && _cursor > _testing) {
_failure(_expect115);
}
return $$;
return data;
}

dynamic parse_Supported() {
Expand Down
5 changes: 4 additions & 1 deletion lib/src/rtc_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class RFC4028Timers {
Timer? timer;
}

class RTCSession extends EventManager {
class RTCSession extends EventManager implements Owner {
RTCSession(UA? ua) {
logger.debug('new');

Expand Down Expand Up @@ -195,6 +195,9 @@ class RTCSession extends EventManager {

RTCPeerConnection? get connection => _connection;

@override
int get TerminatedCode => C.STATUS_TERMINATED;

RTCDTMFSender get dtmfSender =>
_connection!.createDtmfSender(_localMediaStream!.getAudioTracks()[0]);

Expand Down
31 changes: 28 additions & 3 deletions lib/src/sip_ua_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import 'dart:async';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:logger/logger.dart';

import 'package:sip_ua/src/rtc_session/refer_subscriber.dart';
import 'config.dart';
import 'constants.dart' as DartSIP_C;
import 'event_manager/event_manager.dart';
import 'event_manager/subscriber_events.dart';
import 'logger.dart';
import 'message.dart';
import 'rtc_session.dart';
import 'rtc_session/refer_subscriber.dart';
import 'sip_message.dart';
import 'stack_trace_nj.dart';
import 'subscriber.dart';
import 'transports/websocket_interface.dart';
import 'ua.dart';

Expand Down Expand Up @@ -328,6 +331,16 @@ class SIPUAHelper extends EventManager {
return _ua!.sendMessage(target, body, options);
}

void subscribe(String target, String event, String contentType) {
Subscriber s = _ua!.subscribe(target, event, contentType);

s.on(EventNotify(), (EventNotify event) {
_notifyNotifyListeners(event);
});

s.subscribe();
}

void terminateSessions(Map<String, dynamic> options) {
_ua!.terminateSessions(options as Map<String, Object>);
}
Expand Down Expand Up @@ -372,6 +385,12 @@ class SIPUAHelper extends EventManager {
listener.onNewMessage(msg);
}
}

void _notifyNotifyListeners(EventNotify event) {
for (SipUaHelperListener listener in _sipUaHelperListeners) {
listener.onNewNotify(Notify(request: event.request));
}
}
}

enum CallStateEnum {
Expand Down Expand Up @@ -422,7 +441,7 @@ class Call {

void hangup([Map<String, dynamic>? options]) {
assert(_session != null, 'ERROR(hangup): rtc session is invalid!');
_session.terminate(options as Map<String, Object>?);
_session.terminate(options);
}

void hold() {
Expand Down Expand Up @@ -584,8 +603,14 @@ abstract class SipUaHelperListener {
void transportStateChanged(TransportState state);
void registrationStateChanged(RegistrationState state);
void callStateChanged(Call call, CallState state);
//For SIP messaga coming
//For SIP message coming
void onNewMessage(SIPMessageRequest msg);
void onNewNotify(Notify ntf);
}

class Notify {
Notify({this.request});
IncomingRequest? request;
}

class RegisterParams {
Expand Down
Loading