implemented remote streames logic

Signed-off-by: heyhiru <hirentimbadiya74@gmail.com>
Este commit está contenido en:
heyhiru
2023-11-11 20:14:31 +05:30
padre 737b080be0
commit 0068bc39c2
Se han modificado 3 ficheros con 178 adiciones y 19 borrados

39
client/src/service/peer.js Archivo normal
Ver fichero

@@ -0,0 +1,39 @@
class PeerService {
constructor() {
if (!this.peer) {
this.peer = new RTCPeerConnection({
iceServers: [{
urls: [
"stun:stun.l.google.com:19302",
"stun:global.stun.twilio.com:3478",
]
}]
})
}
}
setLocalDescription = async (ans) => {
if(this.peer){
await this.peer.setRemoteDescription(new RTCSessionDescription(ans));
}
}
getAnswer = async (offer) => {
if(this.peer){
await this.peer.setRemoteDescription(offer);
const ans = await this.peer.createAnswer();
await this.peer.setLocalDescription(new RTCSessionDescription(ans));
return ans;
}
}
getOffer = async () => {
if (this.peer) {
const offer = await this.peer.createOffer();
await this.peer.setLocalDescription(new RTCSessionDescription(offer));
return offer;
}
}
}
export default new PeerService();