Comments (5)
As I understand:
LOCAL peer can create SDP, collect all ICE Candidates, and send all at once to REMOTE peer over Signaling Server. REMOTE peer know SDP offer and ICE Candidates -> can send SDP answer over WebRTC.
No, it doesn't work that way.
The REMOTE peer knows the SDP offer and the ICE candidates, so it can send ICE candidates to the LOCAL peer.
But those ICE candidates do not contain the SDP - in particular, they can't send the FINGERPRINT attribute which is critical to establishing the DTLS connection.
People have speculated about the possibility of including the necessary information in the ICE handshake, but so far, nobody (as far as I know) has published a working example of this approach, or undertaken the necessary work of standardization that would be needed to make it part of the official WebRTC spec.
from samples.
@alvestrand thank you. Could please clatify:
Imagin text chat app. Users can connect to chat by link.
To send messages to all users every user must have Peer2Peer WebRTC connection with all users. It is many-to-many.
When new user connect to chat, all current users must receive the new user's SDP. The only way current users can get new user's SDP is by using Signling Server.
Thus: every user must have alive socket connection with Signling Server. Socket connection must be alive all time user in chat.
If all users have full time alive socket connection - what's the benefit of WebRTC ?
from samples.
from samples.
The answer is simple: for that use-case WebRTC offers little benefit. Those come when you add requirements like file transfer and voice/video chat which the signaling/chat server can't handle for capacity reasons.
from samples.
@alvestrand @fippo thank you. I know my questions is not an issue report. But it is the only place where I can get answers.
Code below exchange only SDP between peers. It does not send ICE candidates. And its working,
LOCAL Singnaling REMOTE
peer server peer
| | |
create SDP offer | |
| | |
create ICE candidate 1 | |
create ICE candidate 2 | |
(just subscribe | |
onicecandidate, | |
wait for last ICE | |
don't send ICEs) | |
| | |
send SDP only without ICEs-->|------------>|
| | setRemoteSdp(SDP offer)
| | create SDP answer
|<-------------------------|<----send SDP answer without ICEs
setRemoteSdp(SDP answer) |
| |
|<---------Peer2Peer over WebRTC-------->|
Signaling server mock
const signaling = {
/** @param {string} senderId, @param {RTCSessionDescription} sdp */
sdpAndIceChannelsSend: (senderId, sdp) => {
console.log(`${senderId} SDP send`);
document.dispatchEvent(new CustomEvent('sdp', {detail: { senderId, sdp } }));
},
/** @param {string} clientId, @param {(sdp:RTCSessionDescription)=>void} callBack */
sdpAndIceChannelsOnGet: (clientId, callBack) =>
document.addEventListener('sdp', evt => {
if (evt.detail.senderId !== clientId) {
console.log(`${clientId} SDP onGet`);
callBack(evt.detail.sdp);
}
}),
};
code:
//
// remote peer
{
const remoteClientId = 'REMOTE';
const remoteCon = new RTCPeerConnection();
remoteCon.ondatachannel = evt => {
console.log('REMOTE ondatachannel');
const channel = evt.channel;
channel.onopen = (event) => {
console.log('REMOTE channel onopen');
// send message to LOCAL
const msg = 'Hi from remote';
console.log(`REMOTE message send: ${msg}`);
channel.send(msg);
};
channel.onmessage = (event) => {
console.log('REMOTE onmessage:', event.data);
};
};
signaling.sdpAndIceChannelsOnGet(remoteClientId, async (sdpOffer, iceCandidates) => {
await remoteCon.setRemoteDescription(sdpOffer);
await remoteCon.setLocalDescription();
signaling.sdpAndIceChannelsSend(remoteClientId, remoteCon.localDescription);
});
}
//
// local peer
{
const localClientId = 'LOCAL';
const localCon = new RTCPeerConnection();
const localChannel = localCon.createDataChannel('chat');
localChannel.onopen = evt => {
console.log('LOCAL channel onopen');
// send message to REMOTE
const msg = 'Hi from local';
console.log(`LOCAL message send: ${msg}`);
localChannel.send(msg);
};
localChannel.onmessage = evt =>
console.log('LOCAL onmessage:', evt.data);
// SDP
// creates and sets SDP
await localCon.setLocalDescription();
signaling.sdpAndIceChannelsOnGet(localClientId, async sdpAnswer =>
await localCon.setRemoteDescription(sdpAnswer));
localCon.onicecandidate = evt => {
if (!evt.candidate) {
// all ice candidates getted
signaling.sdpAndIceChannelsSend(localClientId, localCon.localDescription);
}
};
}
Console ouput:
LOCAL SDP send
REMOTE SDP onGet
REMOTE SDP send
LOCAL SDP onGet
LOCAL channel onopen
LOCAL message send: Hi from local
REMOTE ondatachannel
REMOTE channel onopen
REMOTE message send: Hi from remote
REMOTE onmessage: Hi from local
LOCAL onmessage: Hi from remote
Why this code work if ICEs don't exchange?
from samples.
Related Issues (20)
- When I use Android phone to publish stream, I get this problem in my chrome browser: "Uncaught TypeError: Cannot read property 'find' of undefined." HOT 1
- Invite is being truncated HOT 1
- Scalable Video Coding example needs update HOT 3
- Scalable Video Codec prevent incorrect Safari usage
- Scalable Video Codec include an SVC support check HOT 1
- WebGPU code refresh needed: layout parameter now required in createRenderPipeline calls HOT 2
- No SRFLX ICE candidates? HOT 1
- [Sample PeerConnection Channel] - The all sound turn off after enable navigator.mediaDevices.getUserMedia HOT 2
- E2E interop test failures HOT 4
- Update insertable streams section to WebRTC Encoded transforms HOT 4
- Video Analyzer doesn't work on http/default server settings HOT 3
- Can I share some Windows? Let's HOT 1
- Add new sample: Mirroring and recording video from camera stream HOT 1
- navigator.mediaDevices.getUserMedia doesn't work on macos catalyst WKWebView HOT 1
- mp4 mimeType is downloaded with .webm extension, not a mp4. HOT 1
- Can a shared surface select its derivative window? HOT 1
- Script (lit-element) error , not close jsx param.
- On some of my machines I got the error "Error creating offer: SyntaxError: Failed to construct 'RTCPeerConnection': '' is not a valid URL." HOT 8
- ScriptProcessorNode deprecated in Chrome 121. HOT 1
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 samples.