Kurento / bugtracker

[ARCHIVED] Contents migrated to monorepo: https://github.com/Kurento/kurento
46 stars 10 forks source link

Not all events are working for the kurento client (Node) #558

Open marcelrouw opened 3 years ago

marcelrouw commented 3 years ago

Prerequisites

Issue description

From the events of the kurento client in node, only the reconnected works. The disconnected, connectionFailed and connected don't work.

    var kurento = require('kurento-client');
    var kurentoUrl = "";
    kurento(kurentoUrl, function(error, kurentoClient) {
        if (error) {
          console.log("Kurento connection error: " + error + " - " + kurentoUrl);
        }

        // monitor kurento
        kurentoClient.on('reconnected', function(err) {
          console.log("Kurento reconnected " + err);
        });
        kurentoClient.on('disconnected', function() {
          console.log("Kurento disconnected");
        });
        kurentoClient.on('connectionFailed', function() {
          console.log("Kurento connectionFailed");
        });
        kurentoClient.on('connected', function() {
          console.log("Kurento connected");
        });
    });

Context

This makes it impossible to determine the health of the Kurento server and if we still can setup connection to this server or need to revert to an other kurento server

How to reproduce?

By starting and stopping the kurento server.

Expected & current behavior

We expect to get event on disconnected, connectionFailed and connected But we don't get them when starting and stopping of the kurento server

(Optional) Possible solution

INFO about Kurento Media Server

INFO about your Application Server

INFO about end-user clients

INFO about your environment

Run these commands

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
kurento-media-server --version
Kurento Media Server version: 6.15.0
Found modules:
    'core' version 6.15.0
    'elements' version 6.15.0
    'filters' version 6.15.0
dpkg -l | grep -Pi 'kurento|kms-|gst.*1.5|nice'
ii  gstreamer1.5-libav:amd64             1.8.1-1kurento1.18.04               amd64        libav plugin for GStreamer
ii  gstreamer1.5-nice:amd64              0.1.18-0kurento1.18.04              amd64        ICE library (GStreamer 1.5 plugin)
ii  gstreamer1.5-plugins-bad:amd64       1.8.1-1kurento5.18.04               amd64        GStreamer plugins from the "bad" set
ii  gstreamer1.5-plugins-base:amd64      1.8.1-1kurento2.18.04               amd64        GStreamer plugins from the "base" set
ii  gstreamer1.5-plugins-good:amd64      1.8.1-1kurento5.18.04               amd64        GStreamer plugins from the "good" set
ii  gstreamer1.5-plugins-ugly:amd64      1.8.1-1kurento1.18.04               amd64        GStreamer plugins from the "ugly" set
ii  gstreamer1.5-pulseaudio:amd64        1.8.1-1kurento5.18.04               amd64        GStreamer plugin for PulseAudio
ii  gstreamer1.5-x:amd64                 1.8.1-1kurento2.18.04               amd64        GStreamer plugins for X11 and Pango
ii  kms-core                             6.15.0-0kurento1.18.04              amd64        Kurento Core module
ii  kms-elements                         6.15.0-0kurento1.18.04              amd64        Kurento Elements module
ii  kms-filters                          6.15.0-0kurento1.18.04              amd64        Kurento Filters module
ii  kms-jsonrpc                          6.15.0-0kurento1.18.04              amd64        Kurento JSON-RPC library
ii  kmsjsoncpp                           1.6.3-1kurento1.18.04               amd64        Kurento jsoncpp library
ii  kurento-media-server                 6.15.0-0kurento1.18.04              amd64        Kurento Media Server
ii  libgstreamer-plugins-bad1.5-0:amd64  1.8.1-1kurento5.18.04               amd64        GStreamer development files for libraries from the "bad" set
ii  libgstreamer-plugins-base1.5-0:amd64 1.8.1-1kurento2.18.04               amd64        GStreamer libraries from the "base" set
ii  libgstreamer1.5-0:amd64              1.8.1-1kurento2.18.04               amd64        Core GStreamer libraries and elements
ii  libnice10:amd64                      0.1.18-0kurento1.18.04              amd64        ICE library (shared library)
ii  libsrtp0:amd64                       1.6.0-0kurento1.18.04               amd64        Secure RTP (SRTP) and UST Reference Implementations - shared library
ii  libusrsctp                           0.9.2-1kurento1.18.04               amd64        sctp-refimpl library
ii  openh264                             1.5.0-0kurento1.18.04               amd64        H.264 Video Codec provided by Cisco Systems, Inc.
ii  openh264-gst-plugins-bad-1.5:amd64   1.8.1-1kurento5.18.04               amd64        GStreamer plugins from openh264
ii  openwebrtc-gst-plugins               0.10.0-1kurento1.18.04              amd64        OpenWebRTC specific GStreamer plugins
github-actions[bot] commented 3 years ago

Hello @marcelrouw! :wave: we're sorry you found a bug... so first of all, thank you very much for reporting it.

To know about progress, check in Triage. All issues are considered Backlog Candidates until work priorities align and the issue is selected for development. It will then become part of our official Backlog.

whitphx commented 3 years ago

Hi, I found a workaround like below. I'm using it now and it works.

(written in TypeScript with Promise-style)

import { EventEmitter } from 'events'
import kurento, { ClientInstance } from 'kurento-client'

const wsUri = "..."

const kurentoClientPromise = kurento(wsUri)

// HACK: A not published API, `kurentoClientPromise._re`, is used here.
// `kurento-client` uses a forked version of `reconnect-ws` to maintain
// the internal WebSocket connection to KMS and sets its instance
// as `_re` property of the promise object returned from `kurento()`.
// See https://github.com/Kurento/kurento-client-js/blob/718c304d32fc70ca649e1a7c6c7f5fbb293d8319/lib/KurentoClient.js#L917-L921 .
// The forked `reconnect-ws` used in `kurento-client` is https://github.com/KurentoForks/reconnect-ws
// and the document says it publishes events described in https://github.com/juliangruber/reconnect-core#usage .
// So, here we set the event listeners for those events to detect reconnection state changes.
const innerReconnect = ((kurentoClientPromise as unknown) as { _re: EventEmitter })._re

innerReconnect.on('connect', (con: WebSocket) => {
  // connected
})
innerReconnect.on('reconnect', (n: number, delay: number) => {
  // reconnection tried
})
innerReconnect.on('disconnect', (err: Error) => {
  // disconnected
})
innerReconnect.on('error', (err: Error) => {
  // error occurred
})

let clientInstance: ClientInstance
kurentoClientPromise.then((client: ClientInstance) => {
  clientInstance = client
})

I wish these event listeners will be available via public API, without such hacks.

j1elo commented 3 years ago

Actually I would like to get rid of all dependencies of KurentoForks, but not sure it it's possible right now. It would be a good change, removing all forks, to make maintenance easier. Because right now, nobody is in charge of maintaining the forks.

j1elo commented 3 years ago

We focus more on the Java client because that's what is used by OpenVidu. So the JS client is driven by community contributions. I will review your proposal to see if it can be merged; if you have any other improvement feel free to discuss it in the forum to see if a PR makes sense.