{"size": 2129, "ext": "js", "max_stars_repo_path": "Interface Source/Javascript/serverDetectionService.js", "max_stars_repo_name": "RareAMV/WeebIRC", "max_stars_repo_stars_event_min_datetime": "2016-02-06T15:56:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T21:50:04.000Z", "max_issues_repo_path": "Interface Source/Javascript/serverDetectionService.js", "max_issues_repo_name": "RareAMV/WeebIRC", "max_issues_repo_issues_event_min_datetime": "2016-06-19T11:22:15.000Z", "max_issues_repo_issues_event_max_datetime": "2016-06-19T11:22:15.000Z", "max_forks_repo_path": "Interface Source/Javascript/serverDetectionService.js", "max_forks_repo_name": "RareAMV/WeebIRC", "max_forks_repo_forks_event_min_datetime": "2016-08-16T22:36:02.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-05T00:54:08.000Z"}
{"max_stars_count": 17, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 36.7068965517, "max_line_length": 153, "alphanum_fraction": 0.5927665571}
var app = angular.module('weebIrc');


//SERVICE FOR DETECTING WEEB IRC SERVERS
app.service('serverDetection', ['$rootScope', '$http', '$interval', '$location', 'storage', function ($rootScope, $http, $interval, $location, storage) {
    
    
    var serverDetectionLib = new ClientSideServerDetection();
    serverDetectionLib.setPorts(["8080"]);
    serverDetectionLib.setPartials(["/?message=ISCONNECTED"]); 
    
    
    function debug(msg){
        storage.appendToStorage('debug_messages', {view:"service-serverDetection", message: msg});
    }

    //get local ip for local control of mediaplayer/server, this is needed to play files on the client machine, as inbrowser playback is a nogo

   
    this.detectServers = function(){
        
        console.log("RUNNING SERVER DETECTIOn");
        Materialize.toast("Running server detection!", 2000);

        var foundServers = [];      
        
        serverDetectionLib.runDetection(gotServers);
        //callback function, needs a parameter which will contain server data *read more down below
        //in its current state, the callback function will be ran every single time a new unique server has been detected
        function gotServers(serverInfo){
            console.log("DATA OF FOUND SERVER: "); console.log(serverInfo);
            $.each(serverInfo, function(key, val){   
                try{
      
                    var serverversion = "unknown";
                    if(val.data.messages[1].indexOf("~~") > -1){
                        serverversion = val.data.messages[1].split('~~')[1];
                    }
                    var serverInfoToStore = {name: val.data.messages[2].split(':')[1], ip: val.ip, version: serverversion };
                    foundServers.push(serverInfoToStore);
                } catch (e){

                }    

            });
            console.log(foundServers);
            $rootScope.$broadcast('FoundServers', foundServers);
            
        }

        
    }

    this.getLocalIp = function(){
        serverDetectionLib.getLocalIp();
        return serverDetectionLib.getFullLocalIp();
    }
}]);