mirror of
https://github.com/zadam/trilium.git
synced 2025-01-31 11:32:30 +08:00
25 lines
No EOL
578 B
JavaScript
25 lines
No EOL
578 B
JavaScript
const WebSocket = require('ws');
|
|
|
|
let webSocketServer;
|
|
|
|
function init(httpServer) {
|
|
webSocketServer = new WebSocket.Server({server: httpServer});
|
|
webSocketServer.on('connection', function connection(ws, req) {
|
|
console.log("websocket client connected");
|
|
});
|
|
}
|
|
|
|
async function sendMessage(message) {
|
|
const jsonStr = JSON.stringify(message);
|
|
|
|
webSocketServer.clients.forEach(function each(client) {
|
|
if (client.readyState === WebSocket.OPEN) {
|
|
client.send(jsonStr);
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
init,
|
|
sendMessage
|
|
}; |