Symfony3.4 - Send a Server-Sent Event when something happens - events

I'm developing a project with Symfony 3.4.
I would like to send a message to all the clients currently viewing a page when something happens. I evaluated both Server-Sent Events and Websockets, and I decided to go with the former, because the communication is unidirectional (only server to client).
For this purpose, I'm using this library: https://packagist.org/packages/tonyhhyip/sse
It seems to work, but I need to specifically send a message when something happens in the whole system. I tried with the Symfony event system (by creating a custom event), but events seem to be dispatched and captured only within the same session (i.e., the same logged user). In other words, if an action performed by a user triggers an event, it is not captured by other users and therefore a message is not sent to the browser via SSE.
Any suggestion?
Thank you

Related

How to listen to Skype for Business call events

I need to notify a backend server about Skype for Business call events. Calling the backend is not the problem, but listening to call events is. I thought about watching and parsing skype log files, but there seems to be no call information in the log files... And it would be an ugly solution anyway.
Is it possible to somehow listen to SfB call events and trigger custom actions?
I know there are various SfB SDKs, but none of them seem to offer a way to listen to these events...
I would like to be able to do something like this (pseudo code, I don't really care what language is used, but would prefer JavaScript):
skype.onCallIncoming(callInfo => {
console.log(callInfo.user + ' is calling');
// my custom action
});
skype.onCallAccepted(callInfo => {
console.log('The call was accepted');
// my custom action
});
skype.onCallEnded(callInfo => {
console.log('The call was ended');
// my custom action
});
SfB does not provide any live "call events" that you can use in ANY SDK.
For live "calls", the best you can do (with little effort) is to subscribe to a users presence and hook off the "on a call" (on-the-phone) activity token busy status (this presence state is not guaranteed to be correct). The problem with this is you can't really get "all" call events for everyone, since you can only subscribe to endpoints that you know about. There are also problems with working with large scale subscriptions. This can be done with most of the SDK's for Skype include UCWA.
Another option is to use the CDR database, although that is not for "live" calls and the CDR database needs to be enabled for the site. Once enabled you can just use SQL queries again the DB for historical call data.
If you really need large scale call monitoring, then the only option is to create a SIP proxy application that runs on the FE machines and translates "sip" messages into call events. This is a lot of work, it seems simple to do but gets very difficult very fast. This will give you "live" call events but will take someone a long long time to get it right and you have to have a deep understanding of SIP.
If you are talking about just your local Skype desktop client calls ONLY (windows client only), you can use the client SDK to hook into the local client and you can track the call events that way.

How to asynchronously push data to reactJs from Spring api web service to update a progress Bar?

I have an application which allow an user to send a lot of SMS to his contacts (like thousands).
Obviously that tasks can take a lot of time to complete.
So the idea is to display a progress bar on the client side, to indicate the user how many messages have been sent so far.
The back end of my app is a restful spring webservice.
The front end is done with ReactJS and Redux.
The question is:
Is it technically possible from the back end to periodically push data to the client, to update the progress bar, with the amount of messages already sent.
First question regarding the back end architecture:
I've seen that using JAX-RS 2 with spring, I can make asynchronous call in the back end, to execute other tasks(like querying the DB to see the messages already sent) while the other process is sending all messages. Am i looking in the right direction here ?
Second question regarding front end :
So far I use thunk functions for my requests(post/get) to the server, which returns a json response, and it works well. But in this case, the back end would periodically push data to the client side, until the main task is completed, so I don't understand how would that work out exactly ?
I guess I'm not gonna be able to achieve that using the same request ? Should I look at other technologies to achieve that ?
Please let me know, if the description of my problem is not clear.
Cheers
There are two options: you can keep track of the task on the backend and have an API endpoint to check the status and poll it every x seconds.
The other option would be to use sockets, the frontend client would listen for an event and update display onEvent. The backend would be responsible for emitting events.

Real-time chat issue (django/js)

I'm working on a real-time chat. I need to change statuses of the room owner and connected users, together with the UI. Since NodeJS/SocketJS/etc don't guarantee message delivery, I switched to pure Ajax for that.
The system works like that:
- User presses a button to change his status
- An Ajax request is being sent to the server, and a status change request is being saved in the queue in DB
- Users send Ajax heartbeats every second. On the server this heartbeat function also processes the queue (when sent by the room owner). Besides it sends the current statuses of users in the room in response every time.
The issue is: there might be temporary internet problems on both sides, which causes all kinds of problems. This happens due to the fact, that the heartbeat Ajax requests are being processed in an arbitrary order on the server, or the responses are being received in a wrong order on the client side. As a result users have wrong data about current statuses and the UI changes are also wrong.
What is the best approach when making a system like that? What am I doing wrong or how can I fix the issues above?
Thank you!
Have a look at Max's blog a Django-Realtime-Chat and how he does it.

Spring MVC Server-Side Message Listener, Client Side update with WebSockets

I am quite new with Spring MVC and Web technologies.
I need "real time" interactions between the server side and the client side of my web application.
When a user click on a button, I want to execute server side code, create a message and send it to every client.
I think Web Sockets are the solution. I can add methods on the controller part of my application.
When a user click on a button, the Controller method is called. I can execute code and send back a message for every clients.
But now, I can receive messages coming from another website. Let's say that I am using a MessageListener.
How am I supposed to notify my clients? The server side of WebSockets is in the controller. I don't think i am supposed to call this method from the server.
I can create some kind of weird adapter capable to
- Establish WebSocket channel with server (a local channel)
- Receive messages from another website using a broker
- Send the message to the controller
I don't feel like this is an unusual need and my solution looks tricky.
I am sure there is an easier way to do it, but I am not able to find it.
So, am I doing it right? Do you have any idea, any suggestion?
Thank you for your help.
Ben

Implementation of a message service in ASP.NET MVC

I have an infrastructure, bussiness rules and other logic, that I use in a WPF application, in it I have a messaging service that implements an message service interface, this service is register in a Container, I use Castle Windsor.
Every time that the infrastructure needs to show any kind of messages it uses this service and shows a message and waits for the reply, with this I don't have to a request to the GUI/WPF to show a message.
My problem is that I'm using this same infrastructure for a ASP.NET MVC site and I having some problems in find a solution where I can use this same interface. Basically if the message service has to show a messages it should be able to post a message box in the browser, preferably via AJAX and wait for the reply of the user and then continue the execution according to the answer.
I don't know if I'm made my self clear enough on the problem.
Any hints on how to implement such a service would be much appreciated.
Thanks.
The problem is the server knows nothing about open browsers, therefore it can't signal the broswer to show the message.
The solution would appear to be to queue messages from the service, have some script on the page that checks (using ajax) for items in the queue, and display messages as appropriate.

Resources