notgiven688 / webminerpool

Complete sources for a monero webminer.
262 stars 174 forks source link

Check mining in different domains #119

Closed slayerulan closed 4 years ago

slayerulan commented 5 years ago

Hello, For example; i have two tabs, the first one is first.com, the last one is last.com Each of these sites have miner js and i want to run miner from only one domain (say first.com) if its closed, then the current job passed to last.com

As these are two different domains, mine on only one tab not working. How can i do that?

Thanks

VidYen commented 5 years ago

I sort of do this with client js in the VidYen Point System plugin, but only if the first server can't be connected to.

This is just a copy of paste of the php code that it generates the js since its all hidden in the php:

        $simple_miner_output .="

            //This repicks server, does not fire unless error in connecting to server.
            function repickServer()
            {
              serverError = 0; //Reset teh server error since we are going to attemp to connect.

              document.getElementById('status-text').innerText = 'Error Connecting! Attemping other servers please wait.'; //set to working

              " . /*//https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array*/ "
              function shuffle(array) {
                var currentIndex = array.length, temporaryValue, randomIndex;

                // While there remain elements to shuffle...
                while (0 !== currentIndex) {

                  // Pick a remaining element...
                  randomIndex = Math.floor(Math.random() * currentIndex);
                  currentIndex -= 1;

                  // And swap it with the current element.
                  temporaryValue = array[currentIndex];
                  array[currentIndex] = array[randomIndex];
                  array[randomIndex] = temporaryValue;
                }

                return array;
              }";
        $simple_miner_output .='
              server_list = shuffle(server_list); //Why is it alwasy simple?

              '.vyps_point_debug_func($debug_mode, "console.log('Shuff Results: ' + server_list );").'
              current_server = server_list[0][0];
              '.vyps_point_debug_func($debug_mode, "console.log('Current Server is: ' + current_server );").'
              current_port = server_list[0][1];
              '.vyps_point_debug_func($debug_mode, "console.log('Current port is: ' + current_port );");

      $simple_miner_output .="
              //Reset the server.
              server = 'wss://' + current_server + ':' + current_port;

              //Restart the serer. NOTE: The startMining(); has a stopMining(); in it in the js files.
              startMining(\"$mining_pool\",
                \"$sm_site_key$siteName_worker\", \"$password\", $sm_threads);
            }";

So although isn't what you asked for, hopefully it points you in the right direction.

When you run the startMining() function it will stop the previous miner since stopMining() is part of that function.