I have a Sails app and several Sails Shell scripts run by cron or other external triggers (mostly me typing in the shell). I would like to implement notifications in the browser via builtin Sails socket client, which works but only when sails.sockets.broadcast() is called from a Sails Controller, that is, I was able to run the example from the docs.
I can't succeed to broadcast a message from a shell script or even from sails console --dontLift, it seems that the registered clients are only on the socket that is running on the server and the shell/console instantiates another socket... makes sense but isn't possible to get those clients?
Is there any solution to broadcast a message from a Sails shell script to registered browser clients?
Furthermore, can I use Sails socket in a service worker to create push notifications? I understand that socket.io is different from Push, but is somehow feasible?
update
Thanks to #nahanil for pointing to redis, I found this article in the docs Realtime communication in a multi-server (aka "clustered") environment
Thanks!
Luca
Related
If I have an app (let's Express.js app) with a web socket (socket.io) and I want to send message to a client from a different server app, what is the best way to go about that.
Let's assume that both apps are on a public cloud and running on separate containers or VMs. What's the best way to ensure that the message is sent to the right web socket app instance that holds the connection to the client?
You can use redis to ensure that client will get the message no matter which instance of app is sending the message.
But if your other app is a completely different app and does not start a socket server, You can still use socket.io emitter (along with redis adaptor) to send messages to clients without creating another socket server.
For my current web (reactJS) app, i need to implement a push notification system. Backend APIs are written in Python on Django Framework. So how should i implement socket, should I write in python, or may I write in node or node for the client-side and python for the server-side?
Are you looking for Web push or mobile app? The term push is really synonymous with 'push notifications' meaning the client will get them even if the app / website is open or not.
If that is what you are looking for then you need to be looking at service workers and push notification servers.
If you want to simply send alerts to users on your page you can for sure use a simple websocket or long poll done in JS with a node server to emit to.
I am experimenting real time app using Laravel and socket.io. I make a seperate node and redis server. Now I see several tutorials introducing redis to subscribe to channels. But I try without redis and socket.io is able to connect and emit etc.
The question is, what is redis used for and are there any specific scenarios that redis is able to handle that socket.io can't?
Thank you.
Socket IO helps in communicating between two different browser tabs, and that do not have anything to do with Laravel application only using socket.js file. So when you want to communicate between Laravel application and browser like chat or real time notifications about the events that happen in laravel application, then Redis will help you.
Laravel application send the data to Redis and Redis pass data to socket IO, then socket IO sends data to browser.
This is similar to AJAX, but in ajax the client ask for data and server/ laravel application responds to the AJAX request.
In our case the server it self can send updated data, as the change happens with out browser requesting, so this is helpful because the browser does not when the data is updated on the server side.
When I started learning socket IO and Redis I struggled a lot to find and understand this, hope this helps you.
I've try to create a slackbot. Works fine, but my problems are calls from slack to my rest api. My app is an internal service, so it's not available from the internet. I have seen that outgoing webhooks is possible to set, but I have to forward the request back to the internal service which I don't like very much. As far as I know slack is based on websockets, so is it possible to write a bot which run behind my “firewall“ and get it's commands via websocket?
Greetings
Tonka
You can use services like Localtunnel for receiving webhooks behind a firewall.
We use it with a docker container to develop our slack bot in local env.
Webhooks, slash commands, interactive messages, events etc. are based on HTTP.
Only bots use websockets.
But even this bot websocket session still needs to be initiated with an HTTP call.
Not entirely sure how your firewall is set up, but you may want to make your endpoint public to make things easier.
Hello Freswitch Geeks,
I am facing some challenge handling events with the mode event_socket. I create a socket library that implements some of the features of the mod_event_socket in-built ESL. This what I did: I connect to Freeswitch, subscribe to events via events command and execute an originate command using the socket application. When the call is answered FS connects back to a daemon app runnning and based upon this guideline https://wiki.freeswitch.org/wiki/Event_Socket_Outbound#Using_Netcat I am able to handle the call.
However the issue I am facing is some of the events are not received by the deamon app(for instance channel_hangup_complete, record_stop...) I would like to know whether I am missing something.
Thanks
from the link you posted
it's a race,
sometimes the socket connection ends before the channel
the linger socket command was added to tell FS to wait for the last
channel event before ending the connection
just send the command
linger
This is an api command, so you will need to run "api linger" or something similar