【发布时间】:2017-06-13 03:25:43
【问题描述】:
我用 NodeJS 和 Socket io 开始了一个聊天应用程序项目,一切都很好。
后来我决定将我的应用添加到 Electron 框架中,聊天在一个窗口中开始,但我无法关闭这个窗口,退出按钮什么也不做。
在对我的代码进行一些研究以了解问题出在哪里后,我删除了 main.html 中的 socket.io.js 行,然后我可以关闭我的应用程序,但可以肯定我的所有客户端 Websocket 都停止工作了。
<script src="/socket.io/socket.io.js"></script>
这是我的 main.js 中的 createWindow 函数。
function createWindow () {
// Instantiate Express App
app.server = require(__dirname + '/app/app')();
// Create the browser window.
win = new BrowserWindow();
// win.maximize();
// and load the index.html of the app.
win.loadURL('http://localhost:'+config.server.port);
// Open the DevTools.
// win.webContents.openDevTools();
win.focus();
// Emitted when the window is closed.
win.on('closed', () => {
console.log("close");
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
});
}
我的项目文件树是这样的
main.js // Electron, create the window load the app.js
/app/app.js // Express, all my socket function
/views/main.html // Html
请帮帮我!
【问题讨论】:
标签: javascript node.js express socket.io electron