Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ jobs:
channel: 'stable'
- run: flutter packages get
- run: flutter format lib/ test/ --set-exit-if-changed
- run: flutter pub run import_sorter:main --no-comments --exit-if-changed
5 changes: 3 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

linter:
rules:
Expand Down Expand Up @@ -45,7 +45,6 @@ analyzer:
slash_for_doc_comments: ignore
library_prefixes: ignore
unused_field: ignore
top_level_function_literal_block: ignore
avoid_init_to_null: ignore
prefer_is_empty: ignore
unused_element: ignore
Expand All @@ -59,6 +58,8 @@ analyzer:
unused_import: ignore
must_be_immutable: ignore
todo: ignore
non_constant_identifier_names: ignore
unnecessary_null_comparison: ignore

exclude:
- lib/src/grammar_parser.dart
Expand Down
33 changes: 28 additions & 5 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
include: package:pedantic/analysis_options.yaml
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
28 changes: 14 additions & 14 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;

import 'package:flutter/material.dart';
import 'package:sip_ua/sip_ua.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'src/register.dart';
import 'src/dialpad.dart';
import 'src/callscreen.dart';
import 'package:sip_ua/sip_ua.dart';

import 'src/about.dart';
import 'src/callscreen.dart';
import 'src/dialpad.dart';
import 'src/register.dart';

