JavaScript Device Communication - javascript

I need to communicate with an already connected (paired) device attached to my computer via JavaScript.
This is a Bluetooth device however it does NOT use 'low power technology' thus is currently inaccessible via WebBluetooth.
Is there any way to communicate with my device using a different method due to the fact that it is already paired with the computer? Maybe as some sort of serial connection?
Targeting support for Google Chrome.
Node.js or anything outside the realm of HTML5/JavaScript/Chrome Specific JavaScript will not be accepted as an answer. WebBluetooth already shows an example however my device does not use Low-Power-Bluetooth..

You will need to use something like NodeJS. Browsers cannot access hardware attached to the computer unless the browser provides an API for it or you have an app on the host machine that the browser communicates with.
I suggest learning NodeJS as it is a great language and considering you already know JS the syntax will be familiar.

There is a way. Look into pubnub IoT api for bi-dir nearby device communications:
https://www.pubnub.com/solutions/iot/
This is a solution for multiplayer gaming as well. JS api here:
https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk

Related

Making a node.js application a PEER with WebRTC

So, I have a web app that generates large buffers of color information that I want to send to a node application running on another machine in my local network. Web Sockets doesn't seem to be fast enough for me. I was looking to use UDP and it seems WebRTC is the only way to do that from a browser. The caveat, it seems, is WebRTC is only PEER to PEER (browser to browser). I figured, I could use node webkit to emulate being my other "PEER". In my node app I could handle the "signaling" and have it set itself up in a RTCPeerConnection to my web app. Therefore, I could send my data from my web app to my node app (local network). For some context, I have one computer running native software to drive a light fixture and I want to use a web app to control the lights.
To boil the question down, how can I make a RTCPeerConnection from a browser to a node webkit app?
Any help would greatly appreciated.
Thank you!
-Jake
Node-RTCPeerConnection is an attempt (current WIP) to create a spec compliant implementation of RTCPeerConnection for Node.js entirely in JavaScript with no native C or C++ code. This enables browser-peers to speak to non-browser (Node.js) peers.
But you can not use it for production yet.
Then we also have wrtc (node-webrtc) that provides a native module for NodeJS that supports a subset of standards-compliant WebRTC features. Specifically, the PeerConnection and DataChannel APIs.
Too many people are having problems with wrtc. Since it has to download lots of source and build it only to find out that it fails after a long while on certain platforms. Unfortunately it doesn't come with any prebuilt packages described in this issue
You can use either the google implementation of webrtc or a more recent implementation (by Ericsson) called openWebrtc. The developers of openWebRTC are very proud of running their implementation on various pieces of hardware like raspberry pi and iOS devices.
The one that worked best for me was electron-webrtc (which in turn uses electron-prebuilt) for better compatibility. It creates a hidden Electron process (which is based on Chromium, so WebRTC support is great!) and communicates with that process to enable WebRTC in Node.js. This adds a lot of overhead.
It is intended for use with RTCDataChannels, so the MediaStream API is not supported.
Other resources:
https://github.com/webrtcftw/goals/issues/1
Update 2019
Currently, the best and easiest way to solve this problem is to use webrtc module. Check samples for inspiration. This module does what you were looking for, implemented with N-API and using Canvas module to compose new video from the client stream. Hopefully this will help those who face this problem in the future.

TCP/IP socket communication in HTML5

