upgrade function

Future<void> upgrade(
  1. Crdt crdt,
  2. HttpRequest request, {
  3. Duration? pingInterval = defaultPingInterval,
  4. ServerHandshakeDataBuilder? handshakeDataBuilder,
  5. ChangesetBuilder? changesetBuilder,
  6. RecordValidator? validateRecord,
  7. ChangesetMapper? mapIncomingChangeset,
  8. ServerOnConnect? onConnect,
  9. OnDisconnect? onDisconnect,
  10. OnChangeset? onChangesetReceived,
  11. OnChangeset? onChangesetSent,
  12. bool verbose = false,
})

Upgrades an incoming connection to a WebSocket and synchronizes the provided crdt.

See listen for the parameter description.

Implementation

Future<void> upgrade(
  Crdt crdt,
  HttpRequest request, {
  Duration? pingInterval = defaultPingInterval,
  ServerHandshakeDataBuilder? handshakeDataBuilder,
  ChangesetBuilder? changesetBuilder,
  RecordValidator? validateRecord,
  ChangesetMapper? mapIncomingChangeset,
  ServerOnConnect? onConnect,
  OnDisconnect? onDisconnect,
  OnChangeset? onChangesetReceived,
  OnChangeset? onChangesetSent,
  bool verbose = false,
}) async {
  final webSocket =
      IOWebSocketChannel(await WebSocketTransformer.upgrade(request)
        ..pingInterval = pingInterval);
  late final CrdtSync crdtSync;
  crdtSync = CrdtSync.server(
    crdt,
    webSocket,
    handshakeDataBuilder: handshakeDataBuilder,
    changesetBuilder: changesetBuilder,
    validateRecord: validateRecord,
    mapIncomingChangeset: mapIncomingChangeset,
    onConnect: (_, customData) => onConnect?.call(crdtSync, customData),
    onDisconnect: onDisconnect,
    onChangesetReceived: onChangesetReceived,
    onChangesetSent: onChangesetSent,
    verbose: verbose,
  );
}