Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose stateIsSyncronized flag to check if the crdt state is initialized #1020

Merged
merged 11 commits into from
Oct 18, 2024
Prev Previous commit
Next Next commit
add a max amount of retries
  • Loading branch information
gonpombo8 committed Oct 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 46078281a95dcb02acd503fdd468804aa916986b
8 changes: 4 additions & 4 deletions packages/@dcl/sdk/src/network/message-bus-sync.ts
Original file line number Diff line number Diff line change
@@ -81,18 +81,18 @@ export function addSyncTransport(
transport.onmessage!(value)
})

async function requestState() {
async function requestState(retryCount: number = 0) {
let players = Array.from(engine.getEntitiesWith(PlayerIdentityData))
DEBUG_NETWORK_MESSAGES() && console.log(`Requesting state. Players connected: ${players.length - 1}`)
binaryMessageBus.emit(CommsMessage.REQ_CRDT_STATE, engineToCrdt(engine))
await sleep(3000)
players = Array.from(engine.getEntitiesWith(PlayerIdentityData))

if (!stateIsSyncronized) {
if (players.length > 1) {
if (players.length > 1 && retryCount <= 2) {
DEBUG_NETWORK_MESSAGES() &&
console.log(`Requesting state again (no response). Players connected: ${players.length - 1}`)
void requestState()
console.log(`Requesting state again ${retryCount} (no response). Players connected: ${players.length - 1}`)
void requestState(retryCount + 1)
} else {
DEBUG_NETWORK_MESSAGES() && console.log('No active players. State syncronized')
stateIsSyncronized = true
Loading