Skip to content

Commit

Permalink
Library of high-level elements
Browse files Browse the repository at this point in the history
Change-Id: Ic1daf53e8701b1e7a46269096b33ebe323deab90
  • Loading branch information
piranna authored and igracia committed Mar 3, 2014
1 parent 288d567 commit aef4e87
Show file tree
Hide file tree
Showing 41 changed files with 4,218 additions and 80 deletions.
5 changes: 4 additions & 1 deletion doc/JsonRPC messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@
"jsonrpc": "2.0",
"id": 1,

"result": *
"result":
{
"data": "$%&/"
}
}
```

Expand Down
Binary file added doc/classes.dia
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<script src="../dist/KwsMedia.js"></script>
<script src="../../dist/KwsMedia.js"></script>
<script src="index.js"></script>
</head>
<body>
Expand Down
68 changes: 68 additions & 0 deletions example/PlayerEndPoint-HttpEndPoint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var RTCPeerConnection = RTCPeerConnection || webkitRTCPeerConnection;


window.addEventListener('load', function()
{
KwsMedia('ws://192.168.0.110:7788/thrift/ws/websocket',
// KwsMedia('ws://179.111.137.126:7788/thrift/ws/websocket',
function(kwsMedia)
{
// Create pipeline
kwsMedia.createMediaPipeline(function(error, pipeline)
{
if(error) return console.error(error);

// Create pipeline media elements (endpoints & filters)
var type = ['PlayerEndPoint', 'HttpGetEndPoint'];
var params = [{uri: "http://localhost:8000/video.avi"}, null];

pipeline.createMediaElement(type, params,
function(error, mediaElements)
{
if(error) return console.error(error);

var playerEndPoint = mediaElements[0];
var httpGetEndPoint = mediaElements[1];

// Connect media element between them
pipeline.connect(playerEndPoint, httpGetEndPoint,
function(error, pipeline)
{
if(error) return console.error(error);

console.log(pipeline);
});

// Subscribe to PlayerEndPoint EOS event
playerEndPoint.on('EOS', function()
{
console.log("EOS");
});

// Set the video on the video tag
var videoOutput = document.getElementById("videoOutput");

httpGetEndPoint.getUrl(function(error, url)
{
if(error) return console.error(error);

videoOutput.src = url;
console.log(url);

// Start player
playerEndPoint.start(function(error, result)
{
if(error) return console.error(error);

console.log(result);
});
});

});
});
},
function(error)
{
console.error('An error ocurred:',error);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<script src="../../dist/KwsMedia.js"></script>
<script src="index.js"></script>
</head>
<body>
<video id="videoOutput" autoplay />
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var RTCPeerConnection = RTCPeerConnection || webkitRTCPeerConnection;

window.addEventListener('load', function()
{
KwsMedia('ws://localhost:8001', function(kwsMedia)
KwsMedia('ws://192.168.0.115:7788/thrift/ws/websocket',
function(kwsMedia)
{
// Create pipeline
kwsMedia.createMediaPipeline(function(error, pipeline)
Expand Down Expand Up @@ -56,7 +57,7 @@ window.addEventListener('load', function()
{
if(error) return console.error(error);

var stream = peerConnection.getLocalStreams()[0];
var stream = peerConnection.getRemoteStreams()[0];

// Set the stream on the video tag
var videoOutput = document.getElementById("videoOutput");
Expand Down
10 changes: 10 additions & 0 deletions example/WebRtcEndPoint/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<script src="../../dist/KwsMedia.js"></script>
<script src="index.js"></script>
</head>
<body>
<video id="videoInput" autoplay />
<video id="videoOutput" autoplay />
</body>
</html>
75 changes: 75 additions & 0 deletions example/WebRtcEndPoint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var RTCPeerConnection = RTCPeerConnection || webkitRTCPeerConnection;


getUserMedia({'audio': true, 'video': true}, function(stream)
{
var videoInput = document.getElementById("videoInput");
var videoOutput = document.getElementById("videoOutput");

videoInput.src = URL.createObjectURL(stream);


KwsMedia('ws://192.168.0.110:7788/thrift/ws/websocket',
function(kwsMedia)
{
// Create pipeline
kwsMedia.createMediaPipeline(function(error, pipeline)
{
if(error) return console.error(error);

// Create pipeline media elements (endpoints & filters)
pipeline.createMediaElement('WebRtcEndPoint',
function(error, webRtcEndPoint)
{
if(error) return console.error(error);

// Create a PeerConnection client in the browser
var peerConnection = new RTCPeerConnection
(
{iceServers: [{url: 'stun:stun.l.google.com:19302'}]},
{optional: [{DtlsSrtpKeyAgreement: true}]}
);

peerConnection.addStream(stream);

// Connect the pipeline to the PeerConnection client
webRtcEndPoint.generateSdpOffer(function(error, offer)
{
if(error) return console.error(error);

peerConnection.setRemoteDescription(offer, function()
{
peerConnection.createAnswer(function(answer)
{
peerConnection.setLocalDescription(answer, function()
{

webRtcEndPoint.processSdpAnswer(answer, function(error)
{
if(error) return console.error(error);

var stream = peerConnection.getRemoteStreams()[0];

// Set the stream on the video tag
videoOutput.src = URL.createObjectURL(stream);

// // Start player
// pipeline.start();
});

},
console.error);
},
console.error);
},
console.error);

});
});
});
},
function(error)
{
console.error('An error ocurred:',error);
});
});
4 changes: 2 additions & 2 deletions lib/MediaContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ var MediaObject = require('./MediaObject');
* @param {*} parent
* @param {MediaPipeline} [pipeline]
*/
function MediaContainer(objectRef, parent, pipeline)
function MediaContainer(objectRef, parent, pipeline, params)
{
MediaObject.call(this, objectRef, parent, pipeline);
MediaObject.call(this, objectRef, parent, pipeline, params);


// Bubble the event for new MediaObjects
Expand Down
6 changes: 3 additions & 3 deletions lib/MediaElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ var MediaContainer = require('./MediaContainer');
*
* @param {string} type - Type of the element
*/
function MediaElement(objectRef, parent, pipeline)
function MediaElement(objectRef, parent, pipeline, params)
{
MediaContainer.call(this, objectRef, parent, pipeline);
MediaContainer.call(this, objectRef, parent, pipeline, params);


var sourcePads = undefined;
Expand Down Expand Up @@ -69,7 +69,7 @@ function MediaElement(objectRef, parent, pipeline)
};


function getMediaSrcs(pads, type, description)
function getPads(pads, type, description)
{
var result = [];

Expand Down
70 changes: 70 additions & 0 deletions lib/MediaFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* (C) Copyright 2013 Kurento (http://kurento.org/)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/


/**
*
*
* @module
*
* @copyright 2013 Kurento (http://kurento.org/)
* @license LGPL
*/

var MediaObject = require('./MediaObject');


/**
* Represent an instance of a MediaFilter
*
* This is a Javascript API abstraction not available on the Media Server API
*
* @abstract
* @class
*
* @param {} objectRef
* @param {*} parent
* @param {MediaPipeline} [pipeline]
*/
function MediaFilter(objectRef, parent, pipeline, params)
{
MediaObject.call(this, objectRef, parent, pipeline, params);


// Bubble the event for new MediaObjects
this.on('mediaObject', function(mediaObject)
{
parent.emit('mediaObject', mediaObject);
});
};
MediaFilter.prototype.__proto__ = MediaObject.prototype;
MediaFilter.prototype.constructor = MediaFilter;


/**
*
* @param {MediaObjectConstructorParams} params
*
* @throws {SyntaxError}
*
* @returns {MediaObjectConstructorParams}
*/
MediaFilter.checkparams = function(params)
{
return MediaObject.checkparams(params);
};


module.exports = MediaFilter;
Loading

0 comments on commit aef4e87

Please sign in to comment.