serverpod_live_client 0.1.1 copy "serverpod_live_client: ^0.1.1" to clipboard
serverpod_live_client: ^0.1.1 copied to clipboard

Typed, resumable real-time channels, collections, commands, and presence for Serverpod.

example/main.dart

import 'dart:convert';

import 'package:serverpod_live_client/serverpod_live_client.dart';

class TodoChanged {
  const TodoChanged({required this.id, required this.completed});

  final String id;
  final bool completed;
}

final todoChangedCodec = LiveEventCodec<TodoChanged>(
  eventType: 'todo.changed',
  encode: (event) => jsonEncode({
    'id': event.id,
    'completed': event.completed,
  }),
  decode: (payloadJson) {
    final json = jsonDecode(payloadJson) as Map<String, dynamic>;
    return TodoChanged(
      id: json['id']! as String,
      completed: json['completed']! as bool,
    );
  },
);

LiveChannel<TodoChanged> openTodoChannel(Caller moduleCaller) {
  final channel = LiveClient(moduleCaller).channel<TodoChanged>(
    name: 'team:acme:todos',
    codec: todoChangedCodec,
  );
  channel.events.listen((event) {
    print('Todo ${event.value.id} is ${event.value.completed}.');
  });
  channel.resume();
  return channel;
}

void main() {
  print('Pass your generated module caller to openTodoChannel.');
}
0
likes
150
points
21
downloads

Documentation

API reference

Publisher

verified publishersumitgohil.com

Weekly Downloads

Typed, resumable real-time channels, collections, commands, and presence for Serverpod.

Repository (GitHub)
View/report issues

Topics

#serverpod #realtime #collaboration

License

Apache-2.0 (license)

Dependencies

serverpod_client, uuid

More

Packages that depend on serverpod_live_client