feat: revamp sensor add flow
This commit is contained in:
@@ -56,6 +56,28 @@ class RealtimeDataClient {
|
||||
.map((msg) => msg.payload ?? const {});
|
||||
}
|
||||
|
||||
/// Like [channel], but includes the Phoenix event name in each emission.
|
||||
Stream<({String event, Map<String, dynamic> payload})> channelMessages(
|
||||
String topic, {
|
||||
Map<String, dynamic> params = const {},
|
||||
}) {
|
||||
final socket = _socket;
|
||||
if (socket == null) throw StateError('RealtimeDataClient not connected');
|
||||
|
||||
final ch = _channels.putIfAbsent(
|
||||
topic,
|
||||
() {
|
||||
final c = socket.addChannel(topic: topic, parameters: params);
|
||||
c.join();
|
||||
return c;
|
||||
},
|
||||
);
|
||||
|
||||
return ch.messages
|
||||
.where((msg) => msg.event.value != 'phx_reply')
|
||||
.map((msg) => (event: msg.event.value, payload: msg.payload ?? const {}));
|
||||
}
|
||||
|
||||
/// Pushes [event] on [topic] and waits for the server reply.
|
||||
/// The channel must have been joined first via [channel].
|
||||
Future<Map<String, dynamic>> push(
|
||||
|
||||
Reference in New Issue
Block a user