jeudi 23 novembre 2017

Simple-Peer WebRTC App Using Firebase Error: Error processing ICE candidate

I am using Firebase as a signaling intermediary between two tabs in google chrome on my local computer. I am using the most recent build on the simple-peer github repo: simplepeer.min.js. The full error is

Uncaught DOMException: Error processing ICE candidate

My netcode is as follows:

const roomId = extractQueryString('roomId');
firebase.auth().onAuthStateChanged((user) => {
    if (user && roomId) {
    // User is signed in.
    const isAnonymous = user.isAnonymous;
    const uid = user.uid;
    const sessionId = Math.floor(Math.random()*1000000000);
    const testLocation = firebase.database().ref();
    console.log(uid);

    //doesRoomExist(roomId); 

    const p2pConnection = new SimplePeer({
        initiator: document.location.hash === '#initiator'
    });

    p2pConnection.on( 'signal', (signal) => {
        console.log(signal);
        testLocation.child(roomId).child(uid).set({
            sender: sessionId,
            signal: signal
        });
    });

    testLocation.child(roomId).on('child_added', (snapshot) =>{
        if( snapshot.val().sender !== sessionId ) {
            p2pConnection.signal( snapshot.val().signal );
        }
    });

    /*
     * We'll send a message to the other side as soon as
     * the connection is established
     */
    p2pConnection.on( 'connect', () => {
        console.log( 'webrtc datachannel connected' );
        p2pConnection.send( 'Hello from user ' + userName );
    });

    p2pConnection.on( 'close', () => {
        console.log( 'webrtc datachannel closed' );
    });

    p2pConnection.on( 'data', (data) => {
        console.log( 'received data <b>' + data + '</b>' );
    });

    //db.ref().child('ergh').set({ID:uid});
} else {
    // Do stuff if they inputted an invalid room or fb is down
}
});

The error occurs when I open the second browser window and the code:

    testLocation.child(roomId).on('child_added', (snapshot) =>{
    if( snapshot.val().sender !== sessionId ) {
        p2pConnection.signal( snapshot.val().signal );
    }
});

executes.

In case I am missing anything, here is my Index.html:

<!DOCTYPE html>
<html>
    <script src="http://ift.tt/2zvU8cx">
</script>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: "AIzaSyAUEtS1zEakv0a1TIlsTobQwwTyvlUzQGc",
            authDomain: "simple-whiteboard.firebaseapp.com",
            databaseURL: "http://ift.tt/2mT5rWh",
            projectId: "simple-whiteboard",
            storageBucket: "simple-whiteboard.appspot.com",
            messagingSenderId: "272918396058"
        };
        firebase.initializeApp(config);

    firebase.auth().signInAnonymously().catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
    });

</script>
<script src="js/simplepeer.min.js"></script>
<script src="js/draw.js"></script>
<script src="js/RTC-networking.js"></script>

<body onload="init()">
        <canvas id="myCanvas" width="400" height="400"
            style="position:absolute;top:10%;left:10%;border:2px solid;">
        </canvas>
</body>

Any help will be much appreciated. Thank you.




Aucun commentaire:

Enregistrer un commentaire