Sending text information in a p2p network - javascript

I have been attempting to create a simple peer to peer network for quite some time.
I stumbled upon a javascript example found here that I have been working from.
When I run the example found in the repository, the peers never make a connection. I am beginning to wonder if there are problems with the ports I am attempting to use. When I use a port checker online, I can see that most of my ports are stealthed.
Questions:
Do my ports need to be open (not stealthed) to communicate on a P2P network?
How would I go about opening ports?
I have started an issue that describes my problem in more detail found here

Related

How to make Web RTC work behind Symmetric NAT?

I've created 2 simple webpages (for peer 1 and peer 2) that exchange a few messages with WebRTC data channel. You need to manually copy-paste offer and answer between the webpages. After the answer is pasted back to peer 1 the connection is established and those messages are sent and received. But, it only works if both peers are behind normal NAT.
Therefore I tried to use TURN server. I tried self-hosted Coturn server and Xirsys turn service, but just couldn't get them to work.
The web pages on codesandbox are:
Peer 1: https://codesandbox.io/s/web-rtc-peer-1-shared-zl09e
Peer 2: https://codesandbox.io/s/web-rtc-peer-2-shared-9z40r
The sandboxes now have fake credentials for turn servers, but I used real ones (static) in my experiments.
So, if I use this sandboxes in symetric NAT, or I just force the use of turn server with config iceTransportPolicy: "relay", then it does not work - the connection does not open.
Question 1: What do I have to do to make it work?
Question 2: Can you make it work with your own TURN server (and iceTransportPolicy: "relay" config option?

How can we control which port(s) will be used to create peer to peer connection in WebRTC?

I have created an application that uses WebRTC and does the screen and audio sharing.
It is purely a front-end application written mainly in javascript.
Now the concern that has been brought to us by users is, they need a list of specific ports that'll be used to create the peer-to-peer connection.
While debugging the application, I see different ports each time for establishing the connection between peers.
Is there any way I can control the port which will be used to create an offer / establish the connection?
Any help will be really appreciated.
Unfortunately there isn't an easy way to do this today. I would file an issue against webrtc-nv to get the attention of the standards authors. There was talk of exposing these options on ICETransport, but never saw it go anywhere.
What you could do today is create/destroy peerconnections in a loop until it selected the port you wanted.

Webrtc on fails on local network without internet connectivity [duplicate]

WebRTC signalling is driving me crazy. My use-case is quite simple: a bidirectional audio intercom between a kiosk and to a control room webapp. Both computers are on the same network. Neither has internet access, all machines have known static IPs.
Everything I read wants me to use STUN/TURN/ICE servers. The acronyms for this is endless, contributing to my migraine but if this were a standard application, I'd just open a port, tell the other client about it (I can do this via the webapp if I need to) and have the other connect.
Can I do this with WebRTC? Without running a dozen signalling servers?
For the sake of examples, how would you connect a browser running on 192.168.0.101 to one running on 192.168.0.102?
STUN/TURN is different from signaling.
STUN/TURN in WebRTC are used to gather ICE candidates. Signaling is used to transmit between these two PCs the session description (offer and answer).
You can use free STUN server (like stun.l.google.com or stun.services.mozilla.org). There are also free TURN servers, but not too many (these are resource expensive). One is numb.vigenie.ca.
Now there's no signaling server, because these are custom and can be done in many ways. Here's an article that I wrote. I ended up using Stomp now on client side and Spring on server side.
I guess you can tamper with SDP and inject the ICE candidates statically, but you'll still need to exchange SDP (and that's dinamycally generated each session) between these two PCs somehow. Even though, taking into account that the configuration will not change, I guess you can exchange it once (through the means of copy-paste :) ), stored it somewhere and use it every time.
If your end-points have static IPs then you can ignore STUN, TURN and ICE, which are just power-tools to drill holes in firewalls. Most people aren't that lucky.
Due to how WebRTC is structured, end-points do need a way to exchange call setup information (SDP) like media ports and key information ahead of time. How you get that information from A to B and back to A, is entirely up to you ("signaling server" is just a fancy word for this), but most people use something like a web socket server, the tic-tac-toe of client-initiated communication.
I think the simplest way to make this work on a private network without an internet connection is to install a basic web socket server on one of the machines.
As an example I recommend the very simple https://github.com/emannion/webrtc-web-socket which worked on my private network without an internet connection.
Follow the instructions to install the web socket server on e.g. 192.168.1.101, then have both end-points connect to 192.168.0.101:1337 with Chrome or Firefox. Share camera on both ends in the basic demo web UI, and hit Connect and you should be good to go.
If you need to do this entirely without any server, then this answer to a related question at least highlights the information you'd need to send across (in a cut'n'paste demo).

