Solution to controlling a network enabled POS? - javascript

I have a web app hosted on a public hosting platform. I also have a card payment terminal that is connected to my local network. I'd like for the user to click on "Pay with card" and the web app would reach out to the terminal on the client's local network and send the necessary packets.
I dug around a bit, found this SO thread, tried to go the WCF route suggested in the thread, following this tutorial, and possibly calling the WCF endpoint using Javascript's XMLHttpRequest. Is there a better way to do this? Can I somehow realiably test the WCF service in Windows? My experience with C# so far was developing a couple of really simple Console apps a couple of years back, so when it comes to Windows Services and such, I'm completely lost. Any pointers are appreciated!

WCF is an option (although it has a steep learning curve). Once you understand the concept of endpoints, contracts, clients, bindings, and service hosting in WCF you can do a lot of work with a few lines of code. This is the simplest example I could find regarding a working WCF service. If you wanna do it "the old way" you can use socket api. See an example in socket class. It is more straightforward, but you have to implement the communication protocol from scratch.
Also, you can use a WebSocket connection from the website in case the connection needs to be open for longer period of time.

Related

Discover Web Service in local private network with javascript

I searched for a few options on my issue but couldn't find any useful information unfortunately.
Here is my issue:
Suppose I have 1x computer that runs a rest service on a specific port lets say 5555, running in a private network.
Now I have a frontend/browser application (javascript) that could be opened with a mobile phone or computer. When a device is connected to the same network (suppose wireless) and opens the frontend application it should discover in any way the rest service of the other computer, but I can't find a solution to that challenge.
So I can't find the sevices' ipv4 in the network since the webRTC workaround got smashed. I would have to traverse all possible private ip ranges to find that running service, which seems like an overkill.
Anyone got any idea how to solve this challenge?
Most web apps actually use the port-scan approach, which you are trying to avoid. I could think of some other approaches:
Have the service also publish an mDNS service under a specific name, e.g. foo.local. Your web app can simply have a static configuration using that hostname. This will, hovewer, require you to be able to control the service and your network/host need to be capable of using mDNS.
Require the admin of the service to register the local IP adress in a public DNS server. This will require manual config of the URL in the web app, but you can at least avoid dealing with discovering the address.
What you are talking about is sort of network scan, which is a security issue if you can do it, though it is usually possible in home networks. I would add a DNS server for that local network and use a local domain name to access the service. I don't know any other standard way to propagate where the service is.

