-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.js
More file actions
24 lines (16 loc) · 850 Bytes
/
a.js
File metadata and controls
24 lines (16 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Creating a local connection
const localConnection = new RTCPeerConnection()
// Creating a data channel for webRTC, when the name of that channel
const dataChannel = localConnection.createDataChannel("channel")
// Subscribing to important events
dataChannel.onmessage = e => console.log(`Message received: ${e.data}`)
dataChannel.onopen = e => console.log('Connection established')
// Every time we get ice candidate reprint SDP
// Will be called multiple times
localConnection.onicecandidate = e => console.log(`SDP: ${JSON.stringify(localConnection.localDescription)}`)
// Creating an offer
localConnection.createOffer().then(offer => localConnection.setLocalDescription(offer)).then(() => console.log('SDP updated'))
// Last step (after b)
const answer = {""}
localConnection.setRemoteDescription(answer)
dataChannel.send("Hello world")