Kurento Media Server with NodeJS load balancing

Viewed 269

I use kurento media server to mediate webRTC communication in the browser. I use NodeJS for communication between the browser and the webRTC server.

NodeJS is preceded by nginx, which acts as a load balancer. I managed to get to the point where the connection between the browser and the NodeJS server is re-established. However, after the refresh, my video freezes, probably due to a break in communication between the browser and the kurento server.

How can I reconnect?

According to the documentation: here it should work somehow, unfortunately there is no specific example. So far, I have managed to extract MediaPipelines and webRTC endpoints from the kurentoClient object, which represents my connection to the kurento server on NodeJS.

            kurento(wsUrl, (error, kurentoClient) => {
            kurentoClient.getMediaobjectById(pipeline_id).then(mediaObject => {
                mediaObject.getChildren().then(collection => {
                    console.log(collection);
                    collection.forEach(endpoint => {
                        endpoint.getConnectionState().then(state => {
                            console.log('CONNECTION STATE: ' + endpoint.id + ' ' + state);
                        });
                        endpoint.getMediaState().then(state => {
                            console.log('MEDIA STATE: ' + endpoint.id + ' ' + state);
                        });
                    });
                });
            });
        });

The result of this code is:

[
  WebRtcEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/0c933bd6-77e4-45c5-bcba-782e9f085391_kurento.WebRtcEndpoint',
    [Symbol(kCapture)]: false
  },
  WebRtcEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/365b117e-87e7-45e3-aeaa-294d89aa7d0b_kurento.WebRtcEndpoint',
    [Symbol(kCapture)]: false
  },
  RecorderEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/5e14b897-122e-4d53-9d36-b3aad88d51fb_kurento.RecorderEndpoint',
    [Symbol(kCapture)]: false
  },
  WebRtcEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/82116d9a-e8d0-4835-bbe4-168f319ecf49_kurento.WebRtcEndpoint',
    [Symbol(kCapture)]: false
  },
  RecorderEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/9ce3a52e-8684-432a-bf3f-d823a3b67e6f_kurento.RecorderEndpoint',
    [Symbol(kCapture)]: false
  },
  WebRtcEndpoint {
    _events: [Object: null prototype] {
      removeListener: [Function (anonymous)],
      newListener: [Function (anonymous)],
      _describe: [Function: bound ],
      _rpc: [Function: encodeRpc],
      release: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    id: 'bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/c9c64c19-f0e5-4311-8718-960c61f376ad_kurento.WebRtcEndpoint',
    [Symbol(kCapture)]: false
  }
]
CONNECTION STATE: bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/0c933bd6-77e4-45c5-bcba-782e9f085391_kurento.WebRtcEndpoint CONNECTED
MEDIA STATE: bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/0c933bd6-77e4-45c5-bcba-782e9f085391_kurento.WebRtcEndpoint CONNECTED
CONNECTION STATE: bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/365b117e-87e7-45e3-aeaa-294d89aa7d0b_kurento.WebRtcEndpoint CONNECTED
MEDIA STATE: bc971f6e-ba80-4d63-ac35-586b7454e36f_kurento.MediaPipeline/365b117e-87e7-45e3-aeaa-294d89aa7d0b_kurento.WebRtcEndpoint CONNECTED

How should I proceed? Discard existing endpoints and recreate them? Or can I just call connect? Will I have to call anything else in the browser?

0 Answers
Related