peer-connector
A module to accept and request WebRTC multi connections by using WebSockets.
Simple WebRTC video/voice/screen and data channels.
Installing
$ npm install peer-connector
Demo(sample test)
$ git clone https://github.com/goldenthumb/peer-connector.git$ cd peer-connector$ npm install$ npm run dev Now open this URL in your browser: http://localhost:3000/
Usage (basic)
Please refer to the file. (example/src/index.js)
; async { const stream = await ; const peerConnector = stream ; const websocket = await ; const signal = websocket ; signal; peerConnector;};
Usage (custom)
You can implement the signaling logic as you wish. (Using websocket and MQTT or other)
; async { const stream = await ; const peerConnector = ; const websocket = await ; const signal = websocket ; signal; signal; signal; signal; signal; peerConnector;};
API
getMediaStream
/** * @param {{ screen?: boolean, video?: boolean, audio?: boolean }} options * @return */const stream = await ; // Desktop screen sharing. const stream = await ; // Video and audio sharing.const stream = await ;
PeerConnector
/** * @param * @param * @param * @param * @param * @param */const peerConnector = ;
If opts is specified, then the default options (shown below) will be overridden.
{
stream: false,
config: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] },
channel: true,
channelName: '<random string>',
channelConfig: {},
}
Name | type | Description |
---|---|---|
stream | prop | media local stream |
peers | prop | connected peers |
addPeer | method | add peer |
removePeer | method | remove peer |
hasPeer | method | has peer |
getPeer | method | get peer |
close | method | close media local stream |
destroy | method | removes all listeners |
connect | event | triggers when connect WebRTC |
Peer
/** * @param * @param * @param * @param * @param */const peer = ;
If opts is specified, then the default options (shown below) will be overridden.
{
id: '<random string>',
stream: false,
config: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] },
channel: true,
}
Name | type | Description |
---|---|---|
id | prop | peer id |
localSdp | prop | local sdp |
localStream | prop | local media stream |
remoteSdp | prop | remote sdp |
remoteStream | prop | remote media stream |
createOfferSdp | method | create offer and set local sdp |
createAnswerSdp | method | create answer and set local sdp |
createDataChannel | method | create data channel |
setRemoteDescription | method | set remote sdp |
addIceCandidate | method | add ice candidate |
send | method | send data using data channel |
close | method | peer close |
destroy | method | removes all listeners |
iceCandidate | event | triggers when candidates occur |
changeIceState | event | triggers when oniceconnectionstatechange occur |
open | event | triggers when data channel open |
data | event | data received by data channel |
close | event | triggers when ICE connection or data channel close |
error | event | triggers when data channel error |
Signal
/** * @param * @param * @param */const signal = ;
If opts is specified, then the default options (shown below) will be overridden.
{
id: '<random string>',
}
Name | type | Description |
---|---|---|
id | prop | signal id |
send | method | send message |
autoSignal | method | auto signaling |
destroy | method | removes all listeners |
join | event | triggers When user join |
requestConnect | event | triggers when connect request |
sdp | event | triggers when user sdp |
candidate | event | triggers when user candidate |
License
MIT