4
2
Fork 0

updates to heartbeat

pull/43/head
Sudharshan S. 2019-05-19 15:46:06 +08:00
parent bc5731f70c
commit 227bf52dfe
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
6 changed files with 33 additions and 22 deletions

View File

@ -41,15 +41,15 @@ class HeartbeatReceiverBloc {
lastSeen = DateTime.fromMillisecondsSinceEpoch(ping.time * 1000);
status = ping.status;
});
final oneMinute = Duration(minutes: 1);
final timeoutDuration = Duration(minutes: 30);
new Timer.periodic(oneMinute, (Timer t) {
final checkDuration = Duration(seconds: 20);
final timeoutDuration = Duration(minutes: 1);
new Timer.periodic(checkDuration, (Timer t) {
if (status == "on_call") {
_coloursFetcher.sink.add("busy");
} else {
final now = new DateTime.now();
final difference = now.difference(this.lastSeen);
if (difference > timeoutDuration) {
if (difference < timeoutDuration) {
_coloursFetcher.sink.add("online");
} else {
_coloursFetcher.sink.add("offline");

View File

@ -17,7 +17,6 @@ class ConversationManager {
}
Future<int> join(String conversationId) async {
print("JOIN called");
try {
await channel.invokeMethod('join', conversationId);
} on PlatformException catch (e) {

View File

@ -11,8 +11,8 @@ class HeartbeatSendManager {
HeartbeatSendManager() {
status = "a";
heartbeatApiProvider = HeartbeatApiProvider();
const oneMinute = const Duration(minutes: 1);
new Timer.periodic(oneMinute, (Timer t) {
const transmitInterval = const Duration(seconds: 20);
new Timer.periodic(transmitInterval, (Timer t) {
heartbeatApiProvider.ping(status: this.status);
});
}

View File

@ -44,6 +44,7 @@ class _ConversationActiveViewState extends State<ConversationActiveView> {
conversationApiProvider
.fetchConversationMembers(widget.conversationId)
.then((users) {
print(users[0].id);
setState(() {
_users = users
.map((user) =>

View File

@ -23,12 +23,16 @@ class _HomeState extends State<Home> {
int _pageNumber = 0;
PersistentBottomSheetController bottomBarController;
@override
initState() {
super.initState();
controller.addListener(_updatePageNumber);
messageBloc.bus.listen((Map<String, String> data) => _processMessage(data));
messageBloc.bus.listen(
(Map<String, String> data) async => await _processMessage(data));
_setupBottomState();
}
@override
@ -43,33 +47,38 @@ class _HomeState extends State<Home> {
});
}
_processMessage(Map<String, String> data) {
_processMessage(Map<String, String> data) async {
if (data["state"] == "disconnect") {
// Disconnect and change state
_scaffoldKey.currentState.showBottomSheet<void>(
await conversationManager.exit();
bottomBarController.close();
bottomBarController = _scaffoldKey.currentState.showBottomSheet<void>(
(BuildContext context) => BottomBar(conversationId: ""));
} else if (data["state"] == "connect") {
// Connect and change state
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) =>
BottomBar(conversationId: data["conversationId"]));
await conversationManager.join(data["conversationId"]);
bottomBarController.close();
bottomBarController = _scaffoldKey.currentState.showBottomSheet<void>(
(BuildContext context) =>
BottomBar(conversationId: data["conversationId"]));
} else {
// show default
_scaffoldKey.currentState.showBottomSheet<void>(
await conversationManager.exit();
bottomBarController.close();
bottomBarController = _scaffoldKey.currentState.showBottomSheet<void>(
(BuildContext context) => BottomBar(conversationId: ""));
}
}
Future<void> executeAfterBuild() async {
final conversationId = await conversationManager.get();
_scaffoldKey.currentState.showBottomSheet<void>(
(BuildContext context) => BottomBar(conversationId: conversationId));
_setupBottomState() {
conversationManager.get().then((conversationId) {
bottomBarController = _scaffoldKey.currentState.showBottomSheet<void>(
(BuildContext context) => BottomBar(conversationId: conversationId));
});
}
@override
Widget build(BuildContext context) {
executeAfterBuild();
return Scaffold(
key: _scaffoldKey,
body: Column(children: <Widget>[

View File

@ -65,10 +65,12 @@ class _UserAvatarState extends State<UserAvatar> {
width: 12.0,
height: 12.0,
decoration: BoxDecoration(
color: Colors.green[400], shape: BoxShape.circle));
color: Colors.green[400],
shape: BoxShape.circle,
border: Border.all(
width: 1.5, color: const Color(0xFFFFFFFF))));
}
}
return Container();
}),
]));