In webRTC if I am getting remote ice candidates with srflx does that mean that connection should work? (Edit: No that't not all)

I am trying to implement video calls into an existing ionic 3 project for one of our clients, I have used the google code lab as a boiler plate code for sending the offer and answer via Firebase real time data base.
This you probably heard(read) before: "my webRTC doesn't work in external network" and the answer would be that:
Use your own STUN server and don't rely on free stun servers like google.
Use TURN server for backup on failed stun attempts.
Understand webRTC before you implement it.
What I want to ask is the following:
In my current setup (using a free google stun server) testing with two different networks , I am seeing remote candidates with typ srflx, I am also seeing typ host but since it is different networks so it holds no interest for me, and obviously no relay as there is no TURN server. I also see that I am providing local candidates with srflx, does this means that my setup should have been enough to establish a connection? I have spent some time trying to figure this one out and I have found a lot of info in this blogpost, but I wasn't able to fully debug the situation.
Suppose we would like to implement our own TURN/STUN setup, our calls are going to be almost entirely in the same country so we won't need multiple servers. Would anyone have an estimation for the following:
1.How much data per minute would entail one video call (ballpark)?
2.Our client likes google cloud services for his project, How much would it cost to spin a TURN server for this project on google cloud platform (again just a ballpark)? is there any idea on the best setup (I was thinking coturn and was looking on this google coturn implementation)?
Thank you all.
Edit:
After some more digging, I realized that one of the different networks I was testing was sitting behind a symmetric nat, a nice jsfiddle for testing what kind of nat you have I found in this blog post.
In the case of a symmetric nat the iceCandidate received is not suitable for connection and you have to have a TURN server.
So I guess that takes care of the 1st part. Any additional data on the 2nd part would be appreciated.
OK so after all this digging I guess I can agree with the 3rd notation (and no I still don't fully get it not even close), if this might help anyone I will share my experience.
I was brought into a project (ionic 3) and was told to find and implement a video chat. We chose webRTC. webRTC as far as I know is the only widespread opensource option. In our country a huge number of cellular users are behind symmetric nat so p2p with them won't work. I tested a twilio TURN service and immediately everything started to work. The rough numbers for a basic call would be around 1.5Mb per minute. Thank you for anyone who stumbled upon this and tried to figure out if he can help.

Webapp and notification

Which is the best way to notify a webapp (need to work in chrome and safari) from server? (my webapp is in angular for information).
Is it possible to receive UDP broacast with a webapp? (If not, that will not be a problem i can do a little app that will receive the broadcast and translate it to a notification but which is the best one for webapp that the question...)
This probably a double post but i didn't find a real example so if you can give me an example of what i need to do that gona be great :).
I'm not sure of what you want, but if you need to notify your webapp from server in real time you probably will be interested by websocket technology. You can get information about this subject here: https://developer.mozilla.org/fr/docs/WebSockets
If you use a nodeJs server, socket.io seems to be great and there are good exemples and documentation in the official website (http://socket.io/).

Rewriting a Silverlight project into javascript, wcf involved

There is a c# project, hosting several wcf services,including basichttpbinding and nettcpbinding.
And a silverlight project, consuming the services. For the nettcpbinding part, it establishes a connection with the server. When the server gets new data elsewhere, it send the data to the clients connected ,via callback channel.
About silverlight, I know nothing but it runs at the client. I think this is the important thing: since sliverlight runs at the client and is written in c#, it's easy to consume wcf services, including duplex ones.
My task is to rewrite the silverlight project, mainly using javascript.
For the non-duplex part, I wrote several ashx handlers, and invoke it with ajax. (Is that right?)
But for the duplex part, after reading some posts I found polling seems the only way. When the server receive new data, it stores it somewhere, and the client invoke a handler every several seconds, the handler then returns the new data. So the server can't send the data to the client actively.
Am I doing it rightly, or any other ways?
Web sockets is the new HTML5 standard that supports push from server to client. (Actually web sockets are probably superior to the Silverlight duplex classes, which don't use true push under the hood but rather old-fashioned long polling with periodic "keep-alive" signals from the client.)
I'd suggest taking a look at SignalR, which is an ASP.Net component that wraps web socket functionality, and also "falls back to other compatible techniques for older browsers".
I was in a similar position a couple years ago: I had a Silverlight client talking to a duplex WCF server that I needed to port to JavaScript/HTML5. The question was, "What do we do about the backend?" I settled on exactly the same scenario that #McGarnagle describes, namely, switching to SignalR on the backend, and using the SignalR JavaScript client to communicate to that backend. I could have spent a great deal of time rearchitecting the WCF backend to share logic with SignalR, but because we were effectively abandoning our Silverlight client, it ended up making more sense just cutting and pasting the code powering the WCF service into the new SignalR hubs.
About the only thing I didn't like with SignalR (at the time) is that it only used dynamic objects to communicate to the client. I preferred (and continue to prefer) static, compile-time checking. I think there are ways to do that now with SignalR and TypeScript, but I haven't investigated them recently.
The primary alternative, by the way, that I investigated was using JavaScript to talk to the same WCF service. While there were supposedly some ways to get that to work, it didn't seem like they were very mature and were unlikely to be well supported going forward. SignalR is definitely the approach you'll want to use if you're trying to use C# on the backend and JavaScript on the client and need two-way communication: steer well clear of WCF in that scenario.

How does PubNub bind your account with the JavaScript API?

It seems that PubNub binds your account by domain. I can't seem to find a definitive answer in the support nor the API.
By the lack of using publish, subscribe or secret key from JavaScript it seems that your site's domain is what's bound. Is this accurate?
I haven't gotten around to playing with it, but that would be bad because that would mean that I have push up my code to the server just to test.
I need to know about this because I want a way to test my web application using local host.
You are asking about PubNub accounts and binding to a domain. This is a good question regarding how to get started with PubNub. To dispel this quickly, you do not have to provide this information with PubNub in order to connect. You can connect from Anywhere to Anywhere. You can even connect on localhost from your local system. Even better you do not need a web server and can write ordinary html5 and open the file:// from your hard disk. Pretty nifty yah?
Mac:
file:///Users/stephen/index.html
Ubuntu:
file:///home/stephen/index.html
Windows XP:
file:///C:/Documents and Settings/stephen/index.html
Windows 7:
file:///C:/Users/stephen/index.html

Categories

Resources