Can I create multiple datachannels for one PeerConnection ?
Can you provide example as to how it can be achieved, else reason why it is not possible?
Yes, you can create multiple data channels on a single peer connection:
var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
var dc2 = pc.createDataChannel("my other channel");
You can emulate this behaviour by opening up many one-to-one WebRTC connections.
This article discusses many connections going though a MCU server.
Related
I am new here in webrtc, i have strange issue, when i worked with one to one user onaddstream event is working, i am getting its response, but after then 3rd person joined the room onaddstream event is not working, can anyone please help me how to resolve this issue ? here i have added my whole code for it, can anyone please review it and helped me to get event for all the remote users
var pc = new RTCPeerConnection(configuration);
pc.onaddstream = (remoteaddstream) => {
console.log(remoteaddstream);
};
navigator.mediaDevices.getUserMedia({
audio: true,
video: true,
}).then(stream => {
var localstreamid = stream.id;
console.log("stream id :"+localstreamid);
pc.addStream(stream);
}, function(e) {
console.log(e);
});
You need multiple peer connections to connect more than 2 parties, or alternatively you can make all the parties connect to a server that forwards the data.
From https://medium.com/#khan_honney/webrtc-servers-and-multi-party-communication-in-webrtc-6bf3870b15eb
Mesh Topology
Mesh is the simplest topology for a multiparty application. In this topology, every participant sends and receives its media to all other participants. We said it is the simplest because it is the most straightforward method.
Mixing Topology and MCU
Mixing is another topology where each participant sends its media to a central server and receives a media from the central server. This media may contain some or all other participant’s media
Routing Topology and SFU
Routing is a multiparty topology where each participant sends its media to a central server and receives all other’s media from the central server.
I want to create a conference room using pusher and pure javascript, I managed to create a peer-to-peer connection but a many-to-many connection is proving that is a hard nut to crack. What I am trying to do is creating a connection of a specific user to a room and so that any participant that subscribes the channel their stream are share within and also can access all streams present in the channel.
participant= new RTCPeerConnection();
participant.creatOffer().then(function(desc){
//I add a stream fetch from users camera
participant.addStream(stream);
participant.setLocalDescription(new RTCSessionDescription(desc));
//using pusher I send an event that has the desc, room and from
channel.trigger('client-sdp'{
sdp:desc,
roomEvent: rooms,
from:id
})
});
I can share the whole code if required all I need to know is how to handle many-to-many connect in webRTC RTCPeerConnection();
What is the correct way to disconnect gun peers?
I can connect peers with:
Gun(['http://127.0.0.1:8080/gun','http://127.0.0.1:8081/gun'])
But cant disconnect again using
Gun(['http://127.0.0.1:8080/gun')
as peers will still both sync. In the last part of the video I couldn't disconnect the peers as both db's were still syncing.
On a different note the first part of the video shows problems with Chrome not updating however firefox works as it should.
Video and
Source Code
#soth this is a good question. There is currently no standard way to disconnect from a peer. This should probably be added.
This is terrible. But here is a hacky solution for now:
var peers = gun.back('opt.peers');
Object.keys(peers).forEach(function(id){
var peer = peers[id];
peer.retry = 0;
gun.on('bye', peer);
});
This will disconnect from all peers. If you only want one, filter by the ID which will probably be the URL.
Background: I'm using the full Express, http.Server, and Socket.IO to make a game. When each person connects, they have a socket session and I use that to send information between server and client.
What I would like to do now is to add AI to my game, since there is a minimum number of players and AI would make the experience richer. However, I don't know how to pretend each AI player is on the other end of a socket. Is there a way that I could do something like 'var fakeSocket = new Socket(...)'?
You can also open the client connection from your server to your server using "socket.io-client"
var clientIo = require('socket.io-client');
var socket = clientIo.connect(...);
Then use it like normal socket to add a new player to the game.
Your AI players can run on your server and just connect to the server (on the same box) with a webSocket connection. Your server doesn't even need to know if they are AI players or real players. As far as the server is concerned, they are webSocket connections that come from somewhere (it just so happens that some of them come from the same box rather than a distant browser). In this manner, the server doesn't need to treat the AI players any differently than the regular players (unless you choose to invoke different logic for each to favor one over the other).
So, there's no need to use a fake socket. You can more easily just use a real webSocket connection and then there's no socket pretending required.
See this other question/answer for how to create a socket.io connection from your server:
Is it possible to set up a socket.io client running (server-side) on a node.js server?
In summary, you use the socket.io-client module:
var io = require('socket.io-client');
And, then use the io variable like you would from the browser client.
WebRTC Questions
Is there an event for when the users camera stops streaming prematurely?
WebRTC can connect Peer2Peer what about Peer1 having a stream and multiple observers viewing?
Thanks
My experiment with Chrome 24 and 26 show that none of the mediastream/localmediastream or video events fire when a peer disconnects, but the (RTCPeerConnection) icecandidate event does fire several times right after the disconnect: first with the candidate and then without it on the event object.
peer = new RTCPeerConnection({ "iceServers": [{ "url": "stun:stun.l.google.com:19302" }] });
peer.onicecandidate = function(e){
if(!e.candidate) return console.log('Did someone disconnect?',e);
console.log('Someone might have just disconnected. Or maybe not.',e);
}
I've been able to connect 3 peers in chrome successfully as well: as far as I know each peer connection just connects two peers, so to have multiple simultaneous connections the host connects with each one individually.
This is what you wanted:
(await peerConnection.getStats())
.forEach((c)=>{if(c.type =='track')console.log(c)})
That will tell you how many frames have been received. Store that and then ask a second later and compare the two results. if the number of frames is the same it is not getting new data.