Actualmente soy nuevo en webrtc, he visto videos de webrtc pero el problema es que solo es uno a uno, quiero transmitir un video en una URL específica, digamos test.com/live y quien visite esta URL puede ver el Transmitir a diferencia de lo normal de igual a igual
navigator.mediaDevices .getUserMedia({ video: true, audio: true }) .then((currentStream) => { setStream(currentStream); myVideo.current.srcObject = currentStream; });este es el código para obtener mis datos de medios, ¿cómo puedo transmitir estos datos a esta URL en particular? Soy nuevo en webrtc, ¿alguien puede explicarlo?
Este es un fragmento de un transmisor de video que construí. Puede crear un flujo de datos y adjuntarlo. Espero que esto pueda ser útil.
Comunicaciones punto a punto con WebRTC
<script> var RTCPeerConnection = null; var getUserMedia = null; var attachMediaStream = null; var reattachMediaStream = null; var webrtcDetectedBrowser = null; if (navigator.mozGetUserMedia) { console.log("This appears to be Firefox"); webrtcDetectedBrowser = "firefox"; // The RTCPeerConnection object. RTCPeerConnection = mozRTCPeerConnection; // The RTCSessionDescription object. RTCSessionDescription = mozRTCSessionDescription; // The RTCIceCandidate object. RTCIceCandidate = mozRTCIceCandidate; // Get UserMedia (only difference is the prefix). // Code from Adam Barth. getUserMedia = navigator.mozGetUserMedia.bind(navigator); // Attach a media stream to an element. attachMediaStream = function (element, stream) { console.log("Attaching media stream"); element.src = URL.createObjectURL(stream);; element.play(); }; reattachMediaStream = function (to, from) { console.log("Reattaching media stream"); to.mozSrcObject = from.mozSrcObject; to.play(); }; // Fake get{Video,Audio}Tracks MediaStream.prototype.getVideoTracks = function () { return []; }; MediaStream.prototype.getAudioTracks = function () { return []; }; } else if (navigator.webkitGetUserMedia) { console.log("This appears to be Chrome"); webrtcDetectedBrowser = "chrome"; // The RTCPeerConnection object. RTCPeerConnection = webkitRTCPeerConnection; // Get UserMedia (only difference is the prefix). // Code from Adam Barth. getUserMedia = navigator.webkitGetUserMedia.bind(navigator); // Attach a media stream to an element. attachMediaStream = function (element, stream) { element.src = webkitURL.createObjectURL(stream); }; reattachMediaStream = function (to, from) { to.src = from.src; }; // The representation of tracks in a stream is changed in M26. // Unify them for earlier Chrome versions in the coexisting period. if (!webkitMediaStream.prototype.getVideoTracks) { webkitMediaStream.prototype.getVideoTracks = function () { return this.videoTracks; }; webkitMediaStream.prototype.getAudioTracks = function () { return this.audioTracks; }; } // New syntax of getXXXStreams method in M26. if (!webkitRTCPeerConnection.prototype.getLocalStreams) { webkitRTCPeerConnection.prototype.getLocalStreams = function () { return this.localStreams; }; webkitRTCPeerConnection.prototype.getRemoteStreams = function () { return this.remoteStreams; }; } } else { console.log("Browser does not appear to be WebRTC-capable"); } </script>