Erweiterungen
This commit is contained in:
@@ -214,4 +214,89 @@ Zum Testen der STOMP-Funktionalität können Sie:
|
||||
2. Browser-Entwicklertools für WebSocket-Verbindungen nutzen
|
||||
3. Spezialisierte STOMP-Testing-Tools einsetzen
|
||||
|
||||
Die Implementierung ist vollständig und bereit für die Integration mit externen Apps.
|
||||
Die Implementierung ist vollständig und bereit für die Integration mit externen Apps.
|
||||
|
||||
## Neue STOMP-Schnittstelle: Task-Erledigung melden
|
||||
|
||||
Mit dieser Schnittstelle kann ein Client die Erledigung eines Tasks melden.
|
||||
|
||||
- Senden (Client → Server): `/app/task/completed`
|
||||
- Broadcasts (Server → Client):
|
||||
- Global: `/topic/task-updates`
|
||||
- Task-spezifisch: `/topic/tasks/{taskId}`
|
||||
|
||||
Payload (JSON):
|
||||
|
||||
```json
|
||||
{
|
||||
"taskId": "<MongoId als String>",
|
||||
"completedBy": "<optional: Name/ID des Ausführenden>",
|
||||
"note": "<optional: Kommentar>"
|
||||
}
|
||||
```
|
||||
|
||||
Antwort (Beispiel):
|
||||
|
||||
```json
|
||||
{
|
||||
"timestamp": "2025-09-05T09:25:00",
|
||||
"type": "taskCompletedAck",
|
||||
"success": true,
|
||||
"taskId": "...",
|
||||
"jobId": "...",
|
||||
"completed": true,
|
||||
"completedAt": "2025-09-05T09:25:00",
|
||||
"completedBy": "driver01",
|
||||
"note": "Übergabe erfolgreich",
|
||||
"event": "taskCompleted"
|
||||
}
|
||||
```
|
||||
|
||||
JavaScript Beispiel:
|
||||
|
||||
```javascript
|
||||
// Abonnieren der globalen Updates
|
||||
stompClient.subscribe('/topic/task-updates', (frame) => {
|
||||
console.log('Task update:', JSON.parse(frame.body));
|
||||
});
|
||||
|
||||
// Abonnieren eines spezifischen Tasks
|
||||
stompClient.subscribe('/topic/tasks/' + taskId, (frame) => {
|
||||
console.log('Task-specific update:', JSON.parse(frame.body));
|
||||
});
|
||||
|
||||
// Task als erledigt melden
|
||||
stompClient.send('/app/task/completed', {}, JSON.stringify({
|
||||
taskId: taskId,
|
||||
completedBy: 'driver01',
|
||||
note: 'Übergabe erfolgreich'
|
||||
}));
|
||||
```
|
||||
|
||||
Flutter/Dart Beispiel:
|
||||
|
||||
```dart
|
||||
stompClient.subscribe(
|
||||
destination: '/topic/task-updates',
|
||||
callback: (frame) => print('Task update: ${frame.body}'),
|
||||
);
|
||||
|
||||
stompClient.subscribe(
|
||||
destination: '/topic/tasks/$taskId',
|
||||
callback: (frame) => print('Task-specific update: ${frame.body}'),
|
||||
);
|
||||
|
||||
stompClient.send(
|
||||
destination: '/app/task/completed',
|
||||
body: jsonEncode({
|
||||
'taskId': taskId,
|
||||
'completedBy': 'driver01',
|
||||
'note': 'Übergabe erfolgreich',
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
Hinweise:
|
||||
- `taskId` ist Pflicht. Bei ungültiger oder unbekannter `taskId` wird `success=false` zurückgegeben.
|
||||
- Der Server setzt `completed=true` und `completedAt` automatisch.
|
||||
- Zusätzlich zum globalen Broadcast wird ein task-spezifisches Event auf `/topic/tasks/{taskId}` versendet.
|
||||
|
||||
Reference in New Issue
Block a user