-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.html
389 lines (348 loc) · 10.8 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="content-language" content="en-EN" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>GLANCE TRACKER - INTEGRATION DEMO Youtube</title>
<!-- WE INCLUDE THE MAIN SCRIPT -->
<script src="../../dist/jeelizGlanceTracker.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-78159065-6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-78159065-6');
</script>
<script>
"use strict"
let isYoutube = true;
let youtubePlayer = null;
const loadYoutubePlayer = () => {
const tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api'
const firstScriptTag = document.getElementsByTagName('script')[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)
}
loadYoutubePlayer()
function onYouTubeIframeAPIReady() {
youtubePlayer = new YT.Player('player', {
height: '360',
width: '540',
videoId: 'aEzZLXBH3rU',
events: {
'onReady': onPlayerReady
}
})
}
const onPlayerReady = (event) => {
event.target.playVideo()
}
const resumeVideo = () => {
youtubePlayer.playVideo()
}
const pauseVideo = () => {
youtubePlayer.pauseVideo()
}
const loadVideo = (id) => {
youtubePlayer.loadVideoById(id)
}
const searchYoutube = (loadFirst) => {
const query = document.getElementById('query').value
const urlFormatted = encodeURI(`https://www.googleapis.com/youtube/v3/search?q=${query}&maxResults=25&part=snippet`)
const urlToFetch = urlFormatted + '&key=AIzaSyD4hjdTRyjcgRDmn1x6NSUK6dQAnNGmhD4'
$.ajax({
url: urlToFetch,
success: (response) => {
$('#search-container').empty()
Object.keys(response.items).map((index) => {
const item = response.items[index]
const htmlNode = `<div onclick="loadVideo('${item.id.videoId}')" class="searchResultItem"><div class="searchResultItemImgContainer"><img src=${item.snippet.thumbnails.default.url} alt=""></div><div class="searchResultItemTitle">${item.snippet.title}</div></div>`
$('#search-container').append(htmlNode)
})
},
error: (err) => {
console.log('err',err)
}
})
}
const _states = {
idle: 0,
loading: 1,
enabled: 2,
disabled: 3
};
let _state = _states.idle;
function toggle_canvasContainer(isShow){
const DOMcanvasContainer = document.getElementById('glanceTrackerCanvasContainer');
if (!DOMcanvasContainer) return;
DOMcanvasContainer.style.opacity = (isShow) ? '1' : '0';
};
function toggle_glanceTracking(event){ //the user clic on the button
switch(_state){
case _states.idle:
init_glanceTracking();
break;
case _states.loading:
break;
case _states.enabled:
JEELIZGLANCETRACKER.toggle_pause(true, true);
toggle_canvasContainer(false);
_state = _states.disabled;
break;
case _states.disabled:
JEELIZGLANCETRACKER.toggle_pause(false, true);
toggle_canvasContainer(true);
_state = _states.enabled;
break;
}
update_button();
}; //end toggle_glanceTracking()
function update_button(){
const DOMbutton = document.getElementById('toggleGlanceTracking');
let buttonText = 'undefined';
switch(_state){
case _states.idle:
case _states.disabled:
buttonText = 'Enable glance tracking';
DOMbutton.style.backgroundColor = 'rgba(12, 189, 43, 1)';
break;
case _states.loading:
buttonText = 'LOADING...';
break;
case _states.enabled:
buttonText = 'Disable glance tracking';
DOMbutton.style.backgroundColor = 'lightgrey';
break;
}
DOMbutton.innerHTML = buttonText;
}; //end update_button()
function init_glanceTracking(){
_state=_states.loading;
JEELIZGLANCETRACKER.init({
callbackTrack: function(isDetected){
if (isDetected){
resumeVideo()
toggle_canvasContainer(false);
} else {
pauseVideo();
toggle_canvasContainer(true);
}
},
callbackReady: function(error){
if (error){
alert('AN ERROR HAPPENS :( CODE ='+error);
return;
}
console.log('JEELIZGLANCETRACKER is READY YEAH !');
_state = _states.enabled;
update_button();
toggle_canvasContainer(true);
},
isDisplayVideo: true,
canvasId: 'glanceTrackerCanvas',
NNCPath: '../../dist/' // where is NNC.json ?
}); //end JEELIZGLANCETRACKER.init call
}; //end init()
</script>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
<style type='text/css'>
a {color: #7af; text-decoration: none; font-weight: bold}
body {
background-color: #FAFAFA;
margin: 0px;
text-align: center;
font-family: Helvetica Neu, Arial, sans-serif;
}
.baseline {
color: #444;
font-size: 14pt;
}
.buttonEnable {
cursor: pointer;
font-size: 16pt;
margin: 1em;
background: rgba(12, 189, 43, 1);
border: none;
border-radius: 3px;
padding: 10px;
color: white;
box-shadow: 0 0 3px black;
transition: opacity 0.3s ease-in-out;
}
.buttonEnable:hover {
opacity: 0.8;
}
h1 {
font-weight: normal;
padding: 20px;
font-size: 22pt;
border-bottom: solid 1px #444;
margin-top: 0;
background: #444;
color: white;
font-family: monospace;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 0 3px black;
}
.headerYoutube {
margin: 0 10px -1px 20px;
font-family: Helvetica Neu, Arial, sans-serif;
}
.headerYoutube svg {
color: #E83324;
}
#glanceTrackerCanvasContainer {
background-color: #666;
font-size: 10pt;
text-align: center;
border: 1px solid white;
z-index: 99999999999999999; /*above Youtube fullscreen z-index*/
position: fixed;
bottom: 0px;
right: 0px;
opacity: 0;
transition-duration: 1000ms;
}
#glanceTrackerCanvas {
max-width: 25vmin;
}
#jeeVideo {
max-width: 100%; /*for mobiles */
}
#buttons {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
.credits {
max-width: 640px;
text-align: left;
display: inline-block;
color: #444;
font-size: 10pt;
}
li {
white-space: nowrap;
}
.playerSelection {
padding: 20px;
}
.playerSelectionTitle {
font-size: 15pt;
padding-bottom: 10px;
}
.containerFlex {
display: flex;
justify-content: center;
}
.searchSection {
width: 50%;
}
.searchSectionContainer {
margin-left: auto;
width: 540px;
padding: 10px;
background: white;
height: 340px;
border-radius: 3px 3px 0 0;
}
.playerSection {
width: 50%;
}
#search-button {
background: #E83324;
color: white;
height: 34px;
font-size: 11pt;
margin-left: 10px;
border-radius: 3px;
border: none;
cursor: pointer;
transition: opacity 0.3s ease-in-out;
}
#search-button:hover {
opacity: 0.8;
}
#search-container {
max-height: 280px;
margin-left: auto;
overflow-y: auto;
overflow-x: hidden;
padding: 0 20px;
}
.searchResultItem {
display: flex;
color: #444;
font-size: 10pt;
border-bottom: solid 1px #E83324;
padding: 10px;
background-color: white;
cursor: pointer;
}
.searchResultItemTitle {
padding-left: 10px;
padding-top: 10px;
font-weight: bold;
text-align: left;
}
#query {
height: 34px;
font-size: 12pt;
padding-left: 10px;
border-radius: 3px;
border: solid 1px lightgrey;
min-width: 288px;
}
.playerPlaceholder {
display: flex;
}
#player {
margin-left: 20px;
}
h2 {
margin-left: 20px;
margin-top: 0;
}
</style>
</head>
<body onload='update_button();searchYoutube(true);' style='color: white'>
<h1>Jeeliz Glance Tracker: <div class="headerYoutube"><i class="fab fa-youtube"></i> Youtube</div>integration demo</h1>
<div class="baseline">With the glance tracking, the video pauses when you look away.</div>
<button class="buttonEnable" onclick='toggle_glanceTracking(event)' id='toggleGlanceTracking'></button><br/>
<div class="containerFlex">
<div class="searchSection">
<div class="searchSectionContainer">
<div id="buttons">
<input id="query" value='dogs' type="text" />
<button onclick='searchYoutube()' id="search-button">Search</button>
</div>
<div id="search-container">
</div>
</div>
</div>
<div class="playerSection">
<div id='playerPlaceholder' class="playerPlaceholder">
<div id="player"></div>
</div>
</div>
</div>
<br/><div class='credits'>
<h2>Credits</h2>
<ul>
<li>JEELIZ : Deep learning networks in browser - <a href='https://jeeliz.com' target='_blank'>jeeliz.com</a> - Twitter : <a href='https://twitter.com/Jeeliz_AR' target='_blank'>@Jeeliz_AR</a>
<li>Github of the project : <a href='https://github.com/jeeliz/jeelizGlanceTracker' target='_blank'>jeeliz/jeelizGlanceTracker</a>
</ul>
</div>
<div id='glanceTrackerCanvasContainer'>
Tracking your glance ...<br/>
<canvas id='glanceTrackerCanvas'></canvas>
</div>
</body>
</html>