Skip to content

Commit 8095037

Browse files
committed
Release of version 2.1.0
1 parent a0def8b commit 8095037

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## [2.1.0](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Sep 28, 2017)
2+
3+
Features
4+
- Update MQTT.js to 2.13.0. [MQTT.js](https://github.com/mqttjs/MQTT.js/releases/tag/v2.13.0)
5+
6+
Bugfixes/Imporovements
7+
- Propagated 'error' from 'close' event. [#131](https://github.com/aws/aws-iot-device-sdk-js/pull/131)
8+
- Fixed method of handleMessage to be overridden rather than pass-through. [#129](https://github.com/aws/aws-iot-device-sdk-js/pull/129)
9+
- Pass 'connack' parameter in 'connect' event [#99](https://github.com/aws/aws-iot-device-sdk-js/pull/99)
10+
- Update iot service name to 'iotdevicegateway'
11+
112
## [2.0.1](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Jul 2, 2017)
213

314
Bugfixes/Imporovements

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ device
9393
console.log('connect');
9494
device.subscribe('topic_1');
9595
device.publish('topic_2', JSON.stringify({ test_data: 1}));
96-
});
96+
});
9797

9898
device
9999
.on('message', function(topic, payload) {
@@ -573,7 +573,7 @@ directory specified. Default certificate/key file names are as follows:
573573
The '-f' (certificate directory) option can be combined with these so that
574574
you don't have to specify absolute pathnames for each file.
575575

576-
<a href="configurationFile></a>
576+
<a href="configurationFile"></a>
577577
#### Use a configuration file
578578

579579
The [AWS IoT Console](https://console.aws.amazon.com/iot) can generate JSON

device/index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function prepareWebSocketUrl(options, awsAccessId, awsSecretKey, awsSTSToken) {
143143
var now = getDateTimeString();
144144
var today = getDateString(now);
145145
var path = '/mqtt';
146-
var awsServiceName = 'iotdata';
146+
var awsServiceName = 'iotdevicegateway';
147147
var queryParams = 'X-Amz-Algorithm=AWS4-HMAC-SHA256' +
148148
'&X-Amz-Credential=' + awsAccessId + '%2F' + today + '%2F' + options.region + '%2F' + awsServiceName + '%2Faws4_request' +
149149
'&X-Amz-Date=' + now +
@@ -688,7 +688,7 @@ function DeviceClient(options) {
688688
// handled here, *and* propagated upwards.
689689
//
690690

691-
device.on('connect', function() {
691+
device.on('connect', function(connack) {
692692
//
693693
// If not already running, start the connection timer.
694694
//
@@ -706,9 +706,12 @@ function DeviceClient(options) {
706706
drainingTimer = setInterval(_drainOperationQueue,
707707
drainTimeMs);
708708
}
709-
that.emit('connect');
709+
that.emit('connect', connack);
710710
});
711-
device.on('close', function() {
711+
device.on('close', function(err) {
712+
if (!isUndefined(err)) {
713+
that.emit('error', err);
714+
}
712715
if ((!isUndefined(options)) && (options.debug === true)) {
713716
console.log('connection lost - will attempt reconnection in ' +
714717
device.options.reconnectPeriod / 1000 + ' seconds...');
@@ -748,7 +751,6 @@ function DeviceClient(options) {
748751
device.on('message', function(topic, message, packet) {
749752
that.emit('message', topic, message, packet);
750753
});
751-
752754
//
753755
// The signatures of these methods *must* match those of the mqtt.js
754756
// client.
@@ -820,13 +822,13 @@ function DeviceClient(options) {
820822
this.end = function(force, callback) {
821823
device.end(force, callback);
822824
};
823-
this.handleMessage = function(packet, callback) {
824-
device.handleMessage(packet, callback);
825+
826+
this.handleMessage = device.handleMessage.bind(device);
827+
828+
device.handleMessage = function(packet, callback) {
829+
that.handleMessage(packet, callback);
825830
};
826-
//
827-
// Call this function to update the credentials used when
828-
// connecting via WebSocket/SigV4.
829-
//
831+
830832
this.updateWebSocketCredentials = function(accessKeyId, secretKey, sessionToken, expiration) {
831833
awsAccessId = accessKeyId;
832834
awsSecretKey = secretKey;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aws-iot-device-sdk",
33
"description": "AWS IoT Node.js SDK for Embedded Devices",
4-
"version": "2.0.1",
4+
"version": "2.1.0",
55
"author": {
66
"name": "Amazon Web Services",
77
"email": "",
@@ -28,7 +28,7 @@
2828
"mqtt"
2929
],
3030
"dependencies": {
31-
"mqtt": "2.2.1",
31+
"mqtt": "2.13.0",
3232
"minimist": "1.2.0",
3333
"websocket-stream": "^3.3.3",
3434
"crypto-js": "3.1.6"

test/device-unit-tests.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ describe( "device class unit tests", function() {
766766
//
767767
// Verify that the end and handleMessage APIs are passed-through
768768
//
769-
describe("Ensure that the end and handleMessage APIs are passed through", function() {
769+
describe("Ensure that the end and handleMessage APIs are overriding", function() {
770770
var clock;
771771

772772
before( function() { clock = sinon.useFakeTimers(); } );
@@ -788,10 +788,21 @@ describe( "device class unit tests", function() {
788788
mockMQTTClientObject.emit('connect');
789789
device.end( false, null );
790790
assert.equal(mockMQTTClientObject.commandCalled['end'], 1); // Called once
791-
assert.equal(mockMQTTClientObject.commandCalled['handleMessage'], 0); // Not called yet
792-
device.handleMessage( 'message', function() { console.log('callback'); } );
791+
// simulate overriding handleMessage
792+
var expectedPacket = { data: 'packet data' };
793+
var calledOverride = 0;
794+
var calledBack = 0;
795+
device.handleMessage = function customHandleMessage(packet, callback) {
796+
calledOverride++;
797+
assert.deepEqual(packet, expectedPacket);
798+
callback();
799+
}
800+
mockMQTTClientObject.handleMessage(expectedPacket, function() {
801+
calledBack++;
802+
assert.equal(calledOverride, 1);
803+
assert.equal(calledBack, 1);
804+
})
793805
assert.equal(mockMQTTClientObject.commandCalled['end'], 1); // Called once
794-
assert.equal(mockMQTTClientObject.commandCalled['handleMessage'], 1); // Called once
795806
});
796807
});
797808
//
@@ -1617,7 +1628,7 @@ describe( "device class unit tests", function() {
16171628
after( function() { clock.restore(); } );
16181629

16191630
it("calculates the url correctly", function() {
1620-
const expectedUrl='wss://not-a-real-host.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdata%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=2f5c6df9fea874125a491d9bc5cbfd30279fd124b029e1ab18b0e77e8369f55c';
1631+
const expectedUrl='wss://not-a-real-host.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=9bf20395cff4912649c9eb4892e105035137ce350290025388584ebb33893098';
16211632

16221633
var url = deviceModule.prepareWebSocketUrl( { host:'not-a-real-host.com', debug: true }, 'not a valid access key','not a valid secret access key' );
16231634
assert.equal( url, expectedUrl );
@@ -1638,7 +1649,7 @@ describe( "device class unit tests", function() {
16381649

16391650
it("calculates the url correctly", function() {
16401651

1641-
const expectedUrl='wss://not-a-real-host.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdata%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=2f5c6df9fea874125a491d9bc5cbfd30279fd124b029e1ab18b0e77e8369f55c&X-Amz-Security-Token=not%2Fa%2Fvalid%2Fsession%20token';
1652+
const expectedUrl='wss://not-a-real-host.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=9bf20395cff4912649c9eb4892e105035137ce350290025388584ebb33893098&X-Amz-Security-Token=not%2Fa%2Fvalid%2Fsession%20token';
16421653

16431654
var url = deviceModule.prepareWebSocketUrl( { host:'not-a-real-host.com', debug: true }, 'not a valid access key','not a valid secret access key', 'not/a/valid/session token' );
16441655
assert.equal( url, expectedUrl );
@@ -1660,7 +1671,7 @@ describe( "device class unit tests", function() {
16601671

16611672
it("calculates the url correctly", function() {
16621673

1663-
const expectedUrl='wss://not-a-real-host.com:9999/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdata%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=62077f12458301adfe2d7fbb4eb271a060f29fcd3b7bbc22a8979e063ffda5cc&X-Amz-Security-Token=not%2Fa%2Fvalid%2Fsession%20token';
1674+
const expectedUrl='wss://not-a-real-host.com:9999/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=not a valid access key%2F19861115%2Fundefined%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=19861115T080000Z&X-Amz-SignedHeaders=host&X-Amz-Signature=ac89d55d95935fd1d59f44ad51f3fc35f4e79f5efc315f2f79f823a8f82dde4b&X-Amz-Security-Token=not%2Fa%2Fvalid%2Fsession%20token';
16641675

16651676
var url = deviceModule.prepareWebSocketUrl( { host:'not-a-real-host.com', port: 9999, debug: true }, 'not a valid access key','not a valid secret access key', 'not/a/valid/session token' );
16661677
assert.equal( url, expectedUrl );

0 commit comments

Comments
 (0)