title: Kurento endpoints order in order to record screencast
body: <p>I'm trying to record a webcam with <code>kurento</code> media server, here is the function I'm using at the backend:</p>
  
  <pre><code>var startScreen = (sessionId, ws, sdpOffer, callback) =&gt; {
      console.log("Start screen")
    getKurentoClient((error, kurentoClient) =&gt; {
      if (error) {
        return callback(error)
      }
  
      kurentoClient.create('MediaPipeline', (error, pipeline) =&gt; {
        if (error) {
          return callback(error)
        }
  
  
       var recordParams = {
          stopOnEndOfStream: true,
          mediaProfile: 'WEBM_VIDEO_ONLY',
          uri: 'file:///PATH/TO/VIDEO/screen.webm'
        }
        pipeline.create('RecorderEndpoint', recordParams, (error, recorder) =&gt; {
          if (error) return callback(error)
  
          screenRecorder = recorder
          recorder.record(() =&gt; console.log("recording"))
          pipeline.create('WebRtcEndpoint', (error, webRtcEndpoint) =&gt; {
            if (error) {
              pipeline.release()
              return callback(error)
            }
  
          screenRtcEndpoint = webRtcEndpoint
  
            if (candidatesQueue[sessionId]) {
              while(candidatesQueue[sessionId].length) {
                var candidate = candidatesQueue[sessionId].shift()
                webRtcEndpoint.addIceCandidate(candidate)
              }
            }
            webRtcEndpoint.on('OnIceCandidate', (event) =&gt; {
              var candidate = kurento.register.complexTypes.IceCandidate(event.candidate)
              ws.send(JSON.stringify({
                id: 'iceCandidateScreen',
                candidate: candidate
              }))
            })
  
            webRtcEndpoint.processOffer(sdpOffer, (error, sdpAnswer) =&gt; {
              if (error) {
                pipeline.release()
                return callback(error)
              }
  
              sessions[sessionId] = {
                'pipeline': pipeline,
                'webRtcEndpoint': webRtcEndpoint
              }
  
            webRtcEndpoint.connect(webRtcEndpoint, error =&gt; {
              if (error) {
                return callback(error)
              }
              console.log("Connect webrtcEndpoint")
              webRtcEndpoint.connect(screenRecorder, error =&gt; {
                if (error) {
                  return callback(error)
                }
                console.log("connect to the screen recorder")
              })
  
              callback(null, sdpAnswer)
              })
  
            })
  
            webRtcEndpoint.gatherCandidates((error) =&gt; {
              if (error) {
                return callback(error)
              }
            })
          })
        })
      })
    })
  }
  </code></pre>
  
  <p>the pipeline looks something like this:</p>
  
  <pre><code>mediaPipeline -&gt; recorderEndpoint and recorder.record -&gt; WebRtcEndpoint connect webrtcendpoint -&gt; connect recorder endpoint
  </code></pre>
  
  <p>at the front end i do this:</p>
  
  <pre><code>mediaConstrains = {
    audio: false,
    video: {
      mandatory: {
        maxWidth: 640,
        maxHeight: 480,
        maxFrameRate: 15,
        minFrameRate: 1
      }
    }
  }
  
  var getMediaConstrains = () =&gt; mediaConstrains
  
  var setMediaConstrains = (config) =&gt; {
    mediaConstrains = config
  }
  
  var startScreen = () =&gt; {
    var options = {
      mediaConstrains: mediaConstrains,
      onicecandidate: onIceCandidate,
      configuration: { iceServers: [
          {'url': 'turn:numb.viagenie.ca:3478',
            'username': 'email@email.com',
          'credential': 'passwordrandom'}
      ] }
    }
  
    webRtcPeerScreen = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, function (error) {
      if (error) {
        return onError(error)
      }
  
      this.generateOffer(onOfferScreen)
    })
  }
  </code></pre>
  
  <p>This is for only screencast which is not working, I'm using almost the exact same code to record a webcam which its fully working, This is the stop function:</p>
  
  <pre><code>var stop = () =&gt; {
    if (webRtcPeerWebcam &amp;&amp; webRtcPeerScreen) {
      webRtcPeerWebcam.dispose()
      webRtcPeerWebcam = null
      webRtcPeerScreen.dispose()
      webRtcPeerScreen = null
  
      var message = {
        id: 'stop'
      }
      sendMessage(message)
    }
  }
  </code></pre>
  
  <p>Where I dispose the pipeline at the front end but, I send this message to the backend and then this wss message calls this function:</p>
  
  <pre><code>var stop = (sessionId) =&gt; {
    if (sessions[sessionId]) {
      var pipeline = sessions[sessionId].pipeline
      pipeline.release()
      delete sessions[sessionId]
      delete candidatesQueue[sessionId]
    }
  }
  </code></pre>
  
  <p>I think this maybe the problem of why this is not working for recording the screencast or maybe I'm connecting the pipelines improperly</p>
  
  <p>Anyway thanks!</p>
  
  <p>PD: i found this on KMS logs:</p>
  
  <pre><code>KurentoMediaElementImpl MediaElementImpl.cpp:434 mediaFlowOutStateChange() &lt;kmswebrtcendpoint373&gt; Media N OT Flowing OUT in pad default with type video 
  </code></pre>