content/hifi-content/milad/ROLC/Organize/Projects/Stanford-KeyMapping.js.js
2022-02-14 02:04:11 +01:00

98 lines
No EOL
2.7 KiB
JavaScript

var MAPPING_NAME = "Demo Mapping";
var CHANNEL_NAME = "DEMO-DOMAIN-SWITCH";
var mapping = Controller.newMapping(MAPPING_NAME);
// These will need to be switched to the local ip addresses if internal is used
var LOCATION_01 = "hifi://rust";
var LOCATION_02 = "hifi://thespot";
var LOCATION_03 = "hifi://mexico";
var LOCATION_04 = "hifi://zaru";
var LOCATION_05 = "hifi://tomb";
var locations = [
LOCATION_01,
LOCATION_02,
LOCATION_03,
LOCATION_04,
LOCATION_05
];
// The first 3 are for the audience places
// These will switch everyone together
mapping.from(Controller.Hardware.Keyboard["4"]).to(function(value) {
if(value === 1){
Messages.sendMessage(CHANNEL_NAME, JSON.stringify({key: "all", domain: "rust"}));
}
});
mapping.from(Controller.Hardware.Keyboard["5"]).to(function(value) {
if(value === 1){
Messages.sendMessage(CHANNEL_NAME, JSON.stringify({key: "all", domain: "thespot"}));
}
});
mapping.from(Controller.Hardware.Keyboard["6"]).to(function(value) {
if(value === 1){
Messages.sendMessage(CHANNEL_NAME, JSON.stringify({key: "all", domain: "mexico"}));
}
});
mapping.from(Controller.Hardware.Keyboard["7"]).to(function(value) {
if(value === 1){
Messages.sendMessage(CHANNEL_NAME, JSON.stringify({key: "all", domain: "zaru"}));
}
});
mapping.from(Controller.Hardware.Keyboard["8"]).to(function(value) {
if(value === 1){
Messages.sendMessage(CHANNEL_NAME, JSON.stringify({key: "all", domain: "tomb"}));
}
});
Controller.enableMapping(MAPPING_NAME);
Script.scriptEnding.connect(function () {
Controller.disableMapping(MAPPING_NAME);
Messages.unsubscribe(CHANNEL_NAME);
});
Messages.subscribe(CHANNEL_NAME);
// Turn this on for Audience Switching
function messageHandler(channel, messageString, messageID) {
if (channel !== CHANNEL_NAME) {
return;
}
var message = {};
message = JSON.parse(messageString);
if (message.key === "all") {
switch (message.domain) {
case "rust" :
Window.location.handleLookupString(locations[0]);
break;
case "thespot" :
Window.location.handleLookupString(locations[1]);
break;
case "mexico" :
Window.location.handleLookupString(locations[2]);
break;
case "zaru" :
Window.location.handleLookupString(locations[3]);
break;
case "tomb" :
Window.location.handleLookupString(locations[4]);
break;
default:
Window.location.handleLookupString(locations[0]);
}
}
}
Messages.messageReceived.connect(messageHandler);