Skip to content

Commit

Permalink
Merge pull request #121 from notmariazoe/step06-spdparams
Browse files Browse the repository at this point in the history
Fixes step06 according to latest specs: sdpParams in RTCIceCandidate constructor and use promises
  • Loading branch information
samdutton authored Nov 4, 2020
2 parents 93b2d7c + d030e4f commit c96ce33
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions step-06/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ function signalingMessageCallback(message) {

} else if (message.type === 'candidate') {
peerConn.addIceCandidate(new RTCIceCandidate({
candidate: message.candidate
candidate: message.candidate,
sdpMLineIndex: message.label,
sdpMid: message.id
}));

}
}

Expand Down Expand Up @@ -218,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 @@ -230,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 c96ce33

Please sign in to comment.