Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SaurabhKharivale/266d7d4536956a9161c0121061c2cecf to your computer and use it in GitHub Desktop.
Save SaurabhKharivale/266d7d4536956a9161c0121061c2cecf to your computer and use it in GitHub Desktop.
webrtc.js
const iceConfiguration = { }
iceConfiguration.iceServers = [];
//turn server
iceConfiguration.iceServers.push({
urls: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'webrtc@live.com'
})
iceConfiguration.iceServers.push({
urls: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
})
iceConfiguration.iceServers.push({
urls: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
})
//stun server
iceConfiguration.iceServers.push({ urls: 'stun:stun1.l.google.com:19302' })
iceConfiguration.iceServers.push({ urls: 'stun:stun2.l.google.com:19302' })
iceConfiguration.iceServers.push({ urls: 'stun:stun3.l.google.com:19302' })
iceConfiguration.iceServers.push({ urls: 'stun:stun4.l.google.com:19302' })
iceConfiguration.iceServers.push({ urls: 'stun:stun01.sipphone.com' })
iceConfiguration.iceServers.push({ urls: 'stun:stunserver.org' })
const localConnection = new RTCPeerConnection(iceConfiguration)
localConnection.onicecandidate = e => {
console.log(" NEW ice candidnat!! on localconnection reprinting SDP " )
console.log(JSON.stringify(localConnection.localDescription))
}
const sendChannel = localConnection.createDataChannel("sendChannel");
sendChannel.onmessage =e => console.log("messsage received!!!" + e.data )
sendChannel.onopen = e => console.log("open!!!!");
sendChannel.onclose =e => console.log("closed!!!!!!");
localConnection.createOffer().then(o => localConnection.setLocalDescription(o) )
//this opens the connection
localConnection.setRemoteDescription (answer).then(a=>console.log("done"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment