Skip to content

Commit ec66172

Browse files
committed
upgrade intl and logger.
1 parent d4c0a5b commit ec66172

10 files changed

+136
-23
lines changed

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ dependencies:
2424
sip_ua:
2525
path: ../
2626
shared_preferences: ^2.2.0
27-
permission_handler: ^10.4.3
27+
permission_handler: ^11.1.0
2828
flutter_webrtc: ^0.9.40
2929

3030
dev_dependencies:
3131
flutter_test:
3232
sdk: flutter
33-
lints: ^2.1.1
33+
lints: ^3.0.0
3434

3535
# For information on the generic Dart part of this file, see the
3636
# following page: https://dart.dev/tools/pub/pubspec

lib/src/event_manager/event_manager.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class EventManager {
6969
targets.remove(listener);
7070
targets.add(listener);
7171
} catch (e, s) {
72-
logger.e(e.toString(), null, s);
72+
logger.e(e.toString(), error: e, stackTrace: s);
7373
}
7474
}
7575

@@ -108,7 +108,7 @@ class EventManager {
108108
// logger.w("invoking $event on $target");
109109
target(event);
110110
} catch (e, s) {
111-
logger.e(e.toString(), null, s);
111+
logger.e(e.toString(), error: e, stackTrace: s);
112112
}
113113
}
114114
}

lib/src/grammar.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import 'package:parser_error/parser_error.dart';
2-
31
import 'grammar_parser.dart';
2+
import 'parser_error.dart';
43

54
class Grammar {
65
static dynamic parse(String input, String startRule) {

lib/src/parser_error.dart

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import 'package:text/text.dart';
2+
3+
class ParserErrorMessage {
4+
ParserErrorMessage(this.message, this.start, this.end) {
5+
if (end < 0) {
6+
throw ArgumentError.value(end, 'end');
7+
}
8+
9+
if (start < 0 || start > end) {
10+
throw ArgumentError.value(start, 'start');
11+
}
12+
}
13+
14+
/// End position of error.
15+
final int end;
16+
17+
/// Error message.
18+
final String message;
19+
20+
/// Start position of error.
21+
final int start;
22+
}
23+
24+
class ParserErrorFormatter {
25+
/// Returns formatted error as strings.
26+
///
27+
/// Parameters:
28+
/// [String] source
29+
/// Text of source code.
30+
///
31+
/// [List]<[ParserErrorMessage]> error
32+
/// List of parser error messages.
33+
///
34+
/// [int] lineLimit
35+
/// Length limit of the formatted line.
36+
///
37+
/// [int] offset
38+
/// Offset to be added to the values "start" and "end".
39+
///
40+
/// [String] title
41+
/// Title of parser error
42+
static List<String> format(String source, List<ParserErrorMessage> messages,
43+
{int lineLimit = 80, int offset = 0, String title = 'Format exception'}) {
44+
if (lineLimit < 1) {
45+
throw ArgumentError.value(lineLimit, 'lineLimit');
46+
}
47+
48+
if (offset < 0) {
49+
throw ArgumentError.value(offset, 'offset');
50+
}
51+
52+
final List<String> result = <String>[];
53+
final Text text = Text(source);
54+
final int sourceLength = source.length;
55+
for (ParserErrorMessage error in messages) {
56+
int position = error.end + offset;
57+
if (error.start != error.end) {
58+
position = error.start + offset;
59+
}
60+
61+
Location? location;
62+
Line? line;
63+
String locationString = '';
64+
if (position < sourceLength) {
65+
line = text.lineAt(position);
66+
location = text.locationAt(position);
67+
locationString = ' (${location.toString()})';
68+
}
69+
70+
result.add('$title$locationString: ${error.message}');
71+
if (line != null) {
72+
String string = String.fromCharCodes(line.characters);
73+
string = string.replaceAll('\n', '');
74+
string = string.replaceAll('\r', '');
75+
int indicatorLength = 1;
76+
int indicatorPosition = 0;
77+
if (location != null) {
78+
indicatorPosition = location.column - 1;
79+
}
80+
if (error.end != error.start) {
81+
indicatorLength = error.end - error.start;
82+
}
83+
84+
if (indicatorLength > lineLimit) {
85+
indicatorLength = lineLimit;
86+
}
87+
88+
if (indicatorPosition + indicatorLength > lineLimit) {
89+
if (indicatorPosition < lineLimit || indicatorLength < lineLimit) {
90+
final int delta = (indicatorPosition + indicatorLength) - lineLimit;
91+
string = string.substring(delta);
92+
indicatorPosition -= delta;
93+
} else {
94+
string = string.substring(indicatorPosition);
95+
indicatorPosition = 0;
96+
}
97+
}
98+
99+
if (string.length > lineLimit) {
100+
string = string.substring(0, lineLimit);
101+
}
102+
103+
final String prefix = ''.padRight(indicatorPosition, ' ');
104+
final String suffix = ''.padRight(indicatorLength, '^');
105+
final String indicator = '$prefix$suffix';
106+
result.add(string);
107+
result.add(indicator);
108+
}
109+
}
110+
111+
return result;
112+
}
113+
}

lib/src/rtc_session.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ class RTCSession extends EventManager implements Owner {
692692
if (_status == C.STATUS_TERMINATED) {
693693
return;
694694
}
695-
logger.e('Failed to answer(): ${error.toString()}', error, s);
695+
logger.e('Failed to answer(): ${error.toString()}',
696+
error: error, stackTrace: s);
696697
}
697698
}
698699

@@ -2293,7 +2294,7 @@ class RTCSession extends EventManager implements Owner {
22932294

22942295
request_sender.send();
22952296
} catch (error, s) {
2296-
logger.e(error.toString(), null, s);
2297+
logger.e(error.toString(), error: error, stackTrace: s);
22972298
_failed('local', null, null, null, 500, DartSIP_C.CausesType.WEBRTC_ERROR,
22982299
'Can\'t create local SDP');
22992300
if (_status == C.STATUS_TERMINATED) {
@@ -2559,7 +2560,7 @@ class RTCSession extends EventManager implements Owner {
25592560
'eventHandlers': handlers
25602561
});
25612562
} catch (e, s) {
2562-
logger.e(e.toString(), null, s);
2563+
logger.e(e.toString(), error: e, stackTrace: s);
25632564
onFailed();
25642565
}
25652566
}

