Guest User

Untitled

a guest
Jul 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. window.mySocket.onmessage = function(event){
  2. var signal = JSON.parse(event.data);
  3. if (signal.sdp) {
  4. if(init){
  5. log('received offer...');
  6. pc.setRemoteDescription(new RTCSessionDescription(signal))
  7. .then(function(){
  8. pc.createAnswer()
  9. .then(function(answer) {
  10. log('created answer...');
  11. return pc.setLocalDescription(answer);
  12. })
  13. .then(function() {
  14. log('sent answer');
  15. window.mySocket.send(JSON.stringify(pc.localDescription));
  16. })
  17. .catch(function(reason) {
  18. log(reason)
  19. });
  20. })
  21. .catch(function(reason) {
  22. log(reason)
  23. });
  24. }else{
  25. log('received offer...');
  26. pc.setRemoteDescription(signal)
  27. }
  28. }else if(signal.candidate){
  29. pc.addIceCandidate(new RTCIceCandidate(signal));
  30. }
  31.  
  32. }
Add Comment
Please, Sign In to add comment