Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoiani committed Feb 14, 2020
1 parent c5f26d2 commit ff370a0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ All notable changes to this project will be documented in this file.
- `0.5.x` Releases - [0.5.0] [0.5.1] [0.5.2]
- `0.6.x` Releases - [0.6.0] [0.6.1]
- `0.6.x` Releases - [0.6.0] [0.6.1]
- `0.7.x` Releases - [0.7.0] [0.7.1] [0.7.2] [0.7.3] [0.7.4] [0.7.5] [0.7.6] [0.7.7] [0.7.8] [0.7.9] [0.7.11] [0.7.12] [0.7.13]
- `0.7.x` Releases - [0.7.0] [0.7.1] [0.7.2] [0.7.3] [0.7.4] [0.7.5] [0.7.6] [0.7.7] [0.7.8] [0.7.9] [0.7.11] [0.7.12] [0.7.13] [0.7.14]

---

## [0.7.14](https://github.com/space-bunny/node-sdk/releases/tag/v0.7.14)

#### Changed

- Fix connection error handling

---

Expand Down
4 changes: 2 additions & 2 deletions lib/spacebunny.js
Original file line number Diff line number Diff line change
Expand Up @@ -29896,7 +29896,7 @@ return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.de
var amqpMessage=new _amqpMessage2.default({message:message,receiverId:_this2._deviceId,subscriptionOpts:localOpts,channel:ch});var ackNeeded=_this2._autoAck(localOpts.ack);// Check if should be accepted or not
if(amqpMessage.blackListed()){if(ackNeeded){ch.nack(message,localOpts.allUpTo,localOpts.requeue);}return;}// Call message callback
callback(amqpMessage);// Check if ACK is needed
if(ackNeeded){ch.ack(message,localOpts.allUpTo);}},localOpts)]);}).then(function(res){resolve(res);}).catch(function(reason){reject(reason);});});};this.publish=function(channel,message){var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._publishArgs),localOpts);_this2._createChannel('output',localOpts).then(function(ch){var _localOpts=localOpts,_localOpts$routingKey=_localOpts.routingKey,routingKey=_localOpts$routingKey===undefined?undefined:_localOpts$routingKey,_localOpts$topic=_localOpts.topic,topic=_localOpts$topic===undefined?undefined:_localOpts$topic;var promises=[ch.checkExchange(_this2.deviceId()),ch.publish(_this2.deviceId(),_this2._routingKeyFor({channel:channel,routingKey:routingKey,topic:topic}),Buffer.from((0,_utils.encapsulateContent)(message)),localOpts)];if(localOpts.withConfirm===true){promises.push(ch.waitForConfirms());}return _bluebird2.default.all(promises);}).then(function(res){resolve(res);}).catch(function(reason){reject(reason);});});};this.disconnect=function(){return new _bluebird2.default(function(resolve,reject){if(_this2._amqpConnection===undefined){reject(new Error('Not Connected'));}else{_this2._amqpConnection.close().then(function(){_this2._amqpConnection=undefined;_this2._amqpChannels={};_this2.emit('disconnect');resolve(true);}).catch(function(reason){reject(reason);});}});};this.connect=function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new _bluebird2.default(function(resolve,reject){var connectionOpts=_lodash2.default.cloneDeep(opts);connectionOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),connectionOpts);_this2.getEndpointConfigs().then(function(endpointConfigs){var connectionParams=endpointConfigs.connection;if(_this2.isConnected()){resolve(_this2._amqpConnection);return undefined;}else{var connectionString='';if(_this2._tls){connectionString=_this2._tlsProtocol+'://'+(connectionParams.deviceId||connectionParams.client)+':'+(connectionParams.secret+'@'+connectionParams.host+':')+(connectionParams.protocols.amqp.tlsPort+'/'+connectionParams.vhost.replace('/','%2f'));connectionOpts=_lodash2.default.merge(connectionOpts,_this2._tlsOpts);}else{connectionString=_this2._protocol+'://'+(connectionParams.deviceId||connectionParams.client)+':'+(connectionParams.secret+'@'+connectionParams.host+':')+(connectionParams.protocols.amqp.port+'/'+connectionParams.vhost.replace('/','%2f'));}return amqp.connect(connectionString,connectionOpts).then(function(conn){conn.on('error',function(err){_this2.emit('error',err);reject(err);});conn.on('close',function(err){_this2.emit('close',err);_this2._amqpConnection=undefined;});conn.on('blocked',function(reason){_this2.emit('blocked',reason);console.warn(reason);// eslint-disable-line no-console
if(ackNeeded){ch.ack(message,localOpts.allUpTo);}},localOpts)]);}).then(function(res){resolve(res);}).catch(function(reason){reject(reason);});});};this.publish=function(channel,message){var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._publishArgs),localOpts);_this2._createChannel('output',localOpts).then(function(ch){var _localOpts=localOpts,_localOpts$routingKey=_localOpts.routingKey,routingKey=_localOpts$routingKey===undefined?undefined:_localOpts$routingKey,_localOpts$topic=_localOpts.topic,topic=_localOpts$topic===undefined?undefined:_localOpts$topic;var promises=[ch.checkExchange(_this2.deviceId()),ch.publish(_this2.deviceId(),_this2._routingKeyFor({channel:channel,routingKey:routingKey,topic:topic}),Buffer.from((0,_utils.encapsulateContent)(message)),localOpts)];if(localOpts.withConfirm===true){promises.push(ch.waitForConfirms());}return _bluebird2.default.all(promises);}).then(function(res){resolve(res);}).catch(function(reason){reject(reason);});});};this.disconnect=function(){return new _bluebird2.default(function(resolve,reject){if(_this2._amqpConnection===undefined){reject(new Error('Not Connected'));}else{_this2._amqpConnection.close().then(function(){_this2._amqpConnection=undefined;_this2._amqpChannels={};_this2.emit('disconnect');resolve(true);}).catch(function(reason){reject(reason);});}});};this.connect=function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new _bluebird2.default(function(resolve,reject){var connectionOpts=_lodash2.default.cloneDeep(opts);connectionOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),connectionOpts);_this2.getEndpointConfigs().then(function(endpointConfigs){var connectionParams=endpointConfigs.connection;if(_this2.isConnected()){resolve(_this2._amqpConnection);return undefined;}else{var connectionString='';if(_this2._tls){connectionString=_this2._tlsProtocol+'://'+(connectionParams.deviceId||connectionParams.client)+':'+(connectionParams.secret+'@'+connectionParams.host+':')+(connectionParams.protocols.amqp.tlsPort+'/'+connectionParams.vhost.replace('/','%2f'));connectionOpts=_lodash2.default.merge(connectionOpts,_this2._tlsOpts);}else{connectionString=_this2._protocol+'://'+(connectionParams.deviceId||connectionParams.client)+':'+(connectionParams.secret+'@'+connectionParams.host+':')+(connectionParams.protocols.amqp.port+'/'+connectionParams.vhost.replace('/','%2f'));}return amqp.connect(connectionString,connectionOpts).then(function(conn){conn.on('error',function(err){_this2._amqpConnection=undefined;_this2.emit('error',err);reject(err);});conn.on('close',function(err){_this2.emit('close',err);_this2._amqpConnection=undefined;});conn.on('blocked',function(reason){_this2.emit('blocked',reason);console.warn(reason);// eslint-disable-line no-console
});conn.on('unblocked',function(reason){_this2.emit('unblocked',reason);console.warn(reason);// eslint-disable-line no-console
});_this2._amqpConnection=conn;_this2.on('error',function(){});_this2.emit('connect');resolve(_this2._amqpConnection);}).catch(function(reason){reject(reason);});}}).catch(function(reason){reject(reason);});});};this.isConnected=function(){return _this2._amqpConnection!==undefined;};this._createChannel=function(channel){var opts=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return new _bluebird2.default(function(resolve,reject){var _opts$routingKey=opts.routingKey,routingKey=_opts$routingKey===undefined?undefined:_opts$routingKey,_opts$topic=opts.topic,topic=_opts$topic===undefined?undefined:_opts$topic,_opts$withConfirm=opts.withConfirm,withConfirm=_opts$withConfirm===undefined?true:_opts$withConfirm;var suffix=topic||routingKey||'';var channelName=''+channel+suffix+(withConfirm===true?'WithConfirm':'');if(_this2._amqpChannels[channelName]){if(typeof _this2._amqpChannels[channelName]==='boolean'){_this2.on('channelOpen',function(ch){if(ch===channelName){resolve(_this2._amqpChannels[channelName]);}});}else{resolve(_this2._amqpChannels[channelName]);}}else{_this2._amqpChannels[channelName]=true;_this2.connect().then(function(conn){if(opts.withConfirm===true){return conn.createConfirmChannel();}else{return conn.createChannel();}}).then(function(ch){_this2._amqpChannels[channelName]=ch;_this2.emit('channelOpen',channelName);_this2._amqpChannels[channelName].on('error',function(err){if(err){console.error(err);// eslint-disable-line no-console
}// TODO close channel in function of error type??
Expand Down Expand Up @@ -33543,7 +33543,7 @@ var MqttClient=function(_SpaceBunny){(0,_inherits3.default)(MqttClient,_SpaceBun
var _initialiseProps=function _initialiseProps(){var _this2=this;this.onReceive=function(callback){var opts=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};// subscribe for input messages
return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge({},localOpts);_this2.connect(localOpts).then(function(client){_this2._topics[_this2._topicFor(null,_this2._inboxTopic)]=localOpts.qos||_this2._connectionOpts.qos;client.subscribe(_this2._topics,_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),localOpts),function(err){if(err){reject(err);}else{client.on('message',function(topic,message){// TODO filterMine and filterWeb
callback(topic,(0,_utils.parseContent)(message));});resolve(true);}});}).catch(function(reason){reject(reason);});});};this.publish=function(channel,message){var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};// Publish message
return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge({},localOpts);_this2.connect(localOpts).then(function(client){var _sendMessage=function _sendMessage(){var bufferedMessage=Buffer.from((0,_utils.encapsulateContent)(message));var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),localOpts);client.publish(_this2._topicFor(null,channel),bufferedMessage,localOpts,function(){resolve(true);});};if(!client.connected){client.on('connect',function(){_sendMessage();});}else{_sendMessage();}}).catch(function(reason){reject(reason);});});};this.unsubscribe=function(topics){return new _bluebird2.default(function(resolve,reject){try{if(_lodash2.default.isEmpty(topics)){resolve(true);}else{_this2._mqttConnection.unsubscribe((0,_keys2.default)(topics),function(){resolve(true);});}}catch(reason){reject(reason);}});};this.disconnect=function(){return new _bluebird2.default(function(resolve,reject){if(_this2._mqttConnection===undefined){reject(new Error('Invalid connection'));}else{var _closeConnection=function _closeConnection(){_this2._mqttConnection.end(true,function(){_this2._mqttConnection=undefined;_this2.emit('disconnect');resolve(true);});};try{if(_lodash2.default.isEmpty(_this2._topics)){_closeConnection();}else{_this2._mqttConnection.unsubscribe((0,_keys2.default)(_this2._topics),function(){_closeConnection();});}}catch(reason){reject(reason);}}});};this.connect=function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),localOpts);_this2.getEndpointConfigs().then(function(endpointConfigs){var connectionParams=endpointConfigs.connection;if(_this2._mqttConnection!==undefined){resolve(_this2._mqttConnection);}else{try{var mqttConnectionParams=(0,_extends3.default)({host:connectionParams.host,port:_this2._tls?connectionParams.protocols.mqtt.tlsPort:connectionParams.protocols.mqtt.port,username:connectionParams.vhost+':'+(connectionParams.deviceId||connectionParams.client),password:connectionParams.secret,clientId:connectionParams.deviceId||connectionParams.client,connectionTimeout:localOpts.connectionTimeout||_this2._connectionTimeout,clean:localOpts.clean},localOpts);if(_this2._tls){mqttConnectionParams=_lodash2.default.merge(mqttConnectionParams,_this2._tlsOpts);}var client=_mqtt2.default.connect(mqttConnectionParams);client.on('error',function(reason){_this2.emit('error',reason);reject(reason);});client.on('close',function(reason){reject(reason);_this2.emit('close',reason);_this2._mqttConnection=undefined;});client.on('connect',function(){_this2._mqttConnection=client;_this2.emit('connect');resolve(_this2._mqttConnection);});}catch(reason){reject(reason);}}}).catch(function(reason){reject(reason);});});};this.isConnected=function(){return _this2._mqttConnection!==undefined;};this._topicFor=function(deviceId,channel){return(deviceId||_this2.deviceId())+'/'+channel;};};exports.default=MqttClient;
return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge({},localOpts);_this2.connect(localOpts).then(function(client){var _sendMessage=function _sendMessage(){var bufferedMessage=Buffer.from((0,_utils.encapsulateContent)(message));var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),localOpts);client.publish(_this2._topicFor(null,channel),bufferedMessage,localOpts,function(){resolve(true);});};if(!client.connected){client.on('connect',function(){_sendMessage();});}else{_sendMessage();}}).catch(function(reason){reject(reason);});});};this.unsubscribe=function(topics){return new _bluebird2.default(function(resolve,reject){try{if(_lodash2.default.isEmpty(topics)){resolve(true);}else{_this2._mqttConnection.unsubscribe((0,_keys2.default)(topics),function(){resolve(true);});}}catch(reason){reject(reason);}});};this.disconnect=function(){return new _bluebird2.default(function(resolve,reject){if(_this2._mqttConnection===undefined){reject(new Error('Invalid connection'));}else{var _closeConnection=function _closeConnection(){_this2._mqttConnection.end(true,function(){_this2._mqttConnection=undefined;_this2.emit('disconnect');resolve(true);});};try{if(_lodash2.default.isEmpty(_this2._topics)){_closeConnection();}else{_this2._mqttConnection.unsubscribe((0,_keys2.default)(_this2._topics),function(){_closeConnection();});}}catch(reason){reject(reason);}}});};this.connect=function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return new _bluebird2.default(function(resolve,reject){var localOpts=_lodash2.default.cloneDeep(opts);localOpts=_lodash2.default.merge(_lodash2.default.cloneDeep(_this2._connectionOpts),localOpts);_this2.getEndpointConfigs().then(function(endpointConfigs){var connectionParams=endpointConfigs.connection;if(_this2._mqttConnection!==undefined){resolve(_this2._mqttConnection);}else{try{var mqttConnectionParams=(0,_extends3.default)({host:connectionParams.host,port:_this2._tls?connectionParams.protocols.mqtt.tlsPort:connectionParams.protocols.mqtt.port,username:connectionParams.vhost+':'+(connectionParams.deviceId||connectionParams.client),password:connectionParams.secret,clientId:connectionParams.deviceId||connectionParams.client,connectionTimeout:localOpts.connectionTimeout||_this2._connectionTimeout,clean:localOpts.clean},localOpts);if(_this2._tls){mqttConnectionParams=_lodash2.default.merge(mqttConnectionParams,_this2._tlsOpts);}var client=_mqtt2.default.connect(mqttConnectionParams);client.on('error',function(reason){_this2._mqttConnection=undefined;_this2.emit('error',reason);reject(reason);});client.on('close',function(reason){reject(reason);_this2.emit('close',reason);_this2._mqttConnection=undefined;});client.on('connect',function(){_this2._mqttConnection=client;_this2.emit('connect');resolve(_this2._mqttConnection);});}catch(reason){reject(reason);}}}).catch(function(reason){reject(reason);});});};this.isConnected=function(){return _this2._mqttConnection!==undefined;};this._topicFor=function(deviceId,channel){return(deviceId||_this2.deviceId())+'/'+channel;};};exports.default=MqttClient;

/***/ }),
/* 150 */
Expand Down
2 changes: 1 addition & 1 deletion lib/spacebunny.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ff370a0

Please sign in to comment.