Skip to content

Commit

Permalink
Version 2.0.4 (See README notes + CHANGELOG)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thai Dinh Le authored and Thai Dinh Le committed Jul 5, 2021
1 parent 5a5e29a commit 2404a5f
Show file tree
Hide file tree
Showing 56 changed files with 1,032 additions and 1,031 deletions.
34 changes: 21 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
## 1.0.0
## 2.0.4

* Flutter plugin: Public APIs availables for creating and managing an ad hoc network
* Final version (no more updates)
* Update example app to Null Safety version
* Update pubspec.yaml
* Update README.md
* Format code to comply with dartfmt

## 2.0.3

* Fix warnings of pubspec
* Update documentations

## 2.0.2

* Update documentations

## 2.0.1

* Fix export

## 2.0.0

Expand All @@ -11,15 +28,6 @@
* Update LICENSE
* Update dependencies versions

## 2.0.1

* Fix export

## 2.0.2

* Update documentations

## 2.0.3
## 1.0.0

* Fix warnings of pubspec
* Update documentations
* Flutter plugin: Public APIs availables for creating and managing an ad hoc network
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ void _listen() {
_manager.eventStream.listen((event) {
switch (event.type) {
case AdHocType.onDeviceDiscovered:
var device = event.payload as AdHocDevice;
var device = event.device as AdHocDevice;
break;
case AdHocType.onDiscoveryStarted:
break;
case AdHocType.onDiscoveryCompleted:
var discovered = event.payload as Map<String, AdHocDevice>
var discovered = event.data as Map<String?, AdHocDevice?>
break;
case AdHocType.onDataReceived:
var data = event.payload as Object;
var data = event.data as Object;
break;
case AdHocType.onForwardData:
var data = event.payload as Object;
var data = event.data as Object;
break;
case AdHocType.onConnection:
var device = event.payload as AdHocDevice;
var device = event.device as AdHocDevice;
break;
case AdHocType.onConnectionClosed:
var device = event.payload as AdHocDevice;
var device = event.device as AdHocDevice;
break;
case AdHocType.onInternalException:
var exception = event.payload as Exception;
var exception = event.data as Exception;
break;
case AdHocType.onGroupInfo:
var info = event.payload as int;
var info = event.data as int;
break;
case AdHocType.onGroupDataReceived:
var data = event.payload as Object;
var data = event.data as Object;
break;
default:
}
Expand All @@ -93,8 +93,22 @@ void _listen() {

## Application Example

## example
### Music App Sharing

- [Source code](example)

An example showing how to use the library APIs.

### Video (demo)

- [Demo](https://vimeo.com/571293323)

Example of message app.

## Notes

Note that some mobile devices might support partially Bluetooth Low Energy (support BLE GATT server, but not advertisement) or in some case not at all (transfering big file with BLE takes very long time).

Further information about the implementation and library architecture can be found at the following [address (master thesis)](https://matheo.uliege.be/handle/2268.2/11450) (https://matheo.uliege.be/handle/2268.2/11450)

This library will not be updated anymore, but feel free to submit bug reports, feature requests, or pull requests, which will be handled.
11 changes: 0 additions & 11 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.8))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
63 changes: 34 additions & 29 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
final List<AdHocDevice> _discovered = List.empty(growable: true);
final List<AdHocDevice> _peers = List.empty(growable: true);
final List<Pair<String, String>> _playlist = List.empty(growable: true);
final HashMap<String, HashMap<String, PlatformFile>> _globalPlaylist = HashMap();
final HashMap<String, PlatformFile> _localPlaylist = HashMap();
final HashMap<String, HashMap<String, PlatformFile?>> _globalPlaylist = HashMap();
final HashMap<String, PlatformFile?> _localPlaylist = HashMap();
final HashMap<String, bool> _isTransfering = HashMap();
final Set<String> timestamps = <String>{};

bool _requested = false;
bool _display = false;
String _selected = NONE;
String? _selected = NONE;

@override
void initState() {
Expand Down Expand Up @@ -74,10 +74,10 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
var songs = List<String>.empty(growable: true);
_localPlaylist.entries.map((entry) => songs.add(entry.key));

_selected = await showSearch(
_selected = (await showSearch(
context: context,
delegate: SearchBar(songs),
);
))!;

if (_selected == null) {
_selected = NONE;
Expand Down Expand Up @@ -141,7 +141,7 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {

return Card(
child: ListTile(
title: Center(child: Text(device.name)),
title: Center(child: Text(device.name!)),
subtitle: Center(child: Text('$type: $mac')),
onTap: () async {
await _manager.connect(device);
Expand Down Expand Up @@ -235,7 +235,7 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
_processDataReceived(event);
break;
case AdHocType.onConnection:
_peers.add(event.data as AdHocDevice);
_peers.add(event.device as AdHocDevice);
break;
case AdHocType.onConnectionClosed:
break;
Expand Down Expand Up @@ -272,17 +272,17 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {

for (var i = 0; i < peers.length; i++) {
if (peerName == peers[i]) {
entry.putIfAbsent(songs[i] as String, () => null);
entry!.putIfAbsent(songs[i] as String, () => PlatformFile(name: songs[i] as String, size: 0));
} else {
_globalPlaylist[peerName] = entry;
_globalPlaylist[peerName] = entry!;

peerName = peers[i] as String;
entry = _globalPlaylist[peerName];
if (entry == null) {
entry = HashMap();
}

entry.putIfAbsent(songs[i] as String, () => null);
entry.putIfAbsent(songs[i] as String, () => PlatformFile(name: songs[i] as String, size: 0));
}

var pair = Pair<String, String>(peerName, songs[i] as String);
Expand All @@ -291,33 +291,38 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
}
}

_globalPlaylist[peerName] = entry;
_globalPlaylist[peerName] = entry!;

setState(() {});

_manager.broadcastExcept(data, peer);
_manager.broadcastExcept(data, peer!);
break;

case REQUEST:
var name = data['name'] as String;
var found = false;
Uint8List bytes;
PlatformFile file;
Uint8List? bytes;
PlatformFile? file;

if (_localPlaylist.containsKey(name)) {
found = true;
bytes = _localPlaylist[name].bytes;
bytes = _localPlaylist[name]!.bytes!;
} else {
for (final entry in _globalPlaylist.entries) {
var _playlist = entry.value;
if (_playlist.containsKey(name)) {
file = _playlist[name];
if (file == null) {
if (file == null && file!.bytes == null) {
found = false;
break;
} else {
found = true;
bytes = file.bytes;
if (bytes != null) {
found = true;
} else {
found = false;
}
break;
}
}
}
Expand All @@ -330,14 +335,14 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
message = HashMap<String, dynamic>();
message.putIfAbsent('type', () => TRANSFER);
message.putIfAbsent('name', () => name);
_manager.sendMessageTo(message, peer.label);
_manager.sendMessageTo(message, peer!.label!);

message.clear();

message.putIfAbsent('type', () => REPLY);
message.putIfAbsent('name', () => name);
message.putIfAbsent('song', () => bytes);
_manager.sendEncryptedMessageTo(message, peer.label);
_manager.sendMessageTo(message, peer.label!);
}

break;
Expand All @@ -357,13 +362,13 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
)
);

_globalPlaylist.update(peer.label, (value) => entry, ifAbsent: () => entry);
_globalPlaylist.update(peer!.label!, (value) => entry, ifAbsent: () => entry);
setState(() => _requested = false);
break;

case TRANSFER:
var name = data['name'] as String;
_isTransfering.putIfAbsent(name, () => true);
_isTransfering.update(name, (value) => true, ifAbsent: () => true);
break;

default:
Expand All @@ -378,7 +383,7 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {

if(result != null) {
for (var file in result.files) {
var bytes = await File(file.path).readAsBytes();
var bytes = await File(file.path!).readAsBytes();
var song = PlatformFile(
name: file.name,
path: file.path,
Expand Down Expand Up @@ -422,25 +427,25 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
}

void _play() {
if (_selected.compareTo(NONE) == 0) {
if (_selected!.compareTo(NONE) == 0) {
return;
}

PlatformFile file;
PlatformFile? file;
if (_localPlaylist.containsKey(_selected)) {
file = _localPlaylist[_selected];
} else {
_globalPlaylist.forEach((peerName, playlist) {
if (playlist.containsKey(_selected)) {
file = playlist[_selected];
if (file == null) {
if (file == null || file!.size == 0) {
var message = HashMap<String, dynamic>();
message.putIfAbsent('type', () => REQUEST);
message.putIfAbsent('name', () => _selected);
_manager.broadcast(message);

setState(() => _requested = true);
_isTransfering.putIfAbsent(_selected, () => false);
_isTransfering.putIfAbsent(_selected!, () => false);

Timer(Duration(seconds: 30), () {
if (_requested == true && _isTransfering[_selected] == false) {
Expand All @@ -453,20 +458,20 @@ class _AdHocMusicClientState extends State<AdHocMusicClient> {
}

if (_requested == false) {
platform.invokeMethod('play', file.path);
platform.invokeMethod('play', file!.path);
}
}

void _pause() {
if (_selected.compareTo(NONE) == 0) {
if (_selected!.compareTo(NONE) == 0) {
return;
}

platform.invokeMethod('pause');
}

void _stop() {
if (_selected.compareTo(NONE) == 0) {
if (_selected!.compareTo(NONE) == 0) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions example/lib/search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
class SearchBar extends SearchDelegate<String> {
final List<String> _playlist;

List<String> _recentPick;
late List<String> _recentPick;
String _selected = '';

SearchBar(this._playlist) {
Expand All @@ -30,7 +30,7 @@ class SearchBar extends SearchDelegate<String> {
@override
Widget buildResults(BuildContext context) {
close(context, _selected);
return null;
return Container();
}

@override
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Demonstrates how to use the adhoc_plugin plugin.
publish_to: 'none'

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down
1 change: 0 additions & 1 deletion lib/adhoc_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ library adhoc_plugin;

export 'src/appframework/export.dart';
export 'src/datalink/export.dart';
export 'src/network/export.dart';
export 'src/presentation/export.dart';
Loading

0 comments on commit 2404a5f

Please sign in to comment.