send method

  1. @override
Future<void> send(
  1. Map<String, dynamic> payload, {
  2. String? type,
})
override

Sends payload to the channel.

If the channel is disconnected, implementations should buffer the message and send it once reconnected.

Implementation

@override
Future<void> send(Map<String, dynamic> payload, {String? type}) async {
  final ref = _db.ref(_path);
  final envelope = <String, dynamic>{
    'id': _uuid.v4(),
    if (type != null) 'type': type,
    'payload': payload,
    'sentAt': DateTime.now().toIso8601String(),
  };
  // push() creates a new child with a Firebase-generated key.
  await ref.push().set(envelope);
}