Peer.min.js code
Remember the “peer = new Peer(‘osama’,{host: …” has to be different for each person/device/peer to establish a connection.
With this code we were able to send a click alert from one peer to another. That is, if one peer clicks on their browser, another receives an alert “hello world” on their browser.
Class Notes
WebRTC’s RTCDataChannel API doesn’t require a big server-in-the-middle to exchange data between browsers. It can do that with peer-peer setup called RTCPeerConnection (experimental technology). RTCDataChannel uses SCTP protocols (as opposed to UDC and TCP used by servers) and DOES require a basic server setup for signaling (the process of coordinating communication) and ICE (peers exchanging information about network connection) and NATs(network address translation) as well as firewall purposes.
This article explains more on why webRTC needs signalling and ICE/NATs (ICE tries to find the best path to connect peers. NATs provide a device with an IP address for use within a private local network, but this address can’t be used externally. Without a public address, there’s no way for WebRTC peers to communicate. To get around this problem WebRTC uses STUN.) STUN servers live on the public internet and have one simple task: check the IP:port address of an incoming request (from an application running behind a NAT) and send that address back as a response. TURN is used to relay audio/video/data streaming between peers, not signaling data! RTCPeerConnection tries to set up direct communication between peers over UDP. If that fails, RTCPeerConnection resorts to TCP. If that fails, TURN servers can be used as a fallback, relaying data between endpoints.
UDP and SCTP are “message oriented” protocols, TCP is “stream oriented”. Message Oriented protocols send data in distinct chunks or groups. The receiver of data can determine where one message ends and another begins. Stream protocols send a continuous flow of data. Here is an example with mobile phones. Text messages would be a message oriented protocol as each text message is distinct from the other messages. A phone call is stream oriented as there is a continuous flow of audio throughout the call. Common protocols used on the internet are UDP (message oriented) and TCP (stream oriented). Wikipedia these terms for more information.