李勇

1.调整MCU MS选点模块,新增IpManager.js (ServerCheck.js暂停使用),调整选点流程

1 -import Emiter from 'Emiter';  
2 -import Loger from 'Loger';  
3 -import MessageTypes from 'MessageTypes';  
4 -import GlobalConfig from 'GlobalConfig'; 1 +import Emiter from 'src/Emiter';
  2 +import Loger from 'src/Loger';
  3 +import MessageTypes from 'src/MessageTypes';
  4 +import GlobalConfig from 'src/GlobalConfig';
5 import MD5 from "md5"; 5 import MD5 from "md5";
6 -import ApeConsts from 'apes/ApeConsts'; 6 +import ApeConsts from 'src/apes/ApeConsts';
7 import iphunter from 'iphunter'; 7 import iphunter from 'iphunter';
8 -import Server from "config/Server"; 8 +import Server from "src/config/Server";
9 import fetchJsonp from 'fetch-jsonp'; 9 import fetchJsonp from 'fetch-jsonp';
10 10
11 // 日志对象 11 // 日志对象
此 diff 太大无法显示。
@@ -5,7 +5,7 @@ require('string.fromcodepoint'); @@ -5,7 +5,7 @@ require('string.fromcodepoint');
5 5
6 import Emiter from './Emiter'; 6 import Emiter from './Emiter';
7 import Sass from 'Sass'; 7 import Sass from 'Sass';
8 -import ServerCheck from 'ServerCheck'; 8 +import IpManager from 'IpManager';
9 import RecordPlayBackParse from 'RecordPlayBackParse'; 9 import RecordPlayBackParse from 'RecordPlayBackParse';
10 import MD5 from "md5"; 10 import MD5 from "md5";
11 import Mcu from 'mcu'; 11 import Mcu from 'mcu';
@@ -22,15 +22,16 @@ import GlobalConfig from 'GlobalConfig'; @@ -22,15 +22,16 @@ import GlobalConfig from 'GlobalConfig';
22 import ApeConsts from 'apes/ApeConsts'; 22 import ApeConsts from 'apes/ApeConsts';
23 import Base64 from 'base64-js'; 23 import Base64 from 'base64-js';
24 import ArrayBufferUtil from 'libs/ArrayBufferUtil'; 24 import ArrayBufferUtil from 'libs/ArrayBufferUtil';
  25 +import Server from "config/Server";
