Forked from SumindaD/WebRTCChat_createAndSendOffer.js
Created
November 26, 2020 14:15
-
-
Save Amit2016-17/3ba7f851791090890594f84e8bd34660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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