Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace string enum usage with dart enums #479

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions example/lib/src/callscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
bool _speakerOn = false;
bool _hold = false;
bool _mirror = true;
String? _holdOriginator;
Originator? _holdOriginator;
bool _callConfirmed = false;
CallStateEnum _state = CallStateEnum.NONE;

Expand All @@ -47,7 +47,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>

String? get remoteIdentity => call!.remote_identity;

String get direction => call!.direction;
Direction? get direction => call!.direction;

Call? get call => widget._call;

Expand Down Expand Up @@ -177,7 +177,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>

void _handleStreams(CallState event) async {
MediaStream? stream = event.stream;
if (event.originator == 'local') {
if (event.originator == Originator.local) {
if (_localRenderer != null) {
_localRenderer!.srcObject = stream;
}
Expand All @@ -186,7 +186,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
}
_localStream = stream;
}
if (event.originator == 'remote') {
if (event.originator == Originator.remote) {
if (_remoteRenderer != null) {
_remoteRenderer!.srcObject = stream;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
switch (_state) {
case CallStateEnum.NONE:
case CallStateEnum.CONNECTING:
if (direction == 'INCOMING') {
if (direction == Direction.incoming) {
basicActions.add(ActionButton(
title: "Accept",
fillColor: Colors.green,
Expand Down Expand Up @@ -597,7 +597,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
child: Text(
(voiceOnly ? 'VOICE CALL' : 'VIDEO CALL') +
(_hold
? ' PAUSED BY ${_holdOriginator!.toUpperCase()}'
? ' PAUSED BY ${_holdOriginator!.name}'
: ''),
style: TextStyle(fontSize: 24, color: textColor),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version: 1.0.0+1
publish_to: none

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.15.0 <3.0.0"
flutter: ">=1.10.0"

dependencies:
Expand Down
3 changes: 1 addition & 2 deletions lib/sip_ua.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export 'src/enum_helper.dart';
export 'src/enums.dart';
export 'src/sip_message.dart';
export 'src/sip_ua_helper.dart';
export 'src/transport_type.dart';
export 'src/uri.dart';


4 changes: 1 addition & 3 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:sip_ua/sip_ua.dart';
import 'package:sip_ua/src/transports/socket_interface.dart';
import 'package:sip_ua/src/transports/tcp_socket.dart';

import 'constants.dart' as DartSIP_C;
import 'constants.dart';
import 'exceptions.dart' as Exceptions;
import 'grammar.dart';
import 'logger.dart';
import 'transports/web_socket.dart';
import 'uri.dart';
import 'utils.dart' as Utils;

// Default settings.
Expand Down
39 changes: 39 additions & 0 deletions lib/src/enums.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// Defines the direction of a communication,
/// indicating whether it is outgoing or incoming.
///
/// Used to specify the flow of calls or messages.
enum Direction {
/// Represents an outgoing call or message.
outgoing,

/// Represents an incoming call or message.
incoming
}

/// Identifies the originator of a communication,
/// specifying whether the initiator is local or remote.
///
/// This is useful for determining who started the call or message.
enum Originator {
/// Represents the user of this device initiated the communication.
local,

/// Represents the communication was initiated by someone else.
remote,

/// Represents that the communication was initiated by the system (e.g., automated processes).
system,
}

/// Represents the type of SDP (Session Description Protocol) message
/// used in a communication session.
///
/// SDP messages are exchanged between peers during the setup of a media connection.
enum SdpType {
/// Represents an SDP offer, which is the initial proposal sent to set up a media session.
offer,

/// Represents an SDP answer, which is the response to an SDP offer,
/// confirming or adjusting the session parameters.
answer
}
23 changes: 12 additions & 11 deletions lib/src/event_manager/call_events.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:sip_ua/src/enums.dart';

import '../rtc_session.dart';
import '../sip_message.dart';
Expand All @@ -11,9 +12,9 @@ class CallEvent extends EventType {
}

class EventNewRTCSession extends CallEvent {
EventNewRTCSession({RTCSession? session, String? originator, dynamic request})
EventNewRTCSession({RTCSession? session, Originator? originator, dynamic request})
: super(session);
String? originator;
Originator? originator;
dynamic request;
}

Expand All @@ -25,7 +26,7 @@ class EventCallEnded extends CallEvent {
EventCallEnded(
{RTCSession? session, this.originator, this.cause, this.request})
: super(session);
String? originator;
Originator? originator;
ErrorCause? cause;
IncomingRequest? request;
}
Expand All @@ -34,26 +35,26 @@ class EventCallProgress extends CallEvent {
EventCallProgress(
{RTCSession? session, this.originator, this.response, this.cause})
: super(session);
String? originator;
Originator? originator;
dynamic response;
ErrorCause? cause;
}

class EventCallConfirmed extends CallEvent {
EventCallConfirmed({RTCSession? session, this.originator, this.ack})
: super(session);
String? originator;
Originator? originator;
dynamic ack;
}

class EventCallHold extends CallEvent {
EventCallHold({RTCSession? session, this.originator}) : super(session);
String? originator;
Originator? originator;
}

class EventCallUnhold extends CallEvent {
EventCallUnhold({RTCSession? session, String? originator}) : super(session);
String? originator;
EventCallUnhold({RTCSession? session, Originator? originator}) : super(session);
Originator? originator;
}

class EventCallMuted extends CallEvent {
Expand All @@ -73,7 +74,7 @@ class EventCallUnmuted extends CallEvent {
class EventCallAccepted extends CallEvent {
EventCallAccepted({RTCSession? session, this.originator, this.response})
: super(session);
String? originator;
Originator? originator;
dynamic response;
}

Expand All @@ -89,7 +90,7 @@ class EventCallFailed extends CallEvent {
this.status_line})
: super(session);
dynamic response;
String? originator;
Originator? originator;
ErrorCause? cause;
dynamic request;
String? status_line;
Expand All @@ -98,7 +99,7 @@ class EventCallFailed extends CallEvent {
class EventStream extends CallEvent {
EventStream({RTCSession? session, this.originator, this.stream})
: super(session);
String? originator;
Originator? originator;
MediaStream? stream;
}

Expand Down
13 changes: 7 additions & 6 deletions lib/src/event_manager/internal_events.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:sip_ua/src/enums.dart';

import '../rtc_session.dart' show RTCSession;
import '../rtc_session/dtmf.dart';
Expand Down Expand Up @@ -33,8 +34,8 @@ class EventOnAuthenticated extends EventType {

class EventSdp extends EventType {
EventSdp({this.originator, this.type, this.sdp});
String? originator;
String? type;
Originator? originator;
SdpType? type;
String? sdp;
}

Expand All @@ -55,7 +56,7 @@ class EventSetLocalDescriptionFailed extends EventType {

class EventFailedUnderScore extends EventType {
EventFailedUnderScore({this.originator, this.cause});
String? originator;
Originator? originator;
ErrorCause? cause;
}

Expand All @@ -66,14 +67,14 @@ class EventGetUserMediaFailed extends EventType {

class EventNewDTMF extends EventType {
EventNewDTMF({this.originator, this.request, this.dtmf});
String? originator;
Originator? originator;
dynamic request;
DTMF? dtmf;
}

class EventNewInfo extends EventType {
EventNewInfo({this.originator, this.request, this.info});
String? originator;
Originator? originator;
dynamic request;
Info? info;
}
Expand Down Expand Up @@ -127,7 +128,7 @@ class EventOnFialed extends EventType {}

class EventSucceeded extends EventType {
EventSucceeded({this.response, this.originator});
String? originator;
Originator? originator;
IncomingMessage? response;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/event_manager/message_events.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import '../enums.dart';
import '../message.dart';
import 'events.dart';

class EventNewMessage extends EventType {
EventNewMessage({this.message, this.originator, this.request});
dynamic request;
String? originator;
Originator? originator;
Message? message;
}
3 changes: 2 additions & 1 deletion lib/src/event_manager/options_events.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import '../enums.dart';
import '../options.dart';
import 'events.dart';

class EventNewOptions extends EventType {
EventNewOptions({this.message, this.originator, this.request});
dynamic request;
String? originator;
Originator? originator;
Options? message;
}
Loading