question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught RTCError: Transport channel closed and app.js:73056 Uncaught Error: Connection failed. at makeError (app.js:73056) at Peer._onConnectionStateChange (app.js:73698) at RTCPeerConnection.Peer._pc.onconnectionstatechange (app.js:73160)

See original GitHub issue

i create one video call application Laravel & ReactJS (based on WebRTC) , in this when i call to another member i get this error

app.js:8443 Uncaught RTCError: Transport channel closed

app.js:73056 Uncaught Error: Connection failed. at makeError (app.js:73056) at Peer._onConnectionStateChange (app.js:73698) at RTCPeerConnection.Peer._pc.onconnectionstatechange (app.js:73160)

here is my code

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import MediaHandler from '../MediaHandler'
import Pusher from "pusher-js";
import Peer from 'simple-peer';

const APP_KEY='347xxxxxxxxxaf756';


export default class App extends Component{

    constructor() {
        super();

        this.state = {
            hasMedia: false,
            otherUserId: null
        };

        this.user = window.user;
        this.user.stream = null;
        this.peers = {};

        this.mediaHandler = new MediaHandler();
        this.setupPusher();

        this.callTo = this.callTo.bind(this);
        this.setupPusher = this.setupPusher.bind(this);
        this.startPeer = this.startPeer.bind(this);
    }

    UNSAFE_componentWillMount(){
        this.mediaHandler.getPermissions()
            .then((stream) => {
                this.setState({hasMedia: true});
                this.user.stream = stream;

                try {
                    this.myVideo.srcObject = stream;
                } catch (e) {
                    this.myVideo.src = URL.createObjectURL(stream);
                }

                this.myVideo.play();
            })
    }

    setupPusher() {
        this.pusher = new Pusher(APP_KEY, {
            authEndpoint: '/pusher/auth',
            cluster: 'ap2',
            auth: {
                params: this.user.id,
                headers: {
                    'X-CSRF-Token': window.csrfToken
                }
            }
        });

        this.channel = this.pusher.subscribe('presence-video-channel');

        this.channel.bind(`client-signal-${this.user.id}`, (signal) => {
            let peer = this.peers[signal.userId];

            // if peer is not already exists, we got an incoming call
            if(peer === undefined) {
                this.setState({otherUserId: signal.userId});
                peer = this.startPeer(signal.userId, false);
            }

            peer.signal(signal.data);
        });
    }

    startPeer(userId, initiator = true) {
        const peer = new Peer({
            initiator,
            stream: this.user.stream,
            trickle: false
        });

        peer.on('signal', (data) => {
            this.channel.trigger(`client-signal-${userId}`, {
                type: 'signal',
                userId: this.user.id,
                data: data
            });
        });

        peer.on('stream', (stream) => {
            try {
                this.userVideo.srcObject = stream;
            } catch (e) {
                this.userVideo.src = URL.createObjectURL(stream);
            }



            // this.userVideo.pause();
            var playPromise =this.userVideo.play();
            if (playPromise !== undefined) {
                playPromise.then(_ => {
                    // Automatic playback started!
                    // Show playing UI.
                })
                    .catch(error => {
                        // Auto-play was prevented
                        // Show paused UI.
                    });
            }
        });

        peer.on('close', () => {
            let peer = this.peers[userId];
            if(peer !== undefined) {
                peer.destroy();
            }

            this.peers[userId] = undefined;
        });

        return peer;
    }

    callTo(userId) {
        this.peers[userId] = this.startPeer(userId);
    }

    render(){

        return(
            <div className="App">
                {[1,2,3,4].map((userId) => {
                    return this.user.id !== userId ? <button key={userId} onClick={() => this.callTo(userId)}>Call {userId}</button> : null;
                })}
                <div className="video-container">
                    <video className="my-video" ref={(ref) => {this.myVideo = ref;}}></video>
                    <video className="user-video" ref={(ref) => {this.userVideo = ref;}}></video>
                </div>
             </div>
        );
    }
}

if (document.getElementById('app')) {
    ReactDOM.render(<App />, document.getElementById('app'));
}

anyone help mee thanks in advance

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nazar-pccommented, Jul 23, 2020

There are many reasons this could happen. I’m not going to debug your code, sorry. If you can make reproducible demo or clearly define where is the issue in simple-peer itself that is fine, otherwise this is not a generic WebRTC support forum, so we can’t physically help everyone with their apps.

1reaction
RahulDey12commented, Jul 23, 2020

I am also facing this same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

peer.destroy() throws RTCErrorEvent · Issue #657 - GitHub
Uncaught RTCError : Transport channel closed and app.js:73056 Uncaught Error: Connection failed. at makeError (app.js:73056) at Peer.
Read more >
Uncaught Error: Connection failed. rtcpeerconnection.t._pc ...
Here Is the Reactjs Component code It works fine in the same browser after deploying to heroku but when we join room from...
Read more >
index.js:107 subscribe failed Error: connection failed. (v.4.3)
Hello Team, We are currently using Intel CS for WebRTC frame work v.4.2.1 and successfully rinning. Now, We installed v.4.3 on both CentOS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found