georgesamper
georgesamper

Reputation: 5169

socket.io start and complete events

I'm using socket.io with express 3 to build an app.

I would like to set loader animations to display when on a incoming message, and hide it when the message been recieved. Much like jQuerys .ajaxStart and .ajaxComplete where i can do something like $('#loader').show(); etc

Are there any events i can catch in socket.io to achieve this?

Upvotes: 0

Views: 193

Answers (1)

freakish
freakish

Reputation: 56467

You can achieve this using the following idea:

  1. SERVER: emit about_to_start event;
  2. CLIENT: on about_to_start enable the loader and emit download_ready event;
  3. SERVER: on download_ready event send the data, i.e. emit download event;
  4. CLIENT: on download event do something with data and disable the loader;

That's how I would do that.

By the way: are we talking about simple messaging system? I don't think there is a need to do that in that scenario. Downloading won't take more then few seconds and if it will, then you need to optimize app or add some horse power (i.e. if the traffic is too big, add some machines). Skip steps 1,2 and half of 3. On step 4 you just notify the client: "Hey, you have a new message!".

Upvotes: 1

Related Questions