Is there any framework to allow P2P communication via phone? - mobile

I want to build an app that allow P2P communication(send message, exchange files), I build the app with phonegap, since I want my app cross platform.
I know WebRTC allow real-time communication, but browsers doesn't support it very well. I also found Websocket plugin for phonegap, this satisfied part of my requirement, I can use this send message, but if I use websocket to send files from A to B, I guess all traffic will go through my server, it a pressure for server and I don't want my server carry so much traffic. I can't make a peer to peer connection between A and B.
Is there anyway to make a P2P communication on phone? Any workaround solution is also welcome.

You can do peer to peer connections using Flash or the recent WebRTC. Currently these are the only options you can use to do so, as WebSockets will only connect to a server.
As Flash is not supported by most phones (only Android < 4.0 has support), you can only use WebRTC. But WebRTC is only available on Chrome Beta for now, so you'll still have a cross platform app that will not work in most platforms/devices.
You will have to go through server (WebSockets or HTTP) to increase the number of devices you can cover.

You can use Boost asio sockets to build you own P2P app. but you need to build it for Android NDK and IOS.
Please do take a look at these links before you get into a conclusion
Official "Boost library" Support for Android and iOS?
Limitations to using (Boost) Asio with Android NDK
http://beta.boost.org/development/tests/trunk/developer/summary.html
http://www.codeproject.com/Tips/555070/Boost-vs-OSX-iOS-XCode
Hope it helps

On WebRTC you can use RTCDataChannel, in my experience, on chrome, using this involves writing a lot of code around reliability as the packets arrive out of order or not at all if sent too quickly.
However I think as the WebRTC spec evolves this will improve with implementation.
Use this for generating a RTCDataChannel enabled peerconnection:
var localpeer = new webkitRTCPeerConnection(localConfig,{ 'optional': [{'RtpDataChannels': true }] });

Related

Support for DatagramSocket (UDP)?

My app requires minimal support for DatagramSocket (i.e. UDP).
Specifically, I need new DatagramSocket(), send(DatagramPacket p) and receive(DatagramPacket p). I'd like to support both iOS and Android.
My app works in the simulator, but I found this in the documentation: "At this moment Codename One only supports TCP sockets."
Is this likely to change anytime soon? Or will I have to dive into native code to accomplish what I need?
If it works in the simulator I guess you used the java.net API's which aren't supported. You can read this to understand why some API's including the java.net API's aren't supported.
You can use native interfaces to wrap native socket implementations for portability currently there are two such cn1libs but they focus on TCP sockets:
https://github.com/shannah/CN1Sockets and https://github.com/shannah/cn1-websockets
You can write a similar API targeting Datagram. To learn more about native interfaces see https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html

Read BLE Beacons from react PWA

I'm designing a PWA for customer support.
One of the functionalities will require precisely (5 meters error margin) positioning the user's phone.
I'm thinking of using beacons as their range and precision suites my needs.
the thing is: How can I read beacons from a react.js (no native) PWA? Of course for triangulation, this would require reading several beacons.
Sorry, there is no practical way to make a web app that scans for bluetooth beacons due to the lack of browsers' support for bindings to raw bluetooth scanning.
Google Chrome does support BLE interaction via JavaScript through the Web Bluetooth API. However, it only supports discovering and connecting to GATT services, not arbitrary BLE scanning needed to find beacons. This means you cannot find iBeacon, Eddystone or AltBeacon compatible devices.
You might be able to discover a connectable custom BLE device that simulates beacon behavior through a connectable GATT service. But even if you did this, it would only work on Chrome, not on Safari, Microsoft or Firefox browsers, because Web Bluetooth is not supported on those platforms.
Even if you get this working on Chrome with a custom beacon, bluetooth beacons only provide very rough distance estimates. Triangulation only works decently at very close ranges of 3 meters or less. More practical indoor positioning techniques with beacons use RSSI fingerprinting not triangulation. And again, even Google Chrome with Web Bluetooth does not support the arbitrary scanning needed to do this.

iOS Sockets library listen support

