-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.js
More file actions
23 lines (16 loc) · 959 Bytes
/
b.js
File metadata and controls
23 lines (16 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const offer = {""} // SDP from a
// Creating a remote connection
const remoteConnection = new RTCPeerConnection()
// Every time we get ice candidate reprint SDP
// Will be called multiple times
remoteConnection.onicecandidate = e => console.log(`SDP: ${JSON.stringify(remoteConnection.localDescription)}`)
remoteConnection.ondatachannel = e => {
// getting a remote channel, and we need to save that channel
remoteConnection.dc = e.channel // creating a new variable dc, assigning to received channel
remoteConnection.dc.onmessage = e => console.log(`Message received: ${e.data}`)
remoteConnection.dc.onopen = e => console.log('Connection established')
}
remoteConnection.setRemoteDescription(offer).then(() => console.log('Offer set'))
remoteConnection.createAnswer().then(answer => remoteConnection.setLocalDescription(answer)).then(() => console.log('Answer created')) // triggers onicecandidate
// Last step
remoteConnection.dc.send("Test")