Commit dcb39598 authored by liujiangnan's avatar liujiangnan

feat

parent 41985056
......@@ -279,16 +279,7 @@ export default class NewClass extends middleLayerBase {
}
async getOnlineVersion() {
let platform = '';
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
platform = 'ios';
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
platform = 'android';
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_WINDOWS) {
platform = 'windows';
} else {
platform = 'web';
}
let platform = 'web';
const res: any = await this.asyncCallNetworkApiGet('/api/application/v1/checkVersion', {
pkg_name: 'com.iplayabc.oxford.lite',
......@@ -327,12 +318,7 @@ export default class NewClass extends middleLayerBase {
preloadAll(onProgress, onComplete) {
let platform = "web_desktop";
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
platform = "ios";
}
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
platform = "android";
}
this.callNetworkApiGet(`/api/syllabus/v1/allbundles`, { orgid: this.ORG_ID, platform }, (datastr) => {
const data = JSON.parse(datastr);
this.batchPreloadScene(data.rows, [], onProgress, onComplete);
......@@ -706,20 +692,10 @@ export default class NewClass extends middleLayerBase {
const templateBaseUrl = `${this.DOMAIN}h5template/${data.name}/v${data.last_version}`;
this.getConfigInfo(templateBaseUrl, (conf) => {
if (cc.sys.os == cc.sys.OS_IOS) {
sceneName = conf.ios.sceneName;
version = conf.ios.version;
bondleUrl = `${templateBaseUrl}/ios/${conf.ios.sceneName}`;
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
sceneName = conf.android.sceneName;
version = conf.android.version;
bondleUrl = `${templateBaseUrl}/android/${conf.android.sceneName}`;
} else {
sceneName = conf.android.sceneName;
version = "";
bondleUrl = `${templateBaseUrl}/web_desktop`;
}
sceneName = conf.android.sceneName;
version = "";
bondleUrl = `${templateBaseUrl}/web_desktop`;
this.loadBundle(sceneName, version, bondleUrl, () => {
cc.find('middleLayer/ram').active = bundleName == 'NJ_YouLeChang';
cc.find('middleLayer/cross').active = (bundleName == 'NJ_YouLeChang'&&this.gameModel=='cross');
......@@ -741,20 +717,9 @@ export default class NewClass extends middleLayerBase {
let sceneName, version, bondleUrl = "";
const templateBaseUrl = `${this.DOMAIN}h5template/${this.courseItem.template_name}/v${this.courseItem.last_version}`;
this.getConfigInfo(templateBaseUrl, (conf) => {
if (cc.sys.os == cc.sys.OS_IOS) {
sceneName = conf.ios.sceneName;
version = conf.ios.version;
bondleUrl = `${templateBaseUrl}/ios/${conf.ios.sceneName}`;
} else if (cc.sys.os == cc.sys.OS_ANDROID) {
sceneName = conf.android.sceneName;
version = conf.android.version;
bondleUrl = `${templateBaseUrl}/android/${conf.ios.sceneName}`;
} else {
sceneName = conf.android.sceneName;
version = "";
bondleUrl = `${templateBaseUrl}/web_desktop`;
}
sceneName = conf.android.sceneName;
version = "";
bondleUrl = `${templateBaseUrl}/web_desktop`;
this.loadBundle(sceneName, version, bondleUrl, callback);
});
});
......
......@@ -125,118 +125,99 @@ export function initRecorder() {
var isSpeechToText;
export function supportMethod (method, param) {
if (cc.sys.isNative) {
// 原生调用
const paramStr = JSON.stringify(param);
if (cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('RootViewController', `${method}:`, paramStr);
}
if (cc.sys.os == cc.sys.OS_ANDROID) {
return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', method, '(Ljava/lang/String;)Ljava/lang/String;', paramStr);
}
if (cc.sys.os == cc.sys.OS_WINDOWS) {
console.error('暂不支持此平台');
if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 0, uuid: 'debug-njstar-xxxxxx'});
} else if (method == 'startTest') {
// 初始化参数
initSkKouYuParms(param.params, 'para.eval');
const rec = getWebRecordInstanse();
rec.start();
} else if (method == 'stopTest') {
const rec = getWebRecordInstanse();
rec.stop();
rec.getBlob(async (blob) => {
const maxAge = 70 * 365 * 24 * 60 * 60; // 70年
const now = Date.now();
const audioName = `${now}_${Math.random().toString(36).substr(2)}.mp3`;
const oss = await getOssInstanse();
await oss.put(
audioName,
blob,
{
'Cache-Control': `max-age=${70 * 365 * 24 * 60 * 60}`,
Expires: new Date(now + maxAge * 1000).toGMTString(),
'Last-Modified': new Date().toGMTString(),
'Content-type': `audio/mpeg`,
}
);
const audioUrl = `${global.middleLayer.DOMAIN}${audioName}`;
console.log(`上传的录音是:${audioUrl}`);
const formData = new FormData();
formData.append('audio', blob);
formData.append("text", JSON.stringify(pubskyparms));
var xhr = new XMLHttpRequest();
xhr.open("post" , baseUrl + 'para.eval');
xhr.setRequestHeader( "Request-Index" , "0");//Request-Index 固定为0
xhr.send(formData);
xhr.onreadystatechange = function () {
if(xhr.readyState == 4 && xhr.status == 200){
const res = JSON.parse(xhr.responseText);
window.air.testCallBack({...res, audioUrl});
}
};
});
} else if (method == 'startRecord') {
isSpeechToText = param.isSpeechToText;
// 初始化参数
if (isSpeechToText == 1) {
initSkKouYuParms("", 'asr.rec');
}
} else if (cc.sys.isBrowser) {
if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 0, uuid: 'debug-njstar-xxxxxx'});
} else if (method == 'startTest') {
// 初始化参数
initSkKouYuParms(param.params, 'para.eval');
const rec = getWebRecordInstanse();
rec.start();
} else if (method == 'stopTest') {
const rec = getWebRecordInstanse();
rec.stop();
rec.getBlob(async (blob) => {
const maxAge = 70 * 365 * 24 * 60 * 60; // 70年
const now = Date.now();
const audioName = `${now}_${Math.random().toString(36).substr(2)}.mp3`;
const oss = await getOssInstanse();
await oss.put(
audioName,
blob,
{
'Cache-Control': `max-age=${70 * 365 * 24 * 60 * 60}`,
Expires: new Date(now + maxAge * 1000).toGMTString(),
'Last-Modified': new Date().toGMTString(),
'Content-type': `audio/mpeg`,
}
);
const audioUrl = `${global.middleLayer.DOMAIN}${audioName}`;
console.log(`上传的录音是:${audioUrl}`);
const rec = getWebRecordInstanse();
rec.start();
} else if (method == 'stopRecord') {
const rec = getWebRecordInstanse();
rec.stop();
rec.getBlob(async (blob) => {
const maxAge = 70 * 365 * 24 * 60 * 60; // 70年
const now = Date.now();
const audioName = `${now}_${Math.random().toString(36).substr(2)}.mp3`;
const oss = await getOssInstanse();
await oss.put(
audioName,
blob,
{
'Cache-Control': `max-age=${70 * 365 * 24 * 60 * 60}`,
Expires: new Date(now + maxAge * 1000).toGMTString(),
'Last-Modified': new Date().toGMTString(),
'Content-type': `audio/mpeg`,
}
);
const audioUrl = `${global.middleLayer.DOMAIN}${audioName}`;
console.log(`上传的录音是:${audioUrl}`);
if (isSpeechToText == 1) {
const formData = new FormData();
formData.append('audio', blob);
formData.append("text", JSON.stringify(pubskyparms));
var xhr = new XMLHttpRequest();
xhr.open("post" , baseUrl + 'para.eval');
xhr.open("post" , baseUrl + 'asr.rec');
xhr.setRequestHeader( "Request-Index" , "0");//Request-Index 固定为0
xhr.send(formData);
xhr.onreadystatechange = function () {
if(xhr.readyState == 4 && xhr.status == 200){
const res = JSON.parse(xhr.responseText);
window.air.testCallBack({...res, audioUrl});
window.air.recordCallBack({text: res.result.recognition, audioUrl, ...res});
isSpeechToText = 0;
}
};
});
} else if (method == 'startRecord') {
isSpeechToText = param.isSpeechToText;
// 初始化参数
if (isSpeechToText == 1) {
initSkKouYuParms("", 'asr.rec');
} else {
window.air.recordCallBack({audioUrl});
}
const rec = getWebRecordInstanse();
rec.start();
} else if (method == 'stopRecord') {
const rec = getWebRecordInstanse();
rec.stop();
rec.getBlob(async (blob) => {
const maxAge = 70 * 365 * 24 * 60 * 60; // 70年
const now = Date.now();
const audioName = `${now}_${Math.random().toString(36).substr(2)}.mp3`;
const oss = await getOssInstanse();
await oss.put(
audioName,
blob,
{
'Cache-Control': `max-age=${70 * 365 * 24 * 60 * 60}`,
Expires: new Date(now + maxAge * 1000).toGMTString(),
'Last-Modified': new Date().toGMTString(),
'Content-type': `audio/mpeg`,
}
);
const audioUrl = `${global.middleLayer.DOMAIN}${audioName}`;
console.log(`上传的录音是:${audioUrl}`);
if (isSpeechToText == 1) {
const formData = new FormData();
formData.append('audio', blob);
formData.append("text", JSON.stringify(pubskyparms));
var xhr = new XMLHttpRequest();
xhr.open("post" , baseUrl + 'asr.rec');
xhr.setRequestHeader( "Request-Index" , "0");//Request-Index 固定为0
xhr.send(formData);
xhr.onreadystatechange = function () {
if(xhr.readyState == 4 && xhr.status == 200){
const res = JSON.parse(xhr.responseText);
window.air.recordCallBack({text: res.result.recognition, audioUrl, ...res});
isSpeechToText = 0;
}
};
} else {
window.air.recordCallBack({audioUrl});
}
});
} else if (method == 'startBuyToAppStore') {
window.air.startBuyToAppStoreCallBack({productid: 1, puid: 22, receiptData: "HelloWorld", error: ""});
} else{
console.error(`${method}方法还没有Mock数据,请联系技术支持人员添加`);
}
} else {
// 其他环境
if(method == 'getEngineInfo'){
window.air.getEngineInfoCallback({isDev: 1, uuid: 'debug-xxxxxx-xxxxxx'});
}
});
} else if (method == 'startBuyToAppStore') {
window.air.startBuyToAppStoreCallBack({productid: 1, puid: 22, receiptData: "HelloWorld", error: ""});
} else{
console.error(`${method}方法还没有Mock数据,请联系技术支持人员添加`);
}
}
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