Skip to content

Commit

Permalink
Modernize doSignalingHandshake
Browse files Browse the repository at this point in the history
  • Loading branch information
youennf committed Dec 8, 2018
1 parent c7baefa commit b8e143a
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,32 +222,27 @@ function exchangeIceCandidates(pc1OrQueue, pc2OrQueue) {
}

// Helper function for doing one round of offer/answer exchange
// betweeen two local peer connections
function doSignalingHandshake(localPc, remotePc, options={}) {
return localPc.createOffer()
.then(offer => {
// Modify offer if callback has been provided
if (options.modifyOffer) {
offer = options.modifyOffer(offer);
}
// between two local peer connections
async function doSignalingHandshake(localPc, remotePc, options={}) {
let offer = await localPc.createOffer();
// Modify offer if callback has been provided
if (options.modifyOffer) {
offer = await options.modifyOffer(offer);
}

// Apply offer
return Promise.all([
localPc.setLocalDescription(offer),
remotePc.setRemoteDescription(offer)])
})
.then(() => remotePc.createAnswer())
.then(answer => {
// Modify answer if callback has been provided
if (options.modifyAnswer) {
answer = options.modifyAnswer(answer);
}
// Apply offer
await localPc.setLocalDescription(offer);
await remotePc.setRemoteDescription(offer);

let answer = await remotePc.createAnswer();
// Modify answer if callback has been provided
if (options.modifyAnswer) {
answer = await options.modifyAnswer(answer);
}

// Apply answer
return Promise.all([
remotePc.setLocalDescription(answer),
localPc.setRemoteDescription(answer)])
});
await remotePc.setLocalDescription(answer);
await localPc.setRemoteDescription(answer);
}

// Helper function to create a pair of connected data channel.
Expand Down

0 comments on commit b8e143a

Please sign in to comment.