JS
WEBRTC PEER-TO-PEER WITH JS & NODE
NPM INSTALL PEER THEN RUN THIS SCRIPT IN TERMINAL
PEER SERVER
01
const { PeerServer } = require("peer"); const peerServer = PeerServer({ port: 9000, path: "/myapp" });
PEER CLIENT A
02
CONNECT TO PEER SERVER const peer = new Peer("PEER-A", { host: "localhost", port: 9000, path: "/myapp"});
ON RECEIVING MESSAGE peer.on("connection", (conn) => { conn.on("data", (data) => { console.log(data); }); });
PEER CLIENT B
03
CONNECT TO PEER SERVER const peer = new Peer("PEER-B", { host: "localhost", port: 9000, path: "/myapp"});
SEND MESSAGE TO A peer.on("open", (id) => { var conn = peer.connect("PEER-A"); conn.on("open", () => { conn.send("Hi from PEER-B!"); }); });