paradigm shift
This commit is contained in:
@@ -74,7 +74,7 @@ class AnnouncementModule extends InfoModule {
|
||||
final EventDelegate<AnnouncementQueueEntry> onAnnouncement = EventDelegate();
|
||||
|
||||
// Timer
|
||||
Timer refreshTimer() => Timer.periodic(const Duration(milliseconds: 200), (timer) async {
|
||||
Timer refreshTimer() => Timer.periodic(const Duration(milliseconds: 10), (timer) async {
|
||||
|
||||
if (!isPlaying) {
|
||||
|
||||
@@ -84,7 +84,7 @@ class AnnouncementModule extends InfoModule {
|
||||
|
||||
bool proceeding = await _internalAccountForInconsistentTime(
|
||||
announcement: nextAnnouncement,
|
||||
timerInterval: const Duration(milliseconds: 200),
|
||||
timerInterval: const Duration(milliseconds: 10),
|
||||
callback: () {
|
||||
queue.removeAt(0);
|
||||
print("Announcement proceeding");
|
||||
@@ -105,35 +105,21 @@ class AnnouncementModule extends InfoModule {
|
||||
|
||||
if (currentAnnouncement!.audioSources.isNotEmpty) {
|
||||
|
||||
// audioPlayer.loadSource(AudioWrapperAssetSource("assets/audio/5-seconds-of-silence.mp3"));
|
||||
// audioPlayer.play();
|
||||
// await Future.delayed(const Duration(milliseconds: 300));
|
||||
// audioPlayer.stop();
|
||||
// Prime all of the audio sources to be ready to play
|
||||
for (AudioWrapperSource source in currentAnnouncement!.audioSources) {
|
||||
try {
|
||||
await audioPlayer.loadSource(source);
|
||||
await Future.delayed((await audioPlayer.play())!);
|
||||
audioPlayer.stop();
|
||||
|
||||
// try {
|
||||
for (AudioWrapperSource source in currentAnnouncement!.audioSources) {
|
||||
try {
|
||||
await audioPlayer.loadSource(source);
|
||||
|
||||
Duration? duration = await audioPlayer.play();
|
||||
await Future.delayed(duration!);
|
||||
audioPlayer.stop();
|
||||
// await Future.delayed(const Duration(milliseconds: 100));
|
||||
if (currentAnnouncement?.audioSources.last != source) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
} catch (e) {
|
||||
// Do nothing
|
||||
// print("Error playing announcement: $e on ${currentAnnouncement?.displayText}");
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (currentAnnouncement?.audioSources.last != source) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
} catch (e) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
// audioPlayer.stop();
|
||||
}
|
||||
|
||||
// } catch (e) {
|
||||
// // Do nothing
|
||||
// print("Error playing announcement: $e on ${currentAnnouncement?.displayTex}");
|
||||
// }
|
||||
} else {
|
||||
if (queue.isNotEmpty) {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
@@ -179,7 +165,7 @@ class AnnouncementModule extends InfoModule {
|
||||
}
|
||||
|
||||
// Configuration
|
||||
int get defaultAnnouncementDelay => liveInformation.auth.isAuthenticated() ? 2 : 0;
|
||||
int get defaultAnnouncementDelay => liveInformation.auth.isAuthenticated() ? 1 : 0;
|
||||
|
||||
// Methods
|
||||
Future<void> queueAnnounceByAudioName({
|
||||
@@ -199,8 +185,12 @@ class AnnouncementModule extends InfoModule {
|
||||
audioNamesString += "\"$audioName\" ";
|
||||
}
|
||||
|
||||
liveInformation.commandModule.executeCommand(
|
||||
"announce manual \"$displayText\" ${audioNamesString} ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||
liveInformation.SendCommand("announce manual \"$displayText\" $audioNamesString ${scheduledTime.millisecondsSinceEpoch}");
|
||||
queueAnnounceByAudioName(
|
||||
displayText: displayText,
|
||||
audioNames: audioNames,
|
||||
scheduledTime: scheduledTime,
|
||||
sendToServer: false
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -244,9 +234,13 @@ class AnnouncementModule extends InfoModule {
|
||||
|
||||
scheduledTime ??= liveInformation.syncedTimeModule.Now().add(Duration(seconds: defaultAnnouncementDelay));
|
||||
|
||||
liveInformation.commandModule.executeCommand(
|
||||
"announce info $infoIndex ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||
liveInformation.SendCommand("announce info $infoIndex ${scheduledTime.millisecondsSinceEpoch}");
|
||||
queueAnnounementByInfoIndex(
|
||||
infoIndex: infoIndex,
|
||||
scheduledTime: scheduledTime,
|
||||
sendToServer: false
|
||||
);
|
||||
print("Announcement sent to server");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -270,9 +264,16 @@ class AnnouncementModule extends InfoModule {
|
||||
|
||||
scheduledTime ??= liveInformation.syncedTimeModule.Now().add(Duration(seconds: defaultAnnouncementDelay));
|
||||
|
||||
liveInformation.commandModule.executeCommand(
|
||||
"announce dest \"${routeVariant.busRoute.routeNumber}\" ${routeVariant.busRoute.routeVariants.values.toList().indexOf(routeVariant)} ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||
String routeNumber = routeVariant.busRoute.routeNumber;
|
||||
int routeVariantIndex = routeVariant.busRoute.routeVariants.values.toList().indexOf(routeVariant);
|
||||
|
||||
liveInformation.SendCommand("announce dest ${routeNumber} ${routeVariantIndex} ${scheduledTime.millisecondsSinceEpoch}");
|
||||
queueAnnouncementByRouteVariant(
|
||||
routeVariant: routeVariant,
|
||||
scheduledTime: scheduledTime,
|
||||
sendToServer: false
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
print("Checkpoint 4");
|
||||
|
||||
@@ -47,17 +47,37 @@ class CommandModule extends InfoModule {
|
||||
|
||||
final databases = appwrite.Databases(client);
|
||||
|
||||
if (liveInformation.auth.status == AuthStatus.AUTHENTICATED) {
|
||||
final document = await databases.createDocument(
|
||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
||||
collectionId: ApiConstants.COMMANDS_COLLECTION_ID,
|
||||
documentId: appwrite.ID.unique(),
|
||||
if (true) {
|
||||
try {
|
||||
final response = await databases.listDocuments(
|
||||
databaseId: "6633e85400036415ab0f",
|
||||
collectionId: "6633e85d0020f52f3771",
|
||||
queries: [
|
||||
appwrite.Query.search("SessionID", liveInformation.roomCode!)
|
||||
]
|
||||
);
|
||||
|
||||
List<String> pastCommands = [];
|
||||
|
||||
response.documents.first.data["Commands"].forEach((element) {
|
||||
pastCommands.add(element);
|
||||
});
|
||||
|
||||
pastCommands.add(command);
|
||||
|
||||
final document = await databases.updateDocument(
|
||||
databaseId: "6633e85400036415ab0f",
|
||||
collectionId: "6633e85d0020f52f3771",
|
||||
documentId: liveInformation.roomDocumentID!,
|
||||
data: {
|
||||
"session_id": sessionID,
|
||||
"command": command,
|
||||
"client_id": clientID,
|
||||
"Commands": pastCommands,
|
||||
"LastUpdater": clientID,
|
||||
}
|
||||
);
|
||||
);
|
||||
} catch (e) {
|
||||
print("Failed to send command");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_onCommandReceived(CommandInfo(command, clientID));
|
||||
@@ -78,6 +98,10 @@ class CommandModule extends InfoModule {
|
||||
|
||||
if (command == "Response:") {
|
||||
|
||||
}
|
||||
else if (command == "initroom") {
|
||||
// initroom <roomCode>
|
||||
|
||||
}
|
||||
else if (command == "announce") {
|
||||
|
||||
@@ -166,10 +190,41 @@ class CommandModule extends InfoModule {
|
||||
BusRoute route = liveInformation.busSequences.routes[routeNumber]!;
|
||||
BusRouteVariant routeVariant = route.routeVariants.values.toList()[routeVariantIndex];
|
||||
|
||||
liveInformation.setRouteVariant_Internal(
|
||||
liveInformation.setRouteVariant(
|
||||
routeVariant
|
||||
);
|
||||
executeCommand("Response: v \"Client $clientID set its route to ($routeNumber to ${routeVariant.busStops.last.formattedStopName})\"");
|
||||
|
||||
|
||||
// Update the server
|
||||
if (liveInformation.isHost) {
|
||||
print("Updating server");
|
||||
final client = liveInformation.auth.client;
|
||||
final databases = appwrite.Databases(client);
|
||||
|
||||
final response = await databases.listDocuments(
|
||||
databaseId: "6633e85400036415ab0f",
|
||||
collectionId: "6633e85d0020f52f3771",
|
||||
queries: [
|
||||
appwrite.Query.search("SessionID", liveInformation.roomCode!)
|
||||
]
|
||||
);
|
||||
|
||||
final document = await databases.updateDocument(
|
||||
databaseId: "6633e85400036415ab0f",
|
||||
collectionId: "6633e85d0020f52f3771",
|
||||
documentId: response.documents.first.$id,
|
||||
data: {
|
||||
"CurrentRoute": routeNumber,
|
||||
"CurrentRouteVariant": routeVariantIndex,
|
||||
}
|
||||
);
|
||||
try {
|
||||
|
||||
print("Updated server");
|
||||
} catch (e) {
|
||||
print("Failed to update server");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -181,26 +236,26 @@ class CommandModule extends InfoModule {
|
||||
return;
|
||||
}
|
||||
|
||||
final realtime = appwrite.Realtime(LiveInformation().auth.client);
|
||||
|
||||
_subscription = realtime.subscribe(
|
||||
['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.COMMANDS_COLLECTION_ID}.documents']
|
||||
);
|
||||
_subscription!.stream.listen((event) {
|
||||
print(jsonEncode(event.payload));
|
||||
|
||||
// Only do something if the document was created or updated
|
||||
if (!(event.events.first.contains("create") || event.events.first.contains("update"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
final commandInfo = CommandInfo(event.payload['command'], event.payload['client_id']);
|
||||
|
||||
if (commandInfo.clientID != clientID) {
|
||||
_onCommandReceived(commandInfo);
|
||||
}
|
||||
|
||||
});
|
||||
// final realtime = appwrite.Realtime(LiveInformation().auth.client);
|
||||
//
|
||||
// _subscription = realtime.subscribe(
|
||||
// ['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.COMMANDS_COLLECTION_ID}.documents']
|
||||
// );
|
||||
// _subscription!.stream.listen((event) {
|
||||
// print(jsonEncode(event.payload));
|
||||
//
|
||||
// // Only do something if the document was created or updated
|
||||
// if (!(event.events.first.contains("create") || event.events.first.contains("update"))) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final commandInfo = CommandInfo(event.payload['command'], event.payload['client_id']);
|
||||
//
|
||||
// if (commandInfo.clientID != clientID) {
|
||||
// _onCommandReceived(commandInfo);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
|
||||
print("Listening for commands");
|
||||
|
||||
|
||||
@@ -183,7 +183,6 @@ class TrackerModule extends InfoModule {
|
||||
print("Closest stop: ${closestStop.formattedStopName} in ${closestDistance.round()} meters");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
double _calculateRelativeDistance(BusRouteStop stop, double latitude, double longitude) {
|
||||
|
||||
@@ -68,7 +68,7 @@ class TubeStations {
|
||||
double distance = Vector2(stop.easting.toDouble(), stop.northing.toDouble()).distanceTo(OSGrid.toNorthingEasting(station.latitude, station.longitude));
|
||||
|
||||
// if the distance is less than 100m, then we can assume that the bus stop is near the tube station
|
||||
if (distance < 200) {
|
||||
if (distance < 400) {
|
||||
for (TubeLine line in station.lines) {
|
||||
lineMatches[line] = lineMatches[line]! + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user