25 26
26 import UTF8 from 'utf-8'; 27 import UTF8 from 'utf-8';
27 28
28 let loger = Loger.getLoger('McuClient'); 29 let loger = Loger.getLoger('McuClient');
29 -let _sdkInfo = {"version": "v1.9.6.20170418", "author": "www.3mang.com"}; 30 +let _sdkInfo = {"version": "v1.9.11.20170419", "author": "www.3mang.com"};
30 31
31 //APE 32 //APE
32 let _sass; 33 let _sass;
33 -let _serverCheck; 34 +let _ipManager;
34 let _mcu; 35 let _mcu;
35 let _confer_ape; 36 let _confer_ape;
36 let _chat_ape; 37 let _chat_ape;
@@ -49,6 +50,10 @@ export default class MessageEntrance extends Emiter { @@ -49,6 +50,10 @@ export default class MessageEntrance extends Emiter {
49 loger.log(this.sdkInfo); 50 loger.log(this.sdkInfo);
50 51
51 //初始化状态 52 //初始化状态
  53 + this.isGetUserIpCallback = false;//是否获取IP信息返回
  54 + this.isGetFastestMcuCallback = false;//是否MCU选点结束
  55 + this.isGetFastestMsCallback = false;//是否MS选点结束
  56 +
52 GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_0); 57 GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_0);
53 58
54 //全局的Error处理 59 //全局的Error处理
@@ -66,9 +71,8 @@ export default class MessageEntrance extends Emiter { @@ -66,9 +71,8 @@ export default class MessageEntrance extends Emiter {
66 _sass.on(_sass.CLASS_SAVE_RECORD_INFO_SUCCESS, this._sassSaveClassRecordInfoSuccessHandler.bind(this));//保存课堂录制信息 71 _sass.on(_sass.CLASS_SAVE_RECORD_INFO_SUCCESS, this._sassSaveClassRecordInfoSuccessHandler.bind(this));//保存课堂录制信息
67 _sass.on(_sass.DELETE_DOCUMENT_SUCCESS, this._sassDeleteDocumentSuccess.bind(this));//sass删除文档成功 72 _sass.on(_sass.DELETE_DOCUMENT_SUCCESS, this._sassDeleteDocumentSuccess.bind(this));//sass删除文档成功
68 73
69 - //ServerCheck ip  
70 - _serverCheck = ServerCheck;  
71 - _serverCheck.on(_serverCheck.SEVER_CHECK_BEST_IP_SUCCESS, this._serverCheckBestIpSuccessHandler.bind(this));//ip选点,获取最佳ip完成 74 + //选点模块
  75 + _ipManager = new IpManager();
72 76
73 // 底层MCU消息层 77 // 底层MCU消息层
74 _mcu = Mcu; 78 _mcu = Mcu;
@@ -362,9 +366,9 @@ export default class MessageEntrance extends Emiter { @@ -362,9 +366,9 @@ export default class MessageEntrance extends Emiter {
362 GlobalConfig.hasCamera = (typeof _param.hasCamera == "boolean") ? _param.hasCamera : false; 366 GlobalConfig.hasCamera = (typeof _param.hasCamera == "boolean") ? _param.hasCamera : false;
363 GlobalConfig.hasMicrophone = (typeof _param.hasMicrophone == "boolean") ? _param.hasMicrophone : false; 367 GlobalConfig.hasMicrophone = (typeof _param.hasMicrophone == "boolean") ? _param.hasMicrophone : false;
364 368
365 - loger.log("autoLoginMd5", GlobalConfig.classId, GlobalConfig.userId, GlobalConfig.userRole); 369 + //loger.log("autoLoginMd5", GlobalConfig.classId, GlobalConfig.userId, GlobalConfig.userRole);
366 let autoLoginMd5 = MD5("" + GlobalConfig.classId + GlobalConfig.userId + GlobalConfig.userRole); 370 let autoLoginMd5 = MD5("" + GlobalConfig.classId + GlobalConfig.userId + GlobalConfig.userRole);
367 - loger.log("joinClass-GlobalConfig.autoLogin", GlobalConfig.autoLogin, "autoLoginMd5-", autoLoginMd5); 371 + //loger.log("joinClass-GlobalConfig.autoLogin", GlobalConfig.autoLogin, "autoLoginMd5-", autoLoginMd5);
368 if (GlobalConfig.autoLogin && autoLoginMd5 == GlobalConfig.autoLogin) { 372 if (GlobalConfig.autoLogin && autoLoginMd5 == GlobalConfig.autoLogin) {
369 // MD5(classId+userId+userRole)==m 373 // MD5(classId+userId+userRole)==m
370 //自动登录,跳过验证流程 374 //自动登录,跳过验证流程
@@ -438,7 +442,6 @@ export default class MessageEntrance extends Emiter { @@ -438,7 +442,6 @@ export default class MessageEntrance extends Emiter {
438 //视频质量相关设置 442 //视频质量相关设置
439 GlobalConfig.fps = _data.fps || 15; 443 GlobalConfig.fps = _data.fps || 15;
440 GlobalConfig.gop = _data.gop || 3; 444 GlobalConfig.gop = _data.gop || 3;
441 - ;  
442 GlobalConfig.videoQuality = _data.videoQuality || 2; 445 GlobalConfig.videoQuality = _data.videoQuality || 2;
443 446
444 //是否自动开始(身份是host的时候才用到的) 447 //是否自动开始(身份是host的时候才用到的)
@@ -506,7 +509,7 @@ export default class MessageEntrance extends Emiter { @@ -506,7 +509,7 @@ export default class MessageEntrance extends Emiter {
506 } 509 }
507 510
508 511
509 - //录制回放不需要选点 512 + //录制回放不需要获取ip信息和选点
510 if (GlobalConfig.isRecordPlayBack) { 513 if (GlobalConfig.isRecordPlayBack) {
511 if (_recordPlayback) { 514 if (_recordPlayback) {
512 //开启录制回放流程 515 //开启录制回放流程
@@ -516,22 +519,115 @@ export default class MessageEntrance extends Emiter { @@ -516,22 +519,115 @@ export default class MessageEntrance extends Emiter {
516 loger.warn("开启录制回放流程失败,还未创建模块"); 519 loger.warn("开启录制回放流程失败,还未创建模块");
517 } 520 }
518 } else { 521 } else {
519 - //根据用户的userIp获取信息 522 + //根据用户的userIp获取信息,选点
520 this.getUserIpInfo(); 523 this.getUserIpInfo();
521 } 524 }
522 } 525 }
523 526
524 //根据UserIp获取ip信息,选点 527 //根据UserIp获取ip信息,选点
525 getUserIpInfo() { 528 getUserIpInfo() {
526 - if (_serverCheck) {  
527 - _serverCheck.getUserIpInfo("", GlobalConfig.userIp); 529 + if (_ipManager) {
  530 + _ipManager.getUserIpInfo("", GlobalConfig.userIp, this._getUserIpCallbackHandler.bind(this), 1000);
  531 + }
  532 + }
  533 +
  534 + //获取IP信息完成
  535 + _getUserIpCallbackHandler(_data) {
  536 + //获取IP信息,返回一次就不再处理
  537 + if (this.isGetUserIpCallback) {
  538 + return;
  539 + }
  540 + this.isGetUserIpCallback = true;
  541 + if (_data && _data.ret == "ok") {
  542 + GlobalConfig.country = _data.country;//国家
  543 + GlobalConfig.city = _data.city;//城市
  544 + GlobalConfig.province = _data.province;//服务商
  545 + GlobalConfig.isp = _data.isp;//服务商
  546 + }
  547 +
  548 + //合并MCU 、MS的列表
  549 + this._mergeMcuAndMsList();
  550 +
  551 + //开始选点
  552 + let _this = this;
  553 + this._getFastestMsServer(function (_data) {
  554 + loger.log("MS选点结束->", _data);
  555 + if (_data && _data.ip) {
  556 + GlobalConfig.MSServerIP = _data.ip;
  557 + GlobalConfig.MSServerPort = _data.port;
  558 + }
  559 + _this.isGetFastestMcuCallback = true;
  560 + _this._startConnectMCU();
  561 + });
  562 + this._getFastestMcuServer(function (_data) {
  563 + loger.log("MCU选点结束->", _data);
  564 + if (_data && _data.ip) {
  565 + GlobalConfig.MCUServerIP = _data.ip;
  566 + GlobalConfig.MCUServerPort = _data.port;
  567 + }
  568 + _this.isGetFastestMsCallback = true;
  569 + _this._startConnectMCU();
  570 + });
  571 + }
  572 +
  573 + //开始连接MCU(MCU和MS都选点结束之后才开始连接)
  574 + _startConnectMCU() {
  575 + if (this.isGetFastestMcuCallback && this.isGetFastestMsCallback) {
  576 + this._joinMCU();
  577 + }
  578 + }
  579 +
  580 + //合并Sever和Sass的mcu、ms列表
  581 + _mergeMcuAndMsList() {
  582 + if (_ipManager) {
  583 + GlobalConfig.mcuListFromServer = _ipManager.getServerMcuList(
  584 + GlobalConfig.country,
  585 + GlobalConfig.province,
  586 + GlobalConfig.city,
  587 + GlobalConfig.isp,
  588 + Server.serverList);
  589 +
  590 + GlobalConfig.msListFromServer = _ipManager.getServerMsList(
  591 + GlobalConfig.country,
  592 + GlobalConfig.province,
  593 + GlobalConfig.city,
  594 + GlobalConfig.isp,
  595 + Server.serverList);
  596 + }
  597 +
  598 +
  599 + //console.log(" GlobalConfig.mcuListFromServer", GlobalConfig.mcuListFromServer)
  600 + //console.log(" GlobalConfig.msListFromServer", GlobalConfig.msListFromServer)
  601 + //合并所有MCU、MS 列表
  602 + GlobalConfig.mcuListAll.length = 0;
  603 + GlobalConfig.mcuListAll = GlobalConfig.mcuListAll.concat(GlobalConfig.mcuList, GlobalConfig.mcuListFromServer);
  604 + GlobalConfig.msListAll.length = 0;
  605 + GlobalConfig.msListAll = GlobalConfig.msListAll.concat(GlobalConfig.msList, GlobalConfig.msListFromServer);
  606 +
  607 + //console.log(" GlobalConfig.mcuListAll", GlobalConfig.mcuListAll)
  608 + //console.log(" GlobalConfig.msListAll", GlobalConfig.msListAll)
  609 + }
  610 +
  611 + //开始MCU选点操作
  612 + _getFastestMcuServer(_callback) {
  613 + if (_ipManager) {
  614 + _ipManager.getFastestMcuServer(GlobalConfig.mcuListAll, _callback);
  615 + } else {
  616 + if (_callback) {
  617 + _callback({'ip': ""});
  618 + }
528 } 619 }
529 } 620 }
530 621
531 - //MCU MS ip选点完成,开加入MCU  
532 - _serverCheckBestIpSuccessHandler(_data) {  
533 - loger.log("_serverCheckBestIpSuccessHandler,IP选点结束");  
534 - this._joinMCU(); 622 + // //开始MS选点操作
  623 + _getFastestMsServer(_callback) {
  624 + if (_ipManager) {
  625 + _ipManager.getFastestMsServer(GlobalConfig.msListAll, _callback);
  626 + } else {
  627 + if (_callback) {
  628 + _callback({ip: ""});
  629 + }
  630 + }
535 } 631 }
536 632
537 //保存课堂状态信息 633 //保存课堂状态信息
@@ -577,7 +673,7 @@ export default class MessageEntrance extends Emiter { @@ -577,7 +673,7 @@ export default class MessageEntrance extends Emiter {
577 673
578 // MCU 课堂成功 674 // MCU 课堂成功
579 _mcuJoinMCUClassSuccessHandler(_data) { 675 _mcuJoinMCUClassSuccessHandler(_data) {
580 - loger.log('MCU 课堂成功.'); 676 + //loger.log('MCU 课堂成功.');
581 GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_2); 677 GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_2);
582 678
583 //返回给客户端初始化成功的数据 679 //返回给客户端初始化成功的数据
@@ -254,8 +254,8 @@ GlobalConfig.portal="112.126.80.182:80";//Sass IP @@ -254,8 +254,8 @@ GlobalConfig.portal="112.126.80.182:80";//Sass IP
254 //GlobalConfig.ip="112.126.80.182"; 254 //GlobalConfig.ip="112.126.80.182";
255 //GlobalConfig.port="80"; 255 //GlobalConfig.port="80";
256 256
257 -GlobalConfig.MCUServerIP="114.215.195.70";  
258 -GlobalConfig.MCUServerPort=9003; 257 +GlobalConfig.MCUServerIP="";
  258 +GlobalConfig.MCUServerPort='';
259 259
260 GlobalConfig.MSServerIP = "";//推流 播流的地址 260 GlobalConfig.MSServerIP = "";//推流 播流的地址
261 GlobalConfig.MSServerPort =""; 261 GlobalConfig.MSServerPort ="";
@@ -328,6 +328,7 @@ GlobalConfig.videoQuality=2;//画面质量 0-低;1-中;2-高; @@ -328,6 +328,7 @@ GlobalConfig.videoQuality=2;//画面质量 0-低;1-中;2-高;
328 GlobalConfig.classAllParam={};//Sass直接返回的所有课堂信息(最全) 328 GlobalConfig.classAllParam={};//Sass直接返回的所有课堂信息(最全)
329 GlobalConfig.classDetail={};//Sass直接返回的当前课堂基本信息 329 GlobalConfig.classDetail={};//Sass直接返回的当前课堂基本信息
330 330
  331 +//从Sass获取的
331 GlobalConfig.docListPrepare=[]; // 已经提前上传的文档,进入课堂后需要自动加载 332 GlobalConfig.docListPrepare=[]; // 已经提前上传的文档,进入课堂后需要自动加载
332 GlobalConfig.recordList=[];//录制服务器地址集合 333 GlobalConfig.recordList=[];//录制服务器地址集合
333 GlobalConfig.docList=[];//文档服务器地址集合 334 GlobalConfig.docList=[];//文档服务器地址集合
@@ -338,11 +339,18 @@ GlobalConfig.musicListPrepare=[];//提提前上传的music集合 @@ -338,11 +339,18 @@ GlobalConfig.musicListPrepare=[];//提提前上传的music集合
338 GlobalConfig.rsList=[];//录制回放中视频点播地址 339 GlobalConfig.rsList=[];//录制回放中视频点播地址
339 340
340 341
  342 +//根据IP从server获取
  343 +GlobalConfig.mcuListFromServer=[];//根据userIP从server获取的mcu列表
  344 +GlobalConfig.msListFromServer=[];//根据userIP从server获取的ms列表
341 GlobalConfig.country ="";//国家 345 GlobalConfig.country ="";//国家
342 GlobalConfig.city ="";//城市 346 GlobalConfig.city ="";//城市
343 GlobalConfig.province = "";//服务商 347 GlobalConfig.province = "";//服务商
344 GlobalConfig.isp ="";//服务商 348 GlobalConfig.isp ="";//服务商
345 349
  350 +
  351 +GlobalConfig.mcuListAll=[];//所有MCU集合(sass+server)
  352 +GlobalConfig.msListAll=[];//所有MS集合(sass+server)
  353 +
346 GlobalConfig.isRecordPlayBack=false;//是否是录制回放,默认是否 354 GlobalConfig.isRecordPlayBack=false;//是否是录制回放,默认是否
347 GlobalConfig.allowRecordMaxTime=14400;//(秒)允许录制的最长时间,默认是4小时 355 GlobalConfig.allowRecordMaxTime=14400;//(秒)允许录制的最长时间,默认是4小时
348 export default GlobalConfig; 356 export default GlobalConfig;
  1 +/**
  2 + *
  3 + * IP 管理(ip信息或,动态选点)
  4 + * */
  5 +
  6 +import Emiter from 'Emiter';
  7 +import Loger from 'Loger';
  8 +import MD5 from "md5";
  9 +import iphunter from 'iphunter';
  10 +import fetchJsonp from 'fetch-jsonp';
  11 +
  12 +// 日志对象
  13 +const loger = Loger.getLoger('IpManager');
  14 +
  15 +const TIME_OUT = 2000;//选点超时
  16 +const MS_DEFAULT_PORT = "1935";//默认流媒体端口
  17 +const MCU_DEFAULT_PORT = "7777";//默认的mcu端口
  18 +const SPEED_TEST_PORT = '5555';//测速端口(MCU/MS)
  19 +
  20 +class IpManager extends Emiter {
  21 + constructor() {
  22 + super();
  23 + }
  24 +
  25 + //根据userIp获取ip相关的信息,参数是userIp
  26 + getUserIpInfo(token, userIp, _callback, _timeOutDelay) {
  27 + let userIpInfo = {
  28 + ret: -1
  29 + };
  30 + // //("addr=" + ip + "&token=b657c3507b324353e09c1958ee956a98efceb3e3"),转成MD5
  31 + let md5Str = MD5("addr=" + userIp + "&token=b657c3507b324353e09c1958ee956a98efceb3e3");
  32 + let timestamp = new Date().getTime();
  33 + let url = `http://ipapi.ipip.net/find?addr=${userIp}&sid=14&uid=5237&sig=${md5Str}&_=${timestamp}`;
  34 + loger.log("获取IP信息->", url);
  35 + let _this = this;
  36 + fetchJsonp(url, {
  37 + timeout: _timeOutDelay || TIME_OUT,
  38 + }).then(function (response) {
  39 + return response.json();
  40 + }).then(function (json) {
  41 + // loger.log('获取IP信息返回', json)
  42 + if (json) {
  43 + userIpInfo.ret = json.ret;
  44 + userIpInfo.country = json.data[0];//国家
  45 + userIpInfo.province = json.data[1];//省份
  46 + userIpInfo.city = json.data[2];//城市
  47 + userIpInfo.isp = json.data[4];//运营商
  48 + }
  49 + loger.warn('获取IP信息->完成->', userIpInfo);
  50 + if (_callback) {
  51 + _callback(userIpInfo);
  52 + /*/if (userIpInfo.ret == "ok") {
  53 + GlobalConfig.country = userIpInfo.country;//国家
  54 + GlobalConfig.city = userIpInfo.city;//城市
  55 + GlobalConfig.province = userIpInfo.province;//服务商
  56 + GlobalConfig.isp = userIpInfo.isp;//服务商
  57 + // loger.log("获取ip详情成功,country:" + GlobalConfig.country + ",city:" + GlobalConfig.city + ",isp:" + GlobalConfig.isp);
  58 + this._chooseBestIpFromServer();
  59 + }*/
  60 + }
  61 + }).catch(function (ex) {
  62 + loger.warn('获取IP信息->失败->', ex.message);
  63 + if (_callback) {
  64 + _callback(userIpInfo);
  65 + }
  66 + });
  67 + }
  68 +
  69 + //获取最快的MCU服务器地址,参数是一个ip数组
  70 + getFastestMcuServer(_ipList, _callback, _timeOutDelay) {
  71 + loger.log('开始MCU选点-> ', _ipList);
  72 + let callbackData = {ip: ""};
  73 + if (_ipList == null || _ipList.length < 1) {
  74 + if (_callback) {
  75 + _callback(callbackData);
  76 + }
  77 + return;
  78 + }
  79 + //对传入的ip数组进行组织
  80 + let newList = new Set();
  81 + let listLen = _ipList.length;
  82 + for (let i = 0; i < listLen; i++) {
  83 + let msItem = _ipList[i];
  84 + if (msItem && msItem.ip) {
  85 + //测速的时候,ip地址要拼接成带端口的完整地址,测速的端口是固定的
  86 + newList.add((msItem.ip + ':' + SPEED_TEST_PORT));
  87 + }
  88 + }
  89 + //过滤完重复ip
  90 + let ipListArr = Array.from(newList);
  91 + loger.log('MCU选点->列表', ipListArr);
  92 + if (ipListArr == null || ipListArr.length < 1) {
  93 + if (_callback) {
  94 + _callback(callbackData);
  95 + }
  96 + return;
  97 + }
  98 + try {
  99 + iphunter(ipListArr, function (fatest_ip_response) {
  100 + if (!fatest_ip_response) {
  101 + loger.warn('MCU选点-> nothing!');
  102 + if (_callback) {
  103 + _callback(callbackData);
  104 + }
  105 + } else {
  106 + loger.log('MCU选点->done -> ', fatest_ip_response);
  107 + let fastestIp = fatest_ip_response.replace((':' + SPEED_TEST_PORT), '') || ""
  108 + callbackData.ip = fastestIp;
  109 + callbackData.port = '';
  110 +
  111 + //根据ip从原来的ip列表中查找端口
  112 + let listLen = _ipList.length;
  113 + for (let i = 0; i < listLen; i++) {
  114 + let msItem = _ipList[i];
  115 + if (msItem && msItem.ip) {
  116 + if (fastestIp == msItem.ip) {
  117 + callbackData.port = msItem.port || MCU_DEFAULT_PORT;
  118 + break;
  119 + }
  120 + }
  121 + }
  122 +
  123 + //返回数据
  124 + if (_callback) {
  125 + _callback(callbackData);
  126 + }
  127 + }
  128 + }, _timeOutDelay || TIME_OUT);
  129 + } catch (err) {
  130 + loger.log('MCU选点->失败', err.message);
  131 + }
  132 + }
  133 +
  134 + //获取最快的MS服务器地址,参数是一个ip数组
  135 + getFastestMsServer(_ipList, _callback, _timeOutDelay) {
  136 + loger.log('开始MS选点->', _ipList);
  137 + let callbackData = {ip: ""};
  138 + if (_ipList == null || _ipList.length < 1) {
  139 + if (_callback) {
  140 + _callback(callbackData);
  141 + }
  142 + return;
  143 + }
  144 + //对传入的ip数组进行组织
  145 + let newList = new Set();
  146 + let listLen = _ipList.length;
  147 + for (let i = 0; i < listLen; i++) {
  148 + let msItem = _ipList[i];
  149 + if (msItem && msItem.ip) {
  150 + //测速的时候,ip地址要拼接成带端口的完整地址,测速的端口是固定的
  151 + newList.add((msItem.ip + ':' + SPEED_TEST_PORT));
  152 + }
  153 + }
  154 + //过滤完重复ip
  155 + let ipListArr = Array.from(newList);
  156 + if (ipListArr == null || ipListArr.length < 1) {
  157 + if (_callback) {
  158 + _callback(callbackData);
  159 + }
  160 + return;
  161 + }
  162 + loger.log('MS选点->列表', ipListArr);
  163 + try {
  164 + iphunter(ipListArr, function (fatest_ip_response) {
  165 + if (!fatest_ip_response) {
  166 + loger.warn('MS选点-> nothing!');
  167 + if (_callback) {
  168 + _callback(callbackData);
  169 + }
  170 + } else {
  171 + loger.log('MS选点->done -> ', fatest_ip_response);
  172 + let fastestIp = fatest_ip_response.replace((':' + SPEED_TEST_PORT), '') || ""
  173 + callbackData.ip = fastestIp;
  174 + callbackData.port = '';
  175 +
  176 + //根据ip从原来的ip列表中查找端口
  177 + let listLen = _ipList.length;
  178 + for (let i = 0; i < listLen; i++) {
  179 + let msItem = _ipList[i];
  180 + if (msItem && msItem.ip) {
  181 + if (fastestIp == msItem.ip) {
  182 + callbackData.port = msItem.port || MS_DEFAULT_PORT;
  183 + break;
  184 + }
  185 + }
  186 + }
  187 + //返回数据
  188 + if (_callback) {
  189 + _callback(callbackData);
  190 + }
  191 + }
  192 + }, _timeOutDelay || TIME_OUT);
  193 + } catch (err) {
  194 + loger.warn('MS选点->ERROR -> ', err.message);
  195 + if (_callback) {
  196 + _callback(callbackData);
  197 + }
  198 + }
  199 +
  200 + }
  201 +
  202 + //根据user信息从配置文件中MCU连接地址
  203 + getServerMcuList(country, province, ctiy, isp, jsona) {
  204 + let countryData = jsona.MCU[country];
  205 + //按country没有查找到就返回default
  206 + if (!countryData) {
  207 + countryData = jsona.MCU.default || [];
  208 + return countryData;
  209 + }
  210 + if (country != "中国") {
  211 + return countryData;
  212 + }
  213 + //中国的需要细分
  214 + //按isp查找
  215 + let ispData = countryData.isp[isp];
  216 + //isp查找到就返回
  217 + if (ispData) {
  218 + // loger.log("_returnServerMCU->ispData",ispData);
  219 + return ispData;
  220 + }
  221 +
  222 + //isp没查找到,用province
  223 + let provinceData = countryData.province[province];
  224 + //用province查找到就返回
  225 + if (provinceData) {
  226 + // loger.log("_returnServerMCU->provinceData",provinceData);
  227 + return provinceData;
  228 + }
  229 + //isp province都没有,使用default
  230 + let defaultData = countryData.default
  231 + if (defaultData) {
  232 + // loger.log("_returnServerMCU->defaultData",defaultData);
  233 + return defaultData;
  234 + } else {
  235 + // loger.log("_returnServerMCU->defaultData","");
  236 + return [];
  237 + }
  238 + return [];
  239 + }
  240 +
  241 + //根据user信息从配置文件中MS连接地址
  242 + getServerMsList(country, province, ctiy, isp, jsona) {
  243 + let countryData = jsona.MS[country];
  244 + //按country没有查找到就返回default
  245 + if (!countryData) {
  246 + countryData = jsona.MS.default || [];
  247 + // loger.log("_returnServerMS->countryData->default",countryData);
  248 + return countryData;
  249 + }
  250 +
  251 + if (country != "中国") {
  252 + // loger.log("_returnServerMS->countryData",countryData);
  253 + return countryData;
  254 + }
  255 +
  256 + //中国的需要细分
  257 + //按isp查找
  258 + let ispData = countryData.isp[isp];
  259 + //isp查找到就返回
  260 + if (ispData) {
  261 + // loger.log("_returnServerMS->ispData",ispData);
  262 + return ispData;
  263 + }
  264 +
  265 + //isp没查找到,用province
  266 + let provinceData = countryData.province[province];
  267 + //用province查找到就返回
  268 + if (provinceData) {
  269 + // loger.log("_returnServerMS->provinceData",provinceData);
  270 + return provinceData;
  271 + }
  272 +
  273 + //isp province都没有,使用default
  274 + let defaultData = countryData.default
  275 + if (defaultData) {
  276 + // loger.log("_returnServerMS->defaultData",defaultData);
  277 + return defaultData;
  278 + } else {
  279 + // loger.log("_returnServerMS->defaultData","");
  280 + return [];
  281 + }
  282 +
  283 + return [];
  284 + }
  285 +
  286 +}
  287 +export default IpManager;
  288 +