Тестовая синхронизация

This commit is contained in:
RoyceDa
2026-02-13 17:13:21 +02:00
parent 3af1e53a19
commit 6a76061399
2 changed files with 31 additions and 12 deletions

View File

@@ -45,8 +45,7 @@ export function ProtocolProvider(props : ProtocolProviderProps) {
deviceOs: systemInfo.os
}
protocol.connect();
//protocol.startHandshakeExchange(publicKey, privateKey, device);
protocol.on('connect', () => {
const connect = () => {
console.info("Connected to server, starting handshake exchange");
protocol.startHandshakeExchange(publicKey, privateKey, device);
/**
@@ -54,24 +53,41 @@ export function ProtocolProvider(props : ProtocolProviderProps) {
* так как при переподключении они слетают
*/
setOnlineSubscribes([]);
});
protocol.on('reconnect', () => {
}
const reconnect = () => {
log("Connection lost, reconnecting and starting handshake exchange");
setConnect(ProtocolState.RECONNECTING);
});
protocol.on('handshake_start', () => {
}
const handshake_start = () => {
log("Handshake exchange started");
setConnect(ProtocolState.HANDSHAKE_EXCHANGE);
});
protocol.on('handshake_complete', () => {
}
const handshake_complete = () => {
log("Handshake exchange complete");
setConnect(ProtocolState.CONNECTED);
});
protocol.on('handshake_need_device_verification', () => {
}
const handshake_need_device_verification = () => {
log("Handshake exchange needs device verification");
setConnect(ProtocolState.DEVICE_VERIFICATION_REQUIRED);
navigate('/deviceconfirm');
});
}
protocol.on('connect', connect);
protocol.on('reconnect', reconnect);
protocol.on('handshake_start', handshake_start);
protocol.on('handshake_complete', handshake_complete);
protocol.on('handshake_need_device_verification', handshake_need_device_verification);
return () => {
/**
* Отключаем все обработчики событий при размонтировании компонента, чтобы избежать
* утечек памяти и некорректного поведения при повторном монтировании
*/
protocol.off('connect', connect);
protocol.off('reconnect', reconnect);
protocol.off('handshake_start', handshake_start);
protocol.off('handshake_complete', handshake_complete);
protocol.off('handshake_need_device_verification', handshake_need_device_verification);
}
}, [publicKey, privateKey, systemInfo.id]);
return (