Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cease using internet_connection_checker #298

Merged
merged 8 commits into from
Aug 1, 2023
35 changes: 26 additions & 9 deletions packages/sshnoports/lib/sshnpd/sshnpd_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,8 @@ class SSHNPDImpl implements SSHNPD {
}
}

logger.info('Starting connectivity listener');
// Keep an eye on connectivity and report failures if we see them
ConnectivityListener().subscribe().listen((isConnected) {
if (isConnected) {
logger.warning('connection available');
} else {
logger.warning('connection lost');
}
});
logger.info('Starting heartbeat');
startHeartbeat();

logger.info('Subscribing to $device\\.${SSHNPD.namespace}@');
notificationService
Expand All @@ -169,6 +162,30 @@ class SSHNPDImpl implements SSHNPD {
logger.info('Done');
}

void startHeartbeat() {
bool lastHeartbeatOk = true;
Timer.periodic(Duration(seconds: 15), (timer) async {
String? resp;
try {
resp = await atClient
.getRemoteSecondary()
?.atLookUp
.executeCommand('noop:0\n');
} catch (_) {}
if (resp == null || !resp.startsWith('data:ok')) {
if (lastHeartbeatOk) {
logger.shout('connection lost');
}
lastHeartbeatOk = false;
} else {
if (!lastHeartbeatOk) {
logger.shout('connection available');
}
lastHeartbeatOk = true;
}
});
}

void _notificationHandler(AtNotification notification) async {
String notificationKey = notification.key
.replaceAll('${notification.to}:', '')
Expand Down
22 changes: 11 additions & 11 deletions packages/sshnoports/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ packages:
dependency: "direct main"
description:
name: at_client
sha256: "63652edf7f856b875b59002bd48c2df3a5848aab0ac34fea12f07b02d2036db3"
sha256: c7f8316fe97faf010e0698d7e0bd81e35cc39644bf2dcd69a22cf25ba914b8c5
url: "https://pub.dev"
source: hosted
version: "3.0.63"
version: "3.0.64"
at_commons:
dependency: transitive
description:
Expand Down Expand Up @@ -173,10 +173,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -221,10 +221,10 @@ packages:
dependency: transitive
description:
name: dart_internal
sha256: dae3976f383beddcfcd07ad5291a422df2c8c0a8a03c52cda63ac7b4f26e0f4e
sha256: "689dccc3d5f62affd339534cca548dce12b3a6b32f0f10861569d3025efc0567"
url: "https://pub.dev"
source: hosted
version: "0.2.8"
version: "0.2.9"
dartssh2:
dependency: "direct main"
description:
Expand Down Expand Up @@ -589,10 +589,10 @@ packages:
dependency: "direct dev"
description:
name: test
sha256: "67ec5684c7a19b2aba91d2831f3d305a6fd8e1504629c5818f8d64478abf4f38"
sha256: b9a384c4b9c4966dbf7215e7c033a78db1da7e5dcaf8da9232c5f24735f65652
url: "https://pub.dev"
source: hosted
version: "1.24.4"
version: "1.24.5"
test_api:
dependency: transitive
description:
Expand All @@ -605,10 +605,10 @@ packages:
dependency: transitive
description:
name: test_core
sha256: "6b753899253c38ca0523bb0eccff3934ec83d011705dae717c61ecf209e333c9"
sha256: c6a536288535efef8526eea8adfa4e25fdd2849fa7f457ecb2a52099998ce8f7
url: "https://pub.dev"
source: hosted
version: "0.5.4"
version: "0.5.5"
tuple:
dependency: transitive
description:
Expand Down Expand Up @@ -698,4 +698,4 @@ packages:
source: hosted
version: "0.2.0"
sdks:
dart: ">=3.0.0 <3.2.0"
dart: ">=3.0.0 <3.3.0"
4 changes: 2 additions & 2 deletions packages/sshnoports/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:

dependencies:
args: 2.4.2
at_client: 3.0.63
at_client: 3.0.64
at_lookup: 3.0.38
at_onboarding_cli: 1.3.0
at_utils: 3.0.15
Expand All @@ -27,5 +27,5 @@ dependencies:

dev_dependencies:
lints: ^2.1.1
test: ^1.24.3
test: ^1.24.4
mocktail: ^0.3.0