-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNewJerseyDot.js
73 lines (60 loc) · 2 KB
/
NewJerseyDot.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
'use strict';
const fs = require( 'fs' );
const https = require( 'https' );
const cameras = JSON.parse( fs.readFileSync( '../cameras/USA.json' ) );
https.request( 'https://511nj.org/api/client/camera/GetCameraDataByTourId?tourid=3', ( res ) => {
let data = '';
res.on( 'data', ( chunk ) => {
data += chunk;
});
res.on( 'end', () => {
Compile( JSON.parse( data ) );
});
}).end();
class Camera {
constructor ( cam ) {
const parsedObj = videoOrImage( cam );
this.location = {
decsription: cam.name + ' ' + cam.devicedescription,
latitude: cam.latitude,
longitude: cam.longitude
};
this.url = parsedObj.imageOnly ? parsedObj.imageSrc : parsedObj.streamSrc;
this.encoding = parsedObj.imageOnly ? 'JPEG' : 'H.264';
this.format = parsedObj.imageOnly ? 'IMAGE_STREAM' : 'UNIQUE_NEWJERSEYDOT';
this.marked_for_review = cam.StopCameraFlag;
}
}
function videoOrImage ( cam ) {
let imageOnly = true;
let streamSrc, imageSrc;
for ( const camType of cam.CameraMainDetail ) {
if ( camType.cameratype === 'Video' && !camType.URL.includes( 'Camera-Unavailable.png' ) ) {
imageOnly = false;
streamSrc = camType.URL.replace( 'https://', 'http://' ) + '?otp=';
//http for cross domain streaming
//Wowza otp key can be obtained by making requests to "https://511nj.org/api/client/camera/getHlsToken?Id=2"
//Required for streaming
//I have not found a way to get the turnkpike streams to work cross domain https://njtpk-wink.xcmdata.org/turnpike/hls/....
} else {
imageSrc = camType.URL; // These all appear to be "image unavailable" images
}
}
return {
imageOnly: imageOnly,
imageSrc: imageSrc,
streamSrc: streamSrc
};
}
function Compile ( data ) {
if ( !cameras['New Jersey'] ) {
cameras['New Jersey'] = {};
}
for ( const cam of data.Data.CameraData ) {
if ( !cameras['New Jersey'].other ) {
cameras['New Jersey'].other = [];
}
cameras['New Jersey'].other.push( new Camera( cam ) );
}
fs.writeFileSync( '../cameras/USA.json', JSON.stringify( cameras, null, 2 ) );
}