69 lines
2 KiB
JavaScript
69 lines
2 KiB
JavaScript
//
|
|
// stageManager.js
|
|
//
|
|
// Created by Rebecca Stankus on 06/11/18
|
|
// Copyright 2018 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
(function() {
|
|
var TABLET_BUTTON_IMAGE = Script.resolvePath('svg/microphone-i.svg');
|
|
var TABLET_BUTTON_PRESSED = Script.resolvePath('svg/microphone-a.svg');
|
|
|
|
var audioVolume = 0.7;
|
|
var tablet = Tablet.getTablet('com.highfidelity.interface.tablet.system');
|
|
var appPage = Script.resolvePath('karaoke.html?10');
|
|
var button = tablet.addButton({
|
|
text: 'KARAOKE',
|
|
icon: TABLET_BUTTON_IMAGE,
|
|
activeIcon: TABLET_BUTTON_PRESSED
|
|
});
|
|
var open = false;
|
|
var injector;
|
|
|
|
function onClicked() {
|
|
if (open) {
|
|
tablet.gotoHomeScreen();
|
|
} else {
|
|
tablet.gotoWebScreen(appPage);
|
|
}
|
|
}
|
|
|
|
function onWebEventReceived(event) {
|
|
if (typeof event === 'string') {
|
|
// event = JSON.parse(event);
|
|
print(event);
|
|
}
|
|
}
|
|
|
|
function onScreenChanged(type, url) {
|
|
open = (url === appPage);
|
|
button.editProperties({isActive: open});
|
|
}
|
|
|
|
function appEnding() {
|
|
button.clicked.disconnect(onClicked);
|
|
tablet.removeButton(button);
|
|
tablet.screenChanged.disconnect(onScreenChanged);
|
|
tablet.webEventReceived.disconnect(onWebEventReceived);
|
|
}
|
|
|
|
function playSound(sound) {
|
|
if (sound.downloaded) {
|
|
if (injector) {
|
|
injector.stop();
|
|
}
|
|
injector = Audio.playSound(sound, {
|
|
position: MyAvatar.position,
|
|
volume: audioVolume
|
|
});
|
|
}
|
|
}
|
|
|
|
button.clicked.connect(onClicked);
|
|
tablet.screenChanged.connect(onScreenChanged);
|
|
tablet.webEventReceived.connect(onWebEventReceived);
|
|
|
|
Script.scriptEnding.connect(appEnding);
|
|
}());
|