233 lines
No EOL
6 KiB
JavaScript
233 lines
No EOL
6 KiB
JavaScript
(function () {
|
|
|
|
// var URL = "https://script.google.com/macros/s/AKfycbzrcCSD4f2Qq4NEtlV1xlGgkQX6tYq3z9_RgpgYyXtne73-jQ/exec";
|
|
|
|
var live = {};
|
|
var previous = {};
|
|
var interval = null;
|
|
|
|
var isOn = true;
|
|
|
|
var DEBUG = true;
|
|
|
|
var COLOR_LOGGEDIN = { red: 0, blue: 0, green: 255 };
|
|
var COLOR_ANONYMOUS_USER = { red: 255, blue: 0, green: 0 };
|
|
var COLOR_PENDING = { red: 255, blue: 255, green: 255 };
|
|
|
|
var button;
|
|
|
|
var buttonName = "SEEK ANONYMOUS";
|
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
|
|
button = tablet.addButton({
|
|
icon: "http://hifi-content.s3-us-west-1.amazonaws.com/robin/dev/domains/loadtest/Checkin/V2_Checkin/check-in-i.svg",
|
|
activeIcon: "http://hifi-content.s3-us-west-1.amazonaws.com/robin/dev/domains/loadtest/Checkin/V2_Checkin/check-in-a.svg",
|
|
text: buttonName,
|
|
isActive: true,
|
|
// sortOrder: 4
|
|
});
|
|
|
|
button.clicked.connect(toggleStatusOverlays);
|
|
|
|
function start() {
|
|
|
|
if (DEBUG) {
|
|
print("START");
|
|
}
|
|
|
|
interval = Script.setInterval(function () {
|
|
if (DEBUG) {
|
|
print("INTERVAL");
|
|
}
|
|
|
|
newList = AvatarList.getAvatarsInRange(MyAvatar.position, 5);
|
|
|
|
// add user to rendered overlays
|
|
for (var a = 0; a < newList.length; a++) {
|
|
if (DEBUG) {
|
|
print("LOOP2");
|
|
}
|
|
|
|
var uuid = newList[a];
|
|
|
|
var hasUUID = uuid;
|
|
var isMyUUID = MyAvatar.sessionUUID === uuid;
|
|
var isInLiveList = live[uuid] !== undefined;
|
|
|
|
|
|
if (DEBUG) {
|
|
print(hasUUID, !isMyUUID, !isInLiveList);
|
|
}
|
|
|
|
var uuid = newList[a];
|
|
if (hasUUID && !isMyUUID && !isInLiveList) {
|
|
|
|
addUserCreateOverlay(uuid);
|
|
|
|
}
|
|
}
|
|
|
|
// remove
|
|
for (var uuid in live) {
|
|
|
|
if (DEBUG) {
|
|
print("LOOP1");
|
|
}
|
|
|
|
var hasUUID = uuid;
|
|
var isMyUUID = MyAvatar.sessionUUID === uuid;
|
|
var isInNewList = newList.indexOf(uuid) !== -1;
|
|
|
|
if (DEBUG) {
|
|
print("REMOVAL HEE", hasUUID, !isMyUUID, !isInNewList);
|
|
}
|
|
|
|
if (hasUUID && !isMyUUID && !isInNewList) {
|
|
if (DEBUG) {
|
|
print("REMOVE", live[uuid].overlayID);
|
|
}
|
|
|
|
var overlayToDelete = live[uuid].overlayID;
|
|
Overlays.deleteOverlay(overlayToDelete);
|
|
|
|
delete live[uuid];
|
|
}
|
|
}
|
|
|
|
}, 1000);
|
|
}
|
|
|
|
// function encodeURLParams(params) {
|
|
// var paramPairs = [];
|
|
// for (var key in params) {
|
|
// paramPairs.push(key + "=" + params[key]);
|
|
// }
|
|
// return paramPairs.join("&");
|
|
// }
|
|
|
|
function addUserCreateOverlay(uuid) {
|
|
if (DEBUG) {
|
|
print("ADD USER CREATE OVERLAY");
|
|
}
|
|
|
|
var data = AvatarManager.getAvatar(uuid);
|
|
var previousInfo = previous[uuid];
|
|
|
|
var isNewEntry = previousInfo === undefined;
|
|
|
|
var overlayProperties = {
|
|
position: data.position,
|
|
dimensions: { x: 0.3, y: 0.3, z: 0.3 },
|
|
solid: true,
|
|
parentID: uuid,
|
|
color: isNewEntry
|
|
? COLOR_PENDING
|
|
: previousInfo.isLoggedIn
|
|
? COLOR_LOGGEDIN
|
|
: COLOR_PENDING,
|
|
drawInFront: true
|
|
};
|
|
|
|
var overlayID = Overlays.addOverlay("sphere", overlayProperties);
|
|
|
|
var toAdd = {
|
|
sessionUUID: uuid,
|
|
overlayID: overlayID,
|
|
displayName: isNewEntry ? data.displayName : previousInfo.displayName
|
|
};
|
|
|
|
if (isNewEntry || previousInfo.isLoggedIn === false) {
|
|
Users.requestUsernameFromID(uuid);
|
|
}
|
|
|
|
live[uuid] = toAdd;
|
|
}
|
|
|
|
function setLoggedInStatus(uuid, username, machineFingerprint, isAdmin) {
|
|
if (DEBUG) {
|
|
print("SET USERNAME");
|
|
}
|
|
|
|
var isLoggedIn = username ? true : false;
|
|
var color = getOverlayColor(isLoggedIn);
|
|
|
|
if (live[uuid] !== null) {
|
|
live[uuid].isLoggedIn = isLoggedIn;
|
|
Overlays.editOverlay(live[uuid].overlayID, {color: color});
|
|
}
|
|
|
|
var previousInfo = {
|
|
isLoggedIn: isLoggedIn
|
|
};
|
|
|
|
previous[uuid] = previousInfo;
|
|
// previous[uuid] === live[uuid];
|
|
}
|
|
|
|
function toggleStatusOverlays () {
|
|
isOn = !isOn;
|
|
|
|
print("TOGGLE", isOn);
|
|
|
|
button.editProperties({isActive: isOn});
|
|
|
|
if (isOn) {
|
|
start();
|
|
} else {
|
|
stopInterval();
|
|
removeOverlays();
|
|
}
|
|
|
|
}
|
|
|
|
function getOverlayColor(isLoggedIn) {
|
|
var color;
|
|
|
|
if (isLoggedIn) {
|
|
color = COLOR_LOGGEDIN;
|
|
} else {
|
|
color = COLOR_ANONYMOUS_USER;
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
function unload() {
|
|
|
|
button.clicked.disconnect(toggleStatusOverlays);
|
|
if (tablet) {
|
|
tablet.removeButton(button);
|
|
}
|
|
|
|
stopInterval();
|
|
removeOverlays();
|
|
|
|
Users.usernameFromIDReply.disconnect(setLoggedInStatus);
|
|
}
|
|
|
|
function removeOverlays () {
|
|
|
|
|
|
for (var key in live) {
|
|
var overlayToDelete = live[key].overlayID;
|
|
|
|
print("DELETE", overlayToDelete);
|
|
Overlays.deleteOverlay(overlayToDelete);
|
|
}
|
|
|
|
live = {};
|
|
}
|
|
|
|
function stopInterval () {
|
|
if (interval) {
|
|
Script.clearInterval(interval);
|
|
}
|
|
}
|
|
|
|
Script.scriptEnding.connect(unload);
|
|
Users.usernameFromIDReply.connect(setLoggedInStatus);
|
|
|
|
start();
|
|
|
|
})(); |