Skip to content

Commit

Permalink
replace string enum usage with dart enums (#479)
Browse files Browse the repository at this point in the history
* replace usage of direction as a string with an CallDirection enum

* convert more string enums to actual enums

---------

Co-authored-by: Victor Uvarov <[email protected]>
  • Loading branch information
victortive and VictorUvarov authored Dec 27, 2024
1 parent 3d34f90 commit e9fdea4
Show file tree
Hide file tree
Showing 27 changed files with 314 additions and 225 deletions.
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 @@ -189,7 +189,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 @@ -423,7 +423,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 @@ -608,7 +608,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
1 change: 1 addition & 0 deletions lib/sip_ua.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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';
Expand Down
5 changes: 2 additions & 3 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 '../sip_ua.dart';
import 'constants.dart' as DartSIP_C;
import 'constants.dart';
import 'exceptions.dart' as Exceptions;
import 'grammar.dart';
import 'logger.dart';
import 'transports/socket_interface.dart';
import 'transports/web_socket.dart';
import 'utils.dart' as Utils;

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
}
25 changes: 14 additions & 11 deletions lib/src/event_manager/call_events.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_webrtc/flutter_webrtc.dart';

import '../enums.dart';
import '../rtc_session.dart';
import '../sip_message.dart';
import 'events.dart';
Expand All @@ -11,9 +12,10 @@ 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 +27,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 +36,27 @@ 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 +76,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 +92,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 +101,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,5 +1,6 @@
import 'package:flutter_webrtc/flutter_webrtc.dart';

import '../enums.dart';
import '../rtc_session.dart' show RTCSession;
import '../rtc_session/dtmf.dart';
import '../rtc_session/info.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;
}
2 changes: 1 addition & 1 deletion lib/src/event_manager/notifier_events.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:sip_ua/src/sip_message.dart';
import '../sip_message.dart';
import 'events.dart';

class EventTerminated extends EventType {
Expand Down
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;
}
2 changes: 1 addition & 1 deletion lib/src/event_manager/transport_events.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:sip_ua/src/transports/socket_interface.dart';
import '../transports/socket_interface.dart';
import '../transports/web_socket.dart';
import 'events.dart';

Expand Down
Loading

0 comments on commit e9fdea4

Please sign in to comment.