How do I use RtcPeerConnection to connect with other instances?

I have followed the tutorials on http://www.html5rocks.com/en/tutorials/webrtc/basics as well as watch some of the videos but I am so confused. I was able to get 2 peerConnections working on a single page but I have no Idea how build on this to actually allow users on different machines/networks or what ever to actually connect.
From what I can see it involves using socket io and I have found plenty full frameworks and apps doing it but I am struggling to understand it.
Can any one point me to any tutorials that would help me to go from this rtcPeerConnection to communicating with other instances
Any help is greatly appreciated
To allow 2 users establish p2p connection, one of the peer should send "description" (ip address, port, etc) to second peer. Second peer sets it as remote description using setRemoteDescription method of RTCPeerConnection. Second peer invokes createAnswer and sends its localDescription to first peer.
When both peers know about each other, connection can be established. I think that tutorial mentioned by you in first link is comprehensive.
To allow 2 peers exchange "descriptions" you can use any hand-written signalling server. For example client can poll web-server using http.

How can I implement simple serverless p2p browser to browser messaging with minimal overhead?

I'm trying to create some basic implementations of simple games (tic tac toe is the starting project) which can be played over the internet without requiring a central server. The page would not even need to be hosted and could be run locally on the machine, or it could be hosted on a web server. When hosting the game, the page would inform the host of his IP address, which could then be sent by any method (phone, instant message, etc) to a friend. That friend would type or copy/paste the IP into a join dialog and be able to play the game in question. I would like these 2 parties to be able to do this without installing any additional software, and without contacting a central server of any kind.
I have looked into many potential solutions involving node.js, webrtc, websockets, flash, java, etc. Each one of these has a problem associated with it, such as requiring a central server, or requiring the client to potentially have to download something that isn't already installed on their computer, or only transferring audio and video and not being useful for sending data messages. It may seem trivial to tell someone that they need to download java.. or for me to develop the application with flash, but that is all contrary to my ultimate goals.
If it just isn't possible to do what I'm trying to do entirely in javascript, then it just isn't possible. But I don't see why it couldn't be, considering that browsers are capable on their own of sending and receiving text data to URLS which resolve to IPs or directly to IPs. Other solutions are welcome but if this isn't possible to do, it really should be.
The simple explanation of the exact requirements for what I'm trying to do is:
Should use entirely free (as in beer) technologies. (no flash, i realize that web apps for flash player can be coded for free, but peer to peer in stratum requires a signup for a beta key, which assuming i could obtain for free, wouldn't necessarily remain free forever.)
No external servers or false peer to peer. (again as in flash or unity based solutions where the imitation of peer to peer can be acheived, as long as you use their central server)
No client downloads (sure, most people have java or flash installed, but many don't, and java is a pretty hefty download and not friendly for computer illiterate users. It even tries to install toolbars now. On top of this, many of my users would not be willing to download anything at all, including java or unity. Which have their own issues relating to this project as already mentioned)
In summary, if ajax can send a request to a specified IP and listen for a response.. why can't i get simple peer to peer messaging in pure js? Or can I?
I shouldn't need to host a full blown web server or a seperate application or plugin of any kind to send and receive data.
Am I missing something?
After pubnub was recommended, I looked there and was partially impressed. However, I eventually stumbled across exactly what I was looking for UNBELIEVABLY. RTCDataChannel is the answer. This site finally showed that what I want is possible. The browser support for this functionality is small but growing and the entire ordeal has strengthened my faith in the growing support for peer to peer applications in the browser community.
In summary, if ajax can send a request to a specified IP and listen
for a response.. why can't i get simple peer to peer messaging in pure
js? Or can I?
It's due to the fact that an ajax request must be handled by an HTTP server so you still need to install a server to every clients.
say you want
free
no external servers
no client downloads
I would say it is impossible to archive with all of these requirements except that you cut one of them off.
My suggestion is pubnub. This solution still need a server and it is not free(they have a free usage tier). But the good thing is you have an imitate p2p connection without doing server things and no client download needed.

Categories