141 lines
4.2 KiB
JavaScript
141 lines
4.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'cca855RZP5DcbUg+xWi8nQm', 'bridge.remote');
|
|
// Scripts/zbridge/remote/bridge.remote.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* Nx远程配置服务
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
var ERR = require("error");
|
|
var MOD = require("nx.mod");
|
|
var HMRemote = cc.Class({
|
|
"extends": MOD,
|
|
name: "HMRemote",
|
|
// 初始化
|
|
initialize: function initialize(_args) {
|
|
// USPER
|
|
this._super(_args);
|
|
|
|
// 插件
|
|
nx.plugin.add(this, ["view"]);
|
|
|
|
// 视图代理初始化
|
|
this.vattach("Bridge");
|
|
|
|
// 访问接口(设置)
|
|
nx.bridge.remote = this;
|
|
return true;
|
|
},
|
|
// 销毁
|
|
uninitialize: function uninitialize() {
|
|
// 访问接口(关闭)
|
|
nx.bridge.remote = null;
|
|
|
|
// USPER
|
|
return this._super();
|
|
},
|
|
// 获取配置
|
|
fetch: function fetch(_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远程路径(本地缓存+包内原始地址)
|
|
var urls = [];
|
|
var cache = nx.storage.get("FCPHPS");
|
|
if (nx.dt.strNEmpty(cache)) {
|
|
urls = nx.dt.dejson(cache);
|
|
}
|
|
var nat = this.vget("phpUrls");
|
|
if (nx.dt.strNEmpty(nat)) {
|
|
var 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;
|
|
}
|
|
|
|
// 轮询请求远程配置
|
|
var self = this;
|
|
var loop = function loop() {
|
|
// 全部失败
|
|
if (nx.dt.arrEmpty(urls)) {
|
|
nx.error("$Remote:轮询请求远程配置失败!");
|
|
nx.dt.fnInvoke(_cb, nx.genError(ERR.CLI.FailedRemote));
|
|
return;
|
|
}
|
|
var header = self.vget("ssl") ? "https" : "http";
|
|
var url = header + "://" + urls.shift() + "/url_config.php" + "?platform=" + nx.frame.vget("Platform") + "&chanleId=" + self.vget("channel") + "&time=" + cc.sys.now();
|
|
nx.web.get(url, {}, function (_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 queryServers(_account, _sid, _all, _cb) {
|
|
var svr = this.vget("svrsURL");
|
|
var 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, {}, function (_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 isRemoteNative() {
|
|
if (cc.sys.isNative && !cc.sys.isBrowser) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
module.exports = HMRemote;
|
|
|
|
cc._RF.pop(); |