Skip to content

Commit

Permalink
Merge pull request #9 from osociety/dev
Browse files Browse the repository at this point in the history
Prepare release v1.0.1
  • Loading branch information
git-elliot authored Sep 2, 2023
2 parents e007efd + 6ce3d83 commit 90bb02b
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 39 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
name: Flutter

on:
push:
branches: ["main"]
pull_request:
branches: ["main", "dev"]

Expand Down Expand Up @@ -70,6 +68,15 @@ jobs:

- name: Run analyzer
run: flutter analyze

- name: Install coverage tools
run: flutter pub global activate coverage

- name: Run tests
run: flutter test
run: flutter test --coverage

- name: Upload Coverage to CodeCov
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coverage/lcov.info
7 changes: 2 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ jobs:
run: flutter pub global activate coverage

- name: Run tests
run: flutter test --coverage-path="coverage"

- name: Format Coverage
run: $HOME/.pub-cache/bin/format_coverage --lcov --in=coverage --out=coverage/coverage.lcov --report-on=lib
run: flutter test --coverage

- name: Setup Pub Credentials
shell: bash
Expand All @@ -86,4 +83,4 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage/coverage.lcov
file: coverage/lcov.info
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.0.1

* Bug fixes and improvements, add more tests for coverage

## 1.0.0

* Initial support added for ping_ios_dart in network_tools
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Network Tools Flutter