lib/src/sip_ua_helper.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class SIPUAHelper extends EventManager {
100100
_ua!.call(target, options);
101101
return true;
102102
} else {
103-
logger.e(
104-
'Not connected, you will need to register.', null, StackTraceNJ());
103+
logger.e('Not connected, you will need to register.',
104+
stackTrace: StackTraceNJ());
105105
}
106106
return false;
107107
}
@@ -212,8 +212,8 @@ class SIPUAHelper extends EventManager {
212212
});
213213

214214
_ua!.start();
215-
} catch (event, s) {
216-
logger.e(event.toString(), null, s);
215+
} catch (e, s) {
216+
logger.e(e.toString(), error: e, stackTrace: s);
217217
}
218218
}
219219

lib/src/transport.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class Transport {
147147
if (!isConnected()) {
148148
logger.e(
149149
'unable to send message, transport is not connected. Current state is $status',
150-
null,
151-
StackTraceNJ());
150+
error: e,
151+
stackTrace: StackTraceNJ());
152152
return false;
153153
}
154154

lib/src/transports/websocket_interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class WebSocketInterface implements Socket {
109109
protocols: <String>[_websocket_protocol],
110110
webSocketSettings: _webSocketSettings);
111111
} catch (e, s) {
112-
logger.e(e.toString(), null, s);
112+
logger.e(e.toString(), error: e, stackTrace: s);
113113
_connected = false;
114114
logger.e('WebSocket $_url error: $e');
115115
}

lib/src/ua.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ class UA extends EventManager {
330330
if (!rtcSession.isEnded()) {
331331
rtcSession.terminate();
332332
}
333-
} catch (error, s) {
334-
logger.e(error.toString(), null, s);
333+
} catch (e, s) {
334+
logger.e(e.toString(), error: e, stackTrace: s);
335335
}
336336
}
337337
});
@@ -343,8 +343,8 @@ class UA extends EventManager {
343343
try {
344344
Subscriber subscriber = _subscribers[key]!;
345345
subscriber.terminate(null);
346-
} catch (error, s) {
347-
logger.e(error.toString(), null, s);
346+
} catch (e, s) {
347+
logger.e(e.toString(), error: e, stackTrace: s);
348348
}
349349
}
350350
});

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ dependencies:
1111
crypto: ^3.0.3
1212
flutter_webrtc: ^0.9.47
1313
intl: ^0.19.0
14-
logger: ^1.0.0
15-
parser_error: ^0.2.0
14+
logger: ^2.0.2+1
1615
path: ^1.6.4
1716
random_string: ^2.3.1
1817
recase: ^4.1.0
1918
sdp_transform: ^0.3.2
19+
text: ^0.2.0
2020
uuid: ^4.2.1
2121

2222

2323
dev_dependencies:
24-
lints: ^2.0.1
24+
lints: ^3.0.0
2525
test: ^1.6.7

0 commit comments

Comments
 (0)