-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
67 lines (59 loc) · 2.27 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
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>picamera.js demo</title>
</head>
<body>
<div>
<div>
<video id="videoElement" controls autoplay playsinline>
Your browser doesn't support HTML5 video.
</video>
</div>
<div>
<label>Device UID: <input type="text" id="deviceUid" placeholder="Device UID"></label><br>
<label>MQTT Host: <input type="text" id="mqttHost" placeholder="MQTT Host"></label><br>
<label>MQTT Path: <input type="text" id="mqttPath" placeholder="MQTT Path" value="/mqtt"></label><br>
<label>MQTT Port: <input type="number" id="mqttPort" placeholder="MQTT Port" value="8884"></label><br>
<label>MQTT Username: <input type="text" id="mqttUsername" placeholder="MQTT Username"></label><br>
<label>MQTT Password: <input type="password" id="mqttPassword" placeholder="MQTT Password"></label><br>
</div>
<div>
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
</div>
</div>
<script type="module">
import { PiCamera } from 'https://cdn.jsdelivr.net/npm/picamera.js@latest/dist/picamera.esm.js';
let videoRef = document.getElementById('videoElement');
let conn = null;
window.start = function start() {
// 取得使用者輸入的連線參數
const deviceUid = document.getElementById('deviceUid').value;
const mqttHost = document.getElementById('mqttHost').value;
const mqttPath = document.getElementById('mqttPath').value;
const mqttPort = parseInt(document.getElementById('mqttPort').value);
const mqttUsername = document.getElementById('mqttUsername').value;
const mqttPassword = document.getElementById('mqttPassword').value;
// 初始化 PiCamera 連線
conn = new PiCamera({
deviceUid: deviceUid,
mqttHost: mqttHost,
mqttPath: mqttPath,
mqttPort: mqttPort,
mqttUsername: mqttUsername,
mqttPassword: mqttPassword,
stunUrls: ["stun:stun1.l.google.com:19302", "stun:stun2.l.google.com:19302"],
});
conn.attach(videoRef);
conn.connect();
};
window.stop = function stop() {
if (conn) {
conn.terminate();
}
};
</script>
</body>
</html>