Last active
May 21, 2023 01:52
-
-
Save tegila/b70d2119c74eb84edf1f2bca30d242d5 to your computer and use it in GitHub Desktop.
This file contains 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
const log = console.log; | |
(async () => { | |
const localConnection = new RTCPeerConnection(); | |
log(localConnection); | |
const lsendChannel = localConnection.createDataChannel("sendChannel"); | |
const remoteConnection = new RTCPeerConnection(); | |
log(remoteConnection); | |
const rsendChannel = remoteConnection.createDataChannel("sendChannel"); | |
localConnection.onicecandidate = (e) => | |
!e.candidate || remoteConnection.addIceCandidate(e.candidate).catch(log); | |
remoteConnection.onicecandidate = (e) => | |
!e.candidate || localConnection.addIceCandidate(e.candidate).catch(log); | |
// offer | |
const offer = await localConnection.createOffer(); | |
log(offer); | |
await localConnection.setLocalDescription(offer); | |
// answer | |
await remoteConnection.setRemoteDescription(localConnection.localDescription); | |
const answer = await remoteConnection.createAnswer(); | |
await remoteConnection.setLocalDescription(answer); | |
// finish | |
await localConnection.setRemoteDescription(remoteConnection.localDescription); | |
log(remoteConnection); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment