-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node-mock and node-client check if there is a wifi address
- Loading branch information
Showing
2 changed files
with
88 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,65 @@ | ||
// search a WiFi interface to serve | ||
const ip = require("ip") | ||
// ssdp | ||
const Server = require("node-ssdp").Server | ||
const SERVICE_TYPE = "urn:schemas-sbtvd-org:service:GingaCCWebServices:1" | ||
// ws routes | ||
var os = require('os'); | ||
var interfaces = os.networkInterfaces(); | ||
var serveInteface = null; | ||
var serveAddress = null; | ||
const wifiAddressPrefix = '192.168.0' | ||
Object.keys(interfaces).forEach(function (iName) { | ||
interfaces[iName].forEach(function (ipInfo) { | ||
if (ipInfo.address.startsWith(wifiAddressPrefix)) { | ||
console.log(`-- Found WiFi interface named ${iName} with adress ${ipInfo.address}`); | ||
serveInteface = iName; | ||
serveAddress = ipInfo.address; | ||
} | ||
}); | ||
}); | ||
if (serveInteface == null || serveAddress == null) { | ||
console.log('-- WARNING: It was not able to find a WiFi interface'); | ||
} | ||
|
||
// create WebService /location route | ||
const express = require("express"); | ||
const app = express(); | ||
const port = 44642; | ||
|
||
// start ws routes | ||
const wsport = 44642; | ||
app.get("/location", (req, res) => { | ||
res.header("Ext", ""); | ||
res.header("GingaCC-Server-BaseURL", "http://" + ip.address() + ":44642"); | ||
res.header("GingaCC-Server-SecureBaseURL", "https://" + ip.address() + ":44642"); | ||
res.header("GingaCC-Server-BaseURL", "http://" + serveAddress + ":" + wsport); | ||
res.header("GingaCC-Server-SecureBaseURL", "https://" + serveAddress + ":" + wsport); | ||
res.header("GingaCC-Server-PairingMethods", "qcode,kex"); | ||
res.header("GingaCC-Server-Manufacturer", "TeleMidia"); | ||
res.header("GingaCC-Server-ModelName", "TeleMidia GingaCC-Server Mock"); | ||
res.header("GingaCC-Server-FriendlyName", "TeleMidia Ginga Mock "); | ||
res.header("SERVER", "TeleMidia Ginga Mock"); | ||
res.send(); | ||
}); | ||
app.listen(port, () => { | ||
console.log(`-- GingaCC-Server listening on port ${port}.`) | ||
app.listen(wsport, () => { | ||
console.log(`-- GingaCC - Server WS listening on port ${wsport}.`); | ||
}); | ||
|
||
// start ssdp | ||
const server = new Server({ | ||
location: "http://" + ip.address() + ":44642" + "/location", | ||
suppressRootDeviceAdvertisements: true | ||
|
||
// start SSDP | ||
var SSDPServer = require('node-ssdp').Server; | ||
const SERVICE_TYPE = "urn:schemas-sbtvd-org:service:GingaCCWebServices:1" | ||
const server = new SSDPServer({ | ||
location: "http://" + (serveAddress ? serveAddress: ip.address()) + ":" + wsport + "/location", | ||
suppressRootDeviceAdvertisements: true, | ||
// uncoment to only use wifi interface | ||
// interfaces: [ | ||
// serveInteface | ||
// ], | ||
reuseAddr: true, | ||
adInterval: 30000 // hight notify interval because m-search response is more important | ||
}); | ||
server.addUSN(SERVICE_TYPE) | ||
server.addUSN(SERVICE_TYPE); | ||
server.start() | ||
.catch(e => { | ||
console.log("-- Failed to start GingaCC-Server SSDP:", e) | ||
console.log("-- Failed to start GingaCC-Server SSDP:", e); | ||
}) | ||
.then(() => { | ||
console.log("-- GingaCC-Server SSDP started.") | ||
}) | ||
console.log("-- GingaCC-Server SSDP started."); | ||
}) | ||
|
||
process.on('exit', function(){ | ||
server.stop() // advertise shutting down and stop listening | ||
}) |