This commit is contained in:
ImBenji
2024-05-17 17:36:02 +01:00
parent 1f48f8f4b0
commit fff8de13c0
6 changed files with 5734 additions and 358 deletions

View File

@@ -39,7 +39,7 @@ class LiveInformation {
// By default, load the bus sequences from the assets
print("Loading bus sequences from assets");
busSequences = BusSequences.fromCSV(
await rootBundle.loadString("assets/datasets/bus-blinds.csv"),
await rootBundle.loadString("assets/datasets/destinations.json"),
await rootBundle.loadString("assets/datasets/bus-sequences.csv")
);
print("Loaded bus sequences from assets");
@@ -49,7 +49,7 @@ class LiveInformation {
http.Response response = await http.get(Uri.parse('https://tfl.gov.uk/bus-sequences.csv'));
busSequences = BusSequences.fromCSV(
await rootBundle.loadString("assets/datasets/bus-blinds.csv"),
await rootBundle.loadString("assets/datasets/destinations.json"),
response.body
);
@@ -294,7 +294,7 @@ class LiveInformation {
print("Created room with code $roomCode");
}
Future<void> JoinRoom(String roomCode) async {
Future<void> joinRoom(String roomCode) async {
print("Joining room with code $roomCode");
// Disable host mode
@@ -375,6 +375,45 @@ class LiveInformation {
print("Joined room with code $roomCode");
}
Future<void> leaveRoom() async {
if (roomCode == null) {
throw Exception("Not in a room");
}
if (isHost) {
// Access the database
final client = auth.client;
final databases = appwrite.Databases(client);
// Remove any existing documents
final existingDocuments = await databases.listDocuments(
databaseId: "6633e85400036415ab0f",
collectionId: "6633e85d0020f52f3771",
queries: [
appwrite.Query.search("SessionID", roomCode!)
]
);
for (var document in existingDocuments.documents) {
await databases.deleteDocument(
databaseId: "6633e85400036415ab0f",
collectionId: "6633e85d0020f52f3771",
documentId: document.$id
);
}
}
roomCode = null;
roomDocumentID = null;
isHost = false;
_keepAliveConnection?.close();
_keepAliveConnection = null;
// Reset stuff
setRouteVariant(null);
}
String? lastCommand;
Future<void> ServerListener(appwrite.RealtimeMessage response) async {
print("Session update");