h5scluster.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. function H5SClusterHttpGet(url)
  2. {
  3. var xmlHttp = new XMLHttpRequest();
  4. xmlHttp.open("GET", url, false );
  5. xmlHttp.send( null );
  6. return xmlHttp.responseText;
  7. }
  8. function H5SClusterGetConf(conf)
  9. {
  10. var strStatusUrl = conf.protocol + '//' + conf.host + conf.rootpath +
  11. 'api/v1/cluster/GetClusterStatus';
  12. console.log(strStatusUrl);
  13. var strStatus = H5SClusterHttpGet(strStatusUrl);
  14. console.log(strStatus);
  15. var strStatusJson = JSON.parse(strStatus);
  16. if (strStatusJson["bEnable"] == true)
  17. {
  18. console.log("Cluster enable");
  19. var strProtocol = "http";
  20. if (conf.protocol == "https:")
  21. {
  22. strProtocol = "https";
  23. }
  24. var strAddrUrl = conf.protocol + '//' + conf.host + conf.rootpath +
  25. 'api/v1/cluster/GetServiceAddr?service=' + strProtocol + '&token=' + conf.token;
  26. var strAddr = H5SClusterHttpGet(strAddrUrl);
  27. console.log(strAddr);
  28. var strAddrJson = JSON.parse(strAddr);
  29. conf.host = strAddrJson["strAddr"] + ':' + strAddrJson["nPort"];
  30. console.log("Cluster get play host", conf.host);
  31. }
  32. }