Created
November 25, 2014 17:54
-
-
Save ivmos/8d0c1e1bd09fe27761ff to your computer and use it in GitHub Desktop.
Intro to WebRTC: offer, receive offer, create answer, receive answer
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
<video id="v" /> |
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
isCaller = true; | |
error = function (error) { | |
console.log(error); | |
} | |
if (isCaller) { | |
pc = new webkitRTCPeerConnection({ | |
"iceServers": [] | |
}); | |
navigator.webkitGetUserMedia({ | |
video: true, | |
audio: true | |
}, | |
function (localMediaStream) { | |
pc.addStream(localMediaStream); | |
pc.createOffer(function (offer) { | |
pc.setLocalDescription( | |
new RTCSessionDescription(offer), | |
function () { | |
console.log(offer.sdp); | |
console.log("Paste on callee:"); | |
console.log("receiveOffer(atob('" + btoa(offer.sdp) + "'))"); | |
}); | |
}); | |
}, | |
error | |
); | |
} | |
receiveOffer = function (offerSdp) { | |
pc = new webkitRTCPeerConnection({ | |
"iceServers": [] | |
}); | |
navigator.webkitGetUserMedia({ | |
video: true, | |
audio: true | |
}, | |
function (localMediaStream) { | |
pc.addStream(localMediaStream); | |
pc.setRemoteDescription(new RTCSessionDescription({ | |
type: "offer", | |
sdp: offerSdp | |
}), | |
function () { | |
pc.createAnswer(function (answer) { | |
pc.setLocalDescription(answer); | |
console.log(answer.sdp); | |
console.log("Paste on caller:"); | |
console.log("receiveAnswer(atob('" + btoa(answer.sdp) + "'))"); | |
}, | |
error, { | |
mandatory: { | |
OfferToReceiveAudio: true, | |
OfferToReceiveVideo: true | |
} | |
}); | |
}, | |
error); | |
}, | |
error); | |
} | |
receiveAnswer = function (answerSdp) { | |
pc.setRemoteDescription(new RTCSessionDescription({ | |
type: "answer", | |
sdp: answerSdp | |
})); | |
} |
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
name: Intro to WebRTC | |
description: offer, receive offer, create answer, receive answer | |
authors: | |
- Iván Mosquera Paulo | |
resources: | |
- http://some.url.com/some/file.js | |
- http://other.url.com/other_filename.css | |
normalize_css: no | |
wrap: l | |
panel_js: 0 | |
panel_css: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment