overte/examples/entityScripts/recordingEntityScript.js

92 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-11-16 17:27:00 -08:00
//
// recordingEntityScript.js
// examples/entityScripts
//
// Created by Alessandro Signa on 11/12/15.
// Copyright 2015 High Fidelity, Inc.
//
// All the avatars in the area when the master presses the button will start/stop recording.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
2015-11-17 18:01:51 -08:00
(function () {
2015-11-16 17:27:00 -08:00
var _this;
2015-11-18 11:24:17 -08:00
var isAvatarRecording = false;
var channel = "groupRecordingChannel";
var startMessage = "RECONDING STARTED";
var stopMessage = "RECONDING ENDED";
2015-11-16 17:27:00 -08:00
function recordingEntity() {
_this = this;
return;
}
2015-11-17 18:01:51 -08:00
2015-11-18 11:24:17 -08:00
function receivingMessage(channel, message, senderID) {
print("message received on channel:" + channel + ", message:" + message + ", senderID:" + senderID);
if(message === startMessage) {
2015-11-17 18:01:51 -08:00
_this.startRecording();
2015-11-18 11:24:17 -08:00
} else if(message === stopMessage) {
2015-11-17 18:01:51 -08:00
_this.stopRecording();
}
};
2015-11-16 17:27:00 -08:00
recordingEntity.prototype = {
2015-11-17 18:01:51 -08:00
preload: function (entityID) {
print("RECORDING ENTITY PRELOAD");
2015-11-16 17:27:00 -08:00
this.entityID = entityID;
2015-11-18 11:24:17 -08:00
2015-11-17 18:01:51 -08:00
var entityProperties = Entities.getEntityProperties(_this.entityID);
if (!entityProperties.ignoreForCollisions) {
Entities.editEntity(_this.entityID, { ignoreForCollisions: true });
}
2015-11-18 11:24:17 -08:00
Messages.messageReceived.connect(receivingMessage);
2015-11-16 17:27:00 -08:00
},
2015-11-18 11:24:17 -08:00
2015-11-17 18:01:51 -08:00
enterEntity: function (entityID) {
2015-11-16 17:27:00 -08:00
print("entering in the recording area");
2015-11-18 11:24:17 -08:00
Messages.subscribe(channel);
2015-11-16 17:27:00 -08:00
},
2015-11-18 11:24:17 -08:00
2015-11-17 18:01:51 -08:00
leaveEntity: function (entityID) {
2015-11-16 17:27:00 -08:00
print("leaving the recording area");
2015-11-18 11:24:17 -08:00
_this.stopRecording();
Messages.unsubscribe(channel);
2015-11-16 17:27:00 -08:00
},
2015-11-17 18:01:51 -08:00
startRecording: function (entityID) {
2015-11-18 11:24:17 -08:00
if (!isAvatarRecording) {
2015-11-16 17:27:00 -08:00
print("RECORDING STARTED");
Recording.startRecording();
isAvatarRecording = true;
}
},
2015-11-17 18:01:51 -08:00
stopRecording: function (entityID) {
if (isAvatarRecording) {
2015-11-16 17:27:00 -08:00
print("RECORDING ENDED");
Recording.stopRecording();
isAvatarRecording = false;
recordingFile = Window.save("Save recording to file", "./groupRecording", "Recordings (*.hfr)");
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
Recording.saveRecording(recordingFile);
}
}
},
2015-11-18 11:24:17 -08:00
2015-11-17 18:01:51 -08:00
unload: function (entityID) {
print("RECORDING ENTITY UNLOAD");
2015-11-18 11:24:17 -08:00
_this.stopRecording();
Messages.unsubscribe(channel);
Messages.messageReceived.disconnect(receivingMessage);
2015-11-16 17:27:00 -08:00
}
}
2015-11-17 18:01:51 -08:00
2015-11-16 17:27:00 -08:00
return new recordingEntity();
2015-11-17 18:01:51 -08:00
});