问题描述
我正在使用带有电子反应的桌面应用程序。另外我正在使用stompjs连接到RabbitMQ。要只声明一次stompjs的客户端对象,我必须在主流程中声明它。
import { Client,IMessage } from "@stomp/stompjs";
import { app,BrowserWindow,ipcMain } from 'electron';
//
//Create Main Window Code
//
//When renderer request to create client
ipcMain.on('setClient',async (event,argument:any) => {
let client = new Client({
brokerURL: "ws://myurl/ws",connectHeaders: {
login,passcode,host: "/my-host",},debug: function (str) {
console.log(str);
},reconnectDelay: 500000,heartbeatIncoming: 10000,heartbeatOutgoing: 10000,onUnhandledMessage: (messages: IMessage) => {
console.log(messages)
}
});
client.onConnect = () => {
console.log("connected to Stomp");
subscribe(client,login,v4());
}
client.activate();
console.log(client)
}
创建客户端对象成功。但是,当我执行 client.active()错误时。
UnhandledPromiseRejectionWarning:ReferenceError:未定义WebSocket 在Client ../ src / client.ts.Client._createWebSocket(C:\ MyProject \ dist \ main.bundle.js:510:13) 在客户处。 (C:\ MyProject \ dist \ main.bundle.js:450:48) 在步骤(C:\ MyProject \ dist \ main.bundle.js:256:23) 在Object.next(C:\ MyProject \ dist \ main.bundle.js:237:53) 完成时(C:\ MyProject \ main.bundle.js:228:58) 在process._tickCallback(内部/进程/next_tick.js:68:7) 在Function.Module.runMain(内部/模块/cjs/loader.js:755:11)
在启动时(internal / bootstrap / node.js:241:19) 在bootstrapNodeJSCore(internal / bootstrap / node.js:579:3)
此错误来自main.bundle.js。当我在渲染器过程中使用相同的代码时,它起作用了。
你能告诉我为什么会这样吗?有什么解决办法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)