E
E
EYPPNM2019-03-29 19:48:01
JavaScript
EYPPNM, 2019-03-29 19:48:01

What does this code: webrtc-patch.js do?

In continuation to the question toster.ru/q/617746
why many projects on GitHub use this code, what does it do:

'use strict';

window.addEventListener('message', function (e) {
  if (e.origin !== window.location.origin) {
    return;
  }
  if (e.data.to !== 'content') {
    return;
  }
  if (e.data.type === 'webrtc-reload') {
    window.location.reload();
  }
});

(function modifyWebRTC(apis) {
  apis.forEach(function (api) {
    if (!(api && api.prototype.createOffer)) {
      return;
    }
    var createOffer = api.prototype.createOffer;
    api.prototype.createOffer = function () {
      window.postMessage({
        type: 'webrtc-call',
        to: 'background'
      }, window.location.origin);
      return createOffer.apply(this, [].slice.call(arguments));
    };
  });
})([window.RTCPeerConnection, window.webkitRTCPeerConnection, window.mozRTCPeerConnection, window.msRTCPeerConnection]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-03-29
@AleksandrB

1) tuk
2) beech
read more about them yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question