Skip to content

Commit

Permalink
Release of version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fengsongAWS committed Oct 5, 2017
1 parent a0def8b commit 8095037
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [2.1.0](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Sep 28, 2017)

Features
- Update MQTT.js to 2.13.0. [MQTT.js](https://github.com/mqttjs/MQTT.js/releases/tag/v2.13.0)

Bugfixes/Imporovements
- Propagated 'error' from 'close' event. [#131](https://github.com/aws/aws-iot-device-sdk-js/pull/131)
- Fixed method of handleMessage to be overridden rather than pass-through. [#129](https://github.com/aws/aws-iot-device-sdk-js/pull/129)
- Pass 'connack' parameter in 'connect' event [#99](https://github.com/aws/aws-iot-device-sdk-js/pull/99)
- Update iot service name to 'iotdevicegateway'

## [2.0.1](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Jul 2, 2017)

Bugfixes/Imporovements
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ device
console.log('connect');
device.subscribe('topic_1');
device.publish('topic_2', JSON.stringify({ test_data: 1}));
});
});

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

<a href="configurationFile></a>
<a href="configurationFile"></a>
#### Use a configuration file

The [AWS IoT Console](https://console.aws.amazon.com/iot) can generate JSON
Expand Down
24 changes: 13 additions & 11 deletions device/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function prepareWebSocketUrl(options, awsAccessId, awsSecretKey, awsSTSToken) {
var now = getDateTimeString();
var today = getDateString(now);
var path = '/mqtt';
var awsServiceName = 'iotdata';
var awsServiceName = 'iotdevicegateway';
var queryParams = 'X-Amz-Algorithm=AWS4-HMAC-SHA256' +
'&X-Amz-Credential=' + awsAccessId + '%2F' + today + '%2F' + options.region + '%2F' + awsServiceName + '%2Faws4_request' +
'&X-Amz-Date=' + now +
Expand Down Expand Up @@ -688,7 +688,7 @@ function DeviceClient(options) {
// handled here, *and* propagated upwards.
//

device.on('connect', function() {
device.on('connect', function(connack) {
//
// If not already running, start the connection timer.
//
Expand All @@ -706,9 +706,12 @@ function DeviceClient(options) {
drainingTimer = setInterval(_drainOperationQueue,
drainTimeMs);
}
that.emit('connect');
that.emit('connect', connack);
});
device.on('close', function() {
device.on('close', function(err) {
if (!isUndefined(err)) {
that.emit('error', err);
}
if ((!isUndefined(options)) && (options.debug === true)) {
console.log('connection lost - will attempt reconnection in ' +
device.options.reconnectPeriod / 1000 + ' seconds...');
Expand Down Expand Up @@ -748,7 +751,6 @@ function DeviceClient(options) {
device.on('message', function(topic, message, packet) {
that.emit('message', topic, message, packet);
});

//
// The signatures of these methods *must* match those of the mqtt.js
// client.
Expand Down Expand Up @@ -820,13 +822,13 @@ function DeviceClient(options) {
this.end = function(force, callback) {
device.end(force, callback);
};
this.handleMessage = function(packet, callback) {
device.handleMessage(packet, callback);

this.handleMessage = device.handleMessage.bind(device);

device.handleMessage = function(packet, callback) {
that.handleMessage(packet, callback);
};
//
// Call this function to update the credentials used when
// connecting via WebSocket/SigV4.
//

this.updateWebSocketCredentials = function(accessKeyId, secretKey, sessionToken, expiration) {
awsAccessId = accessKeyId;
awsSecretKey = secretKey;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "aws-iot-device-sdk",
"description": "AWS IoT Node.js SDK for Embedded Devices",
"version": "2.0.1",
"version": "2.1.0",
"author": {
"name": "Amazon Web Services",
"email": "",
Expand All @@ -28,7 +28,7 @@
"mqtt"
],
"dependencies": {
"mqtt": "2.2.1",
"mqtt": "2.13.0",
"minimist": "1.2.0",
"websocket-stream": "^3.3.3",
"crypto-js": "3.1.6"
Expand Down
25 changes: 18 additions & 7 deletions test/device-unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ describe( "device class unit tests", function() {
//
// Verify that the end and handleMessage APIs are passed-through
//
describe("Ensure that the end and handleMessage APIs are passed through", function() {
describe("Ensure that the end and handleMessage APIs are overriding", function() {
var clock;

before( function() { clock = sinon.useFakeTimers(); } );
Expand All @@ -788,10 +788,21 @@ describe( "device class unit tests", function() {
mockMQTTClientObject.emit('connect');
device.end( false, null );
assert.equal(mockMQTTClientObject.commandCalled['end'], 1); // Called once
assert.equal(mockMQTTClientObject.commandCalled['handleMessage'], 0); // Not called yet
device.handleMessage( 'message', function() { console.log('callback'); } );
// simulate overriding handleMessage
var expectedPacket = { data: 'packet data' };
var calledOverride = 0;
var calledBack = 0;
device.handleMessage = function customHandleMessage(packet, callback) {
calledOverride++;
assert.deepEqual(packet, expectedPacket);
callback();
}
mockMQTTClientObject.handleMessage(expectedPacket, function() {
calledBack++;
assert.equal(calledOverride, 1);
assert.equal(calledBack, 1);
})
assert.equal(mockMQTTClientObject.commandCalled['end'], 1); // Called once
assert.equal(mockMQTTClientObject.commandCalled['handleMessage'], 1); // Called once
});
});
//
Expand Down Expand Up @@ -1617,7 +1628,7 @@ describe( "device class unit tests", function() {
after( function() { clock.restore(); } );

it("calculates the url correctly", function() {
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';
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';

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

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

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';
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';

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' );
assert.equal( url, expectedUrl );
Expand All @@ -1660,7 +1671,7 @@ describe( "device class unit tests", function() {

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

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';
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';

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' );
assert.equal( url, expectedUrl );
Expand Down

0 comments on commit 8095037

Please sign in to comment.