Skip to content

Using emscripten_sleep for waiting to be finished #21396

@tbuchs

Description

@tbuchs

I am trying to port a c++ framework to the web. Each Client starts the application in a separate browser window and has to wait for all clients to be connected. The connection/communication between the browser windows is established via WebRTC. The WebRTC channels all work perfectly fine, however the waiting (=emscripten_sleep) somehow takes way longer to than expected.

// wait for all other players to connect  
int sleep_interval = 1000;
int time_slept = 0;
while (connected_users < nplayers and time_slept < 60*1000)
{
  cout << "connected users(" << connected_users << "/" << nplayers << ")" << endl;
  emscripten_sleep(sleep_interval);
  time_slept += sleep_interval;
}
if(connected_users < nplayers) {
  cerr << "Timeout - only " << connected_users << " clients!" << endl;
  exit(-1);
}
cout << "All clients connected!" << endl;
emscripten_websocket_close(websocket_conn, 0, "Finshed WebRTC-Connection establishment.");
emscripten_websocket_delete(websocket_conn);

The output is always different - on one browser tab it works perfectly fine, on the other it just outputs once "connected_users(1/3)" then it outputs nothing for like 2 minutes and then it outputs ("All clients connected"). Even though the debug messages for webrtc have been finished after 2 seconds.

I use -sASYNCIFY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions