Commit 397452a5 authored by limingzhe's avatar limingzhe

fix: test_002 转移

parent 4340345d
......@@ -18,7 +18,7 @@
</div>
<iframe *ngIf="isShowFrame" #iframe id="iframe" [src]="safeUrl" style="width: 98%; height: 70vh; border: 1px solid #ccc; padding: 5px;" frameborder="0">
<iframe #iframe id="iframe" [src]="safeUrl" style="width: 98%; height: 70vh; border: 1px solid #ccc; padding: 5px;" frameborder="0">
</iframe>
......
......@@ -42,7 +42,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
_item;
_data;
isShowFrame = true;
@Input()
......@@ -65,22 +64,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
window['air'].getUploadCallback = (url, data) => {
console.log(' in getUploadCallback , url: ', url)
this.uploadUrl = url;
this.uploadData = data;
};
this.setUploadUrl();
if (!window['hw_test_count']) {
window['hw_test_count'] = 0
}
window['hw_test_count'] += 1;
console.log('window_count:', window['hw_test_count'])
}
......@@ -88,30 +76,14 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
if (!this.uploadUrl) {
console.log('this.uploadUrl -- 1 : ', this.uploadUrl)
this.uploadUrl = (<any> window).courseware.uploadUrl();
this.uploadData = (<any> window).courseware.uploadData();
console.log('this.uploadUrl -- 2 : ', this.uploadUrl)
console.log('(<any> window).courseware: ', (<any> window).courseware);
console.log('window_count:', window['hw_test_count'])
// console.log('this.iframe cWindow: ', this.iframe.nativeElement.contentWindow)
setTimeout(() => {
this.setUploadUrl();
}, 500);
} else {
console.log('this.uploadUrl -- 3 : ', this.uploadUrl)
if (this._data) {
this._item = this._data;
console.log(' __ refreshSafeUrl 4')
this.refreshSafeUrl()
}
......@@ -123,11 +95,9 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
if (!formUrl) {
formUrl = this._item.formUrl || '';
}
console.log(' in refreshSafeUrl formUrl:', formUrl)
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(formUrl);
console.log(' in refreshSafeUrl safeUrl:', this.safeUrl)
}
......@@ -145,12 +115,9 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
this._item = {};
}
console.log(' __ refreshSafeUrl 1')
this.initListener();
}
......@@ -188,7 +155,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
console.log('formUrl: ', formUrl)
console.log(' __ refreshSafeUrl 2')
this.refreshSafeUrl();
this.closePanel();
this.sendData();
......@@ -223,7 +189,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
const msgFunc = (e) => {
console.log('!!!e : ', e);
if (!this.iframe || !this.iframe.nativeElement || !this.iframe.nativeElement.contentWindow) {
console.log('this.iframe not exist');
......@@ -254,11 +219,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}
if ( !this.iframe.nativeElement ) {
return;
}
const data = { msg: 'success', data: JSON.stringify(this._item.data)};
// iframeContent.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
this.iframe.nativeElement.contentWindow.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
......@@ -281,9 +241,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
console.log("setData e: ", e);
if (this.iframe) {
console.log('ifram exist: ', this.iframe);
}
if (typeof(msgData.data) === "string") {
......@@ -300,9 +257,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
console.log( ' in getUpload')
if (this.iframe) {
console.log('ifram exist: ', this.iframe);
}
// const iframeContent = this.el.nativeElement.querySelector('#iframe').contentWindow;
......@@ -316,8 +270,10 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}
}
if (this.iframe?.nativeElement?.contentWindow) {
this.iframe.nativeElement.contentWindow.addEventListener('message', msgFunc);
console.log(' init Listener !');
window.addEventListener('message', msgFunc);
}
......@@ -334,17 +290,17 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
c.getTemplates((data) => {
data =
[
{"id": 26, "uuid":"c94fb1b0-3395-42ca-9ae3-03ca7c242d3f", "name": "hw_001", "description": "音频课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/3feddb01-4350-42ad-909f-236ad052fbb2.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 16},
{"id": 27, "uuid":"b8bedc68-9ef6-42a6-ba99-513daa244a6d", "name": "hw_002", "description": "视频课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/1b11d370-9d8b-4358-98d3-4757f825d2a4.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 16},
{"id": 28, "uuid":"068fcffb-4e99-4148-bc8e-2a89ee9bfe7c", "name": "hw_003", "description": "转盘课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/de3d8498-7523-4601-934e-932ac219a408.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 17},
{"id": 29, "uuid":"b2bfd8df-e0e4-41c9-b65f-12160628e1a3", "name": "hw_004", "description": "连线课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/824989ac-78fb-4db7-848a-790cba00effe.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 9 },
{"id": 30, "uuid":"d7be3c21-fc25-482d-a4a6-1a371970457a", "name": "hw_005", "description": "分类课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/aa69d85a-3430-48b2-91bf-a804dee1826d.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 19},
{"id": 31, "uuid":"34e98c65-f3f0-46e4-a7b8-5caf72954847", "name": "hw_006", "description": "翻卡游戏", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/fe54031b-7879-4c65-8de7-102fa5e5e9f5.png", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 5 }
]
resolve(data);
return
// data =
// [
// {"id": 26, "uuid":"c94fb1b0-3395-42ca-9ae3-03ca7c242d3f", "name": "hw_001", "description": "音频课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/3feddb01-4350-42ad-909f-236ad052fbb2.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 16},
// {"id": 27, "uuid":"b8bedc68-9ef6-42a6-ba99-513daa244a6d", "name": "hw_002", "description": "视频课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/1b11d370-9d8b-4358-98d3-4757f825d2a4.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 16},
// {"id": 28, "uuid":"068fcffb-4e99-4148-bc8e-2a89ee9bfe7c", "name": "hw_003", "description": "转盘课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/de3d8498-7523-4601-934e-932ac219a408.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 17},
// {"id": 29, "uuid":"b2bfd8df-e0e4-41c9-b65f-12160628e1a3", "name": "hw_004", "description": "连线课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/824989ac-78fb-4db7-848a-790cba00effe.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 9 },
// {"id": 30, "uuid":"d7be3c21-fc25-482d-a4a6-1a371970457a", "name": "hw_005", "description": "分类课件", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/aa69d85a-3430-48b2-91bf-a804dee1826d.jpg", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 19},
// {"id": 31, "uuid":"34e98c65-f3f0-46e4-a7b8-5caf72954847", "name": "hw_006", "description": "翻卡游戏", "cover": "http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/fe54031b-7879-4c65-8de7-102fa5e5e9f5.png", "type": 1, "t_type": 2, "form_url": "index.html?type=form", "play_url": "index.html", "last_version": 5 }
// ]
// resolve(data);
// return
if (data) {
console.log('data~~~:', data);
resolve(JSON.parse(data));
......@@ -406,7 +362,7 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}
ngOnDestroy() {
this.isShowFrame = false;
}
}
......@@ -28,7 +28,7 @@
</div>
<!-- <div *ngIf="item.templateArr" >
<div *ngIf="item.templateArr" >
<div *ngFor="let template of item.templateArr; let i = index" style="margin-bottom: 10px;">
<app-sub-template
......@@ -44,10 +44,10 @@
<button nz-button nzType="primary" (click)="addSubTemplate()" style="border-radius: 0.5rem; border: 1px solid #ddd; margin-top: 15px;">
<button *ngIf=" item.templateArr.length < 2 " nz-button nzType="primary" (click)="addSubTemplate()" style="border-radius: 0.5rem; border: 1px solid #ddd; margin-top: 15px;">
<i nz-icon nzType="plus" nzTheme="outline"></i>
添加子模板
</button> -->
</button>
<!--
......
......@@ -5,22 +5,27 @@
export async function loadFonts () {
const font = new FontFace(
"DroidSansFallback",
"url(" + "../../assets/play/font/DroidSansFallback.ttf" + ")"
);
// console.log(location.href.split("#")[0] + "assets/play/font/DroidSansFallback.ttf");
// const font = new FontFace(
// "DroidSansFallback",
// "url(" + location.href.split("#")[0] + "assets/play/font/DroidSansFallback.ttf" + ")"
// "url(" + "../../assets/play/font/DroidSansFallback.ttf" + ")"
// );
try {
console.log(location.href.split("#")[0] + "assets/play/font/DroidSansFallback.ttf");
const font = new FontFace(
"DroidSansFallback",
"url(" + location.href.split("#")[0] + "assets/play/font/DroidSansFallback.ttf" + ")"
);
console.log('start: ', new Date().getTime())
await font.load();
console.log('end: ', new Date().getTime())
document.fonts.add(font);
document.body.classList.add("fonts-loaded");
} catch (error) {
console.log(error);
}
console.log('start: ', new Date().getTime())
await font.load();
console.log('end: ', new Date().getTime())
document.fonts.add(font);
document.body.classList.add("fonts-loaded");
}
......
......@@ -4,7 +4,7 @@
<canvas id="canvas" style="width: 100%; height: 100%;" #canvas></canvas>
</div>
<div #iframeContent style="position: absolute; top: 0">
<div #iframeContent style="position: absolute; top: 0;">
<div *ngFor="let t of templateArr; let i = index">
<iframe *ngIf="t.isShow" [src]="t.playUrl || ''" style="width: 100vw; height: 100vh; border: 0px solid #ccc; padding: 5px;" frameborder="0">
</iframe>
......
......@@ -226,7 +226,7 @@ export class PlayComponent implements OnInit, OnDestroy {
initDefaultData() {
const data = {"sentenceArr":[{"text":"1.She was not only _ but also very musical.","answer":"intelligent1"},{"text":"2.She was not only _ but also very musical.","answer":"intelligent2"},{"text":"3.She was not only _ but also very musical.","answer":"intelligent3"},{"text":"4.She was not only _ but also very musical.","answer":"intelligent4"}],"title":"\bVocabulary box"};
const data = {"sentenceArr":[{"text":"222 _ 33333","answer":"2"},{"text":"4444 _ 55 5555","answer":"5"},{"text":"666 666 66 _ 77777","answer":"6"},{"text":"888 88 8 _ 999","answer":"9"}],"templateArr":[{"formUrl":"http://staging-teach.cdn.ireadabc.com/h5template/hw_001/v16/index.html?type=form&key=1","template":{"id":26,"uuid":"c94fb1b0-3395-42ca-9ae3-03ca7c242d3f","name":"hw_001","description":"音频课件","cover":"http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/3feddb01-4350-42ad-909f-236ad052fbb2.jpg","type":1,"t_type":2,"form_url":"index.html?type=form","play_url":"index.html","last_version":16},"data":{"contentObj":{"picArr":[{"pic_url":"http://staging-teach.cdn.ireadabc.com/c8abf7383d65bcbdba8f390785cece60.png","audio_url":"http://staging-teach.cdn.ireadabc.com/85cff126986f5cc11b05e95181da5869.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/f6f4bbef497409fef3c8f1d375893829.png","audio_url":"http://staging-teach.cdn.ireadabc.com/9f0aee80e252005721a445cbbf04e8b1.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/7b18a7931d64f7b9e8b7ecd25cb5e3d4.png","audio_url":""}]}}},{"formUrl":"http://staging-teach.cdn.ireadabc.com/h5template/hw_002/v16/index.html?type=form&key=2","template":{"id":27,"uuid":"b8bedc68-9ef6-42a6-ba99-513daa244a6d","name":"hw_002","description":"视频课件","interaction_type":"个人 | 集体","recommend_type":"| 动画 | 绘本 | 儿歌 | 看图辨意","cover":"http://iplayabc-teach-yun.oss-cn-beijing.aliyuncs.com/1b11d370-9d8b-4358-98d3-4757f825d2a4.jpg","type":1,"t_type":2,"form_url":"index.html?type=form","play_url":"index.html","developer_id":12,"git":"{\"id\":59,\"ssh\":\"git@vcs.ireadabc.com:template/hw_002.git\",\"http\":\"http://vcs.ireadabc.com/template/hw_002.git\"}","del":0,"publish":1,"last_version":16,"pub_date":null,"is_public":1,"created_date":"2019-11-11T10:05:25.000Z","updated_date":"2020-10-12T02:01:13.000Z"},"data":{"contentObj":{"video_url":"http://staging-teach.cdn.ireadabc.com/f309f8dd44d59c65e44f375f818871e1.mp4"}}}],"title":"1111"};
this.data = { contentObj: data };
......@@ -460,6 +460,8 @@ export class PlayComponent implements OnInit, OnDestroy {
const c = window['courseware'];
if (!c) {
console.log(' window.courseware not exist !!!!!!!!')
return;
}
......@@ -472,6 +474,7 @@ export class PlayComponent implements OnInit, OnDestroy {
air.onCourseInScreen = (next) => {
//各种逻辑
// this.showTemplateStartAnima();
console.log('in onCourseInScreen')
this.loadEnd(() => {
next();
});
......@@ -546,23 +549,45 @@ export class PlayComponent implements OnInit, OnDestroy {
this.changeBtnOff();
this.initIframe();
this.initWindowListener();
this.relink();
}
relink() {
const resultData = this.getPageData('resultData')
if (resultData) {
this.initResultView(resultData);
const progress = this.getPageData('progress');
if (this.isTeacher) {
if (progress == '1') {
this.gameStart();
return;
}
return;
}
const progress = this.getPageData('progress');
if (progress == '1') {
const resultData = this.getPageData('resultData')
if (resultData) {
this.initResultView(resultData);
return;
}
this.gameStart();
return;
}
if (progress == '2') {
const submitCount = this.getPageData('submitCount')
this.submitCount = submitCount;
this.checkShowSubTemplateOne();
}
}
......@@ -577,6 +602,7 @@ export class PlayComponent implements OnInit, OnDestroy {
resultLayer;
resultPanel;
moreBtn;
initResultView(data = null) {
if (data) {
......@@ -638,6 +664,7 @@ export class PlayComponent implements OnInit, OnDestroy {
btn.setScaleXY(this.mapScale);
btn.y = panel.y + ( panel.height / 2 + 120 ) * panel.scaleY;
resultLayer.addChild(btn, 2);
this.moreBtn = btn;
const btnShadow = new MySprite();
btnShadow.init(this.images.get("big_btn_shadow"));
......@@ -1230,6 +1257,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.downFlag = true;
if (this.isTeacher) {
if (this.sentBtn && this.sentBtn.visible) {
if (this.checkClickTarget(this.sentBtn)) {
......@@ -1241,6 +1269,13 @@ export class PlayComponent implements OnInit, OnDestroy {
return;
}
if (this.moreBtn) {
if (this.checkClickTarget(this.moreBtn)) {
this.moreBtnClick();
return;
}
}
for (let i = 0; i < this.btnArr.length; i++) {
......@@ -1307,6 +1342,22 @@ export class PlayComponent implements OnInit, OnDestroy {
this.curMoveItem = null;
}
moreBtnClick() {
this.setPageData('progress', '2', false);
this.setPageData('submitCount', this.submitCount);
this.checkShowSubTemplateOne();
}
checkShowSubTemplateOne() {
if (this.submitCount == 1) {
this.showSubTemplate(1);
} else {
this.showSubTemplate(0);
}
}
btnDown(btn) {
this.curMoveItem = btn;
}
......@@ -1540,7 +1591,7 @@ export class PlayComponent implements OnInit, OnDestroy {
templateArr = [];
initIframe() {
this.templateArr = this.data.templateArr;
this.templateArr = this.data.contentObj.templateArr;
console.log('arr: ', this.templateArr);
......@@ -1551,14 +1602,12 @@ export class PlayComponent implements OnInit, OnDestroy {
console.log('playUrl: ', playUrl);
}
this.showSubTemplate(0);
// this.showSubTemplate(0);
setTimeout(() => {
this.showSubTemplate(1);
// setTimeout(() => {
// this.showSubTemplate(1);
}, 5000);
// }, 5000);
}
showSubTemplate(index) {
......
// 刷新CDN路径
// https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js
// https://teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js
const commonPostMessage = function (messageObj) {
const obj = {...messageObj, urlParams: window.location.search}
window.parent.postMessage(obj, '*');
};
const commonPostMessageWithCallback = function (messageObj, callback) {
const onMessage = (e) => {
let msgData = e.data;
if(msgData && msgData.action === messageObj.action){
window.removeEventListener("message", onMessage);
callback && callback(msgData.data);
}
};
window.addEventListener("message", onMessage);
commonPostMessage(messageObj);
};
const realAir = {
uploadUrl: null,
uploadData: null,
getDataCallback: null,
setDataCallback: null,
getUploadCallback: null,
pageLoaded: false,
isCourseInScreen: false,
hideAirClassLoading: function(templateName,loadData){
// 隐藏页面加载时候的loading
if (deleteHistory && typeof (deleteHistory) == 'function') {
deleteHistory();
}
window.parent.postMessage({ action: "course-ready", data: {template:templateName,loadData:loadData,urlParams: window.location.search}, urlParams: window.location.search}, '*');
window.air.pageLoaded = true;
window.courseware.next();
var cc = window.cc;
if (cc && cc.director && cc.director._scene) {
try {
const canvas = cc.find("Canvas");
canvas.on("mousemove", function () {});
cc.director._scene.on("mousemove", function () {
window.parent.postMessage({ action: "mousemove" }, "*");
});
cc.director._scene.on("touchmove", function () {
window.parent.postMessage({ action: "mousemove" }, "*");
});
if (cc.systemEvent && cc.SystemEvent) {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, (event) => {
switch (event.keyCode) {
case cc.KEY.left:
window.parent.postMessage({ action: "ArrowLeft" }, "*");
break;
case cc.KEY.right:
window.parent.postMessage({ action: "ArrowRight" }, "*");
break;
}
});
}
} catch (e) {
console.log("====cc.director._scene绑定事件====");
}
}
},
};
const uploadCallbackQueue = [];
try{
window.air = new Proxy(realAir, {
set: function (target, key, value, receiver) {
if (key=="getUploadCallback") {
uploadCallbackQueue.push(value);
}
return Reflect.set(target, key, value, receiver);
},
get: function (target, key, receiver) {
return Reflect.get(target, key, receiver);
},
deleteProperty: function(target, key){
return Reflect.deleteProperty(target, key);
}
});
}catch(e){
console.error("浏览器不支持ES6新特性Proxy/Reflect,请使用谷歌浏览器!");
}
function deleteHistory() {
const disableBack = () => {
window.history.pushState(null, "", document.URL);
window.addEventListener("popstate", () => {
window.history.pushState(null, "", document.URL);
});
}
disableBack();
window.addEventListener("load", disableBack);
}
deleteHistory();
if (window.self !== window.top) {
window.addEventListener("message", function (e) {
let msgData = e.data;
// console.log("子页面接收到了消息", msgData);
if(msgData.type === "webpackWarnings" || msgData.type === "webpackOk") {
return;
}
if(msgData.action==="airEvents"){
return;
}
if (msgData.action === "getUpload" && msgData.uploadUrl) {
window.air.uploadUrl = msgData.uploadUrl;
window.air.uploadData = msgData.uploadData;
for (let i = 0; i < uploadCallbackQueue.length; i++) {
uploadCallbackQueue[i](msgData.uploadUrl, msgData.uploadData);
}
return;
}
if (msgData.action === "pauseCocos") {
let cc = window.cc;
if (cc && cc.game) {
cc.game.pause();
console.log('pause了');
}
return;
}
if (msgData.action === "resumeCocos") {
let cc = window.cc;
if (cc && cc.game) {
cc.game.resume();
console.log('resume了');
}
return;
}
if (msgData.action === "restartCocos") {
let cc = window.cc;
if (cc && cc.game) {
cc.audioEngine.stopAll();
// cc.game.restart();
console.log('restart了');
}
return;
}
if (msgData.action === "setData") {
window.air.setDataCallback && window.air.setDataCallback();
return;
}
if (msgData.action === "getData") {
try {
const res = JSON.parse(msgData.data);
if (res.msg !== "success") {
console.log('数据加载失败!');
return;
}
if (res.data && res.data != 'null') {
window.air.callData = JSON.parse(res.data);
}
window.air.callDataFlag = true;
return;
} catch (e) {
console.log('数据加载失败!');
}
}
});
window.parent.postMessage({ action: "getUpload" }, '*');
document.onmousemove = function(){
window.parent.postMessage({ action: "mousemove" }, '*');
};
document.ontouchmove = function(){
window.parent.postMessage({ action: "mousemove" }, '*');
};
document.onkeydown = (event) => {
switch(event.key) {
case "ArrowLeft":
window.parent.postMessage({ action: "ArrowLeft" }, '*');
break;
case "ArrowRight":
window.parent.postMessage({ action: "ArrowRight" }, '*');
break;
}
}
document.oncontextmenu = function(){
return false;
}
}
window.courseware = (function () {
let obj = {
airEvents: {},
eventQueue: [],
eventLock: false,
next: () => {
let exe = obj.eventQueue.splice(0,1);
if(exe.length>0){
obj.eventLock = true;
let evtName = exe[0].evtName;
let data = exe[0].data;
if(obj.airEvents[evtName]){
if(evtName === "course-in-screen"){
if(window.air.isCourseInScreen){
return;
}
window.air.isCourseInScreen = true;
}
console.log(`evtName==${evtName}的方法被执行`);
obj.airEvents[evtName](data, obj.next);
} else {
console.warn(`airclass教室交互事件 ${evtName} 没有被捕获,请确认监听事件的先后顺序2`);
obj.next();
}
}else{
obj.eventLock = false;
}
}
};
if (window.self !== window.top) {
window.addEventListener("message", function (e) {
let msgData = e.data;
if(msgData.action!=="airEvents"){
return;
}
let evtName = msgData.evt;
let res = msgData.data;
if (evtName === "course-out-screen"){
console.log(`evtName==${evtName}的方法被执行`);
window.location.reload();
return;
}
if (res&&evtName!='userchange') {
//userchange事件传过来的值不需要转换
res = JSON.parse(res);
}
if(!window.air.pageLoaded){
//如果页面还没有加载完成
obj.eventQueue.push({"evtName": evtName, data: res});
}else{
if (obj.eventQueue.length === 0 && !obj.eventLock) {
//如果没有消息积压并且事件锁未锁定
obj.eventLock = true;
if(obj.airEvents[evtName]){
if(evtName === "course-in-screen"){
if(window.air.isCourseInScreen){
return;
}
window.air.isCourseInScreen = true;
}
console.log(`evtName==${evtName}的方法被执行`);
obj.airEvents[evtName](res, obj.next);
} else {
console.warn(`airclass教室交互事件 ${evtName} 没有被捕获,请确认监听事件的先后顺序1`);
obj.next();
}
} else {
obj.eventQueue.push({"evtName": evtName, data: res});
}
}
});
obj.getData = function (callback, key = '') {
window.parent.postMessage({ action: "getData", data: window.location.search, urlParams: window.location.search }, '*');
window.air.callDataFlag = false;
const liuintval = setInterval(()=>{
if(window.air.callDataFlag){
console.log("========我进来了=========");
clearInterval(liuintval);
setTimeout(() => {
console.log("执行回调,回调数据为:");
console.log(window.air.callData);
callback(window.air.callData);
}, 100);
}
}, 100);
};
obj.setData = function (data, callback, key = '') {
let str = JSON.stringify(data);
console.log("==setData==", str);
window.parent.postMessage({ action: "setData", data: str, urlParams: window.location.search }, '*');
window.air.setDataCallback = callback;
};
obj.uploadUrl = function () {
// return net.getUploadFileURL();
return window.air.uploadUrl;
};
obj.uploadData = function () {
// return net.getAjaxData("uploadFile","");
return window.air.uploadData;
};
obj.beganRecording = function(){
commonPostMessage({ action: "beganRecording" });
};
obj.endRecording = function(callback){
commonPostMessageWithCallback({ action: "endRecording" }, callback);
};
obj.speakPoints = function(audioUrl, evalText, callback){
const obj = {audioUrl, evalText};
commonPostMessageWithCallback({ action: "speakPoints", data: JSON.stringify(obj) }, callback);
};
obj.startRecord = function(testText){
commonPostMessage({ action: "startRecord", data: testText });
};
obj.stopRecord = function(callback){
commonPostMessageWithCallback({ action: "stopRecord" }, callback);
};
obj.startTest = function(testText){
commonPostMessage({ action: "startTest", data: testText });
};
obj.stopTest = function(callback){
commonPostMessageWithCallback({ action: "stopTest" }, callback);
};
obj.getTemplates = function(callback){
commonPostMessageWithCallback({ action: "getTemplates" }, callback);
};
obj.getTemplateUrl = function(templateName, callback){
commonPostMessageWithCallback({ action: "getTemplateUrl", data: templateName}, callback);
};
obj.sendEvent = function(evtName,data,key = ''){
if(evtName==="reconnect"){
console.error("reconnect是内置的断线重连事件名称,请勿使用此名称作为事件名");
return;
}
if(evtName==="userchange"){
console.error("userchange是内置的用户变更事件名称,请勿使用此名称作为事件名");
return;
}
let str = null;
if(data){
str = JSON.stringify(data);
}
window.parent.postMessage({ action: "airEvents",evt: evtName, data: str, urlParams: window.location.search }, '*');
};
obj.onEvent = function(evtName,callback){
obj.airEvents[evtName] = callback;
};
obj.removeEvent = function(evtName){
if(obj.airEvents[evtName]){
delete obj.airEvents[evtName];
}
};
obj.sendErrorLog = function (error) {
// todo 这块预留后面采集模板的报错信息
// window.parent.postMessage({ action: "errorlog", data: error.stack }, '*');
};
} else {
obj.getData = function (callback, key = '') {
let data = localStorage.getItem("courseware_data_" + key);
if (data) {
data = JSON.parse(data);
}
callback && callback(data);
};
obj.setData = function (data, callback, key = '') {
console.log("******local********");
localStorage.setItem("courseware_data_" + key, JSON.stringify(data));
callback && callback();
};
obj.uploadUrl = function () {
var protocolStr = document.location.protocol;
return `${protocolStr}//staging-teach.ireadabc.com/fileUpload`;
};
obj.uploadData = function () {
return {};
};
obj.beganRecording = function(){
console.log("******beganRecording********");
};
obj.endRecording = function(callback){
console.log("******endRecording********");
callback&&callback("");
};
obj.speakPoints = function(audioUrl, evalText, callback){
console.log("******speakPoints********");
callback&&callback("");
};
obj.startRecord = function(){
console.log("******startRecord********");
};
obj.stopRecord = function(callback){
console.log("******stopRecord********");
callback&&callback("");
};
obj.startTest = function(testText){
console.log("******startTest********");
};
obj.stopTest = function(callback){
console.log("******stopTest********");
callback&&callback("");
};
obj.getTemplates = function(callback){
callback&&callback("");
};
obj.getTemplateUrl = function(templateName, callback){
const obj = {
play_url: "",
form_url: "",
};
callback&&callback(JSON.stringify(obj));
};
obj.sendEvent = function(evtName, data, key = ''){
if(evtName==="reconnect"){
console.error("reconnect是内置的断线重连事件名称,请勿使用此名称作为事件名");
return;
}
if(evtName==="userchange"){
console.error("userchange是内置的用户变更事件名称,请勿使用此名称作为事件名");
return;
}
return;
};
obj.onEvent = function(evtName,callback){
console.warn("==本地测试用,onEvent的监听事件会直接触发==", "事件名:"+ evtName);
callback && callback("", function(){});
};
obj.removeEvent = function(evtName){
};
obj.sendErrorLog = function (error) {
};
}
return obj;
})();
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