Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
b8cf9a1801 | |||
a25b0ff3b2 | |||
7907430e95 |
@ -91,6 +91,15 @@ finder.on('serverFound', function(server) {
|
||||
})
|
||||
```
|
||||
|
||||
### constructor(port, address)
|
||||
|
||||
Port is an integer. Address is an IPv4 address of the server as a string.
|
||||
|
||||
Examples:
|
||||
```javascript
|
||||
var client = new ScreenLogic.UnitConnection(80, '10.0.0.85')
|
||||
```
|
||||
|
||||
### connect()
|
||||
|
||||
Connects to the server passed to its constructor.
|
||||
|
13
example.js
13
example.js
@ -2,7 +2,14 @@ const ScreenLogic = require('./index');
|
||||
|
||||
var finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', function(server) {
|
||||
var client = new ScreenLogic.UnitConnection(server);
|
||||
connect(new ScreenLogic.UnitConnection(server));
|
||||
});
|
||||
|
||||
finder.search();
|
||||
|
||||
//connect(new ScreenLogic.UnitConnection(80, '10.0.0.85'));
|
||||
|
||||
function connect(client) {
|
||||
client.on('loggedIn', function() {
|
||||
this.getVersion();
|
||||
this.getPoolStatus();
|
||||
@ -32,6 +39,4 @@ finder.on('serverFound', function(server) {
|
||||
});
|
||||
|
||||
client.connect();
|
||||
});
|
||||
|
||||
finder.search();
|
||||
}
|
||||
|
12
index.js
12
index.js
@ -56,9 +56,15 @@ class FindUnits extends EventEmitter {
|
||||
}
|
||||
|
||||
class UnitConnection extends EventEmitter {
|
||||
constructor(server) {
|
||||
constructor(server, address) {
|
||||
super();
|
||||
this.server = server;
|
||||
if (typeof server === 'object') {
|
||||
this.serverPort = server.port;
|
||||
this.serverAddress = server.address;
|
||||
} else {
|
||||
this.serverPort = server;
|
||||
this.serverAddress = address;
|
||||
}
|
||||
|
||||
this.client = new net.Socket();
|
||||
var _this = this;
|
||||
@ -76,7 +82,7 @@ class UnitConnection extends EventEmitter {
|
||||
connect() {
|
||||
//console.log("connecting...");
|
||||
var _this = this;
|
||||
this.client.connect(this.server.port, this.server.address, function() {
|
||||
this.client.connect(this.serverPort, this.serverAddress, function() {
|
||||
_this.onConnected();
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "node-screenlogic",
|
||||
"description": "Tool for connecting to Pentair ScreenLogic systems on the local network",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/parnic/node-screenlogic.git",
|
||||
|
Reference in New Issue
Block a user