Datachannel is opened, but endpoint mesages aren't received

Hello! I want to create client for text and voice chatting using lib-jitsi-meet

I have a problem. When two participants are in the room, the RTCDataChannel is opening. But if the datachannel is opening too long, endpoint messages aren’t received. I noticed that if less then 3 errors Bridge Channel send: no opened channel in the console, it will work. But If 3 or more, mesages aren’t received already.

I created the prototype which demontrates the bug. File createRoom.html which creates Jitsi room room121212121 . And file enterRoom.html which enters the room and then it is reading endpoint messages. When in first file connection will be established and datachannel will be opened, it will start to send endpoint messages after 5 seconds. The second file will indicate if endpoint message will be received

createRoom.html

<html lang="en">
<head>
    <title>Creator of Jitsi room</title>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://meet.jit.si/libs/lib-jitsi-meet.min.js"></script>
    <script src="roomHelpers.js"></script>
</head>
<body>
    <h1>Creating of room room121212121</h1>

    <p>Connection status: <span id="connection-status">not connected</span></p>
    <p>Datachannel status: <span id="datachannel-status">not opened</span></p>
    <p>Sending endpoint message via datachannel status: <span id="message-send-status">not sent</span></p>

    <script>
        const roomName = 'room121212121';
        let connection, room;

        window.addEventListener("beforeunload", () => {
            if (room) room.leave();
            if (connection) connection.disconnect();
        });

        JitsiMeetJS.init();

        const onConnectionSuccess = () => {
            $('#connection-status').html('<b>established</b>');

            const conferenceOptions = { openBridgeChannel: true };

            room = connection.initJitsiConference(roomName, conferenceOptions);
            room.on(JitsiMeetJS.events.conference.CONFERENCE_JOINED, () => {
                room.rtc.addEventListener('rtc.data_channel_open', () => {
                    $('#datachannel-status').html('<b>opened</b>');
                    $('#message-send-status').html('<b>will sent after 5 seconds</b>');

                    setInterval(() => {
                        room.broadcastEndpointMessage('testMessage');
                        $('#message-send-status').html('<b>will sent every 5 seconds</b>');
                    }, 5000);
                });
            });

            room.join();
        };

        connection = getConnection(roomName, onConnectionSuccess);
        connection.connect();
        $('#connection-status').html('<b>connecting...</b>');
    </script>
</body>
</html>

enterRoom.html

<html lang="en">
<head>
    <title>Entering Jitsi room</title>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://meet.jit.si/libs/lib-jitsi-meet.min.js"></script>
    <script src="roomHelpers.js"></script>
</head>
<body>
    <h1>Entering room room121212121</h1>

    <p>Connection status: <span id="connection-status">not connected</span></p>
    <p>Datachannel status: <span id="datachannel-status">not opened</span></p>
    <p>Receiving endpoint message via datachannel status: <span id="message-receive-status">not received</span></p>

    <script>
        const roomName = 'room121212121';
        let connection, room;

        window.addEventListener("beforeunload", () => {
            if (room) room.leave();
            if (connection) connection.disconnect();
        });

        JitsiMeetJS.init();

        const onConnectionSuccess = () => {
            $('#connection-status').html('<b>established</b>');

            const conferenceOptions = { openBridgeChannel: true };

            room = connection.initJitsiConference(roomName, conferenceOptions);
            room.on(JitsiMeetJS.events.conference.CONFERENCE_JOINED, () => {
                room.rtc.addEventListener('rtc.data_channel_open', () => {
                    $('#datachannel-status').html('<b>opened</b>');
                });
            });
            room.on(JitsiMeetJS.events.conference.ENDPOINT_MESSAGE_RECEIVED, (_, message) => {
                if (message === 'testMessage') {
                    $('#message-receive-status').html('<b>received</b>');
                }
            });

            room.join();
        };

        connection = getConnection(roomName, onConnectionSuccess);
        connection.connect();
        $('#connection-status').html('<b>connecting...</b>');
    </script>
</body>
</html>

And roomHelpers.js

const getConnection = (roomName, onConnectionSuccess) => {
    const options = {
        hosts: {
            domain: 'meet.jit.si',
            muc: 'conference.meet.jit.si',
            focus: 'focus.meet.jit.si',
        },
        serviceUrl: 'https://meet.jit.si/http-bind?room=' + roomName,
        clientNode: 'http://jitsi.org/jitsimeet',
        useStunTurn: true
    }

    connection = new JitsiMeetJS.JitsiConnection(null, null, options);
    connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_ESTABLISHED, onConnectionSuccess);
    connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_FAILED, () => {
        $('#connection-status').text('error');
    });

    return connection;
};

I had opened createRoom.html and then opened enterRoom.html . This is result:
изображение

The console log in tab createRoom.html contains 3 errors Bridge Channel send: no opened channel . Then the datachannel was opened and the script started to broadcast endpoint messages every 5 seconds, but the second tab didn’t receive any messages

This situation may arise not from first attempt. Sometimes I see that error each time when I reload second tab enterRoom.html . Sometimes it need many attempts. And sometimes datachannel is opened fast and I haven’t any errors. But with this error I see jitsi datachannles are unreliable :frowning:

I think that if was 3 and more failed attempts to open datachannel, then it will ‘broken’ (but I don’t know reason)

The test files are located at https://yadi.sk/d/DJZo_TT3XfSWXw. If Yandex.Disk is not comfortable for you, please write me and I will upload to other service

I tested in Firefox 78

Addition: I can’t reproduce the problem in Chrome

Is it possible to reopen datachannel? I have this.room is instance of JitsiConference and, if I don’t receive messages via datachannel (it is broken), I try this:

reopenRTCChannel = () => {
        const session = this.room.jvbJingleSession;
        if (!session) return;
        const pc = session.peerconnection;
        this.room.rtc.closeBridgeChannel();
        this.room.rtc.initializeBridgeChannel(pc, null);
    }

But it doesn’t work :frowning: