mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
master can upload performance file on asset
This commit is contained in:
parent
eecb5b91b2
commit
a306e8d5b1
2 changed files with 97 additions and 17 deletions
|
@ -16,9 +16,11 @@
|
|||
|
||||
var _this;
|
||||
var isAvatarRecording = false;
|
||||
var channel = "groupRecordingChannel";
|
||||
var startMessage = "RECONDING STARTED";
|
||||
var stopMessage = "RECONDING ENDED";
|
||||
var MASTER_TO_CLIENTS_CHANNEL = "startStopChannel";
|
||||
var CLIENTS_TO_MASTER_CHANNEL = "resultsChannel";
|
||||
var START_MESSAGE = "recordingStarted";
|
||||
var STOP_MESSAGE = "recordingEnded";
|
||||
var PARTICIPATING_MESSAGE = "participatingToRecording";
|
||||
|
||||
function recordingEntity() {
|
||||
_this = this;
|
||||
|
@ -26,11 +28,13 @@
|
|||
}
|
||||
|
||||
function receivingMessage(channel, message, senderID) {
|
||||
print("message received on channel:" + channel + ", message:" + message + ", senderID:" + senderID);
|
||||
if(message === startMessage) {
|
||||
_this.startRecording();
|
||||
} else if(message === stopMessage) {
|
||||
_this.stopRecording();
|
||||
if(channel === MASTER_TO_CLIENTS_CHANNEL){
|
||||
print("CLIENT received message:" + message);
|
||||
if(message === START_MESSAGE) {
|
||||
_this.startRecording();
|
||||
} else if(message === STOP_MESSAGE) {
|
||||
_this.stopRecording();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -50,19 +54,20 @@
|
|||
|
||||
enterEntity: function (entityID) {
|
||||
print("entering in the recording area");
|
||||
Messages.subscribe(channel);
|
||||
Messages.subscribe(MASTER_TO_CLIENTS_CHANNEL);
|
||||
|
||||
},
|
||||
|
||||
leaveEntity: function (entityID) {
|
||||
print("leaving the recording area");
|
||||
_this.stopRecording();
|
||||
Messages.unsubscribe(channel);
|
||||
Messages.unsubscribe(MASTER_TO_CLIENTS_CHANNEL);
|
||||
},
|
||||
|
||||
startRecording: function (entityID) {
|
||||
if (!isAvatarRecording) {
|
||||
print("RECORDING STARTED");
|
||||
Messages.sendMessage(CLIENTS_TO_MASTER_CHANNEL, PARTICIPATING_MESSAGE); //tell to master that I'm participating
|
||||
Recording.startRecording();
|
||||
isAvatarRecording = true;
|
||||
}
|
||||
|
@ -77,13 +82,14 @@
|
|||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||
Recording.saveRecording(recordingFile);
|
||||
}
|
||||
Messages.sendMessage(CLIENTS_TO_MASTER_CHANNEL, recordingFile); //send back to the master the url
|
||||
}
|
||||
},
|
||||
|
||||
unload: function (entityID) {
|
||||
print("RECORDING ENTITY UNLOAD");
|
||||
_this.stopRecording();
|
||||
Messages.unsubscribe(channel);
|
||||
Messages.unsubscribe(MASTER_TO_CLIENTS_CHANNEL);
|
||||
Messages.messageReceived.disconnect(receivingMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,24 @@ var TOOL_ICON_URL = HIFI_PUBLIC_BUCKET + "images/tools/";
|
|||
var ALPHA_ON = 1.0;
|
||||
var ALPHA_OFF = 0.7;
|
||||
var COLOR_TOOL_BAR = { red: 0, green: 0, blue: 0 };
|
||||
var MASTER_TO_CLIENTS_CHANNEL = "startStopChannel";
|
||||
var CLIENTS_TO_MASTER_CHANNEL = "resultsChannel";
|
||||
var START_MESSAGE = "recordingStarted";
|
||||
var STOP_MESSAGE = "recordingEnded";
|
||||
var PARTICIPATING_MESSAGE = "participatingToRecording";
|
||||
var TIMEOUT = 20;
|
||||
|
||||
var toolBar = null;
|
||||
var recordIcon;
|
||||
var isRecording = false;
|
||||
var channel = "groupRecordingChannel";
|
||||
var results = [];
|
||||
var performanceJSON = null;
|
||||
var responsesExpected = 0;
|
||||
var waitingForPerformanceFile = true;
|
||||
var totalWaitingTime = 0;
|
||||
var extension = "txt";
|
||||
|
||||
Messages.subscribe(CLIENTS_TO_MASTER_CHANNEL);
|
||||
setupToolBar();
|
||||
|
||||
function setupToolBar() {
|
||||
|
@ -55,22 +68,83 @@ function mousePressEvent(event) {
|
|||
if (recordIcon === toolBar.clicked(clickedOverlay, false)) {
|
||||
if (!isRecording) {
|
||||
print("I'm the master. I want to start recording");
|
||||
var message = "RECONDING STARTED";
|
||||
Messages.sendMessage(channel, message);
|
||||
Messages.sendMessage(MASTER_TO_CLIENTS_CHANNEL, START_MESSAGE);
|
||||
isRecording = true;
|
||||
} else {
|
||||
print("I want to stop recording");
|
||||
var message = "RECONDING ENDED";
|
||||
Messages.sendMessage(channel, message);
|
||||
waitingForPerformanceFile = true;
|
||||
Script.update.connect(update);
|
||||
Messages.sendMessage(MASTER_TO_CLIENTS_CHANNEL, STOP_MESSAGE);
|
||||
isRecording = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function masterReceivingMessage(channel, message, senderID) {
|
||||
if(channel === CLIENTS_TO_MASTER_CHANNEL) {
|
||||
print("MASTER received message:" + 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
if(waitingForPerformanceFile) {
|
||||
totalWaitingTime += deltaTime;
|
||||
if(totalWaitingTime > TIMEOUT || results.length === responsesExpected) {
|
||||
//I can upload the performance file on the asset
|
||||
print("UPLOADING PERFORMANCE FILE");
|
||||
print(JSON.stringify(performanceJSON));
|
||||
if(performanceJSON !== null) {
|
||||
//upload
|
||||
Assets.uploadData(JSON.stringify(performanceJSON), extension, uploadFinished);
|
||||
}
|
||||
//clean things after upload performance file to asset
|
||||
waitingForPerformanceFile = false;
|
||||
responsesExpected = 0;
|
||||
totalWaitingTime = 0;
|
||||
Script.update.disconnect(update);
|
||||
results = [];
|
||||
performanceJSON = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uploadFinished(url){
|
||||
print("data uploaded to:" + url);
|
||||
uploadedFile = url;
|
||||
Assets.downloadData(url, function (data) {
|
||||
print("data downloaded from:" + url + " the data is: ");
|
||||
printPerformanceJSON(JSON.parse(data));
|
||||
});
|
||||
}
|
||||
|
||||
function printPerformanceJSON(obj) {
|
||||
var results = obj.results;
|
||||
results.forEach(function(param) {
|
||||
var hash = param.hashATP;
|
||||
print("url obtained: " + hash);
|
||||
});
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
toolBar.cleanup();
|
||||
Messages.unsubscribe(channel);
|
||||
Messages.unsubscribe(CLIENTS_TO_MASTER_CHANNEL);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Messages.messageReceived.connect(masterReceivingMessage);
|
Loading…
Reference in a new issue