I'd like to know if my idea is even possible, but based on everything I've searched for so far, it seems like it's not possible. I would love to hear what the experts think.
Goal: Interface with laboratory equipment via TCP/IP sockets using HTML/Javascript.
One problem is that I have no control to program the server. Therefore, I can't use HTML5 websockets. The vendor has not implemented websockets. The equipment server waits for a socket connection, and then communicates via API.
Because HTML5 and Javascript are relatively OS-independent and are 'built' for user display, I'd like to create a browser-based program. I've found related questions and answers on SO, but they are older now, so I'm wondering what is the current technology.
Thanks in advance, and please let me know if you have any questions.
The W3C published a first draft for a 'Raw Socket' standard:
http://www.w3.org/TR/raw-sockets/
I think this might be what you're looking for, but I wouldn't count on it being implemented by vendors in the near future, since it's only a first draft.
Another thing I found out while searching, is that chrome apparently enables tcp/ip communications in extensions (did not check this myself, so can't gurantee):
http://developer.chrome.com/apps/app_network.html
If possible, you might consider writing a chrome extension (though it's not really "HTML5").
I read this as needing essentially a telnet session to your equipment.
Currently, there's no way to do this from the browser without a plugin.
This question has some similar discussion: Best way to display high-speed data from a telnet interface on a web view?
Why not use the server where the HTML5/Javascript code is created. To create to connection to the device and convert this to something you can use, like websockets.

Do Windows 8 apps run on standards-compliant JavaScript, HTML5, and CSS3?

Like most .NET developers I was watching the keynote for the Build Event in Anaheim, Cali and had a questions about the new support for building applications for Windows 8 using JavaScript, HTML5 and CSS3.
They showed quite a few examples and even said the new Windows 8 marketplace was written using these technologies. The only thing that kind of has me guessing is when they put JavaScript in the same category of C#, in the sense that you could program your windows apps (have access to .NET directly) using JavaScript.
Obviously being a web developer this was pretty awesome news considering some of the applications I've built using JavaScript, HTML5 and CSS3.
The question I have is whether or not the applications we build for Windows 8 are truly web compliant? Can we build apps for Windows 8 and turn around and launch them on the web? Can web applications that are currently online access some of the features they demoed?
Like I said this would be an awesome advancement. Not to put down Silverlight, which I have written quite a few applications for, and the way it works in blend rocks. And the thought of replacing JavaScript with some of my apps that are written in C# is not even an option.
Is this just to get "web" based developers to develop for Windows or is this a cross platform solution for building applications?
Slight clarification, the Javascript/HTML5/CSS3 windows programs run on a new layer called WinRT (Windows Runtime), not .Net. All of the new Windows Metro style apps will be built on top of this layer rather than the older .Net. If your app utilizes the WinRT features, obviously you would need Windows to run the app. It is your choice if you want to integrate those features. (Obviously it depends on what you are trying to do with your app) I believe you can build an all standards compliant app and have it run on the system just fine - you just won't be using any MS specific features. In that sense, it would be like a webpage that you launch as an app.
Other notes:
MSIE currently uses some -ms specific prefixes until those features are accepted by W3C and given official cross browser names. Not unlike -webkit-border-radius,-moz-border-radius and border-radius.
The HTML5 uses some features such as grids that are not yet implemented in most browsers.
Microsoft includes a lot of Javascript libraries to make it easy to build apps. Many of these are jQuery based. Some are Windows specific. Not sure what the licensing is to use them elsewhere. I assume the jQuery is allowed to be portable whereas the Windows ones, wouldn't make sense to use outside of WinRT.
#Matt
To clarify the "converse", standard web app written in HTML5 running as a Metro application:
Assuming your application isn't doing "Bad Things" then yes. The Metro app environment is restricted by default. In order to access non-local resources (e.g. a website) from within the application in HTML5/JS, you must create what is known as a "Web Context".
The Web Context allows an application access to the internet and unsafe resources while preventing that same context from accessing privileged resources, like the Windows Runtime APIs.
This ultimately means that if you need to host a Bing Maps widget and want to get GPS information from the system, you would need the following:
an iframe inside the page (which is Local Context by default) hosting a Web Context that contains your Bing Maps widget
use window.postMessage to send data between the Local Context and the Web Context (contained in the iframe)
Call the Windows Runtime API for accessing the GPS location of the device from the Local Context mentioned above
This application model affords you the security that no website opened inside the JS application will have rogue JS executing Windows Runtime APIs to scrape your data. This is probably the biggest area that you will have to re-architect in an existing web application to get it running as you must push data between contexts if it comes from an unsafe resource.
Short answer is no -- apps built using the WinRT stack won't be able to run in a "normal" browser. I'm not sure about the converse though -- if a standard web application written with HTML5 can be run as a Metro app.

Smartcard reader access from a web browser?

Is it possible to access a smartcard reader connected to a computer from a web browser running on the same machine, i.e. from an ActionScript, JavaScript or whatsoever script running therein?
For example, I read something about the flash.external.ExternalInterface class in ActionScript. Can it be used for accessing a smartcard reader or is the Sandbox impenetrable?
Q: is it possible to access smartcard reader connected to a computer from a web browser running on the same machine?
A: Yes, it is possible. I was able to do that by using a signed JAVA applet. The java applet needs to be signed since it will require user to grant permission to access system files/hardware(same as letting an applet write/edit/delete a text file for you).
Why java? the smart card reader I used already has a JAVA API, it also have examples on accessing it using java. But the examples are coded in swing. (like a standalone desktop application) What I did is simply porting the java swing code to applet on a browser. I successfully used this applet to make a login and log out on a website/webapp by requiring smart cards, username and password. Pretty secure I would say.
The source code? As much as I would like to share it, but I'm bound on a company contract to not share the code. Just find a sample smart card access using java and just port it to applet(for web)
I hope this helps
You can also have a look at this beta native plugin:
https://github.com/ubinity/webpcsc-firebreath
It is cross-browser/cross-pltaform plugin based on firebreath framework, exposing a subset of the PCSC API.
When this proposal "Smart cards in browsers" gets implemented, we will also be able to use JavaScript for this.
I worked on doing the same circa 2012, back then, I worked on top of a previous work that provided a Java Applet.
Nowadays [December 2015], It makes even less sense to use a Java Applet due to 'recent' security problems, and following dismissal of support for Java Applets, and the native plugin technologies are also being discontinued as well.
Regardless of the current usefulness of a Java Applet, picking up on #Glen Allen's answer, I'm not bound by contract, and here is the open source code of an example Applet:
https://github.com/ist-dsi/signature
It was built upon a thesis work and it produces documents in this format: http://www.w3.org/TR/xmldsig-core/ more info on the why's can be found in the abstract of that MsC thesis https://fenix.tecnico.ulisboa.pt/downloadFile/395139415358/resumo.pdf (the author is a better engineer than thesis writer though, but it might be a good point to start if you want to know the state of the art of the thing, although is old)
There are more requirements that on hindsight and without knowing made some odd choices of technologies on the code that I give you here, just disregard that part :)
One of the answers here hinted on PKCS_11 and open standards. Maybe the trick resides in a smart card reader driver that automatically sets up the certificate infrastructure on the client side, I remember having to go through lots of hoops though to setup my ID card's smart card with a reader on Mac OS X with Chrome [AFAIK it wasn't easy to set up the smart card reader with Apple's keystore, and perhaps also not that easy back then to have Chrome configured so that it would use client authentication and requested access to Apple's keystore].
Or maybe the NFC + SmartCard and a mobile app will be the way to go.
It just is such a waste to have whole countries with IDs with SmartCards, lots of government services already with webapps, and no easy way to connect the two.
Cheers.
You can use a signed Java applet to access the reader. Signed applets are allowed to access hardware peripherials, the smartcard reader can be accessed via the Java Crypto API.
Hope this helps.
If you can access the smartcard on your file system, like when a USB drive is connected and appears as a separate disk, then you can simply use flash.net.FileReference.
You can't achieve this with ActionScript/Flash if you've to stick to the browser.
Adobe AIR could do this, but then you'd have to build an application which the user has to install prior to using it.
Something like this (AIR):
http://cookbooks.adobe.com/post_Mass_Storage_Device_Detection_AIR_2_0-16747.html

