-
Notifications
You must be signed in to change notification settings - Fork 1
/
phone.htm
100 lines (81 loc) · 2.79 KB
/
phone.htm
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Camera API</title>
</head>
<body>
<div class="container">
<h1>Camera API</h1>
<section class="main-content">
<p>
<input type="file" id="take-picture" accept="image/*">
</p>
<p id="error"></p>
</section>
</div>
</body>
</html>
<script type="text/javascript">
(function () {
//connect to the socket
var loc = window.location, new_uri;
if (loc.protocol === "https:") { new_uri = "wss:"; }
else { new_uri = "ws:"; }
new_uri += "//" + loc.host;
var ws = new WebSocket( new_uri + "/phone_socket");
var takePicture = document.querySelector("#take-picture")
takePicture.onchange = function (event) {
file_obj = event.target.files[0]
f_reader = new FileReader()
f_reader.readAsDataURL(file_obj)
f_reader.onloadend=function(){
console.log(f_reader.result);
ws.send(f_reader.result);
}
moose = 10;
}
/*
var takePicture = document.querySelector("#take-picture"),
showPicture = document.querySelector("#show-picture");
if (takePicture && showPicture) {
// Set events
takePicture.onchange = function (event) {
// Get a reference to the taken picture or chosen file
var files = event.target.files,
file;
if (files && files.length > 0) {
file = files[0];
try {
// Get window.URL object
var URL = window.URL || window.webkitURL;
// Create ObjectURL
var imgURL = URL.createObjectURL(file);
// Set img src to ObjectURL
showPicture.src = imgURL;
// Revoke ObjectURL
URL.revokeObjectURL(imgURL);
}
catch (e) {
try {
// Fallback if createObjectURL is not supported
var fileReader = new FileReader();
fileReader.onload = function (event) {
showPicture.src = event.target.result;
};
fileReader.readAsDataURL(file);
}
catch (e) {
//
var error = document.querySelector("#error");
if (error) {
error.innerHTML = "Neither createObjectURL or FileReader are supported";
}
}
}
}
};
}
*/
})();
</script>