-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathproxy.js
More file actions
39 lines (32 loc) · 1.12 KB
/
proxy.js
File metadata and controls
39 lines (32 loc) · 1.12 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
'use strict';
const net = require('net');
const MipcAuth = require('./mipcm-auth.js')
const FilterAuth = require('./filter-auth.js')
const jsonic = require('jsonic')
const fs = require('fs')
// Prepare
const mipc = new MipcAuth();
const config = JSON.parse(fs.readFileSync("./config.json", 'utf8'))
// proxy server
const proxy = net.createServer(function (socket) {
let client;
const filterAuthenticator = new FilterAuth(mipc)
console.log('Client connected to proxy');
// Create a new connection to the TCP server
client = net.connect(config.proxyPort,config.cameraIP);
client.on('error', function(ex) {
console.log('Connection to camera error ', ex);
socket.destroy('Camera not reachable.');
});
// 2-way pipe between client and TCP server
socket.pipe(filterAuthenticator).pipe(client).pipe(socket);
socket.on('close', function () {
console.log('Client disconnected from proxy');
mipc.reInit()
});
socket.on('error', function (err) {
console.log('Error: ' + err.toString());
});
});
proxy.listen(config.proxyPort);
console.log('Proxy listening');