content/hifi-content/faye/tablet-dev/users-friends.html
2022-02-13 23:26:00 +01:00

126 lines
No EOL
4.9 KiB
HTML

<!--
// users.html
//
// Created by Faye Li on 18 Jan 2017
// Copyright 2017 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
-->
<html>
<head>
<title>Users Online</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600,700"" rel="stylesheet">
<style>
body {
margin: 0;
width: 100%;
font-family: 'Raleway', sans-serif;
color: white;
background: linear-gradient(#2b2b2b, #0f212e);
}
.top-bar {
width: 100%;
height: 90px;
background: linear-gradient(#2b2b2b, #1e1e1e);
font-weight: bold;
}
.top-bar .container {
display: flex;
justify-content: space-between;
align-items: center;
margin-left: 30px;
margin-right: 30px;
height: 100%;
}
#refresh-button {
width: 24px;
height: 24px;
}
.main {
padding: 30px;
}
#users-list div {
padding-top: 4px;
padding-bottom: 4px;
}
</style>
</head>
<body>
<div class="top-bar">
<div class="container">
<div>Users Online (Friends)</div>
<img id="refresh-button" onclick="pollUsers()" src="https://hifi-content.s3.amazonaws.com/faye/tablet-dev/refresh-icon.svg"></img>
</div>
</div>
<div class="main">
<div id="users-list"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
var METAVERSE_API_URL = "https://metaverse.highfidelity.com/api/v1/users?status=online&filter=friends";
var myUsername = null;
function displayUsers(data) {
$("#users-list").empty();
for (var i = 0; i < data.users.length; i++) {
// Don't display users who aren't in a domain
if (typeof data.users[i].location.root.name === "undefined") {
console.log(data.users[i].username + "is online but not in a domain");
$("#dev-div").append("<p>" + data.users[i].username + "is online but not in a domain</p>");
} else {
$("#dev-div").append("<div>" + data.users[i].username + " @ " + data.users[i].location.root.name + "</div>");
// Don't display yourself
if (data.users[i].username !== myUsername) {
console.log(data.users[i].username + " @ " + data.users[i].location.root.name);
$("#users-list").append("<div>" + data.users[i].username + " @ " + data.users[i].location.root.name + "</div>");
}
}
}
}
function pollUsers() {
// TODO: better transition visual such as spin wheel or loading bar
$("#dev-div").append("<p>polling users..</p>");
$.ajax({
url: METAVERSE_API_URL,
success: function(response) {
console.log(response);
$("#dev-div").append("<p>polling sucess</p>");
displayUsers(response.data);
}
});
}
function onScriptEventReceived(event) {
$("#dev-div").append("<p>Received a script event, its type is " + typeof event + "</p>");
if (typeof event === "string") {
// Parse the string into an object
event = JSON.parse(event);
}
if (event.type === "sendUsername") {
myUsername = event.data.username;
$("#dev-div").append("<p>myUsername is " + myUsername + "</p>");
consoloe.log("myUsername is " + myUsername);
}
}
$(document).ready(function() {
$("#dev-div").append("<p>ready</p>");
// Listen for events from hifi
EventBridge.scriptEventReceived.connect(onScriptEventReceived);
// Send a ready event to hifi
var eventObject = {"type": "ready"};
EventBridge.emitWebEvent(JSON.stringify(eventObject));
});
</script>
</body>
</html>