Last active
August 29, 2015 13:59
-
-
Save sukhmeet2390/10446179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init(){ | |
localConnection = new RTCPeerConnection(SERVER); | |
localConnection.onicecandidate = function(event){ | |
event.candidate && remoteConnection.addIceCandidate(event.candidate); | |
}; | |
dataChannel = localConnection.createDataChannel("sendDataChannel"); | |
dataChannel.onerror = handleError; | |
//dataChannel.onmessage = function(event){console.log("message recieved" + event.data);} | |
dataChannel.onopen = function(){console.log("Hello world dataChannel is now open");} | |
dataChannel.onclose = function(){console.log("Bye ! Data Channel is now closing");} | |
remoteConnection = new RTCPeerConnection(SERVER); | |
remoteConnection.onicecandidate = function(event){ | |
event.candidate && localConnection.addIceCandidate(event.candidate); | |
}; | |
remoteConnection.ondatachannel = gotDataOnChannel; | |
localConnection.createOffer(sucessfullOffer, handleError); | |
} | |
function sucessfullOffer(description){ | |
//setLocalDescription | |
remoteConnection.setRemoteDescription(description, function(){ // using call back now to avoid race condition https://groups.google.com/forum/#!topic/discuss-webrtc/9zs21EBciNM | |
remoteConnection.createAnswer(sucessfullRemoteAnswer, handleError); | |
localConnection.setLocalDescription(description); | |
}); | |
} | |
function sucessfullRemoteAnswer(description){ | |
localConnection.setRemoteDescription(description); | |
remoteConnection.setLocalDescription(description); | |
} | |
function gotDataOnChannel(event){ | |
recieveChannel = event.channel; | |
recieveChannel.onmessage = function(message){ | |
area2.value = message.data; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment