roomful 0.1.0-alpha.10 copy "roomful: ^0.1.0-alpha.10" to clipboard
roomful: ^0.1.0-alpha.10 copied to clipboard

Open-source, self-hostable realtime collaboration for Dart and Flutter apps — presence, live cursors, comments, locks, shared state, session replay, and AI agents.

example/roomful_example.dart

// Demonstrates the `v2.1-alpha` scaffold: capability negotiation and envelope
// encode/decode. Run with `dart run example/roomful_example.dart`.

import 'package:roomful/roomful.dart';

void main() {
  // Two peers advertise capabilities and negotiate a session.
  final local = ProtocolCapabilities.create(['json', 'msgpack'], 'msgpack');
  final remote = ProtocolCapabilities.create(['json', 'msgpack'], 'msgpack');
  final negotiation = negotiateSession(local, remote, supportsBinary: true);
  print('negotiated: ${negotiation.session?.toJson()} (${negotiation.reason})');

  // Encode a cursor update, then decode it back.
  final session = negotiation.session ?? ProtocolSession.legacyV1;
  final jsonSession = ProtocolSession(
    version: session.version,
    codec: 'json',
    legacy: session.legacy,
  );
  final message = WireMessage(
    type: 'cursor:update',
    roomId: 'room-a',
    fromPeerId: 'peer-a',
    timestamp: DateTime.now().millisecondsSinceEpoch,
    payload: <String, dynamic>{
      'cursor': <String, dynamic>{
        'userId': 'peer-a',
        'name': 'Alice',
        'color': '#5cc7ab',
        'x': 0.5,
        'y': 0.25,
        'xAbsolute': 640,
        'yAbsolute': 360,
        'idle': false,
      },
    },
  );

  final wire = encodeJsonEnvelope(message, jsonSession);
  print('wire: $wire');
  final decoded = decodeJsonEnvelope(wire);
  print('decoded ${decoded.type} from ${decoded.fromPeerId}');
}
0
likes
160
points
6
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Open-source, self-hostable realtime collaboration for Dart and Flutter apps — presence, live cursors, comments, locks, shared state, session replay, and AI agents.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#collaboration #realtime #websocket #presence #multiplayer

License

MIT (license)

Dependencies

msgpack_dart, web_socket_channel

More

Packages that depend on roomful