-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (95 loc) · 3.24 KB
/
index.js
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
require('node-rest-client');
var fs = require('fs');
var request = require('request');
var Client = require('node-rest-client').Client;
var client = new Client();
getInfo = function() {
console.log("button clicked")
client.get("http://192.168.1.1:80/osc/info", function (data, response) {
console.log(data);
// console.log(response);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
state = function() {
var args = {
data: { },
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/state", args, function (data, response) {
// console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
startSession = function() {
var args = {
data: { "name": "camera.startSession" },
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/commands/execute", args, function (data, response) {
console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
takePicture = function() {
var args = {
data: { "name": "camera.takePicture"},
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/commands/execute", args, function (data, response) {
console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
setApiV2 = function() {
var args = {
data: { "name": "camera.setOptions",
"parameters":{
"sessionId": "SID_0001",
"options": {
"clientVersion": 2
}
}
},
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/commands/execute", args, function (data, response) {
console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
getImage = function() {
var lastImageUrl;
var args = {
data: {
"name": "camera.listFiles",
"parameters": {
"fileType": "image",
"entryCount": 1,
"maxThumbSize": 0
}
},
headers: {"Content-Type": "application/json"}
}
client.post("http://192.168.1.1/osc/commands/execute", args, function (data, response) {
lastImageUrl = data.results.entries[0].fileUrl;
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
console.log(lastImageUrl);
// download('http://192.168.1.1/files/744a605553442020024b0202cb00f201/100RICOH/R0012006.JPG', '360_images/lastFile.jpg', function(){
download(lastImageUrl, '360_images/lastFile.jpg', function(){
});
});
}
// Please enable automatic start of session and then set the API to v2
console.log('!!!!!! window loaded');