Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Created April 23, 2015 13:53
Show Gist options
  • Save ryaninvents/6760a3daa7189e5b6ce1 to your computer and use it in GitHub Desktop.
Save ryaninvents/6760a3daa7189e5b6ce1 to your computer and use it in GitHub Desktop.
Creating an offer with RTCPeerConnection
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>Creating an offer using <a href="https://github.com/otalk/RTCPeerConnection">RTCPeerConnection</a></h1>
<pre></pre>
<script src="https://rawgit.com/otalk/RTCPeerConnection/master/rtcpeerconnection.bundle.js"></script>
<script src="index.js"></script>
</body>
</html>
function main(){
var config = {
debug: false,
// makes the entire PC config overridable
peerConnectionConfig: {
iceServers: [{"url": "stun:stun.l.google.com:19302"}]
},
peerConnectionConstraints: {
optional: [
{DtlsSrtpKeyAgreement: true}
]
},
receiveMedia: {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
},
enableDataChannels: true
};
var pc = new PeerConnection(config);
// create an offer
pc.offer(function (err, offer) {
if (!err) $('pre').html(
JSON.stringify(offer, null, 2)
.replace(/\n/g,'<br>')
.replace(/\\r\\n/g, '<br> ')
.replace(/ /g, '&nbsp;')
);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment