Skip to content

Commit

Permalink
Updated createOffer to use promises instead of callbacks as they were…
Browse files Browse the repository at this point in the history
… deprecated. Fixes sending first offer null description.
  • Loading branch information
notmariazoe committed Nov 2, 2020
1 parent d621aa6 commit d030e4f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions step-06/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,15 @@ if (isInitiator) {
onDataChannelCreated(dataChannel);

console.log('Creating an offer');
peerConn.createOffer(onLocalSessionCreated, logError);
peerConn.createOffer().then(function(offer) {
return peerConn.setLocalDescription(offer);
})
.then(() => {
console.log('sending local desc:', peerConn.localDescription);
sendMessage(peerConn.localDescription);
})
.catch(logError);

} else {
peerConn.ondatachannel = function(event) {
console.log('ondatachannel:', event.channel);
Expand All @@ -232,10 +240,10 @@ if (isInitiator) {

function onLocalSessionCreated(desc) {
console.log('local session created:', desc);
peerConn.setLocalDescription(desc, function() {
peerConn.setLocalDescription(desc).then(function() {
console.log('sending local desc:', peerConn.localDescription);
sendMessage(peerConn.localDescription);
}, logError);
}).catch(logError);
}

function onDataChannelCreated(channel) {
Expand Down

0 comments on commit d030e4f

Please sign in to comment.