# RTCPeerConnection event 'ontrack' not work

**URL:** <https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447>\
**Category:** General\
**Created:** [January 24, 2020, 6:46pm UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447 "2020-01-24T18:46:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![talesborn](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/talesborn/32/135_2.png) [@talesborn](https://react-native-webrtc.discourse.group/u/talesborn)\
**Post date:** [January 24, 2020, 6:46pm UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447/1 "2020-01-24T18:46:50Z")

</div>

I’m try implement a video call, but i don’t receive the RTCPeerConnection.ontrack event, in my React Native App, only on web system, I also verified if exists a method to implement it in React Native App, but i don’t finded

Someone can me help?

---

<div class="post-metadata">

**Author:** ![talesborn](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/talesborn/32/135_2.png) [@talesborn](https://react-native-webrtc.discourse.group/u/talesborn)\
**Post date:** [January 25, 2020, 11:36am UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447/2 "2020-01-25T11:36:51Z")

</div>

Someone can me help here???

I have create the post yesterday,  
and nobody even visualized, i need help!!!

---

<div class="post-metadata">

**Author:** ![cryptotractor](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/cryptotractor/32/131_2.png) [@cryptotractor](https://react-native-webrtc.discourse.group/u/cryptotractor)\
**Post date:** [January 30, 2020, 1:54am UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447/3 "2020-01-30T01:54:03Z")

</div>

I was able to use this example to get it going on my react Native app I had to use a a device it won’t work on an emulator or simulator not sure if this will help you but check it out [https://github.com/baconcheese113/react-native-webrtc-minimal](https://github.com/baconcheese113/react-native-webrtc-minimal)

---

<div class="post-metadata">

**Author:** ![talesborn](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/talesborn/32/135_2.png) [@talesborn](https://react-native-webrtc.discourse.group/u/talesborn)\
**Post date:** [January 31, 2020, 8:14pm UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447/4 "2020-01-31T20:14:55Z")

</div>

Thanks @cryptotractor, i executed with another way the stream, see you how i did use the plugin [https://github.com/react-native-webrtc/react-native-webrtc](https://github.com/react-native-webrtc/react-native-webrtc)

```
stream_start(isCaller) {
    let configuration = {
        "iceServers": [
            {url: "stun:opasuite13.ixcsoft.com.br:3478"},
            {username: "opasuite", url: "stun:opasuite13.ixcsoft.com.br", credential: "opasuite"}
        ]
    };
    global.pc = new RTCPeerConnection(configuration);
    global.pc.onicecandidate = (event) => {
        if (event.candidate) {
            global.webview.postMessage(JSON.stringify({
                tipo: 'stream_ice',
                candidate: event.candidate
            }));
        }
    };

    global.pc.onaddstream = function (e) {
        global.WebRTCView.setState({videoURLClient: e.currentTarget._remoteStreams[0].toURL()});
    };

    global.pc.addStream(global.localStream);

    if (isCaller) {
        global.webview.postMessage(JSON.stringify({
            tipo: 'stream_aceita'
        }));

        global.pc.createOffer().then(this.createDescription).catch((error) => {
            console.log(error);
        })
    }

    global.webview.postMessage(JSON.stringify({
        tipo: 'stream_cancela_conexoes'
    }));
}

```

Below is my code when I receive the stream. I used this, because the “ontrack” does not is implemented in the react-native-webrtc plugin

```
global.pc.onaddstream = function (e) {
        global.WebRTCView.setState({videoURLClient: e.currentTarget._remoteStreams[0].toURL()});
    };

```

One more turn, I have to thank for your solution! Thanks @cryptotractor !!!

---

<div class="post-metadata">

**Author:** ![HugoAlvesdutra](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/hugoalvesdutra/32/520_2.png) [@HugoAlvesdutra](https://react-native-webrtc.discourse.group/u/HugoAlvesdutra)\
**Post date:** [October 30, 2021, 12:49pm UTC](https://react-native-webrtc.discourse.group/t/rtcpeerconnection-event-ontrack-not-work/447/5 "2021-10-30T12:49:47Z")

</div>

onaddstream works on mobile devices. Its deprecated, but works.
