Skip to content

Commit

Permalink
upgrade intl and logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Jan 15, 2024
1 parent d4c0a5b commit ec66172
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 23 deletions.
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ dependencies:
sip_ua:
path: ../
shared_preferences: ^2.2.0
permission_handler: ^10.4.3
permission_handler: ^11.1.0
flutter_webrtc: ^0.9.40

dev_dependencies:
flutter_test:
sdk: flutter
lints: ^2.1.1
lints: ^3.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
4 changes: 2 additions & 2 deletions lib/src/event_manager/event_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EventManager {
targets.remove(listener);
targets.add(listener);
} catch (e, s) {
logger.e(e.toString(), null, s);
logger.e(e.toString(), error: e, stackTrace: s);
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ class EventManager {
// logger.w("invoking $event on $target");
target(event);
} catch (e, s) {
logger.e(e.toString(), null, s);
logger.e(e.toString(), error: e, stackTrace: s);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/grammar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:parser_error/parser_error.dart';

import 'grammar_parser.dart';
import 'parser_error.dart';

class Grammar {
static dynamic parse(String input, String startRule) {
Expand Down
113 changes: 113 additions & 0 deletions lib/src/parser_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:text/text.dart';

class ParserErrorMessage {
ParserErrorMessage(this.message, this.start, this.end) {
if (end < 0) {
throw ArgumentError.value(end, 'end');
}

if (start < 0 || start > end) {
throw ArgumentError.value(start, 'start');
}
}

/// End position of error.
final int end;

/// Error message.
final String message;

/// Start position of error.
final int start;
}

class ParserErrorFormatter {
/// Returns formatted error as strings.
///
/// Parameters:
/// [String] source
/// Text of source code.
///
/// [List]<[ParserErrorMessage]> error
/// List of parser error messages.
///
/// [int] lineLimit
/// Length limit of the formatted line.
///
/// [int] offset
/// Offset to be added to the values "start" and "end".
///
/// [String] title
/// Title of parser error
static List<String> format(String source, List<ParserErrorMessage> messages,
{int lineLimit = 80, int offset = 0, String title = 'Format exception'}) {
if (lineLimit < 1) {
throw ArgumentError.value(lineLimit, 'lineLimit');
}

if (offset < 0) {
throw ArgumentError.value(offset, 'offset');
}

final List<String> result = <String>[];
final Text text = Text(source);
final int sourceLength = source.length;
for (ParserErrorMessage error in messages) {
int position = error.end + offset;
if (error.start != error.end) {
position = error.start + offset;
}

Location? location;
Line? line;
String locationString = '';
if (position < sourceLength) {
line = text.lineAt(position);
location = text.locationAt(position);
locationString = ' (${location.toString()})';
}

result.add('$title$locationString: ${error.message}');
if (line != null) {
String string = String.fromCharCodes(line.characters);
string = string.replaceAll('\n', '');
string = string.replaceAll('\r', '');
int indicatorLength = 1;
int indicatorPosition = 0;
if (location != null) {
indicatorPosition = location.column - 1;
}
if (error.end != error.start) {
indicatorLength = error.end - error.start;
}

if (indicatorLength > lineLimit) {
indicatorLength = lineLimit;
}

if (indicatorPosition + indicatorLength > lineLimit) {
if (indicatorPosition < lineLimit || indicatorLength < lineLimit) {
final int delta = (indicatorPosition + indicatorLength) - lineLimit;
string = string.substring(delta);
indicatorPosition -= delta;
} else {
string = string.substring(indicatorPosition);
indicatorPosition = 0;
}
}

if (string.length > lineLimit) {
string = string.substring(0, lineLimit);
}

final String prefix = ''.padRight(indicatorPosition, ' ');
final String suffix = ''.padRight(indicatorLength, '^');
final String indicator = '$prefix$suffix';
result.add(string);
result.add(indicator);
}
}

return result;
}
}
7 changes: 4 additions & 3 deletions lib/src/rtc_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ class RTCSession extends EventManager implements Owner {
if (_status == C.STATUS_TERMINATED) {
return;
}
logger.e('Failed to answer(): ${error.toString()}', error, s);
logger.e('Failed to answer(): ${error.toString()}',
error: error, stackTrace: s);
}
}

Expand Down Expand Up @@ -2293,7 +2294,7 @@ class RTCSession extends EventManager implements Owner {

request_sender.send();
} catch (error, s) {
logger.e(error.toString(), null, s);
logger.e(error.toString(), error: error, stackTrace: s);
_failed('local', null, null, null, 500, DartSIP_C.CausesType.WEBRTC_ERROR,
'Can\'t create local SDP');
if (_status == C.STATUS_TERMINATED) {
Expand Down Expand Up @@ -2559,7 +2560,7 @@ class RTCSession extends EventManager implements Owner {
'eventHandlers': handlers
});
} catch (e, s) {
logger.e(e.toString(), null, s);
logger.e(e.toString(), error: e, stackTrace: s);
onFailed();
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/sip_ua_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class SIPUAHelper extends EventManager {
_ua!.call(target, options);
return true;
} else {
logger.e(
'Not connected, you will need to register.', null, StackTraceNJ());
logger.e('Not connected, you will need to register.',
stackTrace: StackTraceNJ());
}
return false;
}
Expand Down Expand Up @@ -212,8 +212,8 @@ class SIPUAHelper extends EventManager {
});

_ua!.start();
} catch (event, s) {
logger.e(event.toString(), null, s);
} catch (e, s) {
logger.e(e.toString(), error: e, stackTrace: s);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class Transport {
if (!isConnected()) {
logger.e(
'unable to send message, transport is not connected. Current state is $status',
null,
StackTraceNJ());
error: e,
stackTrace: StackTraceNJ());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/transports/websocket_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WebSocketInterface implements Socket {
protocols: <String>[_websocket_protocol],
webSocketSettings: _webSocketSettings);
} catch (e, s) {
logger.e(e.toString(), null, s);
logger.e(e.toString(), error: e, stackTrace: s);
_connected = false;
logger.e('WebSocket $_url error: $e');
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/ua.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ class UA extends EventManager {
if (!rtcSession.isEnded()) {
rtcSession.terminate();
}
} catch (error, s) {
logger.e(error.toString(), null, s);
} catch (e, s) {
logger.e(e.toString(), error: e, stackTrace: s);
}
}
});
Expand All @@ -343,8 +343,8 @@ class UA extends EventManager {
try {
Subscriber subscriber = _subscribers[key]!;
subscriber.terminate(null);
} catch (error, s) {
logger.e(error.toString(), null, s);
} catch (e, s) {
logger.e(e.toString(), error: e, stackTrace: s);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ dependencies:
crypto: ^3.0.3
flutter_webrtc: ^0.9.47
intl: ^0.19.0
logger: ^1.0.0
parser_error: ^0.2.0
logger: ^2.0.2+1
path: ^1.6.4
random_string: ^2.3.1
recase: ^4.1.0
sdp_transform: ^0.3.2
text: ^0.2.0
uuid: ^4.2.1


dev_dependencies:
lints: ^2.0.1
lints: ^3.0.0
test: ^1.6.7

0 comments on commit ec66172

Please sign in to comment.