@ai-lion/ipeer
v2.7.1
Published
**Include the library**
Downloads
147
Readme
IPeer: Simple peer-to-peer with WebRTC, on nodejs,browser
support nodejs, browser
Setup
Include the library
with npm:
npm install @ai-lion/ipeer
with yarn:
yarn add @ai-lion/ipeer
// The usage -
import IPeer from "@ai-lion/ipeer";
Create a Peer
const peer = new IPeer("pick-an-id");
// You can pick your own id or omit the id if you want to get a random one from the server.
Data connections
Connect
const conn = peer.connect("another-peers-id");
conn.on("open", () => {
conn.write("hi!");
});
Receive
peer.on("connection", (socket) => {
socket.on("data", (data) => {
// Will print 'hi!'
console.log(data);
});
socket.on("open", () => {
socket.write("hello!");
});
});