abdelaziz321 / abdelaziz321.github.io

the personal website: https://abdelaziz321.github.io/
https://abdelaziz321.github.io
4 stars 1 forks source link

blog/2020-11-30-diving_deeper_into_real_time_applications #1

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Abdelaziz Mahmoud: Diving Deeper Into SSL Certificates?

https://abdelaziz321.github.io/blog/2021-07-02-diving_deeper_into_ssl_certificates

go4cas commented 3 years ago

Hi @abdelaziz. This is a great article, thanks.

I have a real-time dashboard application, that consists of the following stack:

Now, my question is, if I had to convert the stack to web sockets, would you foresee any issues by opening 40+ WS connections from the vue.js app to the node.js server? Or, is there a better way of dealing with my use case?

abdelaziz321 commented 3 years ago

Hello @go4cas. glad you liked it.

I don't have much experience, so I can't assure what is the best solution, but here are some thoughts that could help:

// fire events at different points in the server code
socket.emit('topSellerUpdated', { 'event_payload': event_payload });
socket.emit('dailyEarningChartDataUpdated', { 'event_payload': event_payload });
socket.emit('newOrderCreated', { 'event_payload': event_payload });
// ....

// listening to the server events and mapping the events payload to the different components.
socket.onAny((event, ...args) => {
  switch (event) {
     case 'topSellerUpdated': this.$store.commit('dashboard/UPDATE_TOP_SELLERS', ...args); break;
     case 'dailyEarningChartDataUpdated': this.$store.commit('dashboard/UPDATE_DAILY_EARNING_CHART_DATA', ...args); break;
     case 'newOrderCreated': this.$store.commit('dashboard/UPDATE_ORDERS', ...args); break;
     // ...
  }
});