175 lines
4.9 KiB
JavaScript
175 lines
4.9 KiB
JavaScript
/*******************************************************************************
|
|
*
|
|
* Nx远程配置服务
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
const ERR = require( "error" );
|
|
const MOD = require( "nx.mod" );
|
|
|
|
var HMRemote = cc.Class( {
|
|
|
|
extends: MOD,
|
|
|
|
name: "HMRemote",
|
|
|
|
// 初始化
|
|
initialize: function( _args ) {
|
|
|
|
// USPER
|
|
this._super( _args );
|
|
|
|
// 插件
|
|
nx.plugin.add( this, [ "view" ] );
|
|
|
|
// 视图代理初始化
|
|
this.vattach( "Bridge" );
|
|
|
|
// 访问接口(设置)
|
|
nx.bridge.remote = this;
|
|
|
|
return true;
|
|
},
|
|
|
|
// 销毁
|
|
uninitialize: function() {
|
|
|
|
// 访问接口(关闭)
|
|
nx.bridge.remote = null;
|
|
|
|
// USPER
|
|
return this._super();
|
|
},
|
|
|
|
// 获取配置
|
|
fetch: function( _cb ) {
|
|
|
|
// 包信息
|
|
// nx.debug( "$SDK:设备ID:", nx.sdk.getDeviceID() );
|
|
// nx.debug( "$SDK:包版本:", nx.sdk.getPackVersion() );
|
|
|
|
// nx.frame.vset( "Platform", nx.getPlatform() );
|
|
// nx.frame.vset( "DeviceID", nx.sdk.getDeviceID() );
|
|
// nx.frame.vset( "ApkVersion", nx.sdk.getPackVersion() );
|
|
// nx.frame.vset( "DebugOpen", CC_DEBUG );
|
|
|
|
// let packArgs = nx.sdk.getPackArgs();
|
|
// this.vset( "gname", packArgs.gname );
|
|
// this.vset( "channel", packArgs.cnn );
|
|
// this.vset( "logLv", parseInt( packArgs.log ) || 0 );
|
|
// this.vset( "gm", packArgs.gm == "1" );
|
|
// this.vset( "ssl", parseInt( packArgs.ssl ) == 1 );
|
|
|
|
// PHP远程路径(本地缓存+包内原始地址)
|
|
let urls = [];
|
|
let cache = nx.storage.get( "FCPHPS" );
|
|
if( nx.dt.strNEmpty( cache ) ) {
|
|
urls = nx.dt.dejson( cache );
|
|
}
|
|
|
|
let nat = this.vget( "phpUrls" );
|
|
if( nx.dt.strNEmpty( nat ) ) {
|
|
let arr = nat.split( "#" );
|
|
urls = urls.concat( arr );
|
|
}
|
|
|
|
if( nx.dt.arrEmpty( urls ) ) {
|
|
nx.error( "$Remote:PHP远程路径未指定!" );
|
|
nx.dt.fnInvoke( _cb, nx.genError( ERR.CLI.FailedRemote ) );
|
|
return;
|
|
}
|
|
|
|
// 轮询请求远程配置
|
|
let self = this;
|
|
let loop = function() {
|
|
|
|
// 全部失败
|
|
if( nx.dt.arrEmpty( urls ) ) {
|
|
nx.error( "$Remote:轮询请求远程配置失败!" );
|
|
nx.dt.fnInvoke( _cb, nx.genError( ERR.CLI.FailedRemote ) );
|
|
return;
|
|
}
|
|
|
|
let header = self.vget( "ssl" ) ? "https" : "http";
|
|
let url = header + "://" + urls.shift() + "/url_config.php" +
|
|
"?platform=" + nx.frame.vget( "Platform" ) +
|
|
"&chanleId=" + self.vget( "channel" ) +
|
|
"&time=" + cc.sys.now();
|
|
|
|
nx.web.get( url, {}, ( _code, _msg ) => {
|
|
|
|
// 失败
|
|
if( _code != ERR.OK || nx.dt.objEmpty( _msg ) ) {
|
|
loop();
|
|
return;
|
|
}
|
|
|
|
// 成功
|
|
self.vset( "svrsURL", _msg.SERVER_LIST_URL || "" );
|
|
self.vset( "dataURL", _msg.DATA_URL || "" );
|
|
self.vset( "payURL", _msg.PAY_URL || "" );
|
|
self.vset( "noticeURL", _msg.NOTICE_URL || "" );
|
|
self.vset( "bugURL", _msg.BUG_URL || "" );
|
|
|
|
if( nx.dt.arrNEmpty( _msg.CDN_URL ) ) {
|
|
nx.storage.set( "FCPHPS", nx.dt.enjson( _msg.CDN_URL ) );
|
|
}
|
|
|
|
if( nx.mTrace ) {
|
|
nx.mTrace.setRouter( _msg.DOT_URL );
|
|
}
|
|
|
|
nx.dt.fnInvoke( _cb );
|
|
|
|
}, false );
|
|
};
|
|
|
|
loop();
|
|
|
|
},
|
|
|
|
// 请求服务器列表
|
|
queryServers: function( _account, _sid, _all, _cb ) {
|
|
|
|
let svr = this.vget( "svrsURL" );
|
|
let url = svr +
|
|
"?platform=" + nx.frame.vget( "Platform" ) +
|
|
"&chanleId=" + this.vget( "channel" ) +
|
|
"&account=" + _account +
|
|
"&srvid=" + _sid +
|
|
"&start=" + 0 +
|
|
"&num=" + ( _all ? 0 : 1 ) +
|
|
"&time=" + client.socket.getTime() +
|
|
"&type=json";
|
|
|
|
nx.web.get( url, {}, ( _code, _msg ) => {
|
|
|
|
// 失败
|
|
if( _code != ERR.OK || nx.dt.objEmpty( _msg ) ) {
|
|
nx.dt.fnInvoke( _cb, nx.genError( ERR.CLI.FailedRemote ) );
|
|
return;
|
|
}
|
|
|
|
// 成功
|
|
// this.vset( "platform", _msg.data.default_zone.platform );
|
|
|
|
nx.dt.fnInvoke( _cb, ERR.OK, _msg );
|
|
|
|
}, false );
|
|
},
|
|
|
|
// 是否远程原生模式(更新同步)
|
|
isRemoteNative: function() {
|
|
|
|
if( cc.sys.isNative && !cc.sys.isBrowser ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
} );
|
|
|
|
module.exports = HMRemote; |