Skip to content

Commit

Permalink
Dowding: add simple test server
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jun 19, 2021
1 parent 04211ee commit d84f633
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ docs/
*.Test/
*.jar
*.cache
/Plugins/Dowding/server/node_modules
/Plugins/Dowding/server/package-lock.json
2 changes: 1 addition & 1 deletion plugins/Dowding/DowdingUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private void but_onvif_Click(object sender, EventArgs e)
private async void OnvifUpdate(object sender, PointLatLngAlt e)
{
await device.SetTrack(HomeLoc,
lastplla).ConfigureAwait(false);
e).ConfigureAwait(false);
}

private async void but_setathome_Click(object sender, EventArgs e)
Expand Down
62 changes: 62 additions & 0 deletions plugins/Dowding/server/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
console.log('Hello World')

const url = require("url");
const http = require('http');
const WebSocket = require('ws');

const requestListener = function (req, res) {
console.log('requestListener');
const pathname = url.parse(req.url).pathname;
if (pathname=== '/ws'){
return;
}

res.setHeader("Content-Type", "application/json");
res.writeHead(200);
if (pathname=== '/api/1.0/authentication/login') {
res.end('{"token":"test"}');
return;
}
res.end('[]');
};


const server = http.createServer(requestListener);

const wss = new WebSocket.Server({ noServer: true });

wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});

});

const interval = setInterval(function ping() {
wss.clients.forEach(function each(ws) {

// var answer = new WebAPIs.Dowding.WSPackaging<VehicleTick>() { datatype = "vehicle_ticks", operation = "create", data = new VehicleTick(Ts: DateTime.Now.AddYears(1).toUnixTime() * 1000, CorrelationId: "iwashereagain", AgentId: Guid.NewGuid().ToString(), Lat: -35, Lon: 145, Hae: 40, Vn: (decimal)-1.7, Ve: (decimal)0.05, Vd: (decimal)0.019, Vendor: "DJI", Model: "mavic mini", Serial: "iwashere", Id: Guid.NewGuid().ToString(), ContactId: Guid.NewGuid().ToString()) }.ToJSON();

time = Math.floor(new Date().getTime());
console.log('interval');
ws.send('{ "datatype": "vehicle_ticks", "data": { "ts": '+time+', "correlation_id": "iwashereagain", "agent_id": "025e98ab-3260-4144-918e-4858d0a7b1fe", "lat": -38.1830, "lon": 144.4148, "hae": 40.0, "vn": -1.7, "ve": 0.05, "vd": 0.019, "vendor": "DJI", "model": "mavic mini", "serial": "iwashere", "id": "4b31b0af-feec-4437-942e-29cccd54cbeb", "contact_id": "9a64d68f-5f99-45e8-8bc5-939a5c395499" }, "operation": "create"}');
ws.send('{ "datatype": "vehicle_ticks", "data": { "ts": '+time+', "correlation_id": "iwashereagain99", "agent_id": "025e98ab-3260-4144-918e-4858d0a7b1fe", "lat": -38.1830, "lon": 144.41485, "hae": 40.0, "vn": -1.7, "ve": 0.05, "vd": 0.019, "vendor": "DJI", "model": "mavic mini", "serial": "iwashere99", "id": "4b31b0af-feec-4437-942e-29cccd54cbec", "contact_id": "9a64d68f-5f99-45e8-8bc5-939a5c395498" }, "operation": "create"}');

});
}, 10000);


server.on('upgrade', function upgrade(request, socket, head) {
console.log('upgrade');
const pathname = url.parse(request.url).pathname;

if (pathname === '/ws') {
wss.handleUpgrade(request, socket, head, function done(ws) {
wss.emit('connection', ws, request);
});
} else {
socket.destroy();
}
});

server.listen(80);
8 changes: 8 additions & 0 deletions plugins/Dowding/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"ws": "^7.4.6"
},
"optionalDependencies": {
"bufferutil": "^4.0.3"
}
}
2 changes: 2 additions & 0 deletions plugins/Dowding/server/runme.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

"C:\Program Files\nodejs\node.exe" node.js

0 comments on commit d84f633

Please sign in to comment.