mardi 28 janvier 2020

Peerjs doesn't open connection with no errors (react)

I almost completely copied an example from https://peerjs.com/docs.html#start, but suddenly it fell down (yesterday it's was working, but not today)

here is my peerjs peace of code

componentDidMount = () => {
    this.peer = new Peer()
    if (this.state.join === "host") {
        this.peer = new Peer()
        this.peer.on("error", err => {
            console.log("error: ", err)
        })
        this.peer.on("open", id => {
            this.props.dispatch({type: "SetPeerId", value: id})
            console.log(id)
        })
        this.peer.on("connection", (con) => {
            console.log("connection opened")
            con.on("data", i => {
                console.log(i)
            })
        })
    } else {
        this.peer = new Peer()
        var con = this.peer.connect(this.state.join)
        con.on("open", () => {
            console.log("opened")
            setInterval(() => {
                con.send("HERE WE ARE")
            }, 100)
        })
        con.on("error", err => {
            console.log("error ", err)
        })
    }
}



Aucun commentaire:

Enregistrer un commentaire