Comments (7)
The simplest way to do that is to create a full-mesh topology. That means that every peer opens a connection to every other peer. To illustrate:
Then, you can just iterate over all the peers and call peer.send
when you want to broadcast a message.
from simple-peer.
Great news! and one last question about this, by having a full-mesh topology does it makes each peer to load 5 times slower, or its up to me to make it fast and keep a low internet useage?
Sorry for bad english
from simple-peer.
Well, say you have 5 peers. Then, when a peer wants to send some data it must send it 4 times, once to each of the other peers. So you're going to want to be a bit careful about the size of the data you send.
Full mesh topologies don't scale well. The total number of edges in the network will be where n is the number of peers.
from simple-peer.
I did some experiments in the past, and once the number of participants starts growing it becomes (much) more effective to distribute data between producer and consumers in a tree based fashion -- instead of using a mesh network. Obvious drawback of this approach is that it breaks the P2P serverless architecture, as you need an MCU type of server in the backend to create this tree-based overlay network. My prototype was based on the Erizo project, which I had to extend to glue multiple servers together into an overlay tree.
from simple-peer.
When extending the example in the readme to use 3 peers, a Failed to set remote answer sdp: Called in wrong state: STATE_RECEIVEDACCEPT
error occurs. I assume this is because the peers are have received an answer and are now waiting for an candidate data, but then they receive another answer from the third peer. Is this correct? Here is a gist of the extended example: https://gist.github.com/tomcartwrightuk/396851af44e8315e378e
from simple-peer.
No, you need to create a peer object for each connection. Like this:
Peer 1
// These are peer1's connections to peer2 and peer3
var peer2 = new SimplePeer({ initiator: true })
var peer3 = new SimplePeer({ initiator: true })
peer2.on('signal', function (data) {
// send this signaling data to peer2 somehow
})
peer2.on('ready', function () {
peer2.send('hi peer2, this is peer1')
})
peer2.on('message', function (data) {
console.log('got a message from peer2: ' + data)
})
peer3.on('signal', function (data) {
// send this signaling data to peer3 somehow
})
peer3.on('ready', function () {
peer3.send('hi peer3, this is peer1')
})
peer3.on('message', function (data) {
console.log('got a message from peer3: ' + data)
})
Peer 2
// These are peer2's connections to peer1 and peer3
var peer1 = new SimplePeer()
var peer3 = new SimplePeer({ initiator: true })
peer1.on('signal', function (data) {
// send this signaling data to peer1 somehow
})
peer1.on('ready', function () {
peer1.send('hi peer1, this is peer2')
})
peer1.on('message', function (data) {
console.log('got a message from peer1: ' + data)
})
peer3.on('signal', function (data) {
// send this signaling data to peer3 somehow
})
peer3.on('ready', function () {
peer3.send('hi peer3, this is peer2')
})
peer3.on('message', function (data) {
console.log('got a message from peer3: ' + data)
})
Peer 3
// These are peer3's connections to peer1 and peer2
var peer1 = new SimplePeer()
var peer2 = new SimplePeer()
peer1.on('signal', function (data) {
// send this signaling data to peer1 somehow
})
peer1.on('ready', function () {
peer1.send('hi peer1, this is peer3')
})
peer1.on('message', function (data) {
console.log('got a message from peer1: ' + data)
})
peer2.on('signal', function (data) {
// send this signaling data to peer2 somehow
})
peer2.on('ready', function () {
peer2.send('hi peer2, this is peer3')
})
peer2.on('message', function (data) {
console.log('got a message from peer2: ' + data)
})
from simple-peer.
Ah I see. That makes more sense. Thanks.
from simple-peer.
Related Issues (20)
- The sample code does not work properly
- Is it possible to provide a token in simple-peer opts HOT 3
- No connection when hosted, but locally ok HOT 1
- Fixing addStream() deprecation HOT 3
- RTCPeerconnection failed on mobile device and on Mac HOT 3
- MException: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: Called in wrong state: stable ( HOT 1
- npm install simple-server fails
- Discussions HOT 1
- So many seemingly dangling peer connections, even if no peer is open HOT 7
- Video and audio are not working after upgrade from react native 0.68.2 to 0.72.6 HOT 1
- Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11
- Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11 HOT 3
- Support renegotiate when adding new media stream HOT 1
- simple-peer won't connect when clients are not in the same network HOT 15
- 'stun:global.stun.twilio.com:3478?transport=udp' is not a valid stun or turn URL on calling new SimplePeer() HOT 2
- simple-peer.js?v=eb7dd428:571 Uncaught (in promise) Error: Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11 at oldBrowser (simple-peer.js?v=eb7dd428:571:13) at new _Peer (simple-peer.js?v=eb7dd428:5966:20) at prepareNewPeerConnection (webRTCHandler.js:59:29) at Socket2.<anonymous> (socketConnection.js:58:5) at Emitter.emit (socket__io-client.js?v=77d8b3f1:427:21) at Socket2.emitEvent (socket__io-client.js?v=77d8b3f1:2731:16) at Socket2.onevent (socket__io-client.js?v=77d8b3f1:2719:12) at Socket2.onpacket (socket__io-client.js?v=77d8b3f1:2690:14) at Emitter.emit (socket__io-client.js?v=77d8b3f1:427:21) at socket__io-client.js?v=77d8b3f1:3287:12 i m getting this error while using react vite please can anybody solve this error i m stuck HOT 3
- Vite-React-Typescript Issue - Uncaught TypeError: Stream is undefined at the time of createing SimplePeer object HOT 3
- Connection is killed if string is too big
- No support for addStream deprecated method
- Get candidate.type when peer is connected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-peer.