Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for binary data recordings #2481

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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