signaling-peer-js
v0.10.1
Published
A JavaScript peer-side library of Signaling.
Downloads
13
Maintainers
Readme
signaling-peer-js
A JavaScript peer-side library of Signaling.
Install
npm i signaling-peer-js
Import
// for runtimes with WebSocket defined (e.g. Browser, Deno):
import { SignalingPeer } from 'signaling-peer-js'
// for Node.js:
import { SignalingPeer } from 'signaling-peer-js/node'
Usage
const signalingAgentAddr = 'ws://127.0.0.1/ws'
const peer1 = new SignalingPeer(signalingAgentAddr)
const pid1 = await peer1.getPid()
peer1.addDataSignalListener(({ from, data }) => {
console.log(`peer1 recv from ${from}:`, data)
})
const peer2 = new SignalingPeer(signalingAgentAddr)
const pid2 = await peer2.getPid()
peer2.addDataSignalListener(({ from, data }) => {
console.log(`peer2 recv from ${from}:`, data)
})
await peer1.send(pid2, 'Hello!')
await peer2.send(pid1, 'Hi!')
License
MIT