Skip to content

Commit

Permalink
Null safety (#234)
Browse files Browse the repository at this point in the history
* update.

* chore: format and import short.

* Add extended header support (#232)

* hangup add the options

hangup function increase self-determination option number of participants, expedient unity communication time notification

* fix: Fix breaking changes.

* Add extended header support

Add extended header support, in order to carry custom information when calling

Co-authored-by: cloudwebrtc <[email protected]>
Co-authored-by: 趙金元 <[email protected]>

* migrate to null safety (#247)

* migrate to null safety

* fix local_seqnum

* support null safety for test folder

* fix: fix issue for digest authentication.

* chore: fix lints.

Co-authored-by: cloudwebrtc <[email protected]>

* update.

Co-authored-by: zi6xuan <[email protected]>
Co-authored-by: 趙金元 <[email protected]>
Co-authored-by: viplifes <[email protected]>
  • Loading branch information
4 people authored Feb 7, 2022
1 parent 5407ecc commit 5068498
Show file tree
Hide file tree
Showing 67 changed files with 8,874 additions and 5,595 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.22.6'
flutter-version: '2.2.3'
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
- run: flutter analyze
- run: flutter test
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
10 changes: 5 additions & 5 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
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

0 comments on commit 5068498

Please sign in to comment.