We are trying to make a centralized chat service and connect to it from different clients, Pubnub was our choice to make the backend service insetead of making it from scratch with Socket.io but we had a big problem to send the message stream using addListner function provided by Pubnub by http request, so can we send this stream by websocket and clients connect to it via websockets too, or we must use Pubnub directly with different clients?
We tried to use pubnub from servers side but it failed
Your PubNub addListener function with Node.js will look as follows:
const listener = {
status: (statusEvent) => {
if (statusEvent.category === "PNConnectedCategory") {
console.log("Connected");
}
},
message: (messageEvent) => {
showMessage(messageEvent.message.description);
},
presence: (presenceEvent) => {
// handle presence
}
};
pubnub.addListener(listener);
You would not use the REST http endpoint in this case, but rather you would use the JavaScript SDK. For more code samples, please see https://www.pubnub.com/docs/sdks/javascript and select the Node.js tab