dry-node
Version:
Initialiseur de structure Node Express typée et modulaire
35 lines (24 loc) • 671 B
JavaScript
const WebSocket = require('ws');
/**
* Format duration
* @param data
* @returns String
*/
const DryWebSocketDispatchFunction= async (data) =>{
try {
const wss = global.wss;
if (wss.clients) {
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(data));
}
});
} else {
console.log("notification not send".red)
}
} catch (e) {
console.log("Error socket".red)
console.log(e);
}
}
module.exports = DryWebSocketDispatchFunction;