mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 07:06:51 +08:00
Move JSfiddle snippets to git
jsfiddle provides a way to create snippets from Github via a URL. This way we can still provide easy demos, but get all the nice things from having them in Git Closes #32
This commit is contained in:
31
examples/save-to-disk/jsfiddle/demo.js
Normal file
31
examples/save-to-disk/jsfiddle/demo.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/* eslint-env browser */
|
||||
|
||||
let pc = new RTCPeerConnection()
|
||||
var log = msg => {
|
||||
document.getElementById('logs').innerHTML += msg + '<br>'
|
||||
}
|
||||
|
||||
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
||||
.then(stream => pc.addStream(document.getElementById('video1').srcObject = stream))
|
||||
.catch(log)
|
||||
|
||||
pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
|
||||
|
||||
pc.onnegotiationneeded = e =>
|
||||
pc.createOffer().then(d => {
|
||||
document.getElementById('localSessionDescription').value = btoa(d.sdp)
|
||||
return pc.setLocalDescription(d)
|
||||
}).catch(log)
|
||||
|
||||
window.startSession = () => {
|
||||
let sd = document.getElementById('remoteSessionDescription').value
|
||||
if (sd === '') {
|
||||
return alert('Session Description must not be empty')
|
||||
}
|
||||
|
||||
try {
|
||||
pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: atob(sd)}))
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user