-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp.js
53 lines (46 loc) · 1.58 KB
/
esp.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
var os = require('os');
var ssdp = require("peer-ssdp/lib/peer-ssdp");
var SERVER = os.type() + "/" + os.release() + " UPnP/1.1 Linux/0.0.1";
var uuid = "6bd5eabd-b7c8-4f7b-ae6c-a30ccdeb5988";
var peer = ssdp.createPeer();
peer.on("ready", function () {
//console.log("ready");
console.log("");
onReady();
console.log("===================================================");})
.on("found", function (headers, address){
console.log("Device Found : ");
//console.log("Device Found on : ", address);
console.log(headers);
console.log("===================================================");})
.on("close", function () {
//console.log("close");
})
.start();
var onReady = function () {
//console.log("notify SSDP alive message");
peer.alive({
NT: "upnp:rootdevice",
USN: "uuid:" + uuid + "::upnp:rootdevice",
LOCATION: "http://{{networkInterfaceAddress}}/upnp/devices/6bd5eabd-b7c8-4f7b-ae6c-a30ccdeb5988/desc.xml",
SERVER: SERVER
});
console.log("Search For Devices");
console.log("");
peer.search({
ST: "upnp:rootdevice"
//ST: "urn:Belkin:device:**"
});
setTimeout(function () {
//console.log("notify SSDP byebye message");
peer.byebye({
NT: "upnp:rootdevice",
USN: "uuid:" + uuid + "::upnp:rootdevice",
LOCATION: "http://{{networkInterfaceAddress}}/upnp/devices/6bd5eabd-b7c8-4f7b-ae6c-a30ccdeb5988/desc.xml",
SERVER: SERVER
}, function () {
peer.close();
console.log("");
});
}, 1000);
};