void main() {
if (WebRTC.platformIsDesktop) {
Expand All @@ -17,23 +17,23 @@ void main() {
}

typedef PageContentBuilder = Widget Function(
[SIPUAHelper helper, Object arguments]);
[SIPUAHelper? helper, Object? arguments]);

// ignore: must_be_immutable
class MyApp extends StatelessWidget {
final SIPUAHelper _helper = SIPUAHelper();
Map<String, PageContentBuilder> routes = {
'/': ([SIPUAHelper helper, Object arguments]) => DialPadWidget(helper),
'/register': ([SIPUAHelper helper, Object arguments]) =>
'/': ([SIPUAHelper? helper, Object? arguments]) => DialPadWidget(helper),
'/register': ([SIPUAHelper? helper, Object? arguments]) =>
RegisterWidget(helper),
'/callscreen': ([SIPUAHelper helper, Object arguments]) =>
CallScreenWidget(helper, arguments as Call),
'/about': ([SIPUAHelper helper, Object arguments]) => AboutWidget(),
'/callscreen': ([SIPUAHelper? helper, Object? arguments]) =>
CallScreenWidget(helper, arguments as Call?),
'/about': ([SIPUAHelper? helper, Object? arguments]) => AboutWidget(),
};

Route<dynamic> _onGenerateRoute(RouteSettings settings) {
final String name = settings.name;
final PageContentBuilder pageContentBuilder = routes[name];
Route<dynamic>? _onGenerateRoute(RouteSettings settings) {
final String? name = settings.name;
final PageContentBuilder? pageContentBuilder = routes[name!];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute<Widget>(
Expand Down
104 changes: 52 additions & 52 deletions example/lib/src/callscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,61 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:sip_ua/sip_ua.dart';

import 'widgets/action_button.dart';
import 'package:sip_ua/sip_ua.dart';

class CallScreenWidget extends StatefulWidget {
final SIPUAHelper _helper;
final Call _call;
CallScreenWidget(this._helper, this._call, {Key key}) : super(key: key);
final SIPUAHelper? _helper;
final Call? _call;
CallScreenWidget(this._helper, this._call, {Key? key}) : super(key: key);
@override
_MyCallScreenWidget createState() => _MyCallScreenWidget();
}

class _MyCallScreenWidget extends State<CallScreenWidget>
implements SipUaHelperListener {
RTCVideoRenderer _localRenderer = RTCVideoRenderer();
RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
double _localVideoHeight;
double _localVideoWidth;
EdgeInsetsGeometry _localVideoMargin;
MediaStream _localStream;
MediaStream _remoteStream;
RTCVideoRenderer? _localRenderer = RTCVideoRenderer();
RTCVideoRenderer? _remoteRenderer = RTCVideoRenderer();
double? _localVideoHeight;
double? _localVideoWidth;
EdgeInsetsGeometry? _localVideoMargin;
MediaStream? _localStream;
MediaStream? _remoteStream;

bool _showNumPad = false;
String _timeLabel = '00:00';
Timer _timer;
late Timer _timer;
bool _audioMuted = false;
bool _videoMuted = false;
bool _speakerOn = false;
bool _hold = false;
String _holdOriginator;
String? _holdOriginator;
CallStateEnum _state = CallStateEnum.NONE;
SIPUAHelper get helper => widget._helper;
SIPUAHelper? get helper => widget._helper;

bool get voiceonly =>
(_localStream == null || _localStream.getVideoTracks().isEmpty) &&
(_remoteStream == null || _remoteStream.getVideoTracks().isEmpty);
(_localStream == null || _localStream!.getVideoTracks().isEmpty) &&
(_remoteStream == null || _remoteStream!.getVideoTracks().isEmpty);

String get remote_identity => call.remote_identity;
String? get remote_identity => call!.remote_identity;

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

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

@override
initState() {
super.initState();
_initRenderers();
helper.addSipUaHelperListener(this);
helper!.addSipUaHelperListener(this);
_startTimer();
}

@override
deactivate() {
super.deactivate();
helper.removeSipUaHelperListener(this);
helper!.removeSipUaHelperListener(this);
_disposeRenderers();
}

Expand All @@ -78,20 +78,20 @@ class _MyCallScreenWidget extends State<CallScreenWidget>

void _initRenderers() async {
if (_localRenderer != null) {
await _localRenderer.initialize();
await _localRenderer!.initialize();
}
if (_remoteRenderer != null) {
await _remoteRenderer.initialize();
await _remoteRenderer!.initialize();
}
}

void _disposeRenderers() {
if (_localRenderer != null) {
_localRenderer.dispose();
_localRenderer!.dispose();
_localRenderer = null;
}
if (_remoteRenderer != null) {
_remoteRenderer.dispose();
_remoteRenderer!.dispose();
_remoteRenderer = null;
}
}
Expand All @@ -107,15 +107,15 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
}

if (callState.state == CallStateEnum.MUTED) {
if (callState.audio) _audioMuted = true;
if (callState.video) _videoMuted = true;
if (callState.audio!) _audioMuted = true;
if (callState.video!) _videoMuted = true;
this.setState(() {});
return;
}

if (callState.state == CallStateEnum.UNMUTED) {
if (callState.audio) _audioMuted = false;
if (callState.video) _videoMuted = false;
if (callState.audio!) _audioMuted = false;
if (callState.video!) _videoMuted = false;
this.setState(() {});
return;
}
Expand Down Expand Up @@ -154,10 +154,10 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
void registrationStateChanged(RegistrationState state) {}

void _cleanUp() {
_localStream?.getTracks()?.forEach((track) {
_localStream?.getTracks().forEach((track) {
track.stop();
});
_localStream.dispose();
_localStream!.dispose();
_localStream = null;
}

Expand All @@ -170,19 +170,19 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
}

void _handelStreams(CallState event) async {
MediaStream stream = event.stream;
MediaStream? stream = event.stream;
if (event.originator == 'local') {
if (_localRenderer != null) {
_localRenderer.srcObject = stream;
_localRenderer!.srcObject = stream;
}
if (!kIsWeb && !WebRTC.platformIsDesktop) {
event.stream?.getAudioTracks()?.first?.enableSpeakerphone(false);
event.stream?.getAudioTracks().first.enableSpeakerphone(false);
}
_localStream = stream;
}
if (event.originator == 'remote') {
if (_remoteRenderer != null) {
_remoteRenderer.srcObject = stream;
_remoteRenderer!.srcObject = stream;
}
_remoteStream = stream;
}
Expand All @@ -205,12 +205,12 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
}

void _handleHangup() {
call.hangup();
call!.hangup();
_timer.cancel();
}

void _handleAccept() async {
bool remote_has_video = call.remote_has_video;
bool remote_has_video = call!.remote_has_video;
final mediaConstraints = <String, dynamic>{
'audio': true,
'video': remote_has_video
Expand All @@ -229,41 +229,41 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
mediaStream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
}

call.answer(helper.buildCallOptions(!remote_has_video),
call!.answer(helper!.buildCallOptions(!remote_has_video),
mediaStream: mediaStream);
}

void _switchCamera() {
if (_localStream != null) {
_localStream.getVideoTracks()[0].switchCamera();
Helper.switchCamera(_localStream!.getVideoTracks()[0]);
}
}

void _muteAudio() {
if (_audioMuted) {
call.unmute(true, false);
call!.unmute(true, false);
} else {
call.mute(true, false);
call!.mute(true, false);
}
}

void _muteVideo() {
if (_videoMuted) {
call.unmute(false, true);
call!.unmute(false, true);
} else {
call.mute(false, true);
call!.mute(false, true);
}
}

void _handleHold() {
if (_hold) {
call.unhold();
call!.unhold();
} else {
call.hold();
call!.hold();
}
}

String _tansfer_target;
late String _tansfer_target;
void _handleTransfer() {
showDialog<Null>(
context: context,
Expand All @@ -286,7 +286,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
TextButton(
child: Text('Ok'),
onPressed: () {
call.refer(_tansfer_target);
call!.refer(_tansfer_target);
Navigator.of(context).pop();
},
),
Expand All @@ -304,7 +304,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>

void _handleDtmf(String tone) {
print('Dtmf tone => $tone');
call.sendDTMF(tone);
call!.sendDTMF(tone);
}

void _handleKeyPad() {
Expand All @@ -317,7 +317,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
if (_localStream != null) {
_speakerOn = !_speakerOn;
if (!kIsWeb) {
_localStream.getAudioTracks()[0].enableSpeakerphone(_speakerOn);
_localStream!.getAudioTracks()[0].enableSpeakerphone(_speakerOn);
}
}
}
Expand Down Expand Up @@ -502,14 +502,14 @@ class _MyCallScreenWidget extends State<CallScreenWidget>

if (!voiceonly && _remoteStream != null) {
stackWidgets.add(Center(
child: RTCVideoView(_remoteRenderer),
child: RTCVideoView(_remoteRenderer!),
));
}

if (!voiceonly && _localStream != null) {
stackWidgets.add(Container(
child: AnimatedContainer(
child: RTCVideoView(_localRenderer),
child: RTCVideoView(_localRenderer!),
height: _localVideoHeight,
width: _localVideoWidth,
alignment: Alignment.topRight,
Expand All @@ -536,7 +536,7 @@ class _MyCallScreenWidget extends State<CallScreenWidget>
child: Text(
(voiceonly ? 'VOICE CALL' : 'VIDEO CALL') +
(_hold
? ' PAUSED BY ${this._holdOriginator.toUpperCase()}'
? ' PAUSED BY ${this._holdOriginator!.toUpperCase()}'
: ''),
style: TextStyle(fontSize: 24, color: Colors.black54),
))),
Expand Down
Loading