-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.html
98 lines (80 loc) · 2.79 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
<html>
<head>
<title>h264-live-player web client demo</title>
<style>
#video-box {
background-color: black;
position: relative;
width: 100%;
height: 0;
padding-bottom: calc(100% * 9 / 16);
}
#video-box > canvas{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.flexbox {
display: flex;
flex-direction: column;
align-items: center;
}
.video-aligner {
width: 70%;
}
@media only screen and (max-width: 800px) {
.video-aligner {
width: 100%;
}
}
</style>
</head>
<body>
<button type="button" onclick="wsavc.send('custom_event_from_client',{ hello:'world' })">Send event to server</button>
<br/>
<p id='frame_buffer'></p>
<br/>
<div class="flexbox">
<div class="video-aligner">
<div id="video-box">
<canvas id='cam' >
</div>
</div>
</div>
<!-- provide WSAvcPlayer -->
<!-- <script type="text/javascript" src="Decoder.js"></script>
<script type="text/javascript" src="YUVCanvas.js"></script>
<script type="text/javascript" src="Player.js"></script> -->
<!-- <script type="text/javascript" src="Decoder.js">;</script> -->
<script type="text/javascript" src="WSAvcPlayer.js">;</script>
<script type="text/javascript">
var canvas = document.getElementById('cam')
var fb = document.getElementById('frame_buffer')
// Create h264 player
var wsavc = new WSAvcPlayer.default({useWorker:true});
document.getElementById('video-box').appendChild(wsavc.AvcPlayer.canvas)
//expose instance for button callbacks
window.wsavc = wsavc;
//maybe get rid of the ws inside the player?
//var uri = "ws://meganeko:3000/videoStream"// + document.location.host;
var uri = "ws://" + document.location.host;
//var uri = "ws://localhost:3333/"
wsavc.connect(uri);
//wsavc.on('message', m=>console.log(m))
wsavc.on('disconnected',()=>console.log('WS Disconnected'))
wsavc.on('connected',()=>console.log('WS connected'))
wsavc.on('frame_shift',(fbl)=>{
fb.innerText = 'fl: '+fbl
})
wsavc.on('resized',(payload)=>{
console.log('resized', payload)
const vb = document.getElementById('video-box')
vb.style = `padding-bottom: calc( 100% * ${payload.height} / ${ payload.width })`
})
wsavc.on('stream_active',active=>console.log('Stream is ',active?'active':'offline'))
wsavc.on('custom_event_from_server',event=>console.log('got event from server', event))
</script>
</body>
</html>