Is there any way (except polling) to watch other processes start event in NodeJS?
I want to pop a notification when a user runs the black-listed apps.
I think you can use a websocket for this. A websocket is a protocol which remains the connection with the user. After you then detect that they run a forbidden application you can emit a signal which then can create this notification.
Socket.io is a convenient NPM package for websockets.
Hopefully this helps!
Related
I'm planning to develop a native app for an already-built web app and nodeJS server that uses socket IO for real-time updates, my concern is if I can generate push notifications using socket io even when the user is away from the app?
If you want something simple, i will advice you to use firebase.
But if you still want to use socket.io, you can do it. The app listen for event emitting and when receive the event, trigger a local notification.
Check this link to learn more about background process.
I'm sorry if this is the wrong stack for this question.
I have a Node.js server running on Heroku. Whenever I commit something, the server restarts. I want to warn the users that there's going to be a restart so that I don't completely ruin their experience. Just a simple notification with the text "Server restart in X minutes".
Let's say I have the client side all set up and a Socket.IO emit is all that's needed for the notification to be shown. How would I do that? I thought of having some sneaky function on the client side that would make the server emit the notification, but I'm afraid it can be easily exploited.
The answer is to detect the SIGTERM signal that Heroku sends to your app to shut it down, and once that signal is detected, to emit the notification to every connected client:
process.on('SIGTERM', () => {
// send your signal
})
https://devcenter.heroku.com/articles/dynos#shutdown
However, a better user experience is just to ensure that users never even know your server restarted. With node this shouldn't be difficult, you only need:
To ensure your process ends and starts quickly (quickly being a few seconds)
To ensure your clients all have reconnection logic (this is built into socket.io so you shouldn't have to do anything)
Optionally, to turn on preboot, which will make the delta between one server going down and another coming up be close to zero (heroku features:enable -a myapp preboot)
https://devcenter.heroku.com/articles/preboot#enabling-and-disabling-preboot
I have a node script I'm working on that connects to an IRC channel for twitch.tv and responds to commands, as well as moderates chat lines that are being sent by other users connected.
Currently I open a terminal to the file location and run node app.js to start the IRC connection. But this runs on my mac and I use my PC to play games and watch the chat, so I have to have the Mac next to me to start and stop the IRC chat client app.
I want to move this to a web server where I can log in and start or stop the chat client app from the website, so I don't have to have the Mac next to me all the time.
What would be the best way to go about this?
If you want to see the script I'm working with you can find it here
https://github.com/Jordan4jc/super-fly-twitch-bot
You could create an HTTP server and listen on a port (if you don't mind overkill, express.js could make things easier for you). This server would contain configurations for the URL, authentication, etc. Within the callback that you provide to a URL path, you could close the IRC channels, database connections, and call process.exit(0) once you're confident that you've done everything necessary and you're sure it's what you want.
You can use socket.io as a way to send signals in real time to the application.
I am using WebRTC to make a audio, video and chat application. How on the server side we can check if the peer is still connected.
Actually, I want to check before making audio/video call that the other user end is still connected. I am able to maintain Presence (i.e online/offline) when user logs in or logs out of the application.
Suppose, the network connection drops or got disconnected, I am not able to get any information on the server side. If I can get, then I can communicate to rest of the peers connected.
So, need help how to get the information if the peer is still connected or not. I am using Nodejs and WebRTC in my application.
Socket.IO has a concept of 'rooms' that makes it very handy for building WebRTC signaling servers, and a disconnect event fired when a user disconnects. You can also set up a custom event to be emited when, for example, a user stops a video stream or leaves a page.
You might want to take a look at the codelab at bitbucket.org/webrtc/codelab, which uses Socket.IO for signaling. (Apologies, once again, for shameless self promotion!)
You would need to implement your own logic to do that.
Since you already have the client registering presence you could:
maintain a persistent connection via websockets
implement a polling/keep alive algorithm between your clients and server
will my server be notified about disconnect on the client side?
I assume the answer is yes if the disconnect happens explictly like below.
pusher.disconnect()
however what happens if the user simply closes the browser?
Another thing is there a way to notify the server that a certain channel has not been in use by the client(s) for some while?
The connection states documentation shows how to bind to connection state changes.
however what happens if the user simply closes the browser?
This really depends on if the browser calls webSocketInstance.onclose so the Pusher JavaScript library is informed before the browser is closed. You could always detect this yourself using window.onbeforeunload, window.onunload or the addEventListener versions.
Another thing is there a way to notify the server that a certain channel has not been in use by the client(s) for some while?
You can use WebHooks so that when a channel becomes vacated your app server will be informed.