ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.23k stars 618 forks source link

DataChannel error on conference.html #3888

Open golgetahir opened 2 years ago

golgetahir commented 2 years ago

Short description

Datachannel sends error when you leave the room while it is enabled to send a notification.

Environment

Steps to reproduce

  1. Enable datachannel for publisher and player
  2. Join room
  3. Leave room

Expected behavior

Not to get an error from datachannel.

Actual behavior

This error is logged:

Data Channel Error: RTCErrorEvent {isTrusted: true, error: RTCError: Transport channel closed, type: 'error', target: RTCDataChannel, currentTarget: RTCDataChannel, …}

golgetahir commented 2 years ago

Hi all

What is going on here is that, before the datachannel closes, the peers leaves the stream. In that case datachannel thinks the stream is still live and tries to send some data ( not important since you already left the stream, just ping like data ) and this error is logged since the stream is ended. You can just ignore this exception or close the data channel earlier while leaving such as;

Change following function in webrtc_adaptor.js (link: https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/js/webrtc_adaptor.js#L605)

leaveFromRoom(roomName, streamId) 
    {
        this.roomName = roomName;
        var jsCmd = {
                command : "leaveFromRoom",
                room: roomName,
        };
        console.log ("leave request is sent for "+ roomName);
        if (this.remotePeerConnection[streamId].dataChannel != null) {
            this.remotePeerConnection[streamId].dataChannel.close();
        }
        this.webSocketAdaptor.send(JSON.stringify(jsCmd));
    }

Thanks