Reputation: 1888
I need to make one way webrtc communication. So a fake media stream from one way can be useful. So far I was not able to put a fake stream in RTCPeerConnection
. Sending stream from both way works. I tried multiple ways. Can anyone tell me a good way to achieve this?
navigator.mediaDevices
.getUserMedia({
audio: false,
})
.then(getUserMediaSuccess)
.catch(errorHandler);
Tried to create fake media capture with canvas from here, but could not succeed.
Tried to add new RTCPeerConnection().addTransceiver().receiver.track
. But not sure what it is and how to use it properly.
function start(isCaller) {
//createMediaStreamFake();
peerConnection.current = new RTCPeerConnection(peerConnectionConfig);
peerConnection.current.onicecandidate = gotIceCandidate;
peerConnection.current.ontrack = gotRemoteStream;
//peerConnection.current.addStream(localStream.current);
peerConnection.current.addStream(
new RTCPeerConnection().addTransceiver().receiver.track
);
}
Upvotes: 1
Views: 1158
Reputation: 17275
You do not need any fake media stream. You can call
pc.createOffer({offerToReceiveAudio: true})
which will indicate to the other side that even though you are not going to send audio, you still want to negotiate and receive audio. This works in Chrome and Firefox, however since that API is declared "legacy" Safari could not be bothered to implemented it, requiring you to call
const t = pc.addTransceiver('audio');
t.direction = 'recvonly';
instead. The adapter.js polyfill does this automatically for you.
Upvotes: 5