我正在尝试将quietjs库实现到非离子项目中,但是有一个我无法理解的错误。
这是我的代码:
app.html
<ion-fab bottom center>
<button ion-button block (tap)="sendQuietData()">
Send
</button>
</ion-fab>
应用程序
//button acction for sending data
sendQuietData() {
this.initQuiet();
Quiet.transmitter({profile: 'ultrasonic', onFinish: this.onTransmitFinish}).transmit(Quiet.str2ab('example text'));
}
//initialize quietjs library
initQuiet() {
Quiet.init({
profilesPrefix: "/assets/data",
memoryInitializerPrefix: "/assets/data",
libfecPrefix: "/assets/data"
});
Quiet.addReadyCallback(this.onQuietReady, this.onQuietFail);
}
//setting up the profile
onQuietReady() {
Quiet.transmitter({profile: 'ultrasonic', onFinish: this.onTransmitFinish});
};
//on failure log it in console
onQuietFail(reason) {
console.log("quiet failed to initialize: " + reason);
};
//on finish log it in the console
onTransmitFinish() {
console.log("quiet finished transmiting: ");
};
我得到的错误是这样的:
ERROR TypeError: Cannot read property 'length' of undefined
at lengthBytesUTF8 (quiet-emscripten.js:1)
at Object.intArrayFromString (quiet-emscripten.js:1)
at Object.transmitter (quiet.js:281)
at AppPage.webpackJsonp.115.AppPage.sendData (app.ts:69)
at Object.eval [as handleEvent] (AppPage.html:8)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
是否有人在Ionic应用程序上遇到此错误,或者是否有关于如何实现安静js的示例。
谢谢!
最佳答案
我设法做到了这一点,如果有人想知道如何做,我将把它留在这里。
首先,在src / assets中创建一个名为quiet的文件夹(或您想要的任何文件,但要记住修改index.html中包含文件的路径),该路径将为src / assets / quiet
在创建的src / assets / quiet文件夹中复制quiet.js和quiet-emscripten.js
将quiet-emscripten.js.mem脚本复制到www文件夹中
在下面输入您的www / index.html此代码:
在head标签之间,它看起来像这样:
脚本data-ionic =“ inject”>
(function(w){var i = w.Ionic = w.Ionic || {}; i.version ='3.9.2'; i.angular ='5.2.5'; i.staticDir ='build /'; })(窗口);
/脚本>
2.在... ion-app>标签之后,您将必须包含库
<ion-app></ion-app>
<script type="text/javascript" src="assets/quiet/quiet.js"></script
<script async type="text/javascript" src="assets/quiet/quiet-emscripten.js"></script>
<script src="build/polyfills.js"></script>
将.ts文件放入要使用该库的位置
声明var Quiet:any;
就是这样,这样做您应该使库正常工作。
关于javascript - QuietJs-Ionic 3错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51689377/