upgrade function
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,
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,
);
}