mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 13:16:29 +02:00
Add countdown delay before starting recording
This commit is contained in:
parent
096909d423
commit
4580b89aa6
1 changed files with 97 additions and 28 deletions
|
@ -18,32 +18,96 @@
|
||||||
APP_URL = Script.resolvePath("html/record.html"),
|
APP_URL = Script.resolvePath("html/record.html"),
|
||||||
isDialogDisplayed = false,
|
isDialogDisplayed = false,
|
||||||
isRecordingEnabled = false,
|
isRecordingEnabled = false,
|
||||||
isRecording = false,
|
IDLE = 0,
|
||||||
|
COUNTING_DOWN = 1,
|
||||||
|
RECORDING = 2,
|
||||||
|
recordingState = IDLE,
|
||||||
tablet,
|
tablet,
|
||||||
button,
|
button,
|
||||||
EVENT_BRIDGE_TYPE = "record",
|
EVENT_BRIDGE_TYPE = "record",
|
||||||
BODY_LOADED_ACTION = "bodyLoaded",
|
BODY_LOADED_ACTION = "bodyLoaded",
|
||||||
USING_TOOLBAR_ACTION = "usingToolbar",
|
USING_TOOLBAR_ACTION = "usingToolbar",
|
||||||
ENABLE_RECORDING_ACTION = "enableRecording";
|
ENABLE_RECORDING_ACTION = "enableRecording",
|
||||||
|
|
||||||
|
CountdownTimer;
|
||||||
|
|
||||||
|
CountdownTimer = (function () {
|
||||||
|
var countdownTimer,
|
||||||
|
countdownSeconds,
|
||||||
|
NUMBER_OF_SECONDS = 3,
|
||||||
|
finishCallback;
|
||||||
|
|
||||||
|
function start(onFinishCallback) {
|
||||||
|
finishCallback = onFinishCallback;
|
||||||
|
countdownSeconds = NUMBER_OF_SECONDS;
|
||||||
|
print(countdownSeconds);
|
||||||
|
countdownTimer = Script.setInterval(function () {
|
||||||
|
countdownSeconds -= 1;
|
||||||
|
if (countdownSeconds <= 0) {
|
||||||
|
Script.clearInterval(countdownTimer);
|
||||||
|
finishCallback();
|
||||||
|
} else {
|
||||||
|
print(countdownSeconds);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
Script.clearInterval(countdownTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: start,
|
||||||
|
cancel: cancel
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
|
|
||||||
function usingToolbar() {
|
function usingToolbar() {
|
||||||
return ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|
return ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|
||||||
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar")));
|
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateButtonState() {
|
||||||
|
button.editProperties({ isActive: isRecordingEnabled || recordingState !== IDLE });
|
||||||
|
}
|
||||||
|
|
||||||
function startRecording() {
|
function startRecording() {
|
||||||
isRecording = true;
|
recordingState = RECORDING;
|
||||||
print("Start recording");
|
updateButtonState();
|
||||||
|
print(APP_NAME + ": Start recording");
|
||||||
}
|
}
|
||||||
|
|
||||||
function finishRecording() {
|
function finishRecording() {
|
||||||
isRecording = false;
|
recordingState = IDLE;
|
||||||
print("Finish recording");
|
updateButtonState();
|
||||||
|
print(APP_NAME + ": Finish recording");
|
||||||
}
|
}
|
||||||
|
|
||||||
function abandonRecording() {
|
function cancelRecording() {
|
||||||
isRecording = false;
|
recordingState = IDLE;
|
||||||
print("Abandon recording");
|
updateButtonState();
|
||||||
|
print(APP_NAME + ": Cancel recording");
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishCountdown() {
|
||||||
|
recordingState = RECORDING;
|
||||||
|
updateButtonState();
|
||||||
|
startRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelCountdown() {
|
||||||
|
recordingState = IDLE;
|
||||||
|
updateButtonState();
|
||||||
|
CountdownTimer.cancel();
|
||||||
|
print(APP_NAME + ": Cancel countdown");
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown() {
|
||||||
|
recordingState = COUNTING_DOWN;
|
||||||
|
updateButtonState();
|
||||||
|
print(APP_NAME + ": Start countdown");
|
||||||
|
CountdownTimer.start(finishCountdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTabletScreenChanged(type, url) {
|
function onTabletScreenChanged(type, url) {
|
||||||
|
@ -53,17 +117,17 @@
|
||||||
HOME_URL = "Tablet.qml";
|
HOME_URL = "Tablet.qml";
|
||||||
|
|
||||||
if (type === "Home" && url === HOME_URL) {
|
if (type === "Home" && url === HOME_URL) {
|
||||||
// Start recording if recording is enabled.
|
// Start countdown if recording is enabled.
|
||||||
if (!isRecording && isRecordingEnabled) {
|
if (isRecordingEnabled && recordingState === IDLE) {
|
||||||
startRecording();
|
startCountdown();
|
||||||
button.editProperties({ isActive: isRecordingEnabled || isRecording });
|
|
||||||
}
|
}
|
||||||
isDialogDisplayed = false;
|
isDialogDisplayed = false;
|
||||||
} else if (type === "Web" && url.slice(-RECORD_URL.length) === RECORD_URL) {
|
} else if (type === "Web" && url.slice(-RECORD_URL.length) === RECORD_URL) {
|
||||||
// Finish recording if is recording.
|
// Cancel countdown or finish recording.
|
||||||
if (isRecording) {
|
if (recordingState === COUNTING_DOWN) {
|
||||||
|
cancelCountdown();
|
||||||
|
} else if (recordingState === RECORDING) {
|
||||||
finishRecording();
|
finishRecording();
|
||||||
button.editProperties({ isActive: isRecordingEnabled || isRecording });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,16 +137,16 @@
|
||||||
isDialogDisplayed = false;
|
isDialogDisplayed = false;
|
||||||
|
|
||||||
if (!tablet.tabletShown) {
|
if (!tablet.tabletShown) {
|
||||||
// Start recording if recording is enabled.
|
// Start countdown if recording is enabled.
|
||||||
if (!isRecording && isRecordingEnabled) {
|
if (isRecordingEnabled && recordingState === IDLE) {
|
||||||
startRecording();
|
startCountdown();
|
||||||
button.editProperties({ isActive: isRecordingEnabled || isRecording });
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Finish recording if is recording.
|
// Cancel countdown or finish recording.
|
||||||
if (isRecording) {
|
if (recordingState === COUNTING_DOWN) {
|
||||||
|
cancelCountdown();
|
||||||
|
} else if (recordingState === RECORDING) {
|
||||||
finishRecording();
|
finishRecording();
|
||||||
button.editProperties({ isActive: isRecordingEnabled || isRecording });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +155,7 @@
|
||||||
var message = JSON.parse(data);
|
var message = JSON.parse(data);
|
||||||
if (message.type === EVENT_BRIDGE_TYPE) {
|
if (message.type === EVENT_BRIDGE_TYPE) {
|
||||||
if (message.action === BODY_LOADED_ACTION) {
|
if (message.action === BODY_LOADED_ACTION) {
|
||||||
|
// Dialog's ready; initialize its state.
|
||||||
tablet.emitScriptEvent(JSON.stringify({
|
tablet.emitScriptEvent(JSON.stringify({
|
||||||
type: EVENT_BRIDGE_TYPE,
|
type: EVENT_BRIDGE_TYPE,
|
||||||
action: ENABLE_RECORDING_ACTION,
|
action: ENABLE_RECORDING_ACTION,
|
||||||
|
@ -102,8 +167,10 @@
|
||||||
value: usingToolbar()
|
value: usingToolbar()
|
||||||
}));
|
}));
|
||||||
} else if (message.action === ENABLE_RECORDING_ACTION) {
|
} else if (message.action === ENABLE_RECORDING_ACTION) {
|
||||||
|
// User update "enable recording" checkbox.
|
||||||
|
// The recording state must be idle because the dialog is open.
|
||||||
isRecordingEnabled = message.value;
|
isRecordingEnabled = message.value;
|
||||||
button.editProperties({ isActive: isRecordingEnabled || isRecording });
|
updateButtonState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +197,7 @@
|
||||||
icon: APP_ICON_INACTIVE,
|
icon: APP_ICON_INACTIVE,
|
||||||
activeIcon: APP_ICON_ACTIVE,
|
activeIcon: APP_ICON_ACTIVE,
|
||||||
text: APP_NAME,
|
text: APP_NAME,
|
||||||
isActive: isRecordingEnabled || isRecording
|
isActive: false
|
||||||
});
|
});
|
||||||
button.clicked.connect(onButtonClicked);
|
button.clicked.connect(onButtonClicked);
|
||||||
|
|
||||||
|
@ -143,8 +210,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
if (isRecording) {
|
if (recordingState === COUNTING_DOWN) {
|
||||||
abandonRecording();
|
cancelCountdown();
|
||||||
|
} else if (recordingState === RECORDING) {
|
||||||
|
cancelRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDialogDisplayed) {
|
if (isDialogDisplayed) {
|
||||||
|
|
Loading…
Reference in a new issue