chore: merging latest master
commit
113bd5a359
|
@ -1,3 +0,0 @@
|
|||
[submodule "utility_packages/dart-eventsource"]
|
||||
path = utility_packages/dart-eventsource
|
||||
url = git@makerforce.io:beep/dart-eventsource.git
|
|
@ -4,4 +4,4 @@ final String baseUrlCore = "http://localhost/core";
|
|||
final String baseUrlSignaling = "http://localhost/signal";
|
||||
final String baseUrlHeartbeat = "http://localhost/heartbeat";
|
||||
final String baseUrlLogin = "http://localhost:1837";
|
||||
final String globalUserId = "u-fb91825f564a3cc110f11836fedea6f4";
|
||||
// final String globalUserId = "u-fb91825f564a3cc110f11836fedea6f4";
|
||||
|
|
|
@ -5,6 +5,7 @@ import "dart:ui";
|
|||
|
||||
import 'package:eventsource/eventsource.dart';
|
||||
import "package:rxdart/rxdart.dart";
|
||||
import "package:http/http.dart" as http;
|
||||
|
||||
import "../models/ping_model.dart";
|
||||
import "../services/login_manager.dart";
|
||||
|
@ -17,44 +18,52 @@ class HeartbeatReceiverBloc {
|
|||
DateTime lastSeen;
|
||||
String status;
|
||||
|
||||
final _coloursFetcher = PublishSubject<Color>();
|
||||
Observable<Color> get colours => _coloursFetcher.stream;
|
||||
final _coloursFetcher = PublishSubject<String>();
|
||||
|
||||
HeartbeatReceiverBloc(String userId) {
|
||||
final http.Client client;
|
||||
Observable<String> get colours => _coloursFetcher.stream;
|
||||
|
||||
HeartbeatReceiverBloc(String userId) : client = http.Client() {
|
||||
this.userId = userId;
|
||||
lastSeen = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
status = "";
|
||||
|
||||
loginManager.getToken().then((token) {
|
||||
EventSource.connect("$baseUrlHeartbeat/subscribe/$userId",
|
||||
authToken: token)
|
||||
EventSource.connect("$baseUrlHeartbeat/subscribe/$userId?token=$token",
|
||||
client: client)
|
||||
.then((es) {
|
||||
es.listen((Event event) {
|
||||
// Guard against empty packets
|
||||
if (event.data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ping ping = Ping.fromJson(jsonDecode(event.data));
|
||||
lastSeen = DateTime.fromMillisecondsSinceEpoch(ping.timestamp);
|
||||
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) {
|
||||
if (status == "on_call") {
|
||||
_coloursFetcher.sink.add(Color.fromARGB(255, 244, 67, 54));
|
||||
_coloursFetcher.sink.add("busy");
|
||||
} else {
|
||||
final now = new DateTime.now();
|
||||
final difference = now.difference(this.lastSeen);
|
||||
if (difference > timeoutDuration) {
|
||||
_coloursFetcher.sink.add(Color.fromARGB(255, 158, 158, 158));
|
||||
_coloursFetcher.sink.add("online");
|
||||
} else {
|
||||
_coloursFetcher.sink.add(Color.fromARGB(255, 76, 175, 80));
|
||||
_coloursFetcher.sink.add("offline");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catchError((e) => print(
|
||||
e)); // Add actual error handling logic for stopped connections
|
||||
});
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_coloursFetcher.close();
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,11 @@ part "ping_model.g.dart";
|
|||
|
||||
@JsonSerializable()
|
||||
class Ping {
|
||||
@JsonKey(name: "timestamp")
|
||||
final int timestamp;
|
||||
|
||||
@JsonKey(name: "status")
|
||||
final int time;
|
||||
final String status;
|
||||
|
||||
Ping(this.timestamp, this.status);
|
||||
Ping(this.time, this.status);
|
||||
|
||||
factory Ping.fromJson(Map<String, dynamic> json) =>
|
||||
_$PingFromJson(json);
|
||||
factory Ping.fromJson(Map<String, dynamic> json) => _$PingFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PingToJson(this);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
import "dart:async";
|
||||
import "dart:io";
|
||||
import 'dart:convert';
|
||||
import "package:http/http.dart" as http;
|
||||
|
||||
import "../../settings.dart";
|
||||
|
||||
import "../services/login_manager.dart";
|
||||
|
||||
class HeartbeatApiProvider {
|
||||
LoginManager loginManager = LoginManager();
|
||||
|
||||
Future<void> ping({ String status = "" }) async {
|
||||
final jwt = loginManager.getToken();
|
||||
Future<void> ping({String status = ""}) async {
|
||||
final jwt = await loginManager.getToken();
|
||||
print("GOT JWT: $jwt");
|
||||
await http.post("$baseUrlHeartbeat/ping",
|
||||
headers: {
|
||||
HttpHeaders.authorizationHeader: "Bearer $jwt"
|
||||
},
|
||||
body: status
|
||||
);
|
||||
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"},
|
||||
body: jsonEncode({"status": status}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@ class HeartbeatSendManager {
|
|||
String status;
|
||||
|
||||
HeartbeatSendManager() {
|
||||
status = "";
|
||||
status = "a";
|
||||
heartbeatApiProvider = HeartbeatApiProvider();
|
||||
const oneMinute = const Duration(minutes: 1);
|
||||
new Timer.periodic(oneMinute, (Timer t) => heartbeatApiProvider.ping(status:this.status));
|
||||
new Timer.periodic(oneMinute, (Timer t) {
|
||||
heartbeatApiProvider.ping(status: this.status);
|
||||
});
|
||||
}
|
||||
|
||||
void setStatus(String status) {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import "dart:async";
|
||||
import "../resources/login_api_provider.dart";
|
||||
import "../models/user_model.dart";
|
||||
import "../resources/user_api_provider.dart";
|
||||
import "../../settings.dart";
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
@ -41,9 +38,9 @@ class LoginManager {
|
|||
}
|
||||
}
|
||||
|
||||
Future<String> loginTest() async {
|
||||
Future<String> loginTest(String userId) async {
|
||||
try {
|
||||
final jwt = await loginApiProvider.loginTest(globalUserId, "1");
|
||||
final jwt = await loginApiProvider.loginTest(userId, "1");
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString("token", jwt);
|
||||
return jwt;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import "package:flutter/material.dart";
|
||||
|
||||
import "../../blocs/bottom_bus_bloc.dart";
|
||||
import "../../services/heartbeat_manager.dart";
|
||||
import "../../services/conversation_manager.dart";
|
||||
import "widgets/conversation_inactive_view.dart";
|
||||
import "widgets/conversation_active_view.dart";
|
||||
|
@ -16,6 +17,7 @@ class _BottomBarState extends State<BottomBar> {
|
|||
final bloc = bottomBusBloc;
|
||||
final conversationManager = ConversationManager();
|
||||
Map<String, String> initialState;
|
||||
final heartbeatSendManager = HeartbeatSendManager();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
|
@ -54,7 +54,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
TextButton(
|
||||
text: "Continue",
|
||||
onClickCallback: () {
|
||||
widget.loginManager.loginTest();
|
||||
print(controller.text);
|
||||
widget.loginManager.loginTest(controller.text);
|
||||
Navigator.pushNamed(context, 'welcome/otp');
|
||||
}),
|
||||
]));
|
||||
|
|
|
@ -7,13 +7,11 @@ class UserAvatar extends StatefulWidget {
|
|||
final User user;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double radius;
|
||||
final bloc;
|
||||
|
||||
UserAvatar(
|
||||
{@required this.user,
|
||||
this.padding: const EdgeInsets.all(0.0),
|
||||
this.radius: 20.0})
|
||||
: bloc = HeartbeatReceiverBloc(user.id);
|
||||
this.radius: 20.0});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
|
@ -22,37 +20,54 @@ class UserAvatar extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _UserAvatarState extends State<UserAvatar> {
|
||||
HeartbeatReceiverBloc bloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
print(widget.user.id);
|
||||
super.initState();
|
||||
bloc = HeartbeatReceiverBloc(widget.user.id);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.bloc.dispose();
|
||||
bloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String firstName =
|
||||
(widget.user.firstName.isEmpty) ? '' : widget.user.firstName[0];
|
||||
String lastName =
|
||||
(widget.user.lastName.isEmpty) ? '' : widget.user.lastName[0];
|
||||
|
||||
return Padding(
|
||||
padding: widget.padding,
|
||||
child: Stack(alignment: Alignment.bottomRight, children: <Widget>[
|
||||
CircleAvatar(
|
||||
backgroundColor: _stringToColor(widget.user.lastName),
|
||||
child: Text(
|
||||
widget.user.firstName[0].toUpperCase() +
|
||||
widget.user.lastName[0].toUpperCase(),
|
||||
firstName.toUpperCase() + lastName.toUpperCase(),
|
||||
style: Theme.of(context).accentTextTheme.title,
|
||||
),
|
||||
radius: widget.radius),
|
||||
StreamBuilder(
|
||||
stream: widget.bloc.colours,
|
||||
builder: (context, AsyncSnapshot<Color> snapshot) {
|
||||
Color colour = Color.fromARGB(255, 158, 158, 158);
|
||||
stream: bloc.colours,
|
||||
builder: (context, AsyncSnapshot<String> snapshot) {
|
||||
String state;
|
||||
if (snapshot.hasData) {
|
||||
colour = snapshot.data;
|
||||
state = snapshot.data;
|
||||
if (state == "online") {
|
||||
return Container(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green[400], shape: BoxShape.circle));
|
||||
}
|
||||
}
|
||||
return Container(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
decoration:
|
||||
BoxDecoration(color: colour, shape: BoxShape.circle));
|
||||
|
||||
return Container();
|
||||
}),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ dependencies:
|
|||
flutter_svg: ^0.10.3
|
||||
shared_preferences: ^0.5.1
|
||||
sqflite: ^1.1.0
|
||||
eventsource:
|
||||
path: ./utility_packages/dart-eventsource
|
||||
eventsource: ^0.2.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 0368fb1fc37d43535f01faba8d2b8a256e6f2643
|
Loading…
Reference in New Issue