Advertisement
Guest User

Untitled

a guest
Jan 17th, 2022
4,809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. (async () => {
  2. await import('https://code.jquery.com/jquery-2.2.4.min.js');
  3.  
  4. jQuery("body").append(jQuery("<textarea>").attr("id", "localSessionDescription"));
  5. jQuery("body").append(jQuery("<textarea>").attr("id", "remoteSessionDescription"));
  6. jQuery("body").append(jQuery("<button>").text("Start session").attr("onclick", "window.startSession()"));
  7. jQuery("body").append(jQuery("<div>").attr("id", "logs"));
  8.  
  9. let pc = new RTCPeerConnection({
  10. iceServers: [
  11. {
  12. urls: ['stun:123123123123', 'turn:123123123123'],
  13. username: 'USERNAME',
  14. credential: 'PASSWORD'
  15. }
  16. ]
  17. })
  18. var log = msg => {
  19. document.getElementById('logs').innerHTML += msg + '<br>'
  20. }
  21.  
  22. navigator.mediaDevices.getUserMedia({ video: true, audio: true })
  23. .then(stream => {
  24.  
  25. var videoStream = document.querySelector('.videoMain_2XS71565b7').captureStream();
  26. videoStream.getTracks().forEach(track => pc.addTrack(track, videoStream));
  27.  
  28. pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log)
  29. }).catch(log)
  30.  
  31. pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)
  32. pc.onicecandidate = event => {
  33. if (event.candidate === null) {
  34. document.getElementById('localSessionDescription').value = btoa(JSON.stringify(pc.localDescription))
  35. }
  36. }
  37.  
  38. window.startSession = () => {
  39. let sd = document.getElementById('remoteSessionDescription').value
  40. if (sd === '') {
  41. return alert('Session Description must not be empty')
  42. }
  43.  
  44. try {
  45. pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd))))
  46. } catch (e) {
  47. alert(e)
  48. }
  49. }
  50. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement