Created
October 10, 2019 06:33
-
-
Save SumindaD/e545b6b43d6973a3acfcabdece31c37d 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