-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
162 lines (141 loc) · 3.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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>beacon</title>
<link rel="stylesheet" href="index.css" />
<style>
.container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
#dot {
width: 100px;
height: 100px;
border-radius: 50%;
border-width: 0px;
background-color: #000000;
visibility: hidden;
}
@keyframes bring-in {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes bring-in-stay {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
<script>
const ipc = require('electron').ipcRenderer
//const remote = require('electron').remote;
const { shell } = require('electron')
const path = require('path')
const config = require('./config')
var COLORS = []
//IPCs
ipc.on('screenInfo', function (event, screenInfo) {
//console.log(screenInfo);
})
ipc.on('beacon', function (event, beaconObj) {
//get dot span
let dot = document.getElementById('dot')
if (!beaconObj.color) {
beaconObj.color = 'red'
}
//get the color obj
let colorObj = COLORS.find((color) => color.id == beaconObj.color)
if (colorObj) {
dot.style.backgroundColor = colorObj.hex
}
if (!beaconObj.speed) {
beaconObj.speed = 0
}
//now convert the speed value of 0-255 to a seconds value between 1 and 10 seconds
let speed = (beaconObj.speed / 255) * 9
if (!beaconObj.repeat) {
beaconObj.repeat = 5
}
dot.style.animation = 'none'
dot.style.visibility = 'visible'
dot.style.opacity = 0
//determine the animation
switch (beaconObj.beaconType) {
case 'set':
dot.style.animation = 'none'
dot.style.opacity = 1
break
case 'fade':
dot.style.animation = `bring-in-stay ${speed}s linear 1`
setTimeout(
function () {
dot.style.opacity = 1
dot.style.animation = 'none'
},
speed * 1000 + 50,
) //little bit of extra time to make sure it's fully visible
break
case 'flash':
dot.style.animation = `bring-in ${speed}s linear ${beaconObj.repeat}`
//have it disappear after the animation is done
setTimeout(
function () {
dot.style.opacity = 0
dot.style.animation = 'none'
},
speed * 1000 * beaconObj.repeat,
)
break
case 'off':
default:
dot.style.animation = 'none'
dot.style.opacity = 0
break
}
})
ipc.on('colors', function (event, colors) {
COLORS = colors
})
ipc.on('sound', function (event, beaconObj, soundObj) {
//play the sound
//beaconObj will define the repeat and other properties
playSound(path.join(__dirname, 'static/' + soundObj.file), beaconObj.soundRepeat)
})
const playSound = (audioURL, playCount = 1) => {
const audioContext = new AudioContext()
audioContext.resume()
let playCountArray = []
for (let i = 0; i < playCount; i++) {
let soundInstance = new Audio(audioURL)
playCountArray.push(soundInstance)
if (playCountArray.length < playCount) {
playCountArray[i].addEventListener('ended', () => {
playCountArray.shift()
playCountArray[0].play()
})
}
}
playCountArray[0].play()
}
</script>
</head>
<body>
<div class="container">
<span id="dot"></span>
</div>
</body>
</html>