dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

reconnect to new hubServerUrl #192

Closed behnam-basketasia closed 5 years ago

behnam-basketasia commented 5 years ago

In my project, I set hubServerUrl in the main.js, but i want to ping many server and then connect to best one, i need to disconnect from previous hubServerUrl and then connect to new hubServerUrl. How can i handle this changing hubServerUrl? Is it possible to change it base on an event? i try to use it for changing url but cant connect to new one:

dotnetify.hub.init()  
dotnetify.hubServerUrl = "http://www.domain.com";
dsuryd commented 5 years ago

It's not currently set up for your use case. Can you just determine the best server before making the initial connect?

behnam-basketasia commented 5 years ago

yes i cant, but my purpose is that i want to check list of servers that get from Backend in an interval and then check best server base on user internet speed and want to change the connection, is there any recommendation for solving this problem? or any update to handle it?

mason-chase commented 5 years ago

This is very useful feature for us if we can have it, a server may go down or get overloaded, so client can determine a better or alternative server at any given time in multi-server environment.

This would eliminate the need for GLSB's such as Amazon Route 53's latency based dns, not to mention with DNS we may not quickly and seamlessly switch user to a new working server as DNS would take a while to update.

dsuryd commented 5 years ago

Try this:

Add the following to main.js, and then you only need to set dotnetify.hubServerUrl to switch server.

import dotnetify from 'dotnetify';

Object.defineProperty(dotnetify, 'hubServerUrl', {
  get: () => dotnetify.hub.url,
  set: url => {
    dotnetify.hub.url = url;
    if (dotnetify._hub) {
      dotnetify._hub = null;
      dotnetify.startHub();
    }
  }
});
behnam-basketasia commented 5 years ago

I'm so grateful for your help