Skip to content

Commit 9c64e15

Browse files
committed
include example source code
0 parents  commit 9c64e15

File tree

14 files changed

+589
-0
lines changed

14 files changed

+589
-0
lines changed

.github/workflows/dart.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Dart CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
container:
15+
image: google/dart:latest
16+
17+
steps:
18+
- uses: actions/checkout@v1
19+
- uses: actions/setup-java@v1
20+
with:
21+
java-version: '12.x'
22+
- uses: subosito/flutter-action@v1
23+
with:
24+
flutter-version: '1.9.1+hotfix.6'
25+
- run: flutter pub get
26+
- run: flutter test
27+

.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
build/
32+
33+
# Android related
34+
**/android/**/gradle-wrapper.jar
35+
**/android/.gradle
36+
**/android/captures/
37+
**/android/gradlew
38+
**/android/gradlew.bat
39+
**/android/local.properties
40+
**/android/**/GeneratedPluginRegistrant.java
41+
42+
# iOS/XCode related
43+
**/ios/**/*.mode1v3
44+
**/ios/**/*.mode2v3
45+
**/ios/**/*.moved-aside
46+
**/ios/**/*.pbxuser
47+
**/ios/**/*.perspectivev3
48+
**/ios/**/*sync/
49+
**/ios/**/.sconsign.dblite
50+
**/ios/**/.tags*
51+
**/ios/**/.vagrant/
52+
**/ios/**/DerivedData/
53+
**/ios/**/Icon?
54+
**/ios/**/Pods/
55+
**/ios/**/.symlinks/
56+
**/ios/**/profile
57+
**/ios/**/xcuserdata
58+
**/ios/.generated/
59+
**/ios/Flutter/App.framework
60+
**/ios/Flutter/Flutter.framework
61+
**/ios/Flutter/Flutter.podspec
62+
**/ios/Flutter/Generated.xcconfig
63+
**/ios/Flutter/app.flx
64+
**/ios/Flutter/app.zip
65+
**/ios/Flutter/flutter_assets/
66+
**/ios/Flutter/flutter_export_environment.sh
67+
**/ios/ServiceDefinitions.json
68+
**/ios/Runner/GeneratedPluginRegistrant.*
69+
70+
# Exceptions to above rules.
71+
!**/ios/**/default.mode1v3
72+
!**/ios/**/default.mode2v3
73+
!**/ios/**/default.pbxuser
74+
!**/ios/**/default.perspectivev3

.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 81a45ec2e5f80fa71d5135f1702ce540558b416d
8+
channel: beta
9+
10+
project_type: package

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: dart
2+
dart:
3+
# Install the latest stable release
4+
- stable
5+
# Install the latest beta release
6+
- beta
7+
# Install the latest dev release
8+
- dev
9+
# Install a specific stable release - 1.15.0
10+
- "1.15.0"
11+
# Install a specific dev release, using a partial download URL - 2.9.0-2.0.dev
12+
- "dev/release/2.9.0-2.0.dev"
13+
# Install a specific beta release, using a partial download URL - 2.9.0-2.0.beta
14+
- "beta/release/2.9.0-2.0.beta"
15+
dart_task:
16+
- dartfmt: true
17+
- test: --platform vm
18+
- test: --platform dartium
19+
install_dartium: true

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 0.0.1 (29-09-2020)
2+
3+
- Include the ability to get network speed
4+
- Include Upload and Download speed
5+
6+
## 1.0.0 (29-09-2020)
7+
8+
- Minor updates to the documentation
9+
10+
## 1.0.1 (29-09-2020)
11+
12+
- Fix code error
13+
- Include Example source code

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2020 Damola Adekoya
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without restriction,
7+
including without limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of the Software,
9+
and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included
13+
in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# FastNet
2+
3+
[![GitHub code](https://img.shields.io/github/languages/code-size/dammak/FastNet)](https://github.com/DAMMAK/FastNet)[![GitHub Releases](https://img.shields.io/github/downloads/dammak/FastNet/total)](https://github.com/DAMMAK/FastNet)[![GitHub](https://img.shields.io/github/license/dammak/FastNet)](https://github.com/DAMMAK/FastNet)
4+
5+
```
6+
A Dart package that allows you to test your network download and upload speed using [fast.com](https://fast.com)
7+
8+
```
9+
10+
## Install
11+
12+
```dart
13+
dependencies:
14+
fastnet: ^0.0.1
15+
16+
```
17+
18+
## Usage
19+
20+
```dart
21+
22+
var fastnet = FastNet(isListenable: false);
23+
var response = await fastnet.getSpeed();
24+
response.listen((Result event) {
25+
print(event.downloadSpeedValue);
26+
});
27+
28+
```
29+
30+
### Inspired
31+
https://github.com/sindresorhus/fast-cli

example/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:fastnet/fastnet.dart';
2+
import 'package:fastnet/src/model/result.dart';
3+
4+
void main() async {
5+
var fastnet = FastNet();
6+
var response = await fastnet.getSpeed();
7+
response.listen((Result result) {
8+
print(
9+
"Download: ${result.downloadSpeedValue} ${result.downloadSpeedUnit}\n Upload: ${result.uploadSpeedValue} ${result.uploadSpeedUnit}");
10+
});
11+
}

lib/fastnet.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'src/fastnet.dart';

lib/src/fastnet.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
library fastnet;
2+
3+
import 'dart:async';
4+
import 'package:fastnet/src/model/result.dart';
5+
import 'package:puppeteer/puppeteer.dart';
6+
7+
/// A .
8+
class FastNet {
9+
//Duration in milliseconds
10+
static void _delay(duration) {
11+
Future.delayed(Duration(milliseconds: duration));
12+
}
13+
14+
static init({
15+
Page page,
16+
Browser browser,
17+
StreamController streamController,
18+
}) async {
19+
Result prevResult;
20+
while (true) {
21+
var content = await page.evaluate('''x=>{
22+
const downloadSpeedValue= document.querySelector("#speed-value").textContent;
23+
const downloadSpeedUnit =document.querySelector("#speed-units").textContent;
24+
const uploadSpeedValue = document.querySelector("#upload-value").textContent;
25+
const uploadSpeedUnit = document.querySelector("#upload-units").textContent;
26+
const isDone= Boolean(
27+
document.querySelector('#speed-value.succeeded') && document.querySelector('#upload-value.succeeded')
28+
);
29+
return{downloadSpeedValue, downloadSpeedUnit, uploadSpeedValue, uploadSpeedUnit, isDone};
30+
}''', args: []);
31+
var result = Result.fromJson(content);
32+
33+
if (result.downloadSpeedValue > 0 && result != prevResult) {
34+
streamController.sink.add(result);
35+
}
36+
37+
if (result.isDone) {
38+
await browser.close();
39+
streamController.close();
40+
return;
41+
}
42+
prevResult = result;
43+
_delay(100);
44+
}
45+
}
46+
47+
getSpeed() async {
48+
StreamController<Result> _streamController = StreamController();
49+
Browser browser = await puppeteer.launch(timeout: Duration(minutes: 10));
50+
Page page = await browser.newPage();
51+
await page.goto('https://fast.com/#');
52+
init(page: page, browser: browser, streamController: _streamController);
53+
return _streamController.stream;
54+
}
55+
}

0 commit comments

Comments
 (0)