innogy-smarthome-lib
Advanced tools
Comparing version 0.1.2 to 0.1.3
const inherits = require('util').inherits; | ||
const EventEmitter = require('events').EventEmitter; | ||
const WebSocket = require('ws'); | ||
const WebSocketClient = require('./../websocketclient'); | ||
const Promise = require('bluebird'); | ||
@@ -251,20 +252,38 @@ | ||
else { | ||
var ws = new WebSocket('wss://' + that._requestor._config.baseConfig.apiHost + that._requestor._config.baseConfig.versionPrefix + 'events?token=' + status.token.access_token); | ||
var reconnectCount = 0; | ||
var ws = new WebSocketClient('wss://' + that._requestor._config.baseConfig.apiHost + that._requestor._config.baseConfig.versionPrefix + 'events?token=' + status.token.access_token); | ||
ws.on('message', function (data) { | ||
var eventArray = JSON.parse(data); | ||
eventArray.forEach(function (event) { | ||
if (event && event.link) { | ||
var cap = that.resolveLink(event.link); | ||
if (Array.isArray(eventArray)) { | ||
eventArray.forEach(function (event) { | ||
if (event && event.link) { | ||
var cap = that.resolveLink(event.link); | ||
if (cap) { | ||
cap.parseEvent(event); | ||
that.emit("stateChanged", cap); | ||
if (cap) { | ||
cap.parseEvent(event); | ||
that.emit("stateChanged", cap); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} else { | ||
that.emit('error', eventArray); | ||
} | ||
}); | ||
ws.on('open', function () { | ||
reconnectCount = 0; | ||
}); | ||
ws.on('error', function (e) { | ||
that.emit('error', e); | ||
}); | ||
ws.on('close', function (e) { | ||
that.emit('error', {error: "closing socket", code: e}); | ||
}); | ||
that._wsClient = ws; | ||
@@ -271,0 +290,0 @@ resolve(ws); |
{ | ||
"name": "innogy-smarthome-lib", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "JavaScript library for the Innogy SmartHome system", | ||
@@ -5,0 +5,0 @@ "main": "./lib/smarthome", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50167
25
1076