overte/script-archive/entityScripts/recordingEntityScript.js

121 lines
4.0 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 MASTER_TO_CLIENTS_CHANNEL = "startStopChannel";
var CLIENTS_TO_MASTER_CHANNEL = "resultsChannel";
var START_MESSAGE = "recordingStarted";
var STOP_MESSAGE = "recordingEnded";
var PARTICIPATING_MESSAGE = "participatingToRecording";
var RECORDING_ICON_URL = "http://cdn.highfidelity.com/alan/production/icons/ICO_rec-active.svg";
var NOT_RECORDING_ICON_URL = "http://cdn.highfidelity.com/alan/production/icons/ICO_rec-inactive.svg";
var ICON_WIDTH = 60;
var ICON_HEIGHT = 60;
var overlay = null;
2015-11-16 17:27:00 -08:00
function recordingEntity() {
_this = this;
return;
2015-11-20 15:22:18 -08:00
};
2015-11-17 18:01:51 -08:00
2015-11-18 11:24:17 -08:00
function receivingMessage(channel, message, senderID) {
2015-11-20 15:22:18 -08:00
if (channel === MASTER_TO_CLIENTS_CHANNEL) {
print("CLIENT received message:" + message);
2015-11-20 15:22:18 -08:00
if (message === START_MESSAGE) {
_this.startRecording();
2015-11-20 15:22:18 -08:00
} else if (message === STOP_MESSAGE) {
_this.stopRecording();
}
2015-11-17 18:01:51 -08:00
}
};
2015-11-20 15:22:18 -08:00
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");
};
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-17 18:01:51 -08:00
var entityProperties = Entities.getEntityProperties(_this.entityID);
if (!entityProperties.collisionless) {
Entities.editEntity(_this.entityID, { collisionless: true });
2015-11-17 18:01:51 -08:00
}
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");
Messages.subscribe(MASTER_TO_CLIENTS_CHANNEL);
overlay = Overlays.addOverlay("image", {
imageURL: NOT_RECORDING_ICON_URL,
width: ICON_HEIGHT,
height: ICON_WIDTH,
2015-11-23 17:59:31 -08:00
x: 275,
y: 0,
visible: true
});
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(MASTER_TO_CLIENTS_CHANNEL);
Overlays.deleteOverlay(overlay);
overlay = null;
2015-11-16 17:27:00 -08:00
},
2015-11-17 18:01:51 -08:00
2015-11-24 18:30:31 -08:00
startRecording: function () {
2015-11-18 11:24:17 -08:00
if (!isAvatarRecording) {
2015-11-16 17:27:00 -08:00
print("RECORDING STARTED");
Messages.sendMessage(CLIENTS_TO_MASTER_CHANNEL, PARTICIPATING_MESSAGE); //tell to master that I'm participating
2015-11-16 17:27:00 -08:00
Recording.startRecording();
isAvatarRecording = true;
Overlays.editOverlay(overlay, {imageURL: RECORDING_ICON_URL});
2015-11-16 17:27:00 -08:00
}
},
2015-11-17 18:01:51 -08:00
2015-11-24 18:30:31 -08:00
stopRecording: function () {
2015-11-17 18:01:51 -08:00
if (isAvatarRecording) {
2015-11-16 17:27:00 -08:00
print("RECORDING ENDED");
Recording.stopRecording();
isAvatarRecording = false;
2015-11-20 16:21:42 -08:00
Recording.saveRecordingToAsset(getClipUrl); //save the clip to the asset and link a callback to get its url
Overlays.editOverlay(overlay, {imageURL: NOT_RECORDING_ICON_URL});
2015-11-16 17:27:00 -08:00
}
},
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(MASTER_TO_CLIENTS_CHANNEL);
2015-11-18 11:24:17 -08:00
Messages.messageReceived.disconnect(receivingMessage);
2015-11-24 18:30:31 -08:00
if (overlay !== null) {
Overlays.deleteOverlay(overlay);
overlay = null;
}
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();
});