mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 12:09:45 +02:00
added clip load to asset + clean code
This commit is contained in:
parent
a306e8d5b1
commit
7069f7d6ab
2 changed files with 35 additions and 36 deletions
|
@ -25,19 +25,24 @@
|
||||||
function recordingEntity() {
|
function recordingEntity() {
|
||||||
_this = this;
|
_this = this;
|
||||||
return;
|
return;
|
||||||
}
|
};
|
||||||
|
|
||||||
function receivingMessage(channel, message, senderID) {
|
function receivingMessage(channel, message, senderID) {
|
||||||
if(channel === MASTER_TO_CLIENTS_CHANNEL){
|
if (channel === MASTER_TO_CLIENTS_CHANNEL) {
|
||||||
print("CLIENT received message:" + message);
|
print("CLIENT received message:" + message);
|
||||||
if(message === START_MESSAGE) {
|
if (message === START_MESSAGE) {
|
||||||
_this.startRecording();
|
_this.startRecording();
|
||||||
} else if(message === STOP_MESSAGE) {
|
} else if (message === STOP_MESSAGE) {
|
||||||
_this.stopRecording();
|
_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 = {
|
recordingEntity.prototype = {
|
||||||
|
|
||||||
preload: function (entityID) {
|
preload: function (entityID) {
|
||||||
|
@ -55,7 +60,6 @@
|
||||||
enterEntity: function (entityID) {
|
enterEntity: function (entityID) {
|
||||||
print("entering in the recording area");
|
print("entering in the recording area");
|
||||||
Messages.subscribe(MASTER_TO_CLIENTS_CHANNEL);
|
Messages.subscribe(MASTER_TO_CLIENTS_CHANNEL);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
leaveEntity: function (entityID) {
|
leaveEntity: function (entityID) {
|
||||||
|
@ -78,11 +82,12 @@
|
||||||
print("RECORDING ENDED");
|
print("RECORDING ENDED");
|
||||||
Recording.stopRecording();
|
Recording.stopRecording();
|
||||||
isAvatarRecording = false;
|
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 === "")) {
|
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
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,14 @@ var TIMEOUT = 20;
|
||||||
var toolBar = null;
|
var toolBar = null;
|
||||||
var recordIcon;
|
var recordIcon;
|
||||||
var isRecording = false;
|
var isRecording = false;
|
||||||
var results = [];
|
var avatarClips = [];
|
||||||
var performanceJSON = null;
|
var performanceJSON = { "avatarClips" : [] };
|
||||||
var responsesExpected = 0;
|
var responsesExpected = 0;
|
||||||
var waitingForPerformanceFile = true;
|
var waitingForPerformanceFile = true;
|
||||||
var totalWaitingTime = 0;
|
var totalWaitingTime = 0;
|
||||||
var extension = "txt";
|
var extension = "txt";
|
||||||
|
|
||||||
|
|
||||||
Messages.subscribe(CLIENTS_TO_MASTER_CHANNEL);
|
Messages.subscribe(CLIENTS_TO_MASTER_CHANNEL);
|
||||||
setupToolBar();
|
setupToolBar();
|
||||||
|
|
||||||
|
@ -81,35 +82,26 @@ function mousePressEvent(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function masterReceivingMessage(channel, message, senderID) {
|
function masterReceivingMessage(channel, message, senderID) {
|
||||||
if(channel === CLIENTS_TO_MASTER_CHANNEL) {
|
if (channel === CLIENTS_TO_MASTER_CHANNEL) {
|
||||||
print("MASTER received message:" + message );
|
print("MASTER received message:" + message );
|
||||||
if(message === PARTICIPATING_MESSAGE){
|
if (message === PARTICIPATING_MESSAGE) {
|
||||||
//increment the counter of all the participants
|
//increment the counter of all the participants
|
||||||
responsesExpected++;
|
responsesExpected++;
|
||||||
} else if(waitingForPerformanceFile) {
|
} else if (waitingForPerformanceFile) {
|
||||||
//I get a atp url from one participant
|
//I get an atp url from one participant
|
||||||
results[results.length] = message;
|
performanceJSON.avatarClips[performanceJSON.avatarClips.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
if(waitingForPerformanceFile) {
|
if (waitingForPerformanceFile) {
|
||||||
totalWaitingTime += deltaTime;
|
totalWaitingTime += deltaTime;
|
||||||
if(totalWaitingTime > TIMEOUT || results.length === responsesExpected) {
|
if (totalWaitingTime > TIMEOUT || performanceJSON.avatarClips.length === responsesExpected) {
|
||||||
//I can upload the performance file on the asset
|
|
||||||
print("UPLOADING PERFORMANCE FILE");
|
print("UPLOADING PERFORMANCE FILE");
|
||||||
print(JSON.stringify(performanceJSON));
|
if (performanceJSON.avatarClips.length !== 0) {
|
||||||
if(performanceJSON !== null) {
|
//I can upload the performance file on the asset
|
||||||
//upload
|
|
||||||
Assets.uploadData(JSON.stringify(performanceJSON), extension, uploadFinished);
|
Assets.uploadData(JSON.stringify(performanceJSON), extension, uploadFinished);
|
||||||
}
|
}
|
||||||
//clean things after upload performance file to asset
|
//clean things after upload performance file to asset
|
||||||
|
@ -117,26 +109,28 @@ function update(deltaTime) {
|
||||||
responsesExpected = 0;
|
responsesExpected = 0;
|
||||||
totalWaitingTime = 0;
|
totalWaitingTime = 0;
|
||||||
Script.update.disconnect(update);
|
Script.update.disconnect(update);
|
||||||
results = [];
|
avatarClips = [];
|
||||||
performanceJSON = null;
|
performanceJSON = { "avatarClips" : [] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFinished(url){
|
function uploadFinished(url){
|
||||||
print("data uploaded to:" + url);
|
print("some info:");
|
||||||
|
print("performance file uploaded to: " + url);
|
||||||
uploadedFile = url;
|
uploadedFile = url;
|
||||||
Assets.downloadData(url, function (data) {
|
Assets.downloadData(url, function (data) {
|
||||||
print("data downloaded from:" + url + " the data is: ");
|
|
||||||
printPerformanceJSON(JSON.parse(data));
|
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) {
|
function printPerformanceJSON(obj) {
|
||||||
var results = obj.results;
|
print("downloaded performance file from asset and examinating its content...");
|
||||||
results.forEach(function(param) {
|
var avatarClips = obj.avatarClips;
|
||||||
var hash = param.hashATP;
|
avatarClips.forEach(function(param) {
|
||||||
print("url obtained: " + hash);
|
print("clip url obtained: " + param);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue