Looking to establish a connection between the Laravel Pusher Socket and NUTX.js (SSR Mode) Application.
The code snippet above adds the socketio.js plugin file, but it seems to be causing some issues.
Can anyone point out what might be going wrong?
And how can I successfully connect to the Socket in NUXT SSR mode?
import Echo from "laravel-echo";
import config from "../config/config.global";
export default async ({ store, $axios }) => {
const port = 6001;
window.io = require("socket.io-client");
window.Pusher = require("pusher-js");
console.log(typeof io, "socketIO");
if (typeof io !== "undefined") {
// connect to web socket
try {
window.Echo = new Echo({
broadcaster: "pusher",
key: config.secretKey,
wsHost: config.socketUrl,
wsPort: port,
disableStats: true,
auth: {
headers: config.header
}
});
console.log("connect to socket");
} catch (error) {
console.log(error.message);
}
}
function listenStock({ channelName, eventName }, callback) {
console.log("callback",callback);
window.Echo.channel(channelName).listen(eventName, callback);
}
// Get user Balance Socket
listenStock(
{
channelName: `BalanceUpdateEvent.${store.getters.GetUserUUID}`,
eventName: "BalanceUpdateEvent"
},
({ data }) => {
try {
console.log(data,"Data");
} catch (ex) {
console.log(ex);
}
}
);
};