WebRTC Turn/Stun config

This commit is contained in:
Abdussamed 2023-04-27 22:40:59 +03:00
parent 2f572972d8
commit 07b871e374
3 changed files with 44 additions and 19 deletions

View File

@ -26,28 +26,53 @@ export default class WebRTC
public events : { [eventname:string]: Function[] } = {}; public events : { [eventname:string]: Function[] } = {};
public channel : RTCDataChannel | undefined; public channel : RTCDataChannel | undefined;
public static defaultRTCConfig : RTCConfiguration = {
iceCandidatePoolSize: 0,
iceTransportPolicy:"all",
rtcpMuxPolicy:"require",
};
public static defaultICEServers : RTCIceServer[] = [{
urls: "stun:stun.l.google.com:19302"
},{
urls: "stun:stun1.l.google.com:19302"
},{
urls: "stun:stun2.l.google.com:19302"
},{
urls: "stun:stun3.l.google.com:19302"
},{
urls: "stun:stun4.l.google.com:19302"
}];
public peer? : Peer; public peer? : Peer;
public FileTransportChannel? : P2PFileSender; public FileTransportChannel? : P2PFileSender;
constructor() constructor(
rtcConfig?: RTCConfiguration,
rtcServers?: RTCIceServer[]
)
{ {
this.rtc = new RTCPeerConnection({ let config : any = {};
iceCandidatePoolSize: 0,
iceTransportPolicy:"all", if(rtcConfig)
rtcpMuxPolicy:"require", {
iceServers:[{ Object.assign(
urls: "stun:stun.l.google.com:19302" config,
},{ WebRTC.defaultRTCConfig,
urls: "stun:stun1.l.google.com:19302" rtcConfig
},{ )
urls: "stun:stun2.l.google.com:19302" }else{
},{ Object.assign(
urls: "stun:stun3.l.google.com:19302" config,
},{ WebRTC.defaultRTCConfig
urls: "stun:stun4.l.google.com:19302" )
}] }
});
config.iceServers = rtcServers || WebRTC.defaultICEServers;
this.rtc = new RTCPeerConnection(config as RTCConfiguration);
this.rtc.addEventListener("connectionstatechange",()=>{ this.rtc.addEventListener("connectionstatechange",()=>{
this.eventConnectionState(); this.eventConnectionState();
}) })

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long