mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge pull request #6445 from AlessandroSigna/groupRecording
DO NOT MERGE Group recording - upload performance file on asset
This commit is contained in:
commit
5f2944c41e
2 changed files with 95 additions and 21 deletions
|
@ -16,24 +16,33 @@
|
|||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
|
@ -50,19 +59,19 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -73,17 +82,19 @@
|
|||
print("RECORDING ENDED");
|
||||
Recording.stopRecording();
|
||||
isAvatarRecording = false;
|
||||
recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
|
||||
|
||||
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
|
||||
}
|
||||
Recording.saveRecordingToAsset(getClipUrl); //save the clip to the asset and link a callback to get its 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 performanceJSON = { "avatarClips" : [] };
|
||||
var responsesExpected = 0;
|
||||
var waitingForPerformanceFile = true;
|
||||
var totalWaitingTime = 0;
|
||||
var extension = "txt";
|
||||
|
||||
|
||||
Messages.subscribe(CLIENTS_TO_MASTER_CHANNEL);
|
||||
setupToolBar();
|
||||
|
||||
function setupToolBar() {
|
||||
|
@ -55,22 +68,72 @@ 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 an atp url from one participant
|
||||
performanceJSON.avatarClips[performanceJSON.avatarClips.length] = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update(deltaTime) {
|
||||
if (waitingForPerformanceFile) {
|
||||
totalWaitingTime += deltaTime;
|
||||
if (totalWaitingTime > TIMEOUT || performanceJSON.avatarClips.length === responsesExpected) {
|
||||
print("UPLOADING PERFORMANCE FILE");
|
||||
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
|
||||
waitingForPerformanceFile = false;
|
||||
responsesExpected = 0;
|
||||
totalWaitingTime = 0;
|
||||
Script.update.disconnect(update);
|
||||
performanceJSON = { "avatarClips" : [] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function uploadFinished(url){
|
||||
//need to print somehow the url here this way the master can copy the url
|
||||
print("PERFORMANCE FILE URL: " + url);
|
||||
Assets.downloadData(url, function (data) {
|
||||
printPerformanceJSON(JSON.parse(data));
|
||||
});
|
||||
}
|
||||
|
||||
function printPerformanceJSON(obj) {
|
||||
print("some info:");
|
||||
print("downloaded performance file from asset and examinating its content...");
|
||||
var avatarClips = obj.avatarClips;
|
||||
avatarClips.forEach(function(param) {
|
||||
print("clip url obtained: " + param);
|
||||
});
|
||||
}
|
||||
|
||||
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