-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fabian Hoffmann
committed
May 3, 2015
1 parent
f0efe52
commit 9eefffd
Showing
3 changed files
with
102 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,67 @@ | ||
var os = require('os'); | ||
var request = require("request"); | ||
|
||
var currentAddress = function() { | ||
var networkInterfaces = os.networkInterfaces( ); | ||
for (var networkInterface in networkInterfaces) { | ||
var iface = networkInterfaces[networkInterface]; | ||
var utils = function() { | ||
|
||
for (var i = 0; i < iface.length; i++) { | ||
var name = iface[i]; | ||
if (name.address !== '127.0.0.1' && name.family === 'IPv4' && !name.internal) { | ||
return "http://" + name.address; | ||
var currentAddress = function() { | ||
var networkInterfaces = os.networkInterfaces( ); | ||
for (var networkInterface in networkInterfaces) { | ||
var iface = networkInterfaces[networkInterface]; | ||
|
||
for (var i = 0; i < iface.length; i++) { | ||
var name = iface[i]; | ||
if (name.address !== '127.0.0.1' && name.family === 'IPv4' && !name.internal) { | ||
return "http://" + name.address; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
currentAddress: currentAddress | ||
}; | ||
}; | ||
|
||
var master = function(masterUrl) { | ||
|
||
/** | ||
* Registers a client at the master. | ||
* | ||
* @param options following options have to be defined: | ||
* - type: type of client (e.g. handler, detector, ..) | ||
* - name: name of client | ||
* - description: description of client. | ||
* - address: network address of client. | ||
* - onSuccess (optional): on success callback function. | ||
* - onError (optional): on error callback function. | ||
*/ | ||
var register = function (options) { | ||
request.post({ | ||
uri: masterUrl + "/alarm/register/" + options.type, | ||
form: { | ||
name: options.name, | ||
description: options.description, | ||
url: options.address | ||
} | ||
}, function (error, _, body) { | ||
if (!error) { | ||
if (options.onSuccess) { | ||
options.onSuccess(JSON.parse(body)); | ||
} | ||
} else { | ||
if (options.onError) { | ||
options.onError(error); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
return { | ||
register: register | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
currentAddress: currentAddress | ||
utils: utils, | ||
master: master | ||
}; |
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