laravel-rabbitmq/consumer/socketio.js

30 lines
552 B
JavaScript

/**
* {
* }
*/
const {io} = require("socket.io-client");
const socket = io("http://socketio:3000");
// event socket init
socket.on("connect", () => {
console.log("SOCKET connect");
socket.emit("join", "notify");
});
socket.on("disconnect", function () {
console.warn("SOCKET disconnected");
});
socket.on("connect_failed", function () {
console.error("SOCKET connection failed");
});
const notify = {
emit: async (msg: null) => {
socket.emit("message", {
to: 'notify',
data: msg
});
},
};
module.exports = notify;