-
Notifications
You must be signed in to change notification settings - Fork 3
/
tethering.dart
69 lines (63 loc) · 2.7 KB
/
tethering.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2023, Halil Durmus. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'package:windows_networking/windows_networking.dart';
Future<void> startTethering(NetworkOperatorTetheringManager manager) async {
final result = await manager.startTetheringAsync();
if (result?.status == TetheringOperationStatus.success) {
print('Tethering started successfully.');
} else {
print('Could not start tethering.');
}
}
Future<void> stopTethering(NetworkOperatorTetheringManager manager) async {
final result = await manager.stopTetheringAsync();
if (result?.status == TetheringOperationStatus.success) {
print('Tethering stopped successfully.');
} else {
print('Could not stop tethering.');
}
}
void printTetheringManagerInformation(NetworkOperatorTetheringManager manager) {
print('Client count: ${manager.clientCount}');
print('Max client count: ${manager.maxClientCount}');
final configuration = manager.getCurrentAccessPointConfiguration();
if (configuration != null) {
final band = switch (configuration.band) {
TetheringWiFiBand.twoPointFourGigahertz => '2.4 GHz',
TetheringWiFiBand.fiveGigahertz => '5 GHz',
TetheringWiFiBand.auto => 'Auto',
};
print('Band: $band');
print('SSID: ${configuration.ssid}');
print('Passphrase: ${configuration.passphrase}');
}
}
void main() async {
final connectionProfile = NetworkInformation.getInternetConnectionProfile();
if (connectionProfile != null) {
final tetheringCapability = NetworkOperatorTetheringManager
.getTetheringCapabilityFromConnectionProfile(connectionProfile);
print('Tethering capability is ${tetheringCapability.name}');
if (tetheringCapability == TetheringCapability.enabled) {
final tetheringManager =
NetworkOperatorTetheringManager.createFromConnectionProfile(
connectionProfile);
if (tetheringManager != null) {
printTetheringManagerInformation(tetheringManager);
switch (tetheringManager.tetheringOperationalState) {
case TetheringOperationalState.off:
print('Tethering is off. Starting tethering...');
await startTethering(tetheringManager);
case TetheringOperationalState.on:
print('Tethering is on. Stopping tethering...');
await stopTethering(tetheringManager);
case TetheringOperationalState.inTransition:
print('Tethering is in transition between the on and off states.');
case TetheringOperationalState.unknown:
print('Current operational state is unknown.');
}
}
}
}
}