Created
March 3, 2015 08:58
-
-
Save morokhovets/636b57866e17c39bcce5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* (C) Copyright 2014 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. | |
* | |
*/ | |
function getopts(args, opts) | |
{ | |
var result = opts.default || {}; | |
args.replace( | |
new RegExp("([^?=&]+)(=([^&]*))?", "g"), | |
function($0, $1, $2, $3) { result[$1] = $3; }); | |
return result; | |
}; | |
var args = getopts(location.search, | |
{ | |
default: | |
{ | |
ws_uri: 'ws://' + 'my_server.com' + ':8888/kurento', // CHANGED | |
file_uri: 'file:///tmp/recorder_demo.webm', //file to be stored in media server | |
ice_servers: undefined | |
} | |
}); | |
if (args.ice_servers) { | |
console.log("Use ICE servers: " + args.ice_servers); | |
kurentoUtils.WebRtcPeer.prototype.server.iceServers = JSON.parse(args.ice_servers); | |
} else { | |
console.log("Use freeice") | |
} | |
window.addEventListener('load', function(event) { | |
var startRecordButton = document.getElementById('startRecordButton'); | |
var playButton = document.getElementById('startPlayButton'); | |
startRecordButton.addEventListener('click', startRecording); | |
playButton.addEventListener('click', startPlaying); | |
}); | |
function startRecording() { | |
console.log("onClick"); | |
var videoInput = document.getElementById("videoInput"); | |
var videoOutput = document.getElementById("videoOutput"); | |
webRtcPeer = kurentoUtils.WebRtcPeer.startSendRecv(videoInput, videoOutput, | |
onOffer, onError); | |
function onOffer(offer) { | |
console.log("Offer ..."); | |
kurentoClient(args.ws_uri, function(error, client) { | |
if (error) return onError(error); | |
client.create('MediaPipeline', function(error, pipeline) { | |
if (error) return onError(error); | |
console.log("Got MediaPipeline"); | |
pipeline.create('RecorderEndpoint', {uri : args.file_uri, mediaProfile: 'WEBM_AUDIO_ONLY'}, // CHANGED | |
function(error, recorder) { | |
if (error) return onError(error); | |
console.log("Got RecorderEndpoint"); | |
pipeline.create('WebRtcEndpoint', function(error, webRtc) { | |
if (error) return onError(error); | |
console.log("Got WebRtcEndpoint"); | |
webRtc.connect(recorder, 'AUDIO', function(error) { // CHANGED | |
if (error) return onError(error); | |
console.log("Connected"); | |
recorder.record(function(error) { | |
if (error) return onError(error); | |
console.log("record"); | |
webRtc.connect(webRtc, function(error) { | |
if (error) return onError(error); | |
console.log("Second connect"); | |
}); | |
webRtc.processOffer(offer, function(error, answer) { | |
if (error) return onError(error); | |
console.log("offer"); | |
webRtcPeer.processSdpAnswer(answer); | |
}); | |
document.getElementById("stopRecordButton").addEventListener("click", | |
function(event){ | |
recorder.stop(); | |
pipeline.release(); | |
webRtcPeer.dispose(); | |
videoInput.src = ""; | |
videoOutput.src = ""; | |
}) | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment