RTCPeerConnection addTrack missing in Chrome (version - 55.0.2883.87)

715 views
Skip to first unread message

Mircea Moisoiu

unread,
Jan 26, 2017, 7:58:43 AM1/26/17
to discuss-webrtc
Hello,

I'm trying to make a project with  WebRTC, and while it seems to work on Firefox, on Chrome it throws me an error pc.addTrack is not a function (pc = RTCPeerConnection), does someone know any workaround? 


This is the code that I'm using for comunication between 2 clients and is working on firefox (version 50.1.0)

Any help appreciated 

    function start(id, init) {
        pc = new RTCPeerConnection(configuration);

        // send any ice candidates to the other peer
        pc.onicecandidate = function (evt) {
            chat.server.sendIceCandidate(id, JSON.stringify({ "candidate": evt.candidate }));
        };

        // let the "negotiationneeded" event trigger offer generation
        pc.onnegotiationneeded = function () {
            pc.createOffer().then(function (offer) {
                return pc.setLocalDescription(offer);
            })
            .then(function () {
                // send the offer to the other peer
                chat.server.sendOffer(id, JSON.stringify({ "desc": pc.localDescription }));
            })
            .catch(logError);
        };

        // once remote video track arrives, show it in the remote video element
        pc.ontrack = function (evt) {
            if (evt.track.kind === "video") {
                remoteView.srcObject = evt.streams[0];
            }
        };

        var constraints = { audio: true, video: { width: 640, height: 480, facingMode: "user" } };

        // get a local stream, show it in a self-view and add it to be sent
        navigator.mediaDevices.getUserMedia(constraints)
            .then(function (stream) {
                selfView.srcObject = stream;
                pc.addTrack(stream.getAudioTracks()[0], stream);
                pc.addTrack(stream.getVideoTracks()[0], stream);                
                //stream.getTracks().forEach(track => pc.addTrack(track, stream));

            })
            .catch(logError);
    }




Kushtrim Pacaj

unread,
Jan 26, 2017, 12:34:14 PM1/26/17
to discuss-webrtc
Add track to a media stream, and then add the stream to the peer connection
Reply all
Reply to author
Forward
0 new messages