[![pub package](https://img.shields.io/pub/v/network_tools_flutter.svg)](https://pub.dev/packages/network_tools_flutter) [![Dart](https://github.com/osociety/network_tools_flutter/actions/workflows/flutter.yml/badge.svg)](https://github.com/osociety/network_tools_flutter/actions/workflows/flutter.yml) [![codecov](https://codecov.io/gh/git-elliot/network_tools_flutter/branch/main/graph/badge.svg?token=J9G2472GQZ)](https://codecov.io/gh/git-elliot/network_tools_flutter)
[![pub package](https://img.shields.io/pub/v/network_tools_flutter.svg)](https://pub.dev/packages/network_tools_flutter) [![Dart](https://github.com/osociety/network_tools_flutter/actions/workflows/flutter.yml/badge.svg)](https://github.com/osociety/network_tools_flutter/actions/workflows/flutter.yml) [![codecov](https://codecov.io/gh/osociety/network_tools_flutter/graph/badge.svg?token=X8UVO7RUA4)](https://codecov.io/gh/osociety/network_tools_flutter)

## Features

Expand Down
40 changes: 40 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';

void main() {
// Logger.root.level = Level.FINE;
// Logger.root.onRecord.listen((record) {
// print(
// '${DateFormat.Hms().format(record.time)}: ${record.level.name}: ${record.loggerName}: ${record.message}',
// );
// });
final log = Logger("host_scan_example");

const String address = '192.168.1.1';
// or You can also get address using network_info_plus package
// final String? address = await (NetworkInfo().getWifiIP());
final String subnet = address.substring(0, address.lastIndexOf('.'));

// You can set [firstHostId] and scan will start from this host in the network.
// Similarly set [lastHostId] and scan will end at this host in the network.
final stream = HostScannerFlutter.getAllPingableDevices(
subnet,
// firstHostId: 1,
// lastHostId: 254,
progressCallback: (progress) {
log.finer('Progress for host discovery : $progress');
},
);

stream.listen(
(ActiveHost host) async {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
log.fine('Found device: ${await host.toStringFull()}');
},
onDone: () {
log.fine('Scan completed');
},
); // Don't forget to cancel the stream when not in use.
}
2 changes: 1 addition & 1 deletion lib/network_tools_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library network_tools_flutter;

export 'src/host_scanner_flutter.dart';
export 'src/port_scanner_flutter.dart';
export 'src/port_scanner_flutter.dart';
8 changes: 4 additions & 4 deletions lib/src/host_scanner_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class HostScannerFlutter {
final receivePort = ReceivePort();
dynamic isolate;

if(Platform.isAndroid || Platform.isIOS){
if (Platform.isAndroid || Platform.isIOS) {
// Flutter isolate is not implemented for other platforms than these two
isolate = await FlutterIsolate.spawn(
isolate = await FlutterIsolate.spawn(
HostScannerFlutter._startSearchingDevices, receivePort.sendPort);
} else {
isolate = await Isolate.spawn(
HostScannerFlutter._startSearchingDevices, receivePort.sendPort);
}

await for (final message in receivePort.asBroadcastStream()) {
if (message is SendPort) {
message.send([
message.send(<String>[
subnet,
i.toString(),
limit.toString(),
Expand Down
29 changes: 20 additions & 9 deletions lib/src/port_scanner_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import 'package:network_tools/network_tools.dart';

/// Flutter flavor of PortScanner, only use if your project is based of flutter.
class PortScannerFlutter {

/// Checks if the single [port] is open or not for the [target].
static Future<ActiveHost?> isOpen(
String target,
int port, {
Duration timeout = const Duration(milliseconds: 2000),
}){
}) {
DartPingIOS.register();
return PortScanner.isOpen(target, port);
return PortScanner.isOpen(target, port, timeout: timeout);
}

/// Scans ports only listed in [portList] for a [target]. Progress can be
Expand All @@ -29,7 +28,11 @@ class PortScannerFlutter {
bool resultsInAddressAscendingOrder = true,
}) {
DartPingIOS.register();
return PortScanner.customDiscover(target);
return PortScanner.customDiscover(target,
portList: portList,
progressCallback: progressCallback,
timeout: timeout,
resultsInAddressAscendingOrder: resultsInAddressAscendingOrder);
}

/// Scans port from [startPort] to [endPort] of [target]. Progress can be
Expand All @@ -42,9 +45,14 @@ class PortScannerFlutter {
ProgressCallback? progressCallback,
Duration timeout = const Duration(milliseconds: 2000),
bool resultsInAddressAscendingOrder = true,
}){
}) {
DartPingIOS.register();
return PortScanner.scanPortsForSingleDevice(target);
return PortScanner.scanPortsForSingleDevice(target,
startPort: startPort,
endPort: endPort,
progressCallback: progressCallback,
timeout: timeout,
resultsInAddressAscendingOrder: resultsInAddressAscendingOrder);
}

static Future<ActiveHost?> connectToPort({
Expand All @@ -55,7 +63,10 @@ class PortScannerFlutter {
int recursionCount = 0,
}) async {
DartPingIOS.register();
return PortScanner.connectToPort(address: address, port: port, timeout: timeout,
activeHostsController: activeHostsController);
return PortScanner.connectToPort(
address: address,
port: port,
timeout: timeout,
activeHostsController: activeHostsController);
}
}
}
19 changes: 12 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: network_tools_flutter
description: Extended features of network_tools for flutter framework.
version: 1.0.0
description: Extended features of network_tools package for flutter framework supporting iOS and Android
version: 1.0.1
issue_tracker: https://github.com/osociety/network_tools_flutter/issues
repository: https://github.com/osociety/network_tools_flutter.git
repository: https://github.com/osociety/network_tools_flutter

environment:
sdk: ">=2.17.6 <4.0.0"
Expand All @@ -11,12 +11,17 @@ environment:
dependencies:
flutter:
sdk: flutter
network_tools: ^3.2.2

# Multi-platform network ping utility.
dart_ping: ^8.0.1
dart_ping_ios: ^3.0.0
universal_io: ^2.2.0
dart_ping: ^9.0.0
dart_ping_ios: ^4.0.0
flutter_isolate: ^2.0.4
# Debugging and error logging.
logging: ^1.2.0
# Deal with internationalized/localized messages and more.
intl: ^0.18.0
network_tools: ^3.2.2
universal_io: ^2.2.0

dev_dependencies:
flutter_test:
Expand Down
26 changes: 17 additions & 9 deletions test/host_scan_flutter_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:universal_io/io.dart';

void main() {
final log = Logger("host_scan_test");
TestWidgetsFlutterBinding.ensureInitialized();
int port = 0;
int hostId = 0;
int firstHostId = 0;
int lastHostId = 0;
String myOwnHost = "0.0.0.0";
String interfaceIp = myOwnHost.substring(0, myOwnHost.lastIndexOf('.'));
late ServerSocket server;
Expand All @@ -28,8 +31,15 @@ void main() {
.address; //gives IP address of GHA local machine.
myOwnHost = address;
interfaceIp = address.substring(0, address.lastIndexOf('.'));
hostId = int.parse(
address.substring(address.lastIndexOf('.') + 1, address.length));
final hostId = int.parse(
address.substring(address.lastIndexOf('.') + 1, address.length),
);
// Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
firstHostId = hostId <= 1 ? hostId : hostId - 1;
lastHostId = hostId >= 254 ? hostId : hostId + 1;
log.fine(
'Fetched own host as $myOwnHost and interface address as $interfaceIp',
);
}
}
});
Expand All @@ -40,9 +50,8 @@ void main() {
//There should be at least one device pingable in network
HostScannerFlutter.getAllPingableDevices(
interfaceIp,
// Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
firstHostId: hostId - 1,
lastHostId: hostId + 1,
firstHostId: firstHostId,
lastHostId: lastHostId,
),
emits(isA<ActiveHost>()),
);
Expand All @@ -52,9 +61,8 @@ void main() {
//Should emit at least our own local machine when pinging all hosts.
HostScannerFlutter.getAllPingableDevices(
interfaceIp,
// Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
firstHostId: hostId - 1,
lastHostId: hostId + 1,
firstHostId: firstHostId,
lastHostId: lastHostId,
),
emitsThrough(ActiveHost(internetAddress: InternetAddress(myOwnHost))),
);
Expand Down
Loading

0 comments on commit 90bb02b

Please sign in to comment.