m28n=(function(window){var BASE_URL="https://api.n.m28.io";var isSecure=window.location.protocol!="http:";function findServers(endpoint,options,cb){if(typeof options=='function'){cb=options;options={};}else{options=options||{};} var version=options.version;get(BASE_URL+"/endpoint/"+endpoint+"/findEach/"+(version?"?version="+version:""),cb);} function findRegionPreference(regions,options,cb){if(typeof options=='function'){cb=options;options={};} options=options||{};options.points=options.points||10;if(typeof options.timeout==="undefined"){options.timeout=isSecure?7000:5000;} findServers("latency",null,function(err,r){if(err)return cb(err);var points={};var wss=[];for(var region in r.servers){(function(region){if(regions.indexOf(region)==-1)return;var info=r.servers[region];var host=isSecure?(info.id+".s.m28n.net"):(info.ipv4||("["+info.ipv6+"]"));var protocol=(isSecure?"wss:":"ws:");var ws=new WebSocket(protocol+"//"+host);wss.push(ws);ws.binaryType='arraybuffer';ws.onopen=function(){var u8=new Uint8Array(1);u8[0]=0x00;ws.send(u8.buffer);} ws.onmessage=function(message){var u8=new Uint8Array(message.data);if(u8[0]==0x00){points[region]=(points[region]||0)+1;if(points[region]>=options.points)return done();ws.send(message.data);}} ws.onerror=function(err){console.warn(err);} ws.onclose=function(){var i=wss.indexOf(ws);if(i!=-1){wss.splice(i,1);if(wss.length==0){done();}}}})(region);} if(wss.length==0){return cb("No latency servers in selected regions");} var timeout;var done=function(){done=function(){};clearTimeout(timeout);for(var i=0;i=200&&r.status<=299&&!obj.error){if(cb)cb(null,obj);}else{if(cb)cb(obj.error||"Non 2xx status code");} cb=null;};r.send(body);} return{findServers:findServers,findRegionPreference:findRegionPreference,findServerPreference:findServerPreference,findServerByID:findServerByID,setBaseURL:function(v){BASE_URL=v;},};})(window);