Serial communication from JavaScript?

Is it possible to communicate over a machine's serial port through JavaScript?
I have to write a short program that sends data to a microcontroller over the serial port that has a GUI and is cross-platform compatible, and I really don't want to use Java's Swing.
JavaScript itself doesn't have any built in functionality to allow you to access the serial port. However, various JavaScript engines (v8, rhino, etc) allow you to write your own custom native objects.
You might want to check out node.js, which is a JavaScript library for v8 that's focused on writing server-side code (rather than web browser client code). It seems that someone's already written a serialport package for that:
https://github.com/voodootikigod/node-serialport
This is an old question, but in case this helps anyone else, Chrome Apps have access to a serial API - http://developer.chrome.com/apps/serial.html - which might help.
It's Chrome specific (obviously..), but Chrome is available cross-platform so might answer the question.
There's a cross platform plugin for serial port communication called jUART.
Yes, it's possible using an ActiveX(I did it). You can make an activeX and use JavaScript to invoke it.
If you prefer, you can make a .net dll and register it using regasm. Take a look at this link
You also can write an activeX using VB6 and register it. Both works fine.
Ps.: if you are using ActiveX, the JavaScript code will run just on IE.
If you have a DLL library (this includes e.g. most Windows APIs) that allows you to communicate over serial port you can invoke it from Firefox chrome code (or content code with universalxpconnect privileges) by using ctypes.
What you could do is to use a Java applet that connects to the local computer's Java application that reads the serial port. The applet would then transfer the data to a JavaScript class or something that can hold the information. Then additional JavaScript code can be used to access the data. It's a complicated solution but should work.
Another way is to create a POJO service.

Categories

Resources