Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async () => {
- await import('https://code.jquery.com/jquery-2.2.4.min.js');
- jQuery("body").append(jQuery("<textarea>").attr("id", "localSessionDescription"));
- jQuery("body").append(jQuery("<textarea>").attr("id", "remoteSessionDescription"));
- jQuery("body").append(jQuery("<button>").text("Start session").attr("onclick", "window.startSession()"));
- jQuery("body").append(jQuery("<div>").attr("id", "logs"));
- let pc = new RTCPeerConnection({
- iceServers: [
- {
- urls: ['stun:123123123123', 'turn:123123123123'],
- username: 'USERNAME',
- credential: 'PASSWORD'
- }
- ]
- })
- var log = msg => {
- document.getElementById('logs').innerHTML += msg + '<br>'
- }
- navigator.mediaDevices.getUserMedia({ video: true, audio: true })
- .then(stream => {
- var videoStream = document.querySelector('.videoMain_2XS71565b7').captureStream();
- videoStream.getTracks().forEach(track => pc.addTrack(track, videoStream));
- pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log)
- }).catch(log)
- pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
- pc.onicecandidate = event => {
- if (event.candidate === null) {
- document.getElementById('localSessionDescription').value = btoa(JSON.stringify(pc.localDescription))
- }
- }
- window.startSession = () => {
- let sd = document.getElementById('remoteSessionDescription').value
- if (sd === '') {
- return alert('Session Description must not be empty')
- }
- try {
- pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd))))
- } catch (e) {
- alert(e)
- }
- }
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement