-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.js
463 lines (435 loc) · 13 KB
/
commands.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
import { POST } from './http-methods'
import { isNumber } from './util'
import { sorts,
imageTypes,
options, } from './camera-constants'
function validType(type) {
if (type && imageTypes.indexOf(type) === -1) {
throw new Error(`Unrecognized image type of ${_type}. Must be one of ${imageTypes.join(", ")}`)
}
return true
}
function validOptions(requestedOptions) {
const offendingOptions = requestedOptions.reduce((opts, option) => {
if (options.indexOf(option) === -1) {
opts.push(option)
}
return opts
}, [])
if (offendingOptions.length > 0) {
throw new Error (`Options ${offendingOptions.join(", ")} are not recognized options. Must be one of ${options.join(", ")}`)
}
return true;
}
class OSCCommands {
constructor(cameraUrl) {
this.cameraUrl = cameraUrl
}
_execute(command, parameters) {
return fetch(`${this.cameraUrl}/osc/commands/execute`, {
method: POST,
body: JSON.stringify({
name: command,
parameters: parameters || {}
})
}).then((response) => {
if (response.status > 300) {
try {
throw new Error(response.json())
} catch (exc) {
throw new Error(response)
}
}
const parsedResults = response.json()
if (parsedResults.state == 'error') {
throw new Error(parsedResults.error)
}
return parsedResults
})
}
/**
* Start a session on the camera
* @returns Promise with session info
* {
* "name": "camera.startSession",
* "state": "done",
* "results": {
* sessionId: "lsdkjfsdkljf",
* timeout: 180
* }
* }
*/
startSession() {
return this._execute('camera.startSession')
}
/**
* Update a session to expire later
* @param sessionId - the id of the session to update
* @returns Promise with session info
* {
* "name": "camera.updateSession",
* "state": "done",
* "results": {
* sessionId: "lsdkjfsdkljf",
* timeout: 180
* }
* }
*/
updateSession(sessionId) {
return this._execute('camera.updateSession', { sessionId })
}
/**
* Disconnects the client from the camera.
* @param sessionId - id of the session to close
* @returns Promise when complete no results
* {
* "name": "camera.closeSession",
* "state": "done",
* "results": {
* }
*/
closeSession(sessionId) {
return this._execute('camera.closeSession', { sessionId })
}
/**
* Turns the wireless LAN off.
* @returns Promise when complete with no results
* {
* "name": "_finishWlan",
* "state": "done",
* "results": {
* }
*/
finishWlan() {
return this._execute('camera._finishWlan')
}
/**
* Captures an equirectangular image, saving lat/long coordinates to EXIF (if your camera
* features its own GPS or GPS is enabled on connected mobile phones). Call setOptions prior to this command call if needed.
* @param sessionId - the id of the session to use
* @returns Promise with picture info
* {
* "name": "camera.takePicture",
* "state": "inProgress",
* "results": {
* "fileUri": "file URI"
* }
* }
*/
takePicture(sessionId) {
return this._execute('camera.takePicture', { sessionId })
}
/**
* Starts interval or video shooting.
* The shooting method differs depending on the shooting mode (captureMode) settings.
* Interval shooting starts when the mode is set to still image capture mode.
* Video shooting starts when the mode is set to video capture mode.
* @param sessionId
* @returns Promise with no results
* {
* "name": "camera._startCapture",
* "state": "inProgress",
* "results": {}
* }
*/
startCapture(sessionId) {
return this._execute('camera._startCapture', { sessionId })
}
/**
* Stops interval or video shooting. Use listAll to retrieve
* @param sessionId
* @returns Promise with no results
* * {
* "name": "camera._stopCapture",
* "state": "done",
* "results": {}
* }
*/
stopCapture(sessionId) {
return this._execute('camera._stopCapture', { sessionId })
}
/**
* Acquires the still image file list. SET maxSize to retrieve a thumbnail
* @param entryCount - No. of still image files to be acquired
* @param continuationToken - Token for reading the continuation from the previous listImages.
* @param maxSize - Fixed value for maximum size of thumbnails: 160 Required parameter when includeThumb is true
* @returns
* {
* "name": "camera.listImages",
* "state": "done",
* "results": {
* {
* "name": "camera._listAll",
* "state": "done",
* "results": {
* "entries": [
* {
* "name": "R0010016.JPG",
* "uri": "100RICOH/R0010016.JPG",
* "size": 4214389,
* "dateTimeZone": "2015:07:10 11:00:35+09:00",
* "width": 5376,
* "height": 2688
* },
* {
* "name": "R0010015.JPG",
* "uri": "100RICOH/R0010015.JPG",
* "size": 4217265,
* "dateTimeZone": "2015:07:10 11:00:34+09:00",
* "width": 5376,
* "height": 2688
* },
* {
* "name": "R0010014.JPG",
* "uri": "100RICOH/R0010014.JPG",
* "size": 4052147,
* "dateTimeZone": "2015:07:10 11:00:13+09:00",
* "width": 5376,
* "height": 2688
* }
* ],
* "totalEntries": 16,
* "continuationToken": "12"
* }
* }
*
*/
listImages(entryCount, continuationToken, maxSize) {
const params = {
entryCount,
continuationToken,
maxSize,
includeThumb: isNumber(maxSize)
}
return this._execute('camera.listImages', params)
}
/**
* Acquires the still image and video file list.
* @param entryCount - No. of still images and video files to be acquired
* @param continuationToken - Token for reading the continuation from the previous _listAll. (optional)
* @param detail - Whether or not file details are acquired true is acquired by default Only values that can be acquired when false is specified are "name", "uri", "size" and "dateTime"
* @param sort - Specify the sort order
* newest (dateTime descending order)/ oldest (dateTime ascending order)
* Default is newest
* @returns Promise with
{
"entries": [
{
"name": "R0010017.MP4",
"uri": "100RICOH/R0010017.MP4",
"size": 5135574,
"dateTimeZone": "2015:07:10 11:05:18+09:00",
"width": 1920,
"height": 1080,
"recordTime": 2
},
{
"name": "R0010016.JPG",
"uri": "100RICOH/R0010016.JPG",
"size": 4214389,
"dateTimeZone": "2015:07:10 11:00:35+09:00",
"width": 5376,
"height": 2688
},
{
"name": "R0010015.JPG",
"uri": "100RICOH/R0010015.JPG",
"size": 4217265,
"dateTimeZone": "2015:07:10 11:00:34+09:00",
"width": 5376,
"height": 2688
}
],
"totalEntries": 16,
"continuationToken": "12"
}
* }
*/
listAll(entryCount, continuationToken, detail, sort) {
if (sort && sorts.indexOf(sort) === -1) {
throw new Error(`Sort type of ${sort} is unrecognized. Must be one of ${sorts.join(", ")}`)
}
const params = {
entryCount,
continuationToken,
detail: detail,
sort: sort || 'newest'
}
return this._execute('camera._listAll', params)
}
/**
* Deletes still image or video files.
* @param fileUri
* @returns Promise with no results
* * {
* "name": "camera.delete",
* "state": "done",
* "results": {}
* }
*/
delete(fileUri) {
return this._execute('camera.delete', { fileUri })
}
/**
* Returns a full-size or scaled image given its URI. Input parameters include resolution
* @param fileUri
* @param _type - Type of file to be acquired Specify "thumb" or "full" Set to "full" by default if unspecified (thumb: Thumbnail image, full: Original size image)
* @returns Promise with binary data of image
*
*/
getImage(fileUri, _type) {
if (validType(_type)) {
const params = {
fileUri,
_type: _type || 'full'
}
return fetch(`${this.cameraUrl}/osc/commands/execute`, {
method: POST,
body: JSON.stringify({
name: 'camera.getImage',
parameters: { fileUri, _type, }
})
}).then((response) => {
if (response.status > 300) {
throw new Error(response)
}
return response.blob();
})
}
}
/**
* Acquires video.
* @param fileUri
* @param type - Type of file to be acquired Specify "thumb" or "full" Set to "full" by default if unspecified (thumb: Thumbnail image, full: Original size video)
* @returns Promise with binary data of thumbnail (JPEG) or video (MP4)
*/
getVideo(fileUri, type) {
if (validType(type)) {
const params = {
fileUri,
type: type || 'full'
}
return this._execute('camera._getVideo', params)
}
}
/**
* Acquires the Live View. Can only be executed in still image capture mode.
* Data acquisition is finished when the camera is operated, shooting starts or the shooting mode is switched.
* @param sessionId
*/
getLivePreview(sessionId) {
throw new Error("Live preview not yet supported")
}
/**
* Shows the meta information for the specified still image.
* @param fileUri
* @returns Promise with
* * {
* "name": "camera.getMetaData",
* "state": "done",
"results": {
"exif": {
...
"ImageWidth": 2000,
"ImageLength": 1000,
...
},
"xmp": {
"ProjectionType": "equirectangular",
"UsePanoramaViewer": true,
...
}
}
* }
*/
getMetaData(fileUri) {
return this._execute('camera.getMetaData', { fileUri })
}
/**
* Returns current settings for requested properties.
* @param sessionId
* @param optionNames - Options must be one of [
'aperture',
'_captureInterval',
'captureMode',
'_captureNumber',
'dateTimeZone',
'exposureCompensation',
'exposureProgram',
'fileFormat',
'_filter',
'gpsInfo',
'_HDMIreso',
'iso',
'isoSupport',
'offDelay',
'remainingPictures',
'remainingSpace',
'_remainingVideos',
'shutterSpeed',
'_shutterVolume',
'sleepDelay',
'totalSpace',
'whiteBalance',
'_wlanChannel'
]
* @returns Promise with
* {
* "name": "camera.getOptions",
* "state": "done",
* "results": {
* "options": {
* "iso": 200,
* ... (options you requested)
* }
*/
getOptions(sessionId, optionNames) {
if (validOptions(optionNames)) {
return this._execute('camera.getOptions', {sessionId, optionNames })
}
}
/**
* Property settings for shooting, the camera, etc.
*
* Check the properties that can be set and specifications by the API v2 reference options category or camera.getOptions.
* @param sessionId
* @param options - options and values to set [
'aperture',
'_captureInterval',
'captureMode',
'_captureNumber',
'dateTimeZone',
'exposureCompensation',
'exposureProgram',
'fileFormat',
'_filter',
'gpsInfo',
'_HDMIreso',
'iso',
'isoSupport',
'offDelay',
'remainingPictures',
'remainingSpace',
'_remainingVideos',
'shutterSpeed',
'_shutterVolume',
'sleepDelay',
'totalSpace',
'whiteBalance',
'_wlanChannel'
]
* @returns Promise with None
*
* * {
* "name": "camera.setOptions",
* "state": "done",
* "results": {}
* }
*/
setOptions(sessionId, options) {
if (validOptions(Object.keys(options))) {
return this._execute('camera.setOptions', {sessionId, options})
}
}
}
export default OSCCommands