peer to peer (p2p) connection between smart tv and smartphone - javascript

So, I program for a couple of years now and I only programmed websites. However, I wanted to make a Web App for my LG TV and already downloaded the SDK, ide, emulator, etc.. And it was pretty easy to get a basic App that works fine. I also used PhoneGap (used to make mobile apps with HTML, CSS, js, node js) to do the same App for my android phone.
So my problem is that I need a way to get p2p (peer to peer) connections between my tv and my smartphone. I want to do a simple game, where the tv is used as a monitor and the phone as a controller. However, I don't want to use a web server. You should be able to play it, without an internet connection, but with a wifi network.
I already looked for WebRTC, but I didn't understand how it works, to be honest. I also read something about socket io. From what I have understood is, that the tv needs to run an HTTP-server and then the phone needs to connect to it? But then, the smartphone somehow needs to know the IP of the HTTP-server. Otherwise, you would have to type the IP every time you want to play.
I don't need a finished code, just a point where I can start and an explanation.
Thanks!

Turns out, there is something called ConnectSDK which solves my problem (It works not only with LG TV's but also with 7 different platforms). The SDK is made by LG, however it took me 8 months to find it.
Why? Because LG is not telling you about this SDK on their own page for TV developers... Even though creating a websocket server on the phone and make the TV join this server by manually typing the ip works, however ConnectSDK provides a much better user experience.
It feels like they don't want that people programm good apps for their TV's.
LG communication skills: 1/10

Given the specifics of the project (small lan), to bypass the necessity of inputing an ip adress, i usually do :
1- Retrieve the phone ip address and subnet with phonegap js api;
2- Scan the subnet range for http server with a predefined route to identify the smart tv app(at most 255*255 adress to scan for big lan; with js its easy to parallelise hundreds/thousands of simultaneous requests);
----> this route should output something readable identifying the appliance, in case of multiple results.
3- Display the list of results on the phone; retrieve user input; then connect.
You need to use websockets (hence, why not socketio implementation) to be able to do real time interaction with small delay given the parameters of your project.
Enjoy !

Related

How would a cloud app get the client's local device information?

How would a cloud web app get Client Device Information such as IP address, Serial Number, etc?
Looking to have an app developed for tracking asset conditions within the school. Just want to make sure my ask is possible before I list it for review.
Basically the user goes to a webpage and fills out a condition report and submits it. I'm wanting to automatically identify the Chromebook or Laptop that is submitting the condition report. With Chromebooks especially, the S/N on the board is not what always is on the case plastics (due to repairs). The aim of making this automatic is to keep data correct.
I could identify the device by serial number, asset number, or local LAN IP. Could potentially identify by any other persistent hardware id that doesn't change.
Thoughts on possible solutions / workarounds:
Maybe there is a unique hardware hash or identifier that Chrome supplies that is persistent and I don't know about. I could manually build a lookup table if its not appropriate to use it directly.
It looks like the WebRTC method no longer works for obtaining local IP address - unless there is a way to force the Chrome Flags for specific sites through Google Workplace policies.
I could create a web service that runs behind the firewall and returns the IP address of the requestor. The client side JavaScript would use that when communicating with the cloud web app and if it cannot connect to the local web service then it prompts the user for the serial number as a last resort.
I could create and force install an extension that the webpage can use to obtain the IP address...
E.g. https://github.com/DoctorLai/what-is-my-ip/
Just wondering if there is an easier way than the above ... One that would work even if the Chromebook wasn't on site...
Thanks

Connect and read data from a bluetooth device with NodeJs?

I have a small hygrometer/thermometer that is bluetooth and comes with a proprietary application that connects to it to read it's data. The device is meant to connect to your smartphone. But I suppose it could connect to my laptop like any other device, but the application it uses is mobile only, so I couldn't do anything with it if I did.
The issue I am really wanting to solve is that obviously I need to be in range of the bluetooth to be able to connect and read data from the device. But I want to be able to monitor it when I am not home. What I was thinking about was keeping a laptop connected to this device, and then running a node server locally that sends the data readings every few minutes to a hosted database, where I then could build a small application that can consume the data sent to the database.
In my limited research, I found this: https://www.npmjs.com/package/node-bluetooth
Which looks like it would help me immensely. And also this post from Google: https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web
I am a bit ignorant on how bluetooth works in terms of how something like your phone for example, actually connects to the BT device. Is it reading an address 'broadcasted' out from the BL device? Would I need a MAC address for the device or something along those lines? I guess I am struggling to understand how that even using the aforementioned library, I actually connect to the device. I think I would need some sort of address to even do that. Furthermore, is it possible this device doesn't allow connections from anywhere other than through it's proprietary application? Excuse my ignorance with this again, this is something I just started diving into this afternoon.
It's maybe not so practical, but I want to see if I can do something like this using just Javascript.

Track background location in webapp (service worker)

I'm wondering if it is possible to track location while a Webapp is backgrounded?
I've heard this functionality is in the pipeline for service workers, though I can't find any literature on exactly how to do it.
It would be fine to just save the location on the phone until the phone is unlocked and then send location data over a network when the user re-opens the browser/tab.
If it isn't possible with purely Web technologies, what would be the best way to do this. Could one build a native app to handle tracking capability and still have a Web interface as the main UI?
A bit of context
I'm developing an app for a charity that allows users to track themselves when out and about etc.. The users are likely to lock their phones when on patrol so I need to account for this. I've built the majority of the app as a Webapp and it would be an big (and boring) task to rewrite it as a native android and apple app!
No, it is not possible for privacy reasons. You also cannot do any sort of accurate scheduling via the Service Workers when the app is in the background, eg. use setTimeout or so (throttled by the browser).
You've probably read about the background sync API which allows you to ask the Service Worker to submit some data when a connection is available. With this API you can implement retry for form POSTs and stuff like that but not have the location tracked. Find out more here: https://davidwalsh.name/background-sync

Capture device name

I would like to capture the "computer name"/"device name" of the user. (Ex: Joes-iPhone) It seems like a nice touch to be able to see what devices have connected with the users login so they can see if there is unauthorized access to their account.
Over and over I see people say this is impossible from a web page for JavaScript, HTML, PHP, etc. Yet when I log into my bank, Facebook, Google. Low and behold, there is every device I've connected with. This means it is most definitely possible.
There was one instance where one of my accounts was logged into by someone and this was a big help in identifying what was going on and I love this feature now. I would like to implement this but am stuck in a city full of dead end roads!
Does anyone have any knowledge of how they are accessing this? Or even theories? I don't care what language or technique.
I'm very curious to see what people come up with. I do have an app for Facebook, so I could see the app accessing it and storing it for the browser site, but I have no app for the bank or Google and I have devices listed in Facebook that were not used within an app, only through the browser. To my knowledge I have never authorized any access to anything beyond what the browser is capable of, so there must be something I'm missing.
Short answer: It's true, it can't be done.
But why not??
Your device name is used when your device connects to your router -- but that's where it stops. Your router doesn't allow that information to be broadcast any further. When your computer/tablet/phone requests a web page, your router is the one actually asking for the page -- and he refers to himself by his public IP, which is shared by all the devices on your LAN.
Second-Best
What can be seen by external Internet entities is your user-agent (the type of browser you're using), which can give someone a pretty good idea of what operating system you're using, and therefore what sort of device you're on (mobile vs. desktop/laptop, Windows vs. Mac, etc.). The user-agent info is available as a string, and can be accessed by PHP via the $_SERVER['HTTP_USER_AGENT'] variable.
The PC name is only accessible through LAN (another PC connected to the same modem/router), if such a request hasn't been blocked on your PC. It is not distributed by browsers.
What browsers transmit is the browser info and operating system as well as the IP address. That's all. Some sites allow you to give a nickname to each machine so you can identify them, and they can then use cookies to remember which is which.
EDIT: The only thing I can see is that they could be using Java or Flash to do it.

Sending an SMS from mobile via HTML5/JavaScript

I'm creating a web application for mobile devices that will be downloaded in one of the markets with a mini web server and run on any OS ( iOS , android , Windows8 , etc. ) .
I want an application to be as independent as possible of the OS. I only wanted to use HTML5 and JavaScript .
The application allows a user to make a number of orders just by clicking buttons. Example : [List contacts ]
I need to click [List contacts ] and is sent a text message automatically to other mobile device with an android application that receives the request and sends the response via sms . The response has to be read by my web application . The application can be able to work without network / Wifi .
I've been searching and I only found ways to open the native application for sending sms.
I see that question, but I want to create my own way to send sms without dependencies of other applications.
Is there any way to make this submission automatically?
Or can I use/create some plugin to use on JavaScript to do that?
[EDIT] Can this might be a possibility? Can someone explain me?
I believe the essential information was already mentioned in the comments, but my 2c here anyway.
As already commented, with current modern mobile operating systems apps don't get unlimited access to SMS functionality. From the user point of view allowing this would be potentially quite a hazard, since SMS's usually cost money and user should be in control of such activity, instead of having a random app sending and receiving SMS's freely (without user knowing it). Android is a bit more flexible regarding this kind of functionality, but as mentioned, iOS and also Windows 8/Windows Phone 8 only allows you to integrate to the SMS sending application and for SMS reception, there's no proper way to get access to incoming SMS's.
So, with a native container (such as PhoneGap) you could get one step forward with Android, but for other platforms the possibilities are limited to using the native SMS application. If you need to use SMS for some reason in the backend side, services such as Twilio are probably your best shot, but using SMS locally on the device is pretty much a no-go, unfortunately.

Categories

Resources