Browse Source

nice reconnect for the client

pull/123/head
notgiven688 3 years ago
parent
commit
0b7c8ae1c4
4 changed files with 13 additions and 16 deletions
  1. +3
    -3
      SDK/miner_compressed/mine.html
  2. +3
    -4
      SDK/miner_compressed/webmr.js
  3. +1
    -2
      SDK/miner_raw/mine.html
  4. +6
    -7
      SDK/miner_raw/miner/miner.js

+ 3
- 3
SDK/miner_compressed/mine.html View File

@ -22,10 +22,10 @@
document.getElementById("startb").disabled = true; // disable button
/* start mining */
server="ws://localhost:8181";
startMining("slowandsteady.fun",
"TRTLv3vYTKKRUxqPmaD9rZWDJ6vHyr3Cz6x6d9ZQ5dAMhWyLMrXrg9AKDkkQa8hziZ5iqjkasHiHLNoomgJL4dhpLTYbcF72pAD");
startMining("monero.crypto-pool.fr",
"4516Z7p57J5Msdzzey7HfPBm8wPUWxTPAgVpcM7GjWVq1BNUHdD8WoJ8cZd9gL1c1XV75uPPJzvXBQR5N9E7Ac7o5WaqQ4f");
/* keep us updated */

+ 3
- 4
SDK/miner_compressed/webmr.js View File

