added clip load to asset + clean code

This commit is contained in:
AlessandroSigna 2015-11-20 15:22:18 -08:00
parent a306e8d5b1
commit 7069f7d6ab
2 changed files with 35 additions and 36 deletions

View file

@ -25,19 +25,24 @@
function recordingEntity() {
_this = this;
return;
}
};
function receivingMessage(channel, message, senderID) {
if(channel === MASTER_TO_CLIENTS_CHANNEL){
if (channel === MASTER_TO_CLIENTS_CHANNEL) {
print("CLIENT received message:" + message);
if(message === START_MESSAGE) {
if (message === START_MESSAGE) {
_this.startRecording();
} else if(message === STOP_MESSAGE) {
} else if (message === STOP_MESSAGE) {
_this.stopRecording();
}
}
};
function getClipUrl(url) {
Messages.sendMessage(CLIENTS_TO_MASTER_CHANNEL, url); //send back the url to the master
print("clip uploaded and url sent to master");
};
recordingEntity.prototype = {
preload: function (entityID) {
@ -55,7 +60,6 @@
enterEntity: function (entityID) {
print("entering in the recording area");
Messages.subscribe(MASTER_TO_CLIENTS_CHANNEL);
},
leaveEntity: function (entityID) {
@ -78,11 +82,12 @@
print("RECORDING ENDED");
Recording.stopRecording();
isAvatarRecording = false;
recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
Recording.saveRecordingToAsset(getClipUrl); //save the clip to the asset and link a callback to get its url
var recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
Recording.saveRecording(recordingFile);
Recording.saveRecording(recordingFile); //save the clip locally
}
Messages.sendMessage(CLIENTS_TO_MASTER_CHANNEL, recordingFile); //send back to the master the url
}
},

View file

@ -32,13 +32,14 @@ var TIMEOUT = 20;
var toolBar = null;
var recordIcon;
var isRecording = false;
var results = [];
var performanceJSON = null;
var avatarClips = [];
var performanceJSON = { "avatarClips" : [] };
var responsesExpected = 0;
var waitingForPerformanceFile = true;
var totalWaitingTime = 0;
var extension = "txt";
Messages.subscribe(CLIENTS_TO_MASTER_CHANNEL);
setupToolBar();
@ -81,35 +82,26 @@ function mousePressEvent(event) {
}
function masterReceivingMessage(channel, message, senderID) {
if(channel === CLIENTS_TO_MASTER_CHANNEL) {
if (channel === CLIENTS_TO_MASTER_CHANNEL) {
print("MASTER received message:" + message );
if(message === PARTICIPATING_MESSAGE){
if (message === PARTICIPATING_MESSAGE) {
//increment the counter of all the participants
responsesExpected++;
} else if(waitingForPerformanceFile) {
//I get a atp url from one participant
results[results.length] = message;
var textJSON = '{ "results" : [';
for (var index = 0; index < results.length; index++) {
var newRecord = index === (results.length - 1) ? '{ "hashATP":"' + results[index] + '" }' : '{ "hashATP":"' + results[index] + '" },';
textJSON += newRecord;
}
textJSON += ']}';
performanceJSON = JSON.parse(textJSON);
} else if (waitingForPerformanceFile) {
//I get an atp url from one participant
performanceJSON.avatarClips[performanceJSON.avatarClips.length] = message;
}
}
}
function update(deltaTime) {
if(waitingForPerformanceFile) {
if (waitingForPerformanceFile) {
totalWaitingTime += deltaTime;
if(totalWaitingTime > TIMEOUT || results.length === responsesExpected) {
//I can upload the performance file on the asset
if (totalWaitingTime > TIMEOUT || performanceJSON.avatarClips.length === responsesExpected) {
print("UPLOADING PERFORMANCE FILE");
print(JSON.stringify(performanceJSON));
if(performanceJSON !== null) {
//upload
if (performanceJSON.avatarClips.length !== 0) {
//I can upload the performance file on the asset
Assets.uploadData(JSON.stringify(performanceJSON), extension, uploadFinished);
}
//clean things after upload performance file to asset
@ -117,26 +109,28 @@ function update(deltaTime) {
responsesExpected = 0;
totalWaitingTime = 0;
Script.update.disconnect(update);
results = [];
performanceJSON = null;
avatarClips = [];
performanceJSON = { "avatarClips" : [] };
}
}
}
function uploadFinished(url){
print("data uploaded to:" + url);
print("some info:");
print("performance file uploaded to: " + url);
uploadedFile = url;
Assets.downloadData(url, function (data) {
print("data downloaded from:" + url + " the data is: ");
printPerformanceJSON(JSON.parse(data));
});
//need to print somehow the url here //this way the master can copy the url
//Window.prompt(url);
}
function printPerformanceJSON(obj) {
var results = obj.results;
results.forEach(function(param) {
var hash = param.hashATP;
print("url obtained: " + hash);
print("downloaded performance file from asset and examinating its content...");
var avatarClips = obj.avatarClips;
avatarClips.forEach(function(param) {
print("clip url obtained: " + param);
});
}