Add checkbox that stops countdown/finishes recording when reopen dialog

This commit is contained in:
David Rowe 2017-04-13 17:59:28 +12:00
parent 84cfe1cb75
commit b508d6882f
3 changed files with 79 additions and 16 deletions

View file

@ -23,14 +23,18 @@ var isUsingToolbar = false,
elShowInfoButton,
elLoadButton,
elRecordButton,
elFinishOnOpen,
elFinishOnOpenLabel,
EVENT_BRIDGE_TYPE = "record",
BODY_LOADED_ACTION = "bodyLoaded",
USING_TOOLBAR_ACTION = "usingToolbar",
RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed",
NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers",
STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording",
LOAD_RECORDING_ACTION = "loadRecording",
START_RECORDING_ACTION = "startRecording",
STOP_RECORDING_ACTION = "stopRecording";
STOP_RECORDING_ACTION = "stopRecording",
FINISH_ON_OPEN_ACTION = "finishOnOpen";
function stopPlayingRecording(event) {
var playerID = event.target.getElementsByTagName("input")[0].value;
@ -41,14 +45,14 @@ function stopPlayingRecording(event) {
}));
}
function orderRecording(a, b) {
return a.filename > b.filename ? 1 : -1;
}
function updatePlayersUnused() {
elPlayersUnused.innerHTML = numberOfPlayers - recordingsBeingPlayed.length;
}
function orderRecording(a, b) {
return a.filename > b.filename ? 1 : -1;
}
function updateRecordings() {
var tbody,
tr,
@ -132,10 +136,24 @@ function updateLoadButton() {
}
}
function updateFinishOnOpenLabel() {
var WINDOW_FINISH_ON_OPEN_LABEL = "Finish recording when open dialog",
TABLET_FINISH_ON_OPEN_LABEL = "Finish recording when open tablet";
elFinishOnOpenLabel.innerHTML = isUsingToolbar ? WINDOW_FINISH_ON_OPEN_LABEL : TABLET_FINISH_ON_OPEN_LABEL;
}
function onScriptEventReceived(data) {
var message = JSON.parse(data);
if (message.type === EVENT_BRIDGE_TYPE) {
switch (message.action) {
case USING_TOOLBAR_ACTION:
isUsingToolbar = message.value;
updateFinishOnOpenLabel();
break;
case FINISH_ON_OPEN_ACTION:
elFinishOnOpen.checked = message.value;
break;
case RECORDINGS_BEING_PLAYED_ACTION:
recordingsBeingPlayed = JSON.parse(message.value);
updateRecordings();
@ -179,6 +197,14 @@ function onRecordButtonClicked() {
}
}
function onFinishOnOpenClicked() {
EventBridge.emitWebEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
action: FINISH_ON_OPEN_ACTION,
value: elFinishOnOpen.checked
}));
}
function signalBodyLoaded() {
EventBridge.emitWebEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
@ -206,5 +232,10 @@ function onBodyLoaded() {
elRecordButton = document.getElementById("record-button");
elRecordButton.onclick = onRecordButtonClicked;
elFinishOnOpen = document.getElementById("finish-on-open");
elFinishOnOpen.onclick = onFinishOnOpenClicked;
elFinishOnOpenLabel = document.getElementById("finish-on-open-label");
signalBodyLoaded();
}

View file

@ -61,6 +61,10 @@
<div>
<input id="record-button" class="red" type="button" value="Record" />
</div>
<div class="property checkbox">
<input type="checkbox" id="finish-on-open">
<label for="finish-on-open" id="finish-on-open-label">Finish recording when open dialog/tablet</label>
</div>
<script>
onBodyLoaded();
</script>

View file

@ -385,14 +385,22 @@
}());
Dialog = (function () {
var EVENT_BRIDGE_TYPE = "record",
var isFinishOnOpen = false,
EVENT_BRIDGE_TYPE = "record",
BODY_LOADED_ACTION = "bodyLoaded",
USING_TOOLBAR_ACTION = "usingToolbar",
RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed",
NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers",
STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording",
LOAD_RECORDING_ACTION = "loadRecording",
START_RECORDING_ACTION = "startRecording",
STOP_RECORDING_ACTION = "stopRecording";
STOP_RECORDING_ACTION = "stopRecording",
FINISH_ON_OPEN_ACTION = "finishOnOpen";
function isUsingToolbar() {
return ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar")));
}
function onWebEventReceived(data) {
var message = JSON.parse(data);
@ -400,6 +408,16 @@
switch (message.action) {
case BODY_LOADED_ACTION:
// Dialog's ready; initialize its state.
tablet.emitScriptEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
action: USING_TOOLBAR_ACTION,
value: isUsingToolbar()
}));
tablet.emitScriptEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
action: FINISH_ON_OPEN_ACTION,
value: isFinishOnOpen
}));
tablet.emitScriptEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
action: NUMBER_OF_PLAYERS_ACTION,
@ -428,6 +446,10 @@
Recorder.finishRecording();
}
break;
case FINISH_ON_OPEN_ACTION:
// Set behavior on dialog open.
isFinishOnOpen = message.value;
break;
}
}
}
@ -458,6 +480,10 @@
}));
}
function finishOnOpen() {
return isFinishOnOpen;
}
function setUp() {
tablet.webEventReceived.connect(onWebEventReceived);
}
@ -468,21 +494,24 @@
return {
updatePlayerDetails: updatePlayerDetails,
finishOnOpen: finishOnOpen,
setUp: setUp,
tearDown: tearDown
};
}());
function onTabletScreenChanged(type, url) {
// Open/close dialog in tablet or window.
// Opened/closed dialog in tablet or window.
var RECORD_URL = "/scripts/system/html/record.html";
if (type === "Web" && url.slice(-RECORD_URL.length) === RECORD_URL) {
// Cancel countdown or finish recording.
if (Recorder.isCountingDown()) {
Recorder.cancelCountdown();
} else if (Recorder.isRecording()) {
Recorder.finishRecording();
if (Dialog.finishOnOpen()) {
// Cancel countdown or finish recording.
if (Recorder.isCountingDown()) {
Recorder.cancelCountdown();
} else if (Recorder.isRecording()) {
Recorder.finishRecording();
}
}
isDialogDisplayed = true;
} else {
@ -492,9 +521,8 @@
}
function onTabletShownChanged() {
// Open/close tablet.
if (tablet.tabletShown) {
// Opened/closed tablet.
if (tablet.tabletShown && Dialog.finishOnOpen()) {
// Cancel countdown or finish recording.
if (Recorder.isCountingDown()) {
Recorder.cancelCountdown();