-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex5.html
80 lines (60 loc) · 2.07 KB
/
index5.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>player</title>
<style>
img {
width: 275px;
height: 210px;
}
</style>
</head>
<body>
<img id="one" src="/api/one/jpeg/image.jpeg"/>
<img id="two" src="/api/two/jpeg/image.jpeg"/>
<img id="three" src="/api/three/jpeg/image.jpeg"/>
<img id="four" src="/api/four/jpeg/image.jpeg"/>
<img id="five" src="/api/five/jpeg/image.jpeg"/>
<img id="six" src="/api/six/jpeg/image.jpeg"/>
<img id="seven" src="/api/seven/jpeg/image.jpeg"/>
<img id="eight" src="/api/eight/jpeg/image.jpeg"/>
<img id="nine" src="/api/nine/jpeg/image.jpeg"/>
<img id="ten" src="/api/ten/jpeg/image.jpeg"/>
<img id="eleven" src="/api/eleven/jpeg/image.jpeg"/>
<img id="twelve" src="/api/twelve/jpeg/image.jpeg"/>
<img id="thirteen" src="/api/thirteen/jpeg/image.jpeg"/>
<img id="forteen" src="/api/forteen/jpeg/image.jpeg"/>
<script src="/socket.io/socket.io.js"></script>
<script>
const imgs = document.getElementsByTagName('img');
for (let i = 0; i < imgs.length; i++) {
const img = imgs[i];
const type = 'jpeg';
const jpegSocket = io.connect(window.location.origin + '/api', {
transports: ['websocket'],
forceNew: true,
reconnection: true,
reconnectionDelay: 500,
query: `id=${img.id}&type=${type}`
})
jpegSocket.on('connect', function onConnect() {
console.log('connect');
})
jpegSocket.on('message', function onStatus(data) {
if (data.status === 'ready') {
setInterval(()=> {
jpegSocket.emit('request', 'single');
}, 500);
}
})
jpegSocket.on('jpeg', function onJpeg(data) {
const arrayBufferView = new Uint8Array(data);
const blob = new window.Blob([arrayBufferView], { type: 'image/jpeg' });
const urlCreator = window.URL || window.webkitURL;
img.src = urlCreator.createObjectURL(blob);
});
}
</script>
</body>
</html>