Skip to content

Commit d5e73cf

Browse files
Release/v1.1.1 (#27)
* chore: start with userId and propagation profile * chore: update version 1.1.1
1 parent 97d4f37 commit d5e73cf

File tree

12 files changed

+173
-77
lines changed

12 files changed

+173
-77
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bridgefy Flutter 1.1.0
1+
# Bridgefy Flutter 1.1.1
22
### BLUETOOTH MESH NETWORKS
33

44
Devices running your app create Bluetooth Low-Energy mesh networks, which work in large crowds, during and after natural disasters, and whenever else your users lose access to the Internet.

README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ To install this SDK, you'll need to either add the following to your `pubspec.ya
4444

4545
```yaml
4646
dependencies:
47-
bridgefy: ^1.1.0
47+
bridgefy: ^1.1.1
4848
```
4949
5050
Or run this flutter command:
@@ -57,11 +57,11 @@ flutter pub add bridgefy
5757

5858
### Initialization
5959

60-
The init method initializes the Bridgefy SDK with the given API key and propagation profile. The
60+
The init method initializes the Bridgefy SDK with the given API key and verbose logging. The
6161
delegate parameter is required and should be an object that conforms to the `BridgefyDelegate`
6262
mixin.
6363

64-
The following code shows how to start the SDK (using your API key) and how to assign the delegate.
64+
The following code shows how to init the SDK (using your API key) and how to assign the delegate.
6565

6666
```dart
6767
import 'package:bridgefy/bridgefy.dart';
@@ -72,13 +72,29 @@ class _MyAppState extends State<MyApp> implements BridgefyDelegate {
7272
@override
7373
void initState() {
7474
super.initState();
75-
_bridgefy.initialize(
76-
apiKey: "<API_KEY>",
77-
propagationProfile: BridgefyPropagationProfile.longReach,
78-
delegate: this
79-
);
75+
try {
76+
await _bridgefy.initialize(
77+
apiKey: "<API_KEY>",
78+
delegate: this,
79+
verboseLogging: true,
80+
);
81+
} catch (e) {
82+
_log("Unable to initialize: $e");
83+
}
8084
}
8185
```
86+
### Start Bridgefy
87+
88+
The following code shows how to start the SDK with propagation profile and custom user Id.
89+
90+
````dart
91+
92+
_bridgefy.start(
93+
userId: "Custom UUID",
94+
propagationProfile: BridgefyPropagationProfile.standard
95+
);
96+
97+
````
8298

8399
### Sending data
84100

@@ -124,6 +140,26 @@ void bridgefyDidReceiveData({
124140
}
125141
```
126142

143+
### Nearby peer detection
144+
145+
The following method is invoked when a peer has established connection:
146+
147+
```dart
148+
@override
149+
void bridgefyDidConnect({required String userID}) {
150+
// `userID` the peer connected
151+
}
152+
```
153+
154+
When a peer is disconnected(out of range), the following method will be invoked:
155+
156+
```dart
157+
@override
158+
void bridgefyDidDisconnect({required String userID}) {
159+
// `userID` the peer disconnected
160+
}
161+
```
162+
127163
To see a full list of events, take a look at the `BridgefyDelegate` mixin.
128164

129165
## Multi-Platform Support

android/src/main/kotlin/me/bridgefy/plugin/flutter/BridgefyPlugin.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ class BridgefyPlugin : FlutterPlugin, MethodCallHandler {
180180
}
181181

182182
private fun start(@NonNull call: MethodCall, @NonNull result: Result) {
183-
bridgefy.start()
183+
val args = call.arguments as HashMap<String, Any>
184+
val userId: String? = args["userId"] as String?
185+
val propagationProfile = propagationProfileFromString(args["propagationProfile"] as String) ?: PropagationProfile.Standard
186+
bridgefy.start(
187+
userId?.let{ UUID.fromString(it)},
188+
propagationProfile
189+
)
184190
result.success(null)
185191
}
186192

example/lib/main.dart

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ class _MyAppState extends State<MyApp> implements BridgefyDelegate {
2626
final _scrollController = ScrollController();
2727

2828
@override
29-
void dispose() {
29+
void dispose() {
3030
_scrollController.dispose();
3131
super.dispose();
3232
}
3333

34-
_goToEnd(){
35-
Timer(const Duration(milliseconds:300), (){
34+
_goToEnd() {
35+
Timer(const Duration(milliseconds: 300), () {
3636
_scrollController.animateTo(
37-
_scrollController.position.maxScrollExtent,
38-
duration: const Duration(milliseconds:200),
37+
_scrollController.position.maxScrollExtent,
38+
duration: const Duration(milliseconds: 200),
3939
curve: Curves.linear,
4040
);
4141
});
@@ -68,10 +68,8 @@ class _MyAppState extends State<MyApp> implements BridgefyDelegate {
6868

6969
@override
7070
Widget build(BuildContext context) {
71-
SystemChrome.setPreferredOrientations([
72-
DeviceOrientation.portraitUp,
73-
DeviceOrientation.portraitDown
74-
]);
71+
SystemChrome.setPreferredOrientations(
72+
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
7573

7674
return MaterialApp(
7775
theme: ThemeData(
@@ -93,28 +91,26 @@ class _MyAppState extends State<MyApp> implements BridgefyDelegate {
9391
mainAxisAlignment: MainAxisAlignment.center,
9492
children: [
9593
ElevatedButton.icon(
96-
icon: _didStart ?
97-
const Icon(Icons.stop_circle) :
98-
const Icon(Icons.check_circle),
99-
onPressed: _toggleStart,
100-
label: Text(_buttonText)
101-
),
94+
icon: _didStart
95+
? const Icon(Icons.stop_circle)
96+
: const Icon(Icons.check_circle),
97+
onPressed: _toggleStart,
98+
label: Text(_buttonText)),
10299
const SizedBox(width: 7),
103100
ElevatedButton.icon(
104-
icon: const Icon(Icons.send),
105-
onPressed: _didStart ? _send : null,
106-
label: const Text("Send")
107-
),
101+
icon: const Icon(Icons.send),
102+
onPressed: _didStart ? _send : null,
103+
label: const Text("Send")),
108104
const SizedBox(width: 7),
109105
ElevatedButton.icon(
110-
icon: const Icon(Icons.delete_forever),
111-
onPressed: _logStr!='' ? _clearLogs : null,
112-
label: const Text("Logs")
113-
),
106+
icon: const Icon(Icons.delete_forever),
107+
onPressed: _logStr != '' ? _clearLogs : null,
108+
label: const Text("Logs")),
114109
],
115110
),
116111
const SizedBox(height: 10),
117-
const Text("Logs", style: TextStyle(fontWeight: FontWeight.bold)),
112+
const Text("Logs",
113+
style: TextStyle(fontWeight: FontWeight.bold)),
118114
const SizedBox(height: 10),
119115
Expanded(
120116
child: SafeArea(
@@ -179,7 +175,8 @@ class _MyAppState extends State<MyApp> implements BridgefyDelegate {
179175
}
180176

181177
@override
182-
void bridgefyDidFailSendingMessage({required String messageID, BridgefyError? error}) {
178+
void bridgefyDidFailSendingMessage(
179+
{required String messageID, BridgefyError? error}) {
183180
_log("bridgefyDidFailSendingMessage: $messageID, $error");
184181
}
185182

example/test/widget_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void main() {
1818
// Verify that platform version is retrieved.
1919
expect(
2020
find.byWidgetPredicate(
21-
(Widget widget) => widget is Text &&
22-
widget.data!.startsWith('Running on:'),
21+
(Widget widget) =>
22+
widget is Text && widget.data!.startsWith('Running on:'),
2323
),
2424
findsOneWidget,
2525
);

lib/bridgefy.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ mixin BridgefyDelegate {
214214
/// - Parameters:
215215
/// - messageId: The id of the message that was tried to be sent
216216
/// - error: Error reason.
217-
void bridgefyDidFailSendingMessage({required String messageID, BridgefyError? error});
217+
void bridgefyDidFailSendingMessage(
218+
{required String messageID, BridgefyError? error});
218219

219220
/// This function is called when a new message is received
220221
/// - Parameters:
@@ -257,8 +258,16 @@ class Bridgefy {
257258
}
258259

259260
/// Start Bridgefy SDK operations
260-
Future<void> start() {
261-
return BridgefyPlatform.instance.start();
261+
/// - Parameters:
262+
/// - userId: set custom user Id
263+
/// - propagationProfile: start with propagation profile
264+
Future<void> start({
265+
String? userId,
266+
BridgefyPropagationProfile propagationProfile =
267+
BridgefyPropagationProfile.standard,
268+
}) async {
269+
return BridgefyPlatform.instance
270+
.start(userId: userId, propagationProfile: propagationProfile);
262271
}
263272

264273
/// Stop Bridgefy SDK operations

lib/bridgefy_method_channel.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ class MethodChannelBridgefy extends BridgefyPlatform {
3939
@override
4040
Future<void> start({
4141
String? userId,
42-
BridgefyPropagationProfile propagationProfile = BridgefyPropagationProfile.standard,
42+
BridgefyPropagationProfile propagationProfile =
43+
BridgefyPropagationProfile.standard,
4344
}) {
4445
assert(_initialized, 'Bridgefy is not initialized');
45-
return methodChannel.invokeMethod(
46-
'start',
47-
{
48-
"userId": userId,
49-
"propagationProfile": propagationProfile.name,
50-
}
51-
);
46+
return methodChannel.invokeMethod('start', {
47+
"userId": userId,
48+
"propagationProfile": propagationProfile.name,
49+
});
5250
}
5351

5452
@override
@@ -62,7 +60,10 @@ class MethodChannelBridgefy extends BridgefyPlatform {
6260
'send',
6361
{
6462
"data": data,
65-
"transmissionMode": {"mode": transmissionMode.type.name, "uuid": transmissionMode.uuid},
63+
"transmissionMode": {
64+
"mode": transmissionMode.type.name,
65+
"uuid": transmissionMode.uuid
66+
},
6667
},
6768
);
6869
return result["messageId"] as String;
@@ -94,7 +95,8 @@ class MethodChannelBridgefy extends BridgefyPlatform {
9495
@override
9596
Future<void> establishSecureConnection({required String userID}) {
9697
assert(_initialized, 'Bridgefy is not initialized');
97-
return methodChannel.invokeMethod('establishSecureConnection', {"userId": userID});
98+
return methodChannel
99+
.invokeMethod('establishSecureConnection', {"userId": userID});
98100
}
99101

100102
@override
@@ -122,7 +124,8 @@ class MethodChannelBridgefy extends BridgefyPlatform {
122124

123125
BridgefyTransmissionMode _transmissionMode(dynamic result) {
124126
return BridgefyTransmissionMode(
125-
type: BridgefyTransmissionModeType.values.byName(result["transmissionMode"]["mode"]),
127+
type: BridgefyTransmissionModeType.values
128+
.byName(result["transmissionMode"]["mode"]),
126129
uuid: result["transmissionMode"]["uuid"],
127130
);
128131
}
@@ -150,7 +153,8 @@ class MethodChannelBridgefy extends BridgefyPlatform {
150153
Future<dynamic> delegateCallHandler(MethodCall call) async {
151154
switch (call.method) {
152155
case "bridgefyDidStart":
153-
_delegate?.bridgefyDidStart(currentUserID: call.arguments['userId'] as String);
156+
_delegate?.bridgefyDidStart(
157+
currentUserID: call.arguments['userId'] as String);
154158
break;
155159
case "bridgefyDidFailToStart":
156160
_delegate?.bridgefyDidFailToStart(
@@ -172,13 +176,16 @@ class MethodChannelBridgefy extends BridgefyPlatform {
172176
_delegate?.bridgefyDidFailToDestroySession();
173177
break;
174178
case "bridgefyDidConnect":
175-
_delegate?.bridgefyDidConnect(userID: call.arguments['userId'] as String);
179+
_delegate?.bridgefyDidConnect(
180+
userID: call.arguments['userId'] as String);
176181
break;
177182
case "bridgefyDidDisconnect":
178-
_delegate?.bridgefyDidDisconnect(userID: call.arguments['userId'] as String);
183+
_delegate?.bridgefyDidDisconnect(
184+
userID: call.arguments['userId'] as String);
179185
break;
180186
case "bridgefyDidEstablishSecureConnection":
181-
_delegate?.bridgefyDidEstablishSecureConnection(userID: call.arguments['userId'] as String);
187+
_delegate?.bridgefyDidEstablishSecureConnection(
188+
userID: call.arguments['userId'] as String);
182189
break;
183190
case "bridgefyDidFailToEstablishSecureConnection":
184191
_delegate?.bridgefyDidFailToEstablishSecureConnection(
@@ -187,7 +194,8 @@ class MethodChannelBridgefy extends BridgefyPlatform {
187194
);
188195
break;
189196
case "bridgefyDidSendMessage":
190-
_delegate?.bridgefyDidSendMessage(messageID: call.arguments['messageId'] as String);
197+
_delegate?.bridgefyDidSendMessage(
198+
messageID: call.arguments['messageId'] as String);
191199
break;
192200
case "bridgefyDidFailSendingMessage":
193201
_delegate?.bridgefyDidFailSendingMessage(

lib/bridgefy_platform_interface.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ abstract class BridgefyPlatform extends PlatformInterface {
3636

3737
Future<void> start({
3838
String? userId,
39-
BridgefyPropagationProfile propagationProfile = BridgefyPropagationProfile.standard,
39+
BridgefyPropagationProfile propagationProfile =
40+
BridgefyPropagationProfile.standard,
4041
}) {
4142
throw UnimplementedError('start() has not been implemented.');
4243
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: bridgefy
22
description: The Bridgefy SDK is a state-of-the-art, plug-and-play package that lets people use apps when they don’t have access to the Internet by using mesh networ
3-
version: 1.1.0
3+
version: 1.1.1
44
homepage: https://bridgefy.me/sdk
55
repository: https://github.com/bridgefy/bridgefy_flutter
66
issue_tracker: https://github.com/bridgefy/bridgefy_flutter/issues

0 commit comments

Comments
 (0)