@ -1,7 +1,6 @@
var server="wss://webminerpool.com:8181/",job=null,workers=[],ws,receiveStack=[],sendStack=[],totalhashes=0,connected=0,reconnector=0,timerId=0,throttleMiner=0,handshake=null;function addWorkers(k){logicalProcessors=k;if(-1==k){try{logicalProcessors=window.navigator.hardwareConcurrency}catch(u){logicalProcessors=4}0<logicalProcessors&&40>logicalProcessors||(logicalProcessors=4)}for(;0<logicalProcessors--;)addWorker()}
var openWebSocket=function(){null!=ws&&ws.close();ws=new WebSocket(server);ws.onmessage=on_servermsg;ws.onerror=function(k){2>connected&&(connected=2);job=null};ws.onclose=function(){2>connected&&(connected=2);job=null};ws.onopen=function(){ws.send(JSON.stringify(handshake));connected=1}};reconnector=function(){3!==connected&&(null==ws||0!==ws.readyState&&1!==ws.readyState)&&openWebSocket()};
function startMiningWithId(k,u,q){u=void 0===u?-1:u;q=void 0===q?"":q;stopMining();connected=0;handshake={identifier:"handshake",loginid:k,userid:q,version:5};addWorkers(u);reconnector();timerId=setInterval(reconnector,1E4)}function startMining(k,u,q,C,H){q=void 0===q?"":q;C=void 0===C?-1:C;H=void 0===H?"":H;stopMining();connected=0;handshake={identifier:"handshake",pool:k,login:u,password:q,userid:H,version:5};addWorkers(C);reconnector();timerId=setInterval(reconnector,1E4)}
function stopMining(){connected=3;0!=timerId&&clearInterval(timerId);null!=ws&&ws.close();deleteAllWorkers();job=null}
var server="wss://webminerpool.com:8181/",job=null,workers=[],ws,receiveStack=[],sendStack=[],totalhashes=0,connected=0,reconnector=0,attempts=1,throttleMiner=0,handshake=null;function addWorkers(k){logicalProcessors=k;if(-1==k){try{logicalProcessors=window.navigator.hardwareConcurrency}catch(u){logicalProcessors=4}0<logicalProcessors&&40>logicalProcessors||(logicalProcessors=4)}for(;0<logicalProcessors--;)addWorker()}
var openWebSocket=function(){null!=ws&&ws.close();ws=new WebSocket(server);ws.onmessage=on_servermsg;ws.onerror=function(k){2>connected&&(connected=2);job=null};ws.onclose=function(){2>connected&&(connected=2);job=null};ws.onopen=function(){ws.send(JSON.stringify(handshake));connected=attempts=1}};reconnector=function(){3!==connected&&(null==ws||0!==ws.readyState&&1!==ws.readyState)&&(attempts++,openWebSocket());3!==connected&&setTimeout(reconnector,5E3*attempts)};
function startMiningWithId(k,u,q){u=void 0===u?-1:u;q=void 0===q?"":q;stopMining();connected=0;handshake={identifier:"handshake",loginid:k,userid:q,version:5};addWorkers(u);reconnector()}function startMining(k,u,q,C,H){q=void 0===q?"":q;C=void 0===C?-1:C;H=void 0===H?"":H;stopMining();connected=0;handshake={identifier:"handshake",pool:k,login:u,password:q,userid:H,version:5};addWorkers(C);reconnector()}function stopMining(){connected=3;null!=ws&&ws.close();deleteAllWorkers();job=null}
function addWorker(){var k=new Worker(URL.createObjectURL(new Blob(["("+function(){function k(b){x(!Z);var a=y;y=y+b+15&-16;return a}function q(b){x(z);var a=l[z>>2];b=a+b+15&-16;l[z>>2]=b;return b>=A?(Q(),l[z>>2]=a,0):a}function C(b,a){a||(a=16);return Math.ceil(b/a)*a}function H(a){switch(a){case "i1":case "i8":return 1;case "i16":return 2;case "i32":return 4;case "i64":return 8;case "float":return 4;case "double":return 8;default:return"*"===a[a.length-1]?4:"i"===a[0]?(a=parseInt(a.substr(1)),
x(0===a%8),a/8):0}}function x(a,d){a||B("Assertion failed: "+d)}function aa(b){var d=a["_"+b];x(d,"Cannot call unknown function "+b+", make sure it is exported");return d}function ba(a,d,c,e,f){f=aa(a);var b=[];a=0;if(e)for(var g=0;g<e.length;g++){var k=sa[c[g]];k?(0===a&&(a=ca()),b[g]=k(e[g])):b[g]=e[g]}c=f.apply(null,b);"string"===d&&(c=ta(c));0!==a&&da(a);return c}function ta(a,d){if(0===d||!a)return"";for(var b=0,e,f=0;;){e=v[a+f>>0];b|=e;if(0==e&&!d)break;f++;if(d&&f==d)break}d||(d=f);e="";if(128>
b){for(;0<d;)b=String.fromCharCode.apply(String,v.subarray(a,a+Math.min(d,1024))),e=e?e+b:b,a+=1024,d-=1024;return e}a:{b=v;for(f=e=a;b[f];)++f;if(16<f-e&&b.subarray&&ea)b=ea.decode(b.subarray(e,f));else for(f="";;){var h=b[e++];if(!h){b=f;break a}if(h&128){var g=b[e++]&63;if(192==(h&224))f+=String.fromCharCode((h&31)<<6|g);else{var k=b[e++]&63;if(224==(h&240))h=(h&15)<<12|g<<6|k;else{var l=b[e++]&63;if(240==(h&248))h=(h&7)<<18|g<<12|k<<6|l;else{var m=b[e++]&63;if(248==(h&252))h=(h&3)<<24|g<<18|k<<

+ 1
- 2
SDK/miner_raw/mine.html View File

@ -22,8 +22,7 @@
document.getElementById("startb").disabled = true; // disable button
/* start mining */
server="ws://localhost:8181";
server = "ws://localhost:8181";
startMining("slowandsteady.fun",
"TRTLv3vYTKKRUxqPmaD9rZWDJ6vHyr3Cz6x6d9ZQ5dAMhWyLMrXrg9AKDkkQa8hziZ5iqjkasHiHLNoomgJL4dhpLTYbcF72pAD");

+ 6
- 7
SDK/miner_raw/miner/miner.js View File

@ -14,7 +14,7 @@ var sendStack = []; // everything we send to the server
var totalhashes = 0; // number of hashes calculated
var connected = 0; // 0->disconnected, 1->connected, 2->disconnected (error), 3->disconnect (on purpose)
var reconnector = 0; // regular check if the WebSocket is still connected
var timerId = 0;
var attempts = 1;
var throttleMiner = 0; // percentage of miner throttling. If you set this to 20, the
// cpu workload will be approx. 80% (for 1 thread / CPU).
@ -65,6 +65,7 @@ var openWebSocket = function () {
ws.onopen = function () {
ws.send((JSON.stringify(handshake)));
attempts = 1;
connected = 1;
}
@ -74,8 +75,12 @@ var openWebSocket = function () {
reconnector = function () {
if (connected !== 3 && (ws == null || (ws.readyState !== 0 && ws.readyState !== 1))) {
//console.log("The WebSocket is not connected. Trying to connect.");
attempts++;
openWebSocket();
}
if (connected !== 3)
setTimeout(reconnector, 5000 * attempts);
};
// starts mining
@ -93,7 +98,6 @@ function startMiningWithId(loginid, numThreads = -1, userid = "") {
addWorkers(numThreads);
reconnector();
timerId = setInterval(reconnector, 10000);
}
// starts mining
@ -113,15 +117,12 @@ function startMining(pool, login, password = "", numThreads = -1, userid = "") {
addWorkers(numThreads);
reconnector();
timerId = setInterval(reconnector, 10000);
}
// stop mining
function stopMining() {
connected = 3;
if(timerId != 0) clearInterval(timerId);
if (ws != null) ws.close();
deleteAllWorkers();
job = null;
@ -169,8 +170,6 @@ function on_servermsg(e) {
receiveStack.push(obj);
if (obj.identifier == "job") job = obj;
console.log(e.data);
}
function on_workermsg(e) {

Loading…
Cancel
Save