simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.65k stars 1.19k forks source link

.disconnect causes errors in console #745

Open stiv-yakovenko opened 6 years ago

stiv-yakovenko commented 6 years ago

If I call .disconnect, then this code is executed:

SimpleWebRTC.prototype.disconnect = function () {
    if (this.connection) {
        this.connection.disconnect();
        delete this.connection;
    }
};

so later it will crash here:

this.webrtc.on('message', function (payload) {
        self.connection.emit('message', payload);
    });

since self.connection is undefined.

dcotoz commented 5 years ago

I guess you can check if the connection is still active before calling emit

stiv-yakovenko commented 5 years ago

it is not me calling self.connection.emit, this is webrtc calling it:

this.webrtc.on('message', function (payload) { self.connection.emit('message', payload); });