Skip to content

Commit

Permalink
Added support for binary data recordings (#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Dec 11, 2020
1 parent 33a72d8 commit d448432
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 73 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ janus_pp_rec_SOURCES = \
postprocessing/pp-rtp.h \
postprocessing/pp-srt.c \
postprocessing/pp-srt.h \
postprocessing/pp-binary.c \
postprocessing/pp-binary.h \
postprocessing/pp-webm.c \
postprocessing/pp-webm.h \
postprocessing/janus-pp-rec.c \
Expand Down
4 changes: 4 additions & 0 deletions html/recordplaytest.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ <h3 class="panel-title"><span id="videotitle">Remote Video</span> <button class=
</div>
<div class="panel-body" id="videobox"></div>
</div>
<div class="input-group margin-bottom-sm hide">
<span class="input-group-addon"><i class="fa fa-cloud-upload fa-fw"></i></span>
<input class="form-control" type="text" placeholder="" autocomplete="off" id="datafield" onkeypress="return checkEnter(event);" disabled />
</div>
</div>
</div>
</div>
Expand Down
43 changes: 34 additions & 9 deletions html/recordplaytest.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ var vcodec = (getQueryStringValue("vcodec") !== "" ? getQueryStringValue("vcodec
var vprofile = (getQueryStringValue("vprofile") !== "" ? getQueryStringValue("vprofile") : null);
var doSimulcast = (getQueryStringValue("simulcast") === "yes" || getQueryStringValue("simulcast") === "true");
var doSimulcast2 = (getQueryStringValue("simulcast2") === "yes" || getQueryStringValue("simulcast2") === "true");

var recordData = (getQueryStringValue("data") !== "" ? getQueryStringValue("data") : null);
if(recordData !== "text" && recordData !== "binary")
recordData = null;

$(document).ready(function() {
// Initialize the library (all console debuggers enabled)
Expand Down Expand Up @@ -316,13 +318,17 @@ $(document).ready(function() {
},
ondataopen: function(data) {
Janus.log("The DataChannel is available!");
$('#videobox').append(
'<input class="form-control" type="text" id="datarecv" disabled></input>'
);
$('#datafield').parent().removeClass('hide');
if(playing === false) {
// We're recording, use this field to send data
$('#datafield').attr('placeholder', 'Write a message to record');
$('#datafield').removeAttr('disabled');
}
},
ondata: function(data) {
Janus.debug("We got data from the DataChannel!", data);
$('#datarecv').val(data);
if(playing === true)
$('#datafield').val(data);
},
oncleanup: function() {
Janus.log(" ::: Got a cleanup notification :::");
Expand All @@ -334,6 +340,8 @@ $(document).ready(function() {
$('#videobox').empty();
$("#videobox").parent().unblock();
$('#video').hide();
$('#datafield').attr('disabled', true).attr('placeholder', '').val('');
$('#datafield').parent().addClass('hide');
recording = false;
playing = false;
$('#record').removeAttr('disabled').click(startRecording);
Expand All @@ -359,17 +367,29 @@ $(document).ready(function() {
}});
});

function checkEnter(field, event) {
function checkEnter(event) {
var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if(theCode == 13) {
if(field.id == 'name')
insertName();
sendData();
return false;
} else {
return true;
}
}

function sendData() {
var data = $('#datafield').val();
if(data === "") {
bootbox.alert('Insert a message to send on the DataChannel');
return;
}
recordplay.data({
text: data,
error: function(reason) { bootbox.alert(reason); },
success: function() { $('#datafield').val(''); },
});
}

function updateRecsList() {
$('#list').unbind('click');
$('#update-list').addClass('fa-spin');
Expand Down Expand Up @@ -436,7 +456,9 @@ function startRecording() {

recordplay.createOffer(
{
// By default, it's sendrecv for audio and video... no datachannels
// By default, it's sendrecv for audio and video... no datachannels,
// unless we've passed the query string argument to record those too
media: { data: (recordData != null) },
// If you want to test simulcasting (Chrome and Firefox only), then
// pass a ?simulcast=true when opening this demo page: it will turn
// the following 'simulcast' property to pass to janus.js to true
Expand All @@ -454,6 +476,9 @@ function startRecording() {
// profile as well (e.g., ?vprofile=2 for VP9, or ?vprofile=42e01f for H.264)
if(vprofile)
body["videoprofile"] = vprofile;
// If we're going to send binary data, let's tell the plugin
if(recordData === "binary")
body["textdata"] = false;
recordplay.send({ message: body, jsep: jsep });
},
error: function(error) {
Expand Down
Loading

0 comments on commit d448432

Please sign in to comment.