Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix(event): fix #883, fix RTCPeerConnection Safari event not triggered issue. #905

Merged
merged 1 commit into from
Sep 17, 2017

Conversation

JiaLiPassion
Copy link
Collaborator

fix #883.

in safari, when trigger RTCPeerConnection event handler this context is not the same with the event target when addEventListener.

<html>
  <head>
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.8.16/zone.js"></script>-->
    <script>
      window.onload = function () {
          console.log('Create RTCPeerConnection')
          const pc = new RTCPeerConnection()

          console.log('Add "track" event listener')
          let event
          pc.addEventListener('track', function(_event) {
            console.log('this === pc', this === pc);
            console.log('track event', _event);
            event = _event
          });
          /*pc.ontrack = function(_event) {
            console.log('this === pc', this === pc);
            console.log('track event', _event);
            event = _event
          };*/

          console.log('Dispatch "track" event')
          pc.dispatchEvent(new Event('track'))

          if (event) {
            console.log('Success!')
          } else {
            console.error('Failure!')
       }
      }
    </script>
  </head>
</html>

in above case, this === pc will be false.

So in this PR, we allow user to load an additional js webapis-rtc-peer-connection.js to let zone.js patch RTCPeerConnection without using the globalCallback.

to make this PR available, please load the js as following order.

 <script src="node_modules/zone.js/dist/zone.js"></script>
 <script src="node_modules/zone.js/dist/webapis-rtc-peer-connection.js"></script>

@mhevery mhevery merged commit 6f74efb into angular:master Sep 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zone.js 0.8.13+ breaks addEventListener in Safari 11.0, 11.1
4 participants