Skip to content

Reconnection #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 22, 2018
Merged
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ const myDeviceListQuery = new DeviceListQuery({
networkId: 1
});

// Push message handler
myDeviceHive.on(DeviceHive.MESSAGE_EVENT, (message) => {
console.log(message);
});

// Error handler
myDeviceHive.on(DeviceHive.ERROR_EVENT, (error) => {
console.error(error);
});

// Connecting and usin API
myDeviceHive.connect()
.then(() => myDeviceHive.device.list(myDeviceListQuery))
Expand Down Expand Up @@ -145,9 +155,19 @@ DeviceHive module

<a name="DeviceHive+connect"></a>

### deviceHive.connect()
### deviceHive.connect({ accessToken, refreshToken, login, password, reconnectionAttempts, reconnectionInterval })
Connect and authorize

Params:
| Param | Type | Description |
| --- | --- | --- |
| options.accessToken | <code>string</code> | Access token (default DeviceHive constructor configuration) (optional) |
| options.refreshToken | <code>string</code> | Refresh token (default DeviceHive constructor configuration) (optional) |
| options.login | <code>string</code> | Login (default DeviceHive constructor configuration) (optional) |
| options.password | <code>string</code> | Password (default DeviceHive constructor configuration) (optional) |
| options.reconnectionAttempts | <code>number</code> | Reconnection attempts (default infinity (-1)) (optional) |
| options.reconnectionInterval | <code>number</code> | Reconnection interval in ms (default 5000) (optional) |

<a name="DeviceHive.models"></a>

### DeviceHive.models : <code>Object</code>
Expand Down
5 changes: 2 additions & 3 deletions eslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions" : {
"ecmaVersion" : 6,
"ecmaVersion" : 7,
"sourceType" : "module",
"ecmaFeatures" : {
"impliedStrict" : true,
Expand Down Expand Up @@ -39,7 +39,7 @@
"dot-notation" : "warn",
"eqeqeq" : "error",
"no-case-declarations" : "error",
"no-empty-function" : "error",
"no-empty-function" : "warn",
"no-empty-pattern" : "error",
"no-eval" : "error",
"no-extend-native" : "error",
Expand Down Expand Up @@ -96,7 +96,6 @@
"sort-imports" : "error",
"arrow-spacing" : "error",
"no-class-assign" : "error",
"no-confusing-arrow" : "error",
"no-dupe-class-members" : "error",
"no-duplicate-imports" : "error",
"no-this-before-super" : "error",
Expand Down
1 change: 0 additions & 1 deletion example/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void async function start () {
console.log(await httpDeviceHive.device.list(deviceListQuery));
console.log(await httpDeviceHive.deviceType.list(deviceTypeListQuery));
console.log(await httpDeviceHive.network.list(networkListQuery));
console.log(await httpDeviceHive.network.list(networkListQuery));
console.log(await httpDeviceHive.token.refresh(refreshToken));
}

Expand Down
41 changes: 41 additions & 0 deletions example/node/subscriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const DeviceHive = require(`../../index`);

const deviceHive = new DeviceHive({
login: `dhadmin`,
password: `dhadmin_#911`,
//mainServiceURL: 'ws://localhost:8080/dh/websocket',
mainServiceURL: 'http://localhost:8080/dh/rest',
authServiceURL: 'http://localhost:8090/dh/rest',
pluginServiceURL: 'http://localhost:8110/dh/rest',
autoUpdateSession: true
});


void async function start () {
try {
deviceHive.on(DeviceHive.MESSAGE_EVENT, (message) => {
console.log(message);
});

deviceHive.on(DeviceHive.ERROR_EVENT, (error) => {
console.error(error);
});

await deviceHive.connect();

const { subscriptionId } = await deviceHive.notification.subscribe(new DeviceHive.models.query.NotificationPollQuery({
deviceId: `e50d6085-2aba-48e9-b1c3-73c673e414be`,
names: [`test`]
}));

console.log(subscriptionId);

setTimeout(async () => {
await deviceHive.notification.unsubscribe(subscriptionId);
console.log(`unsubscribed`);
}, 10000);

} catch (error) {
console.warn(error);
}
}();
Loading