Web service to interact with running electron app - web-services

I looking for some advice on the best way to set up a project. Not sure if this is the right place to ask but I will give it a go.
I am looking to create a "Smart Mirror". I know there are options already available for this but I want to go through the process of creating my own.
I have created the UI using electron and I am using this on a raspberry pi 3b+ using raspian stretch.
Now this is where my knowledge is lacking, due to no experience and not sure if what search terms to look for.
I would like to create a plug in on Chrome(used on my mobile phone) or a process that runs separately, to say "Send page/video to Smart Mirror". What I envisage is that this plug in will copy the URL for the page or the video and send this via a web service call. The running electron app on my raspberry pi will receive this call and process the URL and then display the page/video within a portion of the application.
I have only ever consumed a web service from within an application.
I am not sure how to set this up. Can my electron app be set up to receive this call? If so what search terms should I be looking for?
I hope this makes sense.
Please let me know your thoughts or if I am thinking about this all wrong

Related

windows service to Desktop Application communication

I'm new to programming. There are quite a lot of Q/A on this, but I couldn't find a concrete answer. Hence the question. I'm writing a screen sharing application. Now I want to turn that application to windows service. which I already did with. Apparently, the application works like this. When the counter party sends the screenshots, the application receives it and parses the data to RGB and shows on a window renderer. Because now its a service, although it receives the data, i believe that it may not be able to open renderer in the current desktop due to session isolation, the way to get around this would be to use IPC between Desktop App an the service. However, it makes it complected. Is there any simple way to solve this problem?

Can Web Applications detect local printers?

