Skip to content

Commit e9fdea4

Browse files
replace string enum usage with dart enums (#479)
* replace usage of direction as a string with an CallDirection enum * convert more string enums to actual enums --------- Co-authored-by: Victor Uvarov <victoruvarov23@gmail.com>
1 parent 3d34f90 commit e9fdea4

27 files changed

+314
-225
lines changed

example/lib/src/callscreen.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
3434
bool _speakerOn = false;
3535
bool _hold = false;
3636
bool _mirror = true;
37-
String? _holdOriginator;
37+
Originator? _holdOriginator;
3838
bool _callConfirmed = false;
3939
CallStateEnum _state = CallStateEnum.NONE;
4040

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

4848
String? get remoteIdentity => call!.remote_identity;
4949

50-
String get direction => call!.direction;
50+
Direction? get direction => call!.direction;
5151

5252
Call? get call => widget._call;
5353

@@ -177,7 +177,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
177177

178178
void _handleStreams(CallState event) async {
179179
MediaStream? stream = event.stream;
180-
if (event.originator == 'local') {
180+
if (event.originator == Originator.local) {
181181
if (_localRenderer != null) {
182182
_localRenderer!.srcObject = stream;
183183
}
@@ -189,7 +189,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
189189
}
190190
_localStream = stream;
191191
}
192-
if (event.originator == 'remote') {
192+
if (event.originator == Originator.remote) {
193193
if (_remoteRenderer != null) {
194194
_remoteRenderer!.srcObject = stream;
195195
}
@@ -423,7 +423,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
423423
switch (_state) {
424424
case CallStateEnum.NONE:
425425
case CallStateEnum.CONNECTING:
426-
if (direction == 'INCOMING') {
426+
if (direction == Direction.incoming) {
427427
basicActions.add(ActionButton(
428428
title: "Accept",
429429
fillColor: Colors.green,
@@ -608,7 +608,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
608608
child: Text(
609609
(voiceOnly ? 'VOICE CALL' : 'VIDEO CALL') +
610610
(_hold
611-
? ' PAUSED BY ${_holdOriginator!.toUpperCase()}'
611+
? ' PAUSED BY ${_holdOriginator!.name}'
612612
: ''),
613613
style: TextStyle(fontSize: 24, color: textColor),
614614
),

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version: 1.0.0+1
1515
publish_to: none
1616

1717
environment:
18-
sdk: ">=2.12.0 <3.0.0"
18+
sdk: ">=2.15.0 <3.0.0"
1919
flutter: ">=1.10.0"
2020

2121
dependencies:

lib/sip_ua.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export 'src/enum_helper.dart';
2+
export 'src/enums.dart';
23
export 'src/sip_message.dart';
34
export 'src/sip_ua_helper.dart';
45
export 'src/transport_type.dart';

lib/src/config.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import 'package:sip_ua/sip_ua.dart';
2-
import 'package:sip_ua/src/transports/socket_interface.dart';
3-
import 'package:sip_ua/src/transports/tcp_socket.dart';
1+
import '../sip_ua.dart';
42
import 'constants.dart' as DartSIP_C;
53
import 'constants.dart';
64
import 'exceptions.dart' as Exceptions;
75
import 'grammar.dart';
86
import 'logger.dart';
7+
import 'transports/socket_interface.dart';
98
import 'transports/web_socket.dart';
109
import 'utils.dart' as Utils;
1110

lib/src/enums.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Defines the direction of a communication,
2+
/// indicating whether it is outgoing or incoming.
3+
///
4+
/// Used to specify the flow of calls or messages.
5+
enum Direction {
6+
/// Represents an outgoing call or message.
7+
outgoing,
8+
9+
/// Represents an incoming call or message.
10+
incoming
11+
}
12+
13+
/// Identifies the originator of a communication,
14+
/// specifying whether the initiator is local or remote.
15+
///
16+
/// This is useful for determining who started the call or message.
17+
enum Originator {
18+
/// Represents the user of this device initiated the communication.
19+
local,
20+
21+
/// Represents the communication was initiated by someone else.
22+
remote,
23+
24+
/// Represents that the communication was initiated by the system (e.g., automated processes).
25+
system,
26+
}
27+
28+
/// Represents the type of SDP (Session Description Protocol) message
29+
/// used in a communication session.
30+
///
31+
/// SDP messages are exchanged between peers during the setup of a media connection.
32+
enum SdpType {
33+
/// Represents an SDP offer, which is the initial proposal sent to set up a media session.
34+
offer,
35+
36+
/// Represents an SDP answer, which is the response to an SDP offer,
37+
/// confirming or adjusting the session parameters.
38+
answer
39+
}

lib/src/event_manager/call_events.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter_webrtc/flutter_webrtc.dart';
22

3+
import '../enums.dart';
34
import '../rtc_session.dart';
45
import '../sip_message.dart';
56
import 'events.dart';
@@ -11,9 +12,10 @@ class CallEvent extends EventType {
1112
}
1213

1314
class EventNewRTCSession extends CallEvent {
14-
EventNewRTCSession({RTCSession? session, String? originator, dynamic request})
15+
EventNewRTCSession(
16+
{RTCSession? session, Originator? originator, dynamic request})
1517
: super(session);
16-
String? originator;
18+
Originator? originator;
1719
dynamic request;
1820
}
1921

@@ -25,7 +27,7 @@ class EventCallEnded extends CallEvent {
2527
EventCallEnded(
2628
{RTCSession? session, this.originator, this.cause, this.request})
2729
: super(session);
28-
String? originator;
30+
Originator? originator;
2931
ErrorCause? cause;
3032
IncomingRequest? request;
3133
}
@@ -34,26 +36,27 @@ class EventCallProgress extends CallEvent {
3436
EventCallProgress(
3537
{RTCSession? session, this.originator, this.response, this.cause})
3638
: super(session);
37-
String? originator;
39+
Originator? originator;
3840
dynamic response;
3941
ErrorCause? cause;
4042
}
4143

4244
class EventCallConfirmed extends CallEvent {
4345
EventCallConfirmed({RTCSession? session, this.originator, this.ack})
4446
: super(session);
45-
String? originator;
47+
Originator? originator;
4648
dynamic ack;
4749
}
4850

4951
class EventCallHold extends CallEvent {
5052
EventCallHold({RTCSession? session, this.originator}) : super(session);
51-
String? originator;
53+
Originator? originator;
5254
}
5355

5456
class EventCallUnhold extends CallEvent {
55-
EventCallUnhold({RTCSession? session, String? originator}) : super(session);
56-
String? originator;
57+
EventCallUnhold({RTCSession? session, Originator? originator})
58+
: super(session);
59+
Originator? originator;
5760
}
5861

5962
class EventCallMuted extends CallEvent {
@@ -73,7 +76,7 @@ class EventCallUnmuted extends CallEvent {
7376
class EventCallAccepted extends CallEvent {
7477
EventCallAccepted({RTCSession? session, this.originator, this.response})
7578
: super(session);
76-
String? originator;
79+
Originator? originator;
7780
dynamic response;
7881
}
7982

@@ -89,7 +92,7 @@ class EventCallFailed extends CallEvent {
8992
this.status_line})
9093
: super(session);
9194
dynamic response;
92-
String? originator;
95+
Originator? originator;
9396
ErrorCause? cause;
9497
dynamic request;
9598
String? status_line;
@@ -98,7 +101,7 @@ class EventCallFailed extends CallEvent {
98101
class EventStream extends CallEvent {
99102
EventStream({RTCSession? session, this.originator, this.stream})
100103
: super(session);
101-
String? originator;
104+
Originator? originator;
102105
MediaStream? stream;
103106
}
104107

lib/src/event_manager/internal_events.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter_webrtc/flutter_webrtc.dart';
22

3+
import '../enums.dart';
34
import '../rtc_session.dart' show RTCSession;
45
import '../rtc_session/dtmf.dart';
56
import '../rtc_session/info.dart';
@@ -33,8 +34,8 @@ class EventOnAuthenticated extends EventType {
3334

3435
class EventSdp extends EventType {
3536
EventSdp({this.originator, this.type, this.sdp});
36-
String? originator;
37-
String? type;
37+
Originator? originator;
38+
SdpType? type;
3839
String? sdp;
3940
}
4041

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

5657
class EventFailedUnderScore extends EventType {
5758
EventFailedUnderScore({this.originator, this.cause});
58-
String? originator;
59+
Originator? originator;
5960
ErrorCause? cause;
6061
}
6162

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

6768
class EventNewDTMF extends EventType {
6869
EventNewDTMF({this.originator, this.request, this.dtmf});
69-
String? originator;
70+
Originator? originator;
7071
dynamic request;
7172
DTMF? dtmf;
7273
}
7374

7475
class EventNewInfo extends EventType {
7576
EventNewInfo({this.originator, this.request, this.info});
76-
String? originator;
77+
Originator? originator;
7778
dynamic request;
7879
Info? info;
7980
}
@@ -127,7 +128,7 @@ class EventOnFialed extends EventType {}
127128

128129
class EventSucceeded extends EventType {
129130
EventSucceeded({this.response, this.originator});
130-
String? originator;
131+
Originator? originator;
131132
IncomingMessage? response;
132133
}
133134

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import '../enums.dart';
12
import '../message.dart';
23
import 'events.dart';
34

45
class EventNewMessage extends EventType {
56
EventNewMessage({this.message, this.originator, this.request});
67
dynamic request;
7-
String? originator;
8+
Originator? originator;
89
Message? message;
910
}

lib/src/event_manager/notifier_events.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:sip_ua/src/sip_message.dart';
1+
import '../sip_message.dart';
22
import 'events.dart';
33

44
class EventTerminated extends EventType {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import '../enums.dart';
12
import '../options.dart';
23
import 'events.dart';
34

45
class EventNewOptions extends EventType {
56
EventNewOptions({this.message, this.originator, this.request});
67
dynamic request;
7-
String? originator;
8+
Originator? originator;
89
Options? message;
910
}

0 commit comments

Comments
 (0)