-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
90 lines (78 loc) · 2.44 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
html,
body,
.frame {
width:100vw;
height: 100vh;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans,
Droid Sans, Helvetica Neue, sans-serif;
font-size: 14px;
}
.warning {
background-color: #df68a2;
padding: 3px;
border-radius: 5px;
color: white;
}
</style>
</head>
<body>
<iframe id="frame" class="frame" allow="camera *; microphone *"></iframe>
<script>
const subdomain = 'demo'; // Replace with your custom subdomain
const frame = document.getElementById('frame');
frame.src = `https://${subdomain}.readyplayer.me/avatar?frameApi`;
window.addEventListener('message', subscribe);
document.addEventListener('message', subscribe);
function subscribe(event) {
console.log(event);
const json = parse(event);
if (json?.source !== 'readyplayerme') {
return;
}
// Susbribe to all events sent from Ready Player Me once frame is ready
if (json.eventName === 'v1.frame.ready') {
frame.contentWindow.postMessage(
JSON.stringify({
target: 'readyplayerme',
type: 'subscribe',
eventName: 'v1.**'
}),
'*'
);
consol.log("Ready");
}
// Get avatar GLB URL
if (json.eventName === 'v1.avatar.exported') {
console.log(`Avatar URL: ${json.data.url}`);
document.getElementById('avatarUrl').innerHTML = `Avatar URL: ${json.data.url}`;
document.getElementById('frame').hidden = true;
}
// Get user id
if (json.eventName === 'v1.user.set') {
console.log(`User with id ${json.data.id} set: ${JSON.stringify(json)}`);
}
}
function parse(event) {
try {
return JSON.parse(event.data);
} catch (error) {
return null;
}
}
function displayIframe() {
document.getElementById('frame').hidden = false;
}
</script>
</body>
</html>