I was wondering if it is possible for a Web Application (hosted on a remote server) able to detect printers connected to a host(the one accessing the Web Application)?
Also, is it also possible to be able to send print-jobs (mainly images) to the host's printer?
For instance, assume you have a local WPF application (Windows Presentation Foundation, C#) running on the desktop.
To print an image:
Select an Image on the WPF application (loaded from a directory on the local harddisk)
Click the "Print Button"
This will run this line of C# code:
e.Graphics.DrawImage(image, x-coordinate, y-coordinate, imageWidth, imageHeight);
And it will send a print job of the image to the default printer of the local computer.
So now, instead of a WPF application, you have a Web Application. The user will:
Type in the URL of the Web Application
The Web-App will load a page similar to the WPF application
The Web-App will display images that are loaded from say, a database.
User select image he wants to print
User clicks "Print Image"
However, in order to Print the image, I would imagine the Web-App would need to recognise the printers the user has on his local computer, and be able to communicate with the printer.
Of course, the Web-App does not need to be in .NET. I was just using WPF/C# as an example.
Bluntly, the answer is no. Server-side code can't talk with client-side resources in that manner.
A possible solution might be to embed some client-side component into your web app which does what you
want, such as a Java applet or Silverlight item. I don't know off the top of my head whether they're capable of printing, but it might be an option worth investigating.
However, I would suggest the best way to handle it (if your use-case allows), is to serve up something capable of printing via native browser methods. You are able to serve a stylesheet which applies to printing specifically using the media="print" attribute on your link element. If that remains too imprecise (you'd have no control over the browser's paper size, margins, headers/footers etc), perhaps another option might be to serve a print-specific file such as a PDF. Ultimately though, what you are asking is not possible and it is a case of finding another way to fulfil your requirements.
I have a similar issue, which I haven't programmed, but, I have found that HP printers can receive print jobs, through the HP network. If you are WiFi enabled, there should be a way to email the print job to the printer. I'm still researching this. But, I have a friend who did something similar using AWS.
Been a while, but I have learned that HP printers can be WiFi enabled. Which means, they get an email address and can be printed to, at that address, through the internet, if they are connected to a WiFi net connected to the internet. The email goes through the internet directly to the printer, where it is then printed. So, you can email a print doc.

Web interface for a C++ program

I am developing a project for the end of my studies. This project is basically acting as a server, is cross-platform and developed in C++.
I was wondering if it was possible to make a web interface that could be used like for instance the listener design pattern to log what the program does. This would be cross platform, and is ideal since the program is supposed to run on a distant server.
My question is: is there any web technology to could let me update my web page live when the program logs something. I know this is something unusual and I'm not an expert in web technos, that's why I am asking.
Would Erlang do it ?
Thanks for your help
EDIT: To give a more concrete example, I would like to be able to follow the execution of my program live and see the logs of my program appear on the page. The idea would be to use a web page like I would use WPF on Windows or GTK on Linux for instance. Like someone said, it would be some kind on monitor for my application.
It's much easier than you might think. A web server basically gets a request as a path name, and returns a page. If you set it up correctly, it will invoke a program to create the content. This is called "CGI".
If you can do it without live updating, it's then super-easy: just refresh the page and your program can be called again.
If you want live updating, you'll need to do a little more. The easiest way is with a little lightweight javascript. The magic word here is AJAX. There are a number of tutorials on line for both of these, just google.
The main thing is to start with a very very simple example and add to it. Javascript in particular is a little peculiar; follow the tutorials, though, and you'll get it.
You can embed a web server such as http://code.google.com/p/mongoose and poll it using xhr or better use websockets.
Or use a monitoring solution such as Nagios (Nagios Core is free).

Do I want an embedded web-server, or what?

So, someone want me to hack some code for him. He has a 42" TFT display on which he will display some application/business related data.
However, 75% of the screen real estate is unused, so he wants to fill it with "TV/adverts/flash/you know, that kind of thing... web based....".
Any advice? Do I want an embedded web-server? If so, which? (he wants free & open source, or as cheap as possible) Do I display it in a browser? (duh! probably, dude) But I don't want/need a menu, address bar, toolbar, etc - it should be full screen (does that mean "kiosk mode"?).
Sorry, folks, the requirements are not clear, but I hope that you can guess what he probably means (he is not very techie). How should I proceed with this? Thanks.
I am working on such a display system, although ours already quite evolved, with support for multi-screen, multi-user and a lot more.
A few hints :
We use firefox with the "full fullscreen" extensiton (https://addons.mozilla.org/fr/firefox/addon/1568) that allows to not display any menu bar, status bar etc. and to automatically start Firefox in that mode. Then you just need a startup script to launch firefox specifying the right URL when the machine is started.
Our system is web based, but as a multiscreen system it has one server and several client PCs connected to the server via HTTP, and each one to a TFT screen via VGA cables. If you have only one screen you could install the browser and the web server on the same machine. Only restriction : we use wake-on-lan from the server to the clients to automatically start the display every morning. This will not be possible with a single machine system !
To give you some ideas, the display mechanism basically works like that : first, the browser loads a html page with lots of javascript (that javascript constitutes what we will call the "client application".) This client application is written using the Prototype.js library (just an indication, there are many other possibilities). Then the client application asks the server for the content to be displayed. That content is passed as a JSON stream representing a playlist of objects (images, videos, text news, etc.). The client app displays each object in the playlist sequentially. The objects stay displayed for a specific duration (lots of setTimeout in the code). The transitions use effects from the Scriptaculous library (fade-in, fade-out...). When all objects have been shown, the client asks the server again for the playlist (in case changes have been made), and the process starts again. There is actually never a full reload of the page.
Then we also have a multi-content mode, where the screen is separated in various zones that are updated separately.
For one machine and a realtively static system (i.e. no GUI to add content), maybe you could implement that mechanism in a local site accessed via file://... The whole "intelligence" of the system would be in the javascript. That would save you the server part. I see one possible restriction : I think flash can't play video files from the client's machine (security restriction) so check this if you plan to use flash videos.
Well, I hope these few ideas can help you. Good luck !
Get one these
They offer a VESA mount for it I think if the screen your using supports that.
Full screen firefox would be one option.
A more flexible option would be a full screen QT app written in the language of your choice using the webkit widget for display, this would likely make flash content more difficult.
As for the content, i would put a LAMP setup on the fit pc. Build the web page using whatever feeds you want and just display the web page aka http://localhost
Alternatively you could host the "web parts" of the display on a standard web hosting server and display the data coming in on RS-422 in a separate QT widget.

How to keep a C++ realtime server application with a modern web client interface?

I develop industrial client/server application (C++) with strong real time requirements.
I feel it is time to change the look of the client interface - which is developed in MFC - but I am wondering which would be the right choice.
If I go for a web client is there any way to exchange data between C++ and javascript other than AJAX <-> Web service <-> COM ?
Requirements for the web client are: Quick statuses refresh, user commands, tables
My team had to make that same decision a few months ago...
The cool thing about making it a web application would be that it would be very easy to modify later on. Even the user of the interface (with a little know-how) could modify it to suit his/her needs. Custom software becomes just that much easier.
We went with a web interface and ajax seems the way to go, it was quite responsive.
On the other hand, depending on how strong your real time requirements are, it might prove difficult. We had the challenge of plotting real time data through a browser, we ended up going with a firefox plugin to draw the plot. If you're simply trying to display real time text data, it shouldn't be as big an issue.
Run some tests for your specific application and see what it looks like.
Something else to consider, if you are having a web page be an interface to your server, keep in mind you will need to figure a way to update one client when another changes the state of the server if you plan on allowing multiple interfaces to your server.
I usually build my applications 2-folded :
Have the real heavy-duty application CLI-only. The protocol used is usually text-only based, composed of requests and answers.
Wrap a GUI around as another process that talks to the CLI back-end.
The web interface is then just another GUI to wrap around. It is also much easier to wrap a REST/JSON based API on the CLI interface (just automatically translate the messages).
The debugging is also quite easy to do, since you can just dump the requests between the 2 elements and reproduce the bugs much more easily.
Write an HTTP server in your server to handle the AJAX feedback. If you don't want to serve files, create your server on a non-standard port (eg. 8081) and use a regular web server for the actual web page delivery. Now have your AJAX engine communicate with the server on the Bizarro port instead of port 80.
But it's not that hard to write the file server part, also. If you do that, you also get to generate web pages on-the-fly with your data pre-filled, if you want.
Google Desktop Search does this now. When I search my desktop for 'foobar', the URL that opens is this:
http://127.0.0.1:4664/search?q=foobar&flags=68&num=10
In this case, the 4664 is the Bizarro port. (GoogleDesktop serves all the data here; it only uses the Bizarro port to avoid conflicts with any web server I might be running.)
You may want to consider where your data lives. If your application feeds a back-end database, you could write a web app leaving your c++ code in tact -- the web application would be independent and offer up pages to web users and talk directly to the database -- In this case you have as many options, and more, as you have indicated.