-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
122 lines (114 loc) · 3.3 KB
/
Copy pathindex.js
File metadata and controls
122 lines (114 loc) · 3.3 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
const axios = require('axios');
const version = "1.0";
const errors = {
"0" : "OK",
"1" : "Any",
"2" : "Timeout",
"3" : "Illegal Argument",
"4" : "Illegal Data Format",
"5": "Illegal Request",
"6": "Illegal Response",
"7": "Illegal State",
"8": "Illegal Type",
"9": "Index Out Of Bounds",
"10": "No Such Element",
"11": "No Such Field",
"12": "No Such Method",
"13": "Null Pointer",
"14": "Unsupported Version",
"15": "Unsupported Operation",
"40400": "Shooting fail",
"40401": "Camera Not Ready",
"40402": "Already Running Polling Api",
"40403": "Still Capturing Not Finished",
"41003": "Some content could not be deleted",
"401": "Unauthorized",
"403": "Forbidden",
"404": "Not Found",
"406": "Not Acceptable",
"413": "Request Entity Too Large",
"414": "Request-URI Too Long",
"501": "Not Implemented",
"503": "Service Unavailable",
};
var id = 2;
function execute(method, params,id, version){
let p = new Promise(function(resolve,reject){
let _params = params === false ? [false] : (params === null ? [] : params === undefined ? [] : [params] );
console.log(`\n${Date()} -- POST /${method} with ${_params} --- id: ${id}, version: ${version}`);
axios.post("http://10.0.0.1:10000/sony/camera", {
"method" : method,
"params": _params,
"id": id,
"version" : version
}).then((res)=>{
if(res.data.hasOwnProperty("result")){
//console.log(`${Date()} -- id:${res.data.id} -- ${res.status} -|\n\n result: ${JSON.stringify(res.data.result)}\n` );
console.log(`${Date()} -- id:${res.data.id} -- ${res.status} -|\n\n ` );
resolve(res);
} else {
reject(res);
}
}).catch((err)=>{
reject(err);
});
});
return p;
}
function post(method, params, ver){
return () => {
id = id + 1;
return execute(method, params , id, ver ? ver : version)
}
}
function wait(ms){
return () => {
let p = new Promise((resolve, reject)=>{
console.log(`${Date()} -- waiting... ${ms}`);
setTimeout(()=>{resolve()},ms);
});
return p;
}
}
execute("setShootMode","movie", id, version)
.then(post("getShootMode",null))
//.then(post("getSupportedShootMode",null))
//.then(post("getAvailableShootMode",null))
//.then(post("setShootMode","movie"))
.then(wait(1000))
.then(post("startMovieRec"))
.then(post("getEvent",true,"1.1"))
.then((res)=>{
return new Promise((resolve, reject)=>{
console.log(res.data.result[1]["cameraStatus"], "\n");
resolve(res);
});
})
.then(wait(1000))
.then(post("stopMovieRec"))
.then(post("getEvent",true,"1.1"))
.then((res)=>{
return new Promise((resolve, reject)=>{
console.log(res.data.result[1]["cameraStatus"], "\n");
resolve(res);
});
})
.then(post("setCameraFunction","Contents Transfer","1.1"))
.then(post("getEvent",true,"1.1"))
.then((res)=>{
return new Promise((resolve, reject)=>{
console.log(res.data.result[1]["cameraStatus"], "\n");
resolve(res);
});
})
.catch((err)=>{
console.log("---------------------------------------------------");
console.log(err);
console.log("---------------------------------------------------");
if(errors.hasOwnProperty(err.data.error[0])){
console.error(`Error : ${errors[err.data.error[0]]} `);
} else {
console.error("unhandled error");
}
});