Skip to content

Commit

Permalink
GitHub #58 - Add timeout option to client
Browse files Browse the repository at this point in the history
  • Loading branch information
sqmk committed Mar 8, 2016
1 parent 622af7f commit 42e46df
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ let client = new huejay.Client({
host: '123.0.12.34',
port: 80, // Optional
username: 'bridgeusername', // Optional
timeout: 15000, // Optional, timeout in milliseconds (15000 is the default)
});
```

If a *username* is not provided, nearly all commands will fail due to failure to
authenticate with the bridge. Be sure to provide a valid *username* to use all
client commands.

The *timeout* option applies to bridge commands. The default value is 15000
milliseconds (or 15 seconds).

### Users

Huejay provides several commands for managing users on Philips Hue bridges.
Expand Down
21 changes: 20 additions & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DEFAULT_CONFIG = {
host: undefined,
port: 80,
username: undefined,
timeout: 15000,
};

/**
Expand Down Expand Up @@ -70,12 +71,30 @@ class Client {
/**
* Set username
*
* @param {string} username Username
* @param {string} username Username
*/
set username(username) {
this.config.username = username;
}

/**
* Get timeout
*
* @return {int} Timeout
*/
get timeout() {
return this.config.timeout;
}

/**
* Set timeout
*
* @param {int} timeout Timeout
*/
set timeout(timeout) {
this.config.timeout = Number(timeout);
}

/**
* Get bridge accessor
*
Expand Down
5 changes: 4 additions & 1 deletion lib/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Transport {
headers: {
'Content-Type': 'application/json'
},
timeout: this.client.timeout,
transformRequest: [
(data) => {
return JSON.stringify(data);
Expand Down Expand Up @@ -98,7 +99,9 @@ class Transport {
return result;
})
.catch(error => {
throw error;
throw new HuejayError({
message: error.message
});
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "huejay",
"version": "1.0.4",
"version": "1.1.0",
"description": "Philips Hue client for Node.js",
"keywords": [
"hue",
Expand Down

0 comments on commit 42e46df

Please sign in to comment.