Commit 5d613c4c authored by huoshizhe's avatar huoshizhe

feat: 加载线上包

parent b9b6e1f3
......@@ -243,8 +243,8 @@
"width": 1280,
"height": 720
},
"_fitWidth": true,
"_fitHeight": false,
"_fitWidth": false,
"_fitHeight": true,
"_id": "59Cd0ovbdF4byw5sbjJDx7"
},
{
......@@ -271,7 +271,7 @@
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_originalHeight": 720,
"_id": "29zXboiXFBKoIV4PQ2liTe"
},
{
......@@ -652,7 +652,7 @@
"__id__": 7
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 15
......@@ -847,7 +847,7 @@
"__id__": 7
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 19
......
......@@ -3,6 +3,8 @@ cc.Class({
properties: {},
getData(callBack) {
callBack(null);
return;
if (this.localMode) {
callBack(null);
return;
......@@ -16,6 +18,7 @@ cc.Class({
},
onHomeworkFinish(callBack) {
return;
if (this.role == 'teacher') {
return;
}
......@@ -30,27 +33,6 @@ cc.Class({
this.callNetworkApiPost(uri, data, callBack);
},
callNetworkApiGet(uri, data, callBack) {
let queryStr = '?';
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
const value = data[key];
queryStr += `${key}=${value}`;
}
}
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
const responseData = JSON.parse(xhr.responseText);
callBack(JSON.parse(responseData.data));
}
};
const url = `${this.baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
callNetworkApiPost(uri, data, callBack) {
const xhr = new XMLHttpRequest();
const url = `${this.baseUrl}${uri}`;
......@@ -65,17 +47,11 @@ cc.Class({
},
start() {
this.node.zIndex = 9999;
// this.showWaitingLetters();
cc.game.addPersistRootNode(this.node);
this.initListener();
// this.getBundleInfoList();
},
asyncDelayLog(str) {
......@@ -87,108 +63,24 @@ cc.Class({
});
},
getBundleInfoList() {
const jsonStr = this.callNativeFunction({ name: 'loadSceneList', value: '' });
// const jsonStr = `{"bundleInfoList":[{"sceneName":"dfzx_cocos_T_FT_01","version":"c1a41","bondleUrl":"http://staging-teach.cdn.ireadabc.com//h5template/dfzx_cocos_T_FT_01/v3/android/dfzx_cocos_T_FT_01","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NDYyLCJ1dWlkIjoiZDNlODE0OGItOTNlNC00NzdiLWEyMmEtMjNkYTk4ZWVlMGYwIiwicGhvbmUiOiIxNTk0MDgzMzk1MCIsIm5pY2tfbmFtZSI6IuaZk-aFp-a1i-ivlSIsIm9yZ19pZCI6MTEsInNjaG9vbF9pZCI6MjA0LCJjbGFzc19pZCI6MTQxLCJkZnp4X3VzZXJfdXVpZCI6ImVmMTNhNTI3ZDg2ZDQ1MGY4MWJjMWE1OWQ0NDcyZTQwIiwiZGVsIjowLCJjcmVhdGVkX2RhdGUiOiIyMDIwLTA4LTA2VDA2OjA1OjUxLjAwMFoiLCJ1cGRhdGVkX2RhdGUiOiIyMDIwLTA4LTA3VDA4OjI3OjQwLjAwMFoiLCJhY2NvdW50X3R5cGUiOjIsImVuZF9kYXRlIjoiMjAyMS0xMC0xM1QxNjowMDowMC4wMDBaIiwiY2xhc3NSb2xlIjoic3R1IiwiaWF0IjoxNjI5ODYyMTA2LCJleHAiOjE2MzI0NTQxMDZ9.pKvGgI9yijd57vJBLAM9wuiPV5KkCriezV-FlD8fmLI","baseUrl":"http://staging-teach.ireadabc.com/api/","homework_id":"313","syllabus_id":"18984","role":"student"},{"sceneName":"dfzx_cocos_T_FT_01","version":"c1a41","bondleUrl":"http://staging-teach.cdn.ireadabc.com//h5template/dfzx_cocos_T_FT_01/v3/android/dfzx_cocos_T_FT_01","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NDYyLCJ1dWlkIjoiZDNlODE0OGItOTNlNC00NzdiLWEyMmEtMjNkYTk4ZWVlMGYwIiwicGhvbmUiOiIxNTk0MDgzMzk1MCIsIm5pY2tfbmFtZSI6IuaZk-aFp-a1i-ivlSIsIm9yZ19pZCI6MTEsInNjaG9vbF9pZCI6MjA0LCJjbGFzc19pZCI6MTQxLCJkZnp4X3VzZXJfdXVpZCI6ImVmMTNhNTI3ZDg2ZDQ1MGY4MWJjMWE1OWQ0NDcyZTQwIiwiZGVsIjowLCJjcmVhdGVkX2RhdGUiOiIyMDIwLTA4LTA2VDA2OjA1OjUxLjAwMFoiLCJ1cGRhdGVkX2RhdGUiOiIyMDIwLTA4LTA3VDA4OjI3OjQwLjAwMFoiLCJhY2NvdW50X3R5cGUiOjIsImVuZF9kYXRlIjoiMjAyMS0xMC0xM1QxNjowMDowMC4wMDBaIiwiY2xhc3NSb2xlIjoic3R1IiwiaWF0IjoxNjI5ODYyMTA2LCJleHAiOjE2MzI0NTQxMDZ9.pKvGgI9yijd57vJBLAM9wuiPV5KkCriezV-FlD8fmLI","baseUrl":"http://staging-teach.ireadabc.com/api/","homework_id":"313","syllabus_id":"18984","role":"student"}],"defaultBundleIdx":0}`;
const { bundleInfoList, defaultBundleIdx } = JSON.parse(jsonStr);
this.bundleInfoList = bundleInfoList;
this.jumpToBundleByIndex(defaultBundleIdx);
},
jumpToBundleByIndex(index) {
this.currentBundleIndex = index;
const currentBundleInfo = this.bundleInfoList[this.currentBundleIndex];
const btnLeft = this.node.getChildByName('BtnLeft');
const btnRight = this.node.getChildByName('BtnRight');
btnLeft.active = true;
btnRight.active = true;
if (this.currentBundleIndex == 0) {
btnLeft.active = false;
}
if (this.currentBundleIndex == this.bundleInfoList.length - 1) {
btnRight.active = false;
}
this.baseUrl = currentBundleInfo.baseUrl;
this.token = currentBundleInfo.token;
this.homework_id = currentBundleInfo.homework_id;
this.syllabus_id = currentBundleInfo.syllabus_id;
this.role = currentBundleInfo.role;
cc.assetManager.loadBundle(currentBundleInfo.bondleUrl, { version: currentBundleInfo.version }, async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
callNetworkApiGet(baseUrl, uri, data, callBack) {
let queryStr = '?';
for (const key in data) {
if (Object.hasOwnProperty.call(data, key)) {
const value = data[key];
queryStr += `${key}=${value}`;
}
bundle.loadScene(currentBundleInfo.sceneName, (err, scene) => {
if (err) {
this.asyncDelayLog('err: ', err);
}
this.hideWaitingLetters();
cc.director.runScene(scene);
});
});
},
loadDefaultBundle() {
const jsonStr = this.callNativeFunction({ name: 'loadScene', value: '' });
const {
sceneName,
version,
bondleUrl,
token,
baseUrl,
homework_id,
syllabus_id,
role
} = JSON.parse(jsonStr);
this.baseUrl = baseUrl;
this.token = token;
this.homework_id = homework_id;
this.syllabus_id = syllabus_id;
this.role = role;
cc.assetManager.loadBundle(bondleUrl, { version: version }, (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
callBack(xhr.responseText);
}
bundle.loadScene(sceneName, (err, scene) => {
this.hideWaitingLetters();
cc.director.runScene(scene);
});
});
};
const url = `${baseUrl}${uri}${queryStr}`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
initListener() {
......@@ -200,40 +92,32 @@ cc.Class({
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(() => {
cc.game.removePersistRootNode(this.node);
cc.director.loadScene("emptyScene", () => {
this.callNativeFunction({ name: 'exit', value: '' });
cc.director.loadScene("middleLayer_for_debug", () => {
});
})
.start();
});
const btnLeft = this.node.getChildByName('BtnLeft');
btnLeft.on('click', () => {
if (this.currentBundleIndex - 1 < 0) {
return;
}
this.jumpToBundleByIndex(this.currentBundleIndex - 1);
});
const btnRight = this.node.getChildByName('BtnRight');
btnRight.on('click', () => {
if (this.currentBundleIndex + 1 >= this.bundleInfoList.length) {
return;
}
this.jumpToBundleByIndex(this.currentBundleIndex + 1);
});
const BtnStartLocal = cc.find('middleLayer/ui/BtnStartLocal');
BtnStartLocal.on('click', () => {
const addressText = cc.find('middleLayer/ui/address');
const str = addressText.getComponent(cc.EditBox).string;
const address = str.split(':')[0];
const port = str.split(':')[0] | 8081;
console.log('汪汪汪: ' + `address = ${address}, port = ${port}`);
this.localMode = true;
this.loadBundle(address, port);
this.loadLocalBundle(address, port);
this.showWaitingLetters();
this.hideUI();
});
const BtnStartOnline = cc.find('middleLayer/ui/BtnStartOnline');
BtnStartOnline.on('click', () => {
this.showWaitingLetters();
this.hideUI();
const nameText = cc.find('middleLayer/ui/bundleName');
const bundleName = nameText.getComponent(cc.EditBox).string;
this.loadOnlineBundle(bundleName);
});
},
......@@ -241,18 +125,34 @@ cc.Class({
cc.find('middleLayer/ui').active = false;
},
loadBundle(address, port) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
const data = JSON.parse(xhr.responseText);
const configData = data.android;
const bondleUrl = `http://${address}:${port}/publish/android/${configData.sceneName}/`;
cc.assetManager.loadBundle(bondleUrl, { version: configData.version }, async (err, bundle) => {
loadOnlineBundle(bundleName) {
this.callNetworkApiGet(`http://staging-teach.ireadabc.com`, `/api/template/v1/${bundleName}`, {}, (datastr) => {
const data = JSON.parse(datastr);
const configData = data.data.conf.android;
const sceneName = configData.sceneName;
const version = configData.version;
const bondleUrl = configData.bondleUrl;
this.loadBundle(sceneName, version, bondleUrl);
});
},
loadLocalBundle(address, port) {
this.callNetworkApiGet(`http://${address}:${port}`, '/publish/config.json', {}, (datastr) => {
const data = JSON.parse(datastr);
console.log(JSON.stringify(data));
const sceneName = data.android.sceneName;
const version = data.android.version;
const bondleUrl = `http://${address}:${port}/publish/android/${sceneName}/`;
this.loadBundle(sceneName, version, bondleUrl);
});
},
loadBundle(sceneName, version, bondleUrl) {
cc.assetManager.loadBundle(bondleUrl, { version: version }, async (err, bundle) => {
if (err) {
return this.asyncDelayLog(err);
}
bundle.loadScene(configData.sceneName, (err, scene) => {
bundle.loadScene(sceneName, (err, scene) => {
if (err) {
this.asyncDelayLog('err: ', err);
}
......@@ -260,12 +160,6 @@ cc.Class({
cc.director.runScene(scene);
});
});
}
};
const url = `http://${address}:${port}/publish/config.json`;
console.log('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
},
callNativeFunction(param) {
......
......@@ -3,6 +3,6 @@
"packages": "packages",
"name": "play",
"id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231",
"version": "2.4.4",
"version": "2.4.0",
"isNew": false
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment