Skip to content

Commit

Permalink
Update and format flutter_webrtc_demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
wanchao-xu committed Nov 3, 2023
1 parent 5876bad commit 3182fc6
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 130 deletions.
1 change: 1 addition & 0 deletions packages/flutter_webrtc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Increase the minimum Flutter version to 3.3.
* Update libwebrtc to m114 version.
* Update flutter_webrtc to 0.9.46.
* Update and format flutter_webrtc_demo.
* Support the empty candidate for 'addIceCandidate' api.

## 0.1.2
Expand Down
14 changes: 5 additions & 9 deletions packages/flutter_webrtc/example/flutter_webrtc_demo/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# flutter-webrtc-demo

[![slack](https://img.shields.io/badge/join-us%20on%20slack-gray.svg?longCache=true&logo=slack&colorB=brightgreen)](https://join.slack.com/t/flutterwebrtc/shared_invite/zt-q83o7y1s-FExGLWEvtkPKM8ku_F8cEQ)

Flutter WebRTC plugin Demo

Online Demo: <https://demo.cloudwebrtc.com:8086/>
Online Demo: https://flutter-webrtc.github.io/flutter-webrtc-demo/

## Usage

- `cd flutter_webrtc_demo`
- `flutter-tizen pub get`
- `flutter-tizen run`

## Note

- If you want to test `P2P Call Sample`, please use the [webrtc-flutter-server](https://github.com/cloudwebrtc/flutter-webrtc-server), and enter your server address into the example app.

## screenshots

### iOS

# iOS
<img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/flutter-webrtc-ios-example.png"/> <img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/ios-01.jpeg"/> <img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/ios-02.jpeg"/>

### Android

# Android
<img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/flutter-webrtc-android-example.png"/> <img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/android-01.png"/> <img width="180" height="320" src="https://raw.githubusercontent.com/cloudwebrtc/flutter-webrtc-demo/master/screenshots/android-02.png"/>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _MyAppState extends State<MyApp> {
_initItems();
}

ListBody _buildRow(context, item) {
Widget _buildRow(context, item) {
return ListBody(children: <Widget>[
ListTile(
title: Text(item.title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class _CallSampleState extends State<CallSample> {
final RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
bool _inCalling = false;
Session? _session;

bool _waitAccept = false;

@override
Expand Down Expand Up @@ -67,7 +66,7 @@ class _CallSampleState extends State<CallSample> {
});
break;
case CallState.CallStateRinging:
var accept = await _showAcceptDialog();
bool? accept = await _showAcceptDialog();
if (accept!) {
_accept();
setState(() {
Expand All @@ -92,7 +91,7 @@ class _CallSampleState extends State<CallSample> {
break;
case CallState.CallStateInvite:
_waitAccept = true;
await _showInvateDialog();
await _showInviteDialog();
break;
case CallState.CallStateConnected:
if (_waitAccept) {
Expand Down Expand Up @@ -156,7 +155,7 @@ class _CallSampleState extends State<CallSample> {
);
}

Future<bool?> _showInvateDialog() {
Future<bool?> _showInviteDialog() {
return showDialog<bool?>(
context: context,
builder: (context) {
Expand Down Expand Up @@ -214,7 +213,7 @@ class _CallSampleState extends State<CallSample> {
);
if (source != null) {
try {
var stream =
MediaStream stream =
await navigator.mediaDevices.getDisplayMedia(<String, dynamic>{
'video': {
'deviceId': {'exact': source.id},
Expand Down Expand Up @@ -245,7 +244,7 @@ class _CallSampleState extends State<CallSample> {
}

ListBody _buildRow(context, peer) {
var self = peer['id'] == _selfId;
bool self = peer['id'] == _selfId;
return ListBody(children: <Widget>[
ListTile(
title: Text(self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
RTCDataChannel? _dataChannel;
Session? _session;
Timer? _timer;
var _text = '';
String _text = '';
bool _waitAccept = false;

@override
Expand Down Expand Up @@ -69,7 +69,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
);
}

Future<bool?> _showInvateDialog() {
Future<bool?> _showInviteDialog() {
return showDialog<bool?>(
context: context,
builder: (context) {
Expand All @@ -93,6 +93,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
void _connect(BuildContext context) async {
_signaling ??= Signaling(widget.host, context);
await _signaling!.connect();

_signaling?.onDataChannelMessage = (_, dc, RTCDataChannelMessage data) {
setState(() {
if (data.isBinary) {
Expand Down Expand Up @@ -140,7 +141,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
break;
case CallState.CallStateInvite:
_waitAccept = true;
await _showInvateDialog();
await _showInviteDialog();
break;
case CallState.CallStateConnected:
if (_waitAccept) {
Expand All @@ -152,7 +153,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
});
break;
case CallState.CallStateRinging:
var accept = await _showAcceptDialog();
bool? accept = await _showAcceptDialog();
if (accept!) {
_accept();
setState(() {
Expand Down Expand Up @@ -187,7 +188,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
}

Future<void> _handleDataChannelTest(Timer timer) async {
var text = 'Say hello ${timer.tick} times, from [$_selfId]';
String text = 'Say hello ${timer.tick} times, from [$_selfId]';
await _dataChannel
?.send(RTCDataChannelMessage.fromBinary(Uint8List(timer.tick + 1)));
await _dataChannel?.send(RTCDataChannelMessage(text));
Expand All @@ -203,8 +204,8 @@ class _DataChannelSampleState extends State<DataChannelSample> {
_signaling?.bye(_session!.sid);
}

ListBody _buildRow(context, peer) {
var self = peer['id'] == _selfId;
Widget _buildRow(context, peer) {
bool self = peer['id'] == _selfId;
return ListBody(children: <Widget>[
ListTile(
title: Text(self
Expand Down Expand Up @@ -242,7 +243,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
body: _inCalling
? Center(
child: Container(
child: Text('Recevied => $_text'),
child: Text('Received => $_text'),
),
)
: ListView.builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const UPPER_ALPHA_END = 90;
/// Generates a random integer where [from] <= [to].
int randomBetween(int from, int to) {
if (from > to) throw Exception('$from cannot be > $to');
var rand = Random();
Random rand = Random();
return ((to - from) * rand.nextDouble()).toInt() + from;
}

Expand Down
Loading

0 comments on commit 3182fc6

Please sign in to comment.