Skip to content

Commit

Permalink
start update realtime.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuamshana committed Apr 10, 2021
1 parent 50d669a commit f06368f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Refer to [BFastProject](http://bfast.fahamutech.com/docs) for better documentations.
Always use latest version

## [4.1.0] - 12/11/2020
## [4.1.1] - 04/10/2021

## [4.1.0] - 04/10/2021

remove ttl in cache.
update depencies.
Expand Down
2 changes: 1 addition & 1 deletion lib/bfast_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BFastFunctions {
/// @param onConnect {function} callback when connection established
/// @param onDisconnect {function} callback when connection terminated
SocketController event(String eventName,
{Function(dynamic data) onConnect, Function(dynamic data) onDisconnect}) {
{Function() onConnect, Function() onDisconnect}) {
return new SocketController(eventName,
appName: this._appName,
onConnect: onConnect,
Expand Down
48 changes: 29 additions & 19 deletions lib/controller/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,41 @@ class QueryController {
}

DatabaseChangesController changes(
[Function onConnect, Function onDisconnect]) {
var socketController = new SocketController('/__changes__',
appName: this.appName,
onConnect: onConnect,
onDisconnect: onDisconnect);
var applicationId =
{Function onConnect, Function onDisconnect, RequestOptions options}) {
String applicationId =
BFastConfig.getInstance().getAppCredential(this.appName).applicationId;
String projectId =
BFastConfig.getInstance().getAppCredential(this.appName).projectId;
String masterKey =
BFastConfig.getInstance().getAppCredential(this.appName).appPassword;
var match = {};
if (this._buildQuery() != null && this._buildQuery().filter != null) {
if (this._buildQuery != null && this._buildQuery().filter != null) {
match = this._buildQuery().filter;
match.forEach((key, value) {
match['fullDocument.$key'] = value;
match.keys.forEach((key) {
match['fullDocument.$key'] = match[key];
match.remove(key);
});
}
socketController.emit(auth: {
"applicationId": applicationId
}, body: {
"domain": this.domain,
"pipeline": match != null
? [
{"\$match": match}
]
: []
});

SocketController socketController;
socketController = new SocketController('/v2/__changes__',
appName: this.appName, onConnect: () {
if (onConnect != null) {
onConnect();
}
socketController.emit(auth: {
'applicationId': applicationId,
'topic': '${projectId}_${this.domain}',
'masterKey': options.useMasterKey == true ? masterKey : null
}, body: {
'domain': this.domain,
'pipeline': match != null
? [
{'\$match': match}
]
: []
});
}, onDisconnect: onDisconnect);
return new DatabaseChangesController(socketController);
}

Expand Down
15 changes: 10 additions & 5 deletions lib/controller/realtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@ class SocketController {

SocketController(String eventName,
{appName = BFastConfig.DEFAULT_APP,
void Function(dynamic e) onConnect,
void Function(dynamic e) onDisconnect}) {
dynamic Function() onConnect,
dynamic Function() onDisconnect}) {
String path = eventName.length > 0 && eventName[0] == '/'
? eventName
: '/' + eventName;
var url = path == '/__changes__'
var url = path == '/v2/__changes__'
? BFastConfig.getInstance().databaseURL(appName, path)
: BFastConfig.getInstance().functionsURL(path, appName);
this.socket = io(url, <String, dynamic>{
'transports': ['websocket'],
'autoConnect': false,
'reconnection': true,
'reconnectionAttempts': double.infinity,
'reconnectionDelay': 2000, // how long to initially wait before attempting a new reconnection
'reconnectionDelayMax': 5000, // maximum amount of time to wait between reconnection attempts. Each attempt increases the reconnection delay by 2x along with a randomization factor
'randomizationFactor': 0.5,
// 'extraHeaders': {'foo': 'bar'} // optional
});
this.eventName = eventName;
if (onConnect != null) {
this.socket.on("connect", (data) => onConnect(data));
this.socket.on("connect", (_) => onConnect());
}
if (onDisconnect != null) {
this.socket.on("disconnect", (data) => onDisconnect(data));
this.socket.on("disconnect", (_) => onDisconnect());
}
this.open();
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bfast
description: BFast client sdk for flutter
version: 4.1.0
version: 4.1.1
homepage: http://github.com/fahamutech/bfast-flutter

environment:
Expand Down

0 comments on commit f06368f

Please sign in to comment.