Last active
August 16, 2019 09:03
-
-
Save yinxin630/29da61f1f447551adce868609fc11351 to your computer and use it in GitHub Desktop.
|-|&tag=code
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
| <title>webrtc</title> | |
| </head> | |
| <body> | |
| <script> | |
| console.log('start'); | |
| const reveiveConnection = new RTCPeerConnection(); | |
| reveiveConnection.addEventListener('icecandidate', (event) => { | |
| console.log('-- receiver icecandidate --', JSON.stringify(event.candidate)); | |
| }); | |
| reveiveConnection.addEventListener('datachannel', (event) => { | |
| console.log('-- datachannel --', event.channel); | |
| event.channel.onmessage = ({ data }) => { | |
| console.log('receive data', data); | |
| reveiveConnection.close(); | |
| }; | |
| }); | |
| window.setOffer = async (sdp) => { | |
| const offer = new RTCSessionDescription({ | |
| sdp, | |
| type: 'offer', | |
| }); | |
| await reveiveConnection.setRemoteDescription(offer); | |
| const answer = await reveiveConnection.createAnswer(); | |
| console.log('answer', JSON.stringify(answer.sdp)); | |
| await reveiveConnection.setLocalDescription(answer); | |
| }; | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment