Next.js, Socket.io and WebRTC middleware - websocket

I have an "SFU" server, it uses socket.io for signaling and it triggers WebRTC functions to return values back to the front-client through socket.io . this SFU is horizontaly scalable. Im trying to build a nextjs frontend app that connects with this SFU server through Socket io. But I'm confussed about the fact that nextjs doesn't supports websockets. What is this puzzle piece that is left in order to work as "Middleware" to connect my nextjs front to my SFU server (node) ? (My SFU instances will be connected through a load balancer)
should I use the next.js api folder in order to fetch data from my sfu server(external)?

Related

Redis Pub Sub directly use with frontend without using websocket,

Can frontend directly subscribe to redis pub sub for getting messages. Most of the blogs in internet says client has to interact with backend using web socket and web socket service will communicate with redis. Can frontend directly subscribe with redis an get the updates without using web sockets.
We are trying to make a dashboard on which graphs refreshes to show correct metrics real time. Will that work or this design has any cons?
The browser (the frontend) is stateless by nature (HTTP is stateless). The instance of the (Javascript) code that "subscribes" to something effectively goes away after a page reloads. Web Sockets give you a persistent full-duplex communication channel between the browser and the server.
Before Web Sockets (and Server-Sent Events), you had to poll the server, a.k.a. check for messages for your instance/user/etc. in a loop that eats up a lot of CPU cycles. So, yes, you need Web Sockets or SSE to do async messaging efficiently on a browser.

Redis pub sub for real time graph UI updates without using websocket

Can browser directly subscribe to redis pub sub for getting messages. Most of the blogs in internet says client has to interact with backend using web socket and web socket service will communicate with redis. Can browser directly subscribe with redis an get the updates without using web sockets.
We are trying to make a dashboard on which graphs show correct metrics real time. Will that work or this design has any cons?

Should I use web sockets to pull data from server or just a flag and use that flag to send API request for data?

I am working on a project which is basically a Customer Feedback Analysis Dashboard. There are few graphs on the dashboard and data for each graph is fetched from the server through API requests.
Right now the dashboard is updated every time the page is refreshed. I want it to be updated immediately when there is a new feedback in the system. I am confused, whether I use websockets to send data for each graph or just a flag and use that flag to fetch data through API requests.
Like, facebook/twitter does. They tell you about new posts/tweets and when you click that button your feed/wall gets updated.
If you want to "push" data from server to client and you want that data to show up in a timely fashion (e.g. within 10-20 seconds of when it was available on the server), then you will want to implement some sort of "push" solution where the server can efficiently push data to the client whenever there is new data to send.
There are several possible approaches:
webSockets
socket.io
Server-sent events
Mobile platform-specific push (Android and iOS)
For a general purpose solution that works within a browser, you will want to use one of the first three. socket.io is built on top of webSockets (it just adds more features) so architecturally, they are similar.
Server-sent events are fairly new (modern browsers only) and are only for one way communication (from server to client). webSockets can be used for communication either way.
I'd personally recommend socket.io because of the features it offers (such as automatic client reconnection) and a simplified messaging layer. You can see the feature difference between socket.io and webSockets here. With socket.io, the client makes a connection to the server when the web page is loaded and that connection is persistent. After the connection is established, then either client or server can send messages to the other at any time in a very efficient manner.
Other useful references:
Push notification | is websocket mandatory?
websocket vs rest API for real time data?
Why to use websocket and what is the advantage of using it?
What are the pitfalls of using Websockets in place of RESTful HTTP?
Ajax vs Socket.io

save text chat in the server with architecture of webrtc+socket.io+nodejs

I am building a chat system where I am using webrtc and socket.io + node js for building the system. My problem is how to put back up of text chats on my server while there is 1-o-1 chat.
Approach one could be using webrtc for the chat that is peer to peer communication and with every successful message sent I would hit a web service through Which I could update the db. But this seems to me not a good approach as I have to update db from client everytime and network bandwidth seems to be an issue specially for mobile clients.
Another approach could be sending the messages through socket.io and from the node js server save the chat in db from node js server.
Second approach makes more sense to me but I am looking for the best approach.
When I wrote my chat application (using socket.io), persisting chat history was done on the socket.io server side
i.e.
socket.on('chat:message', function(message){
//persist message to db here
io.emit('chat:message', message);
});
it worked fine for me

Heroku: Suitable for a Real-Time Game Server?

I am trying to run a real-time game server on Heroku using Java/Netty. The game server uses a non-standard port for communication (4876/tcp). I have built the game client using Unity3D. The game client communicates with the game server using a binary protocol (i.e. it is not using HTTP).
Is it possible for me to host this on Heroku? Heroku looks like it can only host web apps on port 80 or 443 (i.e. the web process in the procfile).
To complicate things slightly I also have a web services app built using Java/Embedded Jetty which needs to be able to communicate with the game client and the real-time game server which I also want to host on Heroku. Is this possible because I know there can be no inter-process communication? What if I create two seperate apps (one fore web services and one for real-time game server) on Heroku?
As of the time of this answer, heroku only supports http and hptts as you have noticed.
You could try modifying your game to use http as a transport for the binary protocol.

Resources