Skip to content

Instantly share code, notes, and snippets.

@SumindaD
Created October 10, 2019 06:33
Show Gist options
  • Save SumindaD/e545b6b43d6973a3acfcabdece31c37d to your computer and use it in GitHub Desktop.
Save SumindaD/e545b6b43d6973a3acfcabdece31c37d to your computer and use it in GitHub Desktop.
function createAndSendOffer(){
if(channel){
channel.close();
}
// Create Data channel
channel = connection.createDataChannel('channel', {});
setChannelEvents(channel);
// Create Offer
connection.createOffer().then(
offer => {
log('Sent The Offer.');
// Send Offer to other peer
socket.send(JSON.stringify(
{
action: 'onMessage',
type: 'offer',
data: offer,
id: clientId
}
));
// Set Offer for negotiation
connection.setLocalDescription(offer);
},
error => {
log('Error when creating an offer.');
console.error(error);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment