mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
websocket reimplementation of status requests
This commit is contained in:
26
services/messaging.js
Normal file
26
services/messaging.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const utils = require('../services/utils');
|
||||
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 send(message) {
|
||||
const jsonStr = JSON.stringify(message);
|
||||
|
||||
webSocketServer.clients.forEach(function each(client) {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(jsonStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
send
|
||||
};
|
||||
Reference in New Issue
Block a user