I am finding some conflicting articles, some are old, about CN1 not having Sockets but I see the library com.codename1.io.Socket. I have seen some articles saying it works on Android as well but not iOS. I need the capability to listen on a socket on iOS and was hoping to use an internal library. The shannah/CN1Sockets project doesn't appear to support listening.
From 2014, https://www.codenameone.com/blog/sockets-multiline-trees.html , and lists non iOS support. Any update on this?
Codova/Phonegap does have a few libraries and someone implements Chrome's TCP/UDP API for it as well.
Server sockets are very problematic across platforms as the iOS implementation is radically different from the Android implementation and a bit challenging to implement using the listen paradigm.
It's probably possible to implement server sockets on iOS but because there wasn't much demand and this required some work we chose not to do it. It's also not very useful ans phones move around/change networks. You won't get a stable IP to work against anyway. A better way would be to initiate communication from the client and then communicate back. Notice you won't be able to use a server socket in a background process in iOS anyway as the process will be killed when sent to background!
The only Cordova implementation I found is this: https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-tcpServer
You can probably use that with native interfaces or just use it as a baseline for a pull request to implement server sockets on iOS but again it's very unlikely that what you are trying to do with server sockets won't work due to iOS limitations.

Stream Video from Mobile

I'm looking the best solution for video streaming from Mobile devices.
As far as I understand, The most efficient way is using RTMP \ RTSP \ UDP protocol,
or TCP \ websockets.
So far I've found few options:
HTTP Live Streaming (IOS) - but it's only for IOS
HTML5 LIVE VIDEO STREAMING VIA WEBSOCKETS - which works on node.js, but with no audio!
BinaryJS - bidrectional realtime binary data with binary websockets (also websockets on Node.js)
WebRTC - for client side
The thing is - I don't really know how to work it out on different kinds of mobile devices, or what protocols are best to used (and the least work to do... :)
Any suggestions \ ideas \ comments ?
Thanks!
It's depend upon your platform,Any way my suggestions
Desktop(win/mac/linux)-WebRTC is best,Because its peer to peer communication means browser to browser hd video chat not only video.And also Audio,file,etc main feature is without plugin no need to install any plugin(Note:its support chrome,opera,firefox only)
Android:WebRTC
IOS:BinaryJS is good option
There is an iOS library I can recommend. It can stream through RTMP from mobile devices and you can use HLS for downlink playback. It's called the ANGL library, and it can be used for streaming live content to a media server like Wowza, which then can broadcast the stream in a multitude of formats.

How to send UDP multicast packets through Silverlight?

I'm trying to find a way to send a udp broadcast packets through a silverlight application. Most of the research i've done lists that this is not possible through silverlight due to the support for sockets being limited to tcp only. But is there some other way to send a broadcast packet for example through javascript or something that the silverlight application can call?
Silverlight 4 supports UDP for multicast.
Articles / Examples
example of using UDP multicast support in Silverlight 4
blog entry from the System.Net Team
Classes
UdpAnySourceMulticastClient
UdpSingleSourceMulticastClient
The only plugins that support UDP client sending is Unity3D or Java. The problem mainly is when you use UDP you also need NAT punchthrough usually. So it is more complex (need a third party facilitator) since typically it is also peer to peer not just client-server.
You might be able to rig something with a proxy with Unity3D or Java but that would be a serious slowdown passing it into silverlight.
Silverlight and Flash only support TCP sockets currently.. Flash 10 does have some support for RTMFP which is UDP based but that is primarily for flash media server integration.
A response on the support of UDP in Silverlight: http://silverlight.net/forums/t/20249.aspx
You'll probably need to create your own custom browser plugin to do that for you.
As far as I know it isn't possible to use UDP with the major browser plugins, Flash, Silverlight etc. TCP is the lowest you get.
Browser based JS does not give programmatic access to UDP or even TCP. That is why you have AJAX, HTTP binding, Comet, XMPP Bosh etc. They try to emulate TCP's features with HTTP...
It appears Flash supports UDP as of Flash 10. I haven't tried it out but it sounds like it is not a low level API, only through RTMFP.
http://www.flashcomguru.com/index.cfm/2008/5/15/player-10-beta-speex-p2p-rtmfp
http://justin.everett-church.com/index.php/2008/05/23/astrop2p/
Flash Player 10.1 supports P2P with Adobe RTMFP and Stratus service. Stratus service is a Beta hosted rendezvous service that aids establishing communications between Flash Player endpoints. Unlike Flash Media Server, Stratus service mainly focuses on network address lookup and NAT traversal services for Flash Player endpoints, instead of supporting media relay, shared objects. This kind of service will also be integrated into next version of FMS.
No there isn't. Most browsers limit you to HTTP or FTP so calling out to Javascript isn't going to help either.

Resources