diff --git a/assets/Script/Manager.ts b/assets/Script/Manager.ts index 632151d..e0189d9 100644 --- a/assets/Script/Manager.ts +++ b/assets/Script/Manager.ts @@ -35,7 +35,9 @@ export default class Manager extends cc.Component { let data: any = e.data; let method: string = data.method; let value: any = data.value; - self.Birdge(method, ...value); + if (method) { + self.Birdge(method, ...value); + } }, false); if (!window["Bridge"]) { @@ -43,14 +45,23 @@ export default class Manager extends cc.Component { self.Birdge(method, value); }; } + let scheme: string = "jmka"; + this.webview.setJavascriptInterfaceScheme(scheme); + this.webview.setOnJSCallback((sender, url) => { + let data: JSON = JSON.parse(decodeURI(url.split(`${scheme}://`)[1])); + let method: any = data["method"]; + let value: any = data["value"]; + if (method) { + self.Birdge(method, ...value); + } + }); let href: string = window.location.href; + let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/Test/?host=${href}&v=${Date.now()}`; // let url: string = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; - // let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/BJ_Casino_Rank/?v=${Date.now()}`; // let url: string = `http://karol.jianmiau.cf/jm-expense-vue-ts/?v=${Date.now()}`; - let url: string = `https://jm-expense-2022.firebaseapp.com/login?v=${Date.now()}`; + // let url: string = `https://jm-expense-2022.firebaseapp.com/login?host=${href}&v=${Date.now()}`; this.webview.url = url; - // this.webview.url = `http://localhost:8080/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`; this.webview.node.active = true; cc.view.setResizeCallback(this._resize.bind(this)); diff --git a/assets/Script/NativeClass.ts b/assets/Script/NativeClass.ts index baba1d8..3d2b8c7 100644 --- a/assets/Script/NativeClass.ts +++ b/assets/Script/NativeClass.ts @@ -1,3 +1,5 @@ +// import Text_to_Speech from "./Text_to_Speech"; + const { ccclass } = cc._decorator; @ccclass @@ -17,6 +19,12 @@ export default class NativeClass extends cc.Component { //#endregion + //#region private + + // private _text_to_Speech: Text_to_Speech; + + //#endregion + //#region Lifecycle constructor() { @@ -27,6 +35,7 @@ export default class NativeClass extends cc.Component { private init(): void { let self: this = this; + // this._text_to_Speech = new Text_to_Speech(); let HttpData: any[] = []; // let HttpParmData: any[] = []; // 註冊要被Java、OC呼叫的事件 @@ -135,6 +144,7 @@ export default class NativeClass extends cc.Component { } case cc.sys.OS_ANDROID: { jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "TTS_Play", "(Ljava/lang/String;)V", msg); + // this._text_to_Speech.speak(msg); break; } diff --git a/assets/Script/NativeClass.ts.meta b/assets/Script/NativeClass.ts.meta index 83b965d..4bbe34c 100644 --- a/assets/Script/NativeClass.ts.meta +++ b/assets/Script/NativeClass.ts.meta @@ -1,6 +1,7 @@ { - "ver": "1.0.8", + "ver": "1.1.0", "uuid": "5558f747-ed9e-4040-9a01-3b89b99ac37a", + "importer": "typescript", "isPlugin": false, "loadPluginInWeb": true, "loadPluginInNative": true, diff --git a/assets/Script/Text_to_Speech.ts b/assets/Script/Text_to_Speech.ts new file mode 100644 index 0000000..836d6a0 --- /dev/null +++ b/assets/Script/Text_to_Speech.ts @@ -0,0 +1,41 @@ +const responsiveVoice = window["responsiveVoice"]; + +export default class Text_to_Speech { + //#region 外調參數 + + private voice: string = null; + + //#endregion + + //#region Custom + + constructor() { + let self: this = this; + responsiveVoice.init(); + var voicelist = responsiveVoice.getVoices(); + this.setDefaultVoice(voicelist[14].name); + } + + public setDefaultVoice(voice: string): void { + this.voice = voice; + responsiveVoice.setDefaultVoice(voice); + } + + public speak(msg: string): void { + let self: this = this; + if (responsiveVoice.voiceSupport()) { + responsiveVoice.speak(msg, this.voice, { + onstart: function (Callback: any): void { + console.log(`onstart msg: ${msg}`); + }, + onend: function (Callback: any): void { + console.log(`onstart msg: ${msg}`); + }, + }); + } else { + console.error(`!responsiveVoice.voiceSupport`); + } + } + + //#endregion +} diff --git a/assets/Script/Text_to_Speech.ts.meta b/assets/Script/Text_to_Speech.ts.meta new file mode 100644 index 0000000..423e0b8 --- /dev/null +++ b/assets/Script/Text_to_Speech.ts.meta @@ -0,0 +1,10 @@ +{ + "ver": "1.1.0", + "uuid": "59151148-7427-4d5f-a981-41c6adb57700", + "importer": "typescript", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file