Skip to content

Instantly share code, notes, and snippets.

@pgasiorowski
Last active August 29, 2015 14:17
Show Gist options
  • Save pgasiorowski/870cb5a4700abddce55e to your computer and use it in GitHub Desktop.
Save pgasiorowski/870cb5a4700abddce55e to your computer and use it in GitHub Desktop.
console.log('Creating kurentoClient');
kurento(ws_uri, function(error, kurentoClient) {
if (error) return wsError(ws, "ERROR 1: Could not find media server at address" + ws_uri + ". Exiting with error " + error);
// Create pipline
console.log('Creating MediaPipline');
kurentoClient.create('MediaPipeline', function(error, pipeline) {
if (error) return wsError(ws, "ERROR 2: " + error);
activePipeline = pipeline;
// Create player
console.log('Creating PlayerEndpoint');
pipeline.create('PlayerEndpoint', {uri: rtsp_uri, useEncodedMedia: true}, function(error, playerEndpoint) {
if (error) return wsError(ws, "ERROR 3: " + error);
playerEndpoint.on('EndOfStream', function() {
console.log('END OF STREAM');
pipeline.release();
});
console.log('Now Playing');
playerEndpoint.play(function(error) {
if (error) return wsError(ws, "ERROR 4: " + error);
// Create WebRTCEndpoint
console.log('Creating WebRTCEndpoint');
pipeline.create('WebRtcEndpoint', function(error, webRtcEndpoint) {
if (error) return wsError(ws, "ERROR 5: " + error);
// Create Filter
console.log('Creating Filter');
var cmd = 'videoflip method=2';
// var cmd = 'video/x-raw-yuv,format=(fourcc)YUY2;video/x-raw-yuv,format=(fourcc)YV12';
// var cmd = 'capsfilter caps=video/x-raw,width=1280,height=720';
pipeline.create('GStreamerFilter', {command: cmd}, function(error, filter) {
if (error) return wsError(ws, "ERROR 5-1: " + error);
console.log('Processing SDP offer');
webRtcEndpoint.processOffer(message.sdpOffer, function(error, sdpAnswer) {
if (error) return wsError(ws, "ERROR 6: " + error);
console.log('Connecting to endpoint');
playerEndpoint.connect(filter, function(error) {
if (error) return wsError(ws, "ERROR 6-1: " + error);
filter.connect(webRtcEndpoint, function(error) {
if (error) return wsError(ws, "ERROR 7: " + error);
console.log('Connected!');
ws.send(JSON.stringify({
id : 'viewerResponse',
response : 'accepted',
sdpAnswer : sdpAnswer
}));
});
});
});
// });
});
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment