-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
188 lines (164 loc) · 4.95 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<title>A-Frame Sharedspace Component</title>
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<script src="./dist/aframe-sharedspace-component.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
html {
font-size: 14pt;
font-family: sans-serif;;
}
.hide {
color: black;
margin: 0;
padding: 1rem;
float: right;
text-align: right;
position: relative;
z-index: 110;
background-color: white;
font-size: 1rem;
}
section {
box-sizing: border-box;
padding: 0.5rem;
position: relative;
z-index: 100;
background-color: white;
transform: translateY(0);
transition: transform 500ms;
}
section.hidden {
transform: translateY(-100%);
}
p {
margin-top: 0.75rem;
margin-bottom: 0.3rem;
}
.options {
display: flex;
}
a-scene {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
.link,
.move {
display: block;
border-radius: 5px;
border: 2px dashed grey;
padding: 0.4rem;
margin-top: 1rem;
}
.move {
background-color: #61B8EC;
border: 2px solid #61B8EC;
}
a.move {
color: white;
font-weight: strong;
text-decoration: none;
}
</style>
</head>
<body>
<a class="hide" href="#">Hide</a>
<section class="instructions">
<h1>A-Frame Sharedspace Component</h1>
<p>
Grant this site permission to access your microphone and share the following link with your friends (or open it in another browser). Wait for a friend to start chatting.
</p>
<span class="link"></span>
<a class="move" href="./">Move to another room.</a>
</section>
<a-scene embedded>
<a-entity sharedspace="audio: true; hold: true" avatars>
<!-- Room -->
<a-sky color="#333"></a-sky>
<a-plane rotation="-90 0 0"
width="15" height="15" color="#777">
</a-plane>
<!-- Table -->
<a-cylinder class="table"
position="0 0.8 0"
height="0.02" color="#8ae0f4"
segments-height="1" segments-radial="6">
</a-cylinder>
</a-entity>
</a-scene>
<template>
<a-entity position-around>
<a-entity obj-model="obj: url(https://cdn.glitch.com/4e53a88a-96d2-46e5-ab4b-f8f1b9c2d486%2Fface.obj?1506059732633)" rotation="0 180 0" scale="0.01 0.01 0.01" position="0 -0.1 0.15"></a-entity>
<!--
Anime Face Model Stocking(https://sketchfab.com/models/d049b6a85d204057b170ef9dbc851200) by stocking(https://sketchfab.com/stocking) is licensed under CC Attribution(http://creativecommons.org/licenses/by/4.0/)
-->
</a-entity>
</template>
<script>
var instructions = document.querySelector('.instructions');
document.querySelector('.hide').onclick = function (evt) {
instructions.classList.toggle('hidden');
this.textContent = instructions.classList.contains('hidden') ? 'Show': 'Hide';
return false;
};
var scene = document.querySelector('a-scene');
var room = document.querySelector('[sharedspace]');
var table = document.querySelector('.table');
// Make the participant to look at the center of the table.
room.addEventListener('avataradded', function onAdded(evt) {
var avatar = evt.detail.avatar;
if (!avatar.hasLoaded) {
avatar.addEventListener('loaded', onAdded.bind(null, evt));
return;
}
var tablePosition = table.getAttribute('position');
var avatarY = avatar.getAttribute('position').y;
avatar.object3D.lookAt(new THREE.Vector3(
tablePosition.x, avatarY, tablePosition.z
));
// It is not enough to modify the underlaying Three object. It is
// neccessary to use the A-Frame API for the sharedspace component to
// be able of serialize the rotation correctly.
var radToDeg = THREE.Math.radToDeg;
var rotation = avatar.object3D.rotation;
rotation.y += Math.PI;
avatar.setAttribute('rotation', {
x: radToDeg(rotation.x),
y: radToDeg(rotation.y),
z: radToDeg(rotation.z)
});
});
// Create a new room or join one.
let roomName = window.location.search.substr(1);
if (!roomName) {
roomName = 'demo-' + Date.now();
history.pushState({}, '', window.location + `?${roomName}`);
}
connect();
function connect() {
if (!scene.hasLoaded) {
scene.addEventListener('loaded', connect);
return;
}
room.setAttribute('sharedspace', { room: roomName, hold: false });
}
// Select link on click.
var link = document.querySelector('.link');
link.textContent = window.location.href;
link.onclick = function () {
var range = document.createRange();
range.selectNode(link);
var selection = document.getSelection();
selection.empty();
selection.addRange(range);
};
</script>
</body>
</html>