Factor device SDK transports into their own packages
Currently when users download the Node.js device SDK package, they are forced to pull in *all* transports even if they only want to use one or two. Mqtt requires compilation of some native code, which makes it even more annoying if they don't want MQTT. This change factors all device SDK (and common) transports into their own packages. Previously we had: azure-iot-common azure-iot-device Now we have: azure-iot-amqp-base (not directly referenced by users) azure-iot-http-base (not directly referenced by users) azure-iot-mqtt-base (not directly referenced by users) azure-iot-common azure-iot-device azure-iot-device-amqp azure-iot-device-http azure-iot-device-mqtt
This commit is contained in:
Родитель
2a642ff2c3
Коммит
f99de43786
|
@ -49,10 +49,31 @@ if %integration-tests%==0 echo -- Linting and running unit tests --
|
|||
if %integration-tests%==1 echo -- Linting and running unit + integration tests --
|
||||
echo.
|
||||
|
||||
call :lint-and-test %node-root%\common
|
||||
call :lint-and-test %node-root%\common\core
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device
|
||||
call :lint-and-test %node-root%\common\transport\amqp
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\common\transport\http
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\common\transport\mqtt
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device\core
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device\transport\amqp
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device\transport\amqp-ws
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device\transport\http
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\device\transport\mqtt
|
||||
if errorlevel 1 goto :eof
|
||||
|
||||
call :lint-and-test %node-root%\service
|
||||
|
|
|
@ -60,10 +60,31 @@ else
|
|||
fi
|
||||
echo ""
|
||||
|
||||
lint_and_test $node_root/common
|
||||
lint_and_test $node_root/common/core
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device
|
||||
lint_and_test $node_root/common/transport/amqp
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/common/transport/http
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/common/transport/mqtt
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device/core
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device/transport/amqp
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device/transport/amqp-ws
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device/transport/http
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/device/transport/mqtt
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
lint_and_test $node_root/service
|
||||
|
|
|
@ -8,26 +8,76 @@ set node-root=%~dp0..
|
|||
REM // resolve to fully qualified path
|
||||
for %%i in ("%node-root%") do set node-root=%%~fi
|
||||
|
||||
cd %node-root%
|
||||
|
||||
cd common
|
||||
cd %node-root%\common\core
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link
|
||||
|
||||
cd ..\device
|
||||
cd %node-root%\common\transport\amqp
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
call npm link
|
||||
|
||||
cd ..\service
|
||||
cd %node-root%\common\transport\http
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
call npm link
|
||||
|
||||
cd ..\..\tools\iothub-explorer
|
||||
cd %node-root%\common\transport\mqtt
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
call npm link
|
||||
|
||||
cd %node-root%\device\core
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
call npm link
|
||||
|
||||
cd %node-root%\device\transport\amqp
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-amqp-base
|
||||
call npm link azure-iot-common
|
||||
call npm link azure-iot-device
|
||||
call npm link
|
||||
|
||||
cd %node-root%\device\transport\amqp-ws
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-amqp-base
|
||||
call npm link azure-iot-common
|
||||
call npm link azure-iot-device
|
||||
call npm link azure-iot-device-amqp
|
||||
call npm link
|
||||
|
||||
cd %node-root%\device\transport\http
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-http-base
|
||||
call npm link azure-iot-common
|
||||
call npm link azure-iot-device
|
||||
call npm link
|
||||
|
||||
cd %node-root%\device\transport\mqtt
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-mqtt-base
|
||||
call npm link azure-iot-device
|
||||
call npm link
|
||||
|
||||
cd %node-root%\service
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
call npm link azure-iot-amqp-base
|
||||
call npm link azure-iot-http-base
|
||||
call npm link
|
||||
|
||||
cd %node-root%\..\tools\iothub-explorer
|
||||
echo.
|
||||
echo -- Creating links for %cd% --
|
||||
call npm link azure-iot-common
|
||||
|
|
|
@ -4,26 +4,77 @@
|
|||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
node_root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd $node_root
|
||||
|
||||
cd common
|
||||
cd $node_root/common/core
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd ../device
|
||||
cd $node_root/common/transport/amqp
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd ../service
|
||||
cd $node_root/common/transport/http
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd ../../tools/iothub-explorer
|
||||
cd $node_root/common/transport/mqtt
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/device/core
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/device/transport/amqp
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-amqp-base
|
||||
npm link azure-iot-common
|
||||
npm link azure-iot-device
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/device/transport/amqp-ws
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-amqp-base
|
||||
npm link azure-iot-common
|
||||
npm link azure-iot-device
|
||||
npm link azure-iot-device-amqp
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/device/transport/http
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-http-base
|
||||
npm link azure-iot-common
|
||||
npm link azure-iot-device
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/device/transport/mqtt
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-mqtt-base
|
||||
npm link azure-iot-device
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/service
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link azure-iot-amqp-base
|
||||
npm link azure-iot-http-base
|
||||
npm link
|
||||
[ $? -eq 0 ] || exit $?
|
||||
|
||||
cd $node_root/../tools/iothub-explorer
|
||||
echo "\n-- Creating links for `pwd` --"
|
||||
npm link azure-iot-common
|
||||
npm link azure-iothub
|
||||
|
|
|
@ -16,13 +16,58 @@ call npm rm azure-iot-common
|
|||
cd %node-root%\service
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-http-base
|
||||
call npm rm azure-iot-amqp-base
|
||||
call npm rm azure-iot-common
|
||||
|
||||
cd ..\device
|
||||
cd %node-root%\device\transport\mqtt
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-device
|
||||
call npm rm azure-iot-mqtt-base
|
||||
|
||||
cd %node-root%\device\transport\http
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-device
|
||||
call npm rm azure-iot-common
|
||||
call npm rm azure-iot-http-base
|
||||
|
||||
cd %node-root%\device\transport\amqp-ws
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-device-amqp
|
||||
call npm rm azure-iot-device
|
||||
call npm rm azure-iot-common
|
||||
call npm rm azure-iot-amqp-base
|
||||
|
||||
cd %node-root%\device\transport\amqp
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-device
|
||||
call npm rm azure-iot-common
|
||||
call npm rm azure-iot-amqp-base
|
||||
|
||||
cd %node-root%\device\core
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-common
|
||||
|
||||
cd ..\common
|
||||
cd %node-root%\common\transport\mqtt
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-common
|
||||
|
||||
cd %node-root%\common\transport\http
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-common
|
||||
|
||||
cd %node-root%\common\transport\amqp
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
||||
call npm rm azure-iot-common
|
||||
|
||||
cd %node-root%\common\core
|
||||
echo -- Removing links for %cd% --
|
||||
call npm rm
|
|
@ -13,13 +13,58 @@ npm rm azure-iot-common
|
|||
cd $node_root/service
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-http-base
|
||||
npm rm azure-iot-amqp-base
|
||||
npm rm azure-iot-common
|
||||
|
||||
cd $node_root/device
|
||||
cd $node_root/device/transport/mqtt
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-device
|
||||
npm rm azure-iot-mqtt-base
|
||||
|
||||
cd $node_root/device/transport/http
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-device
|
||||
npm rm azure-iot-common
|
||||
npm rm azure-iot-http-base
|
||||
|
||||
cd $node_root/device/transport/amqp-ws
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-device-amqp
|
||||
npm rm azure-iot-device
|
||||
npm rm azure-iot-common
|
||||
npm rm azure-iot-amqp-base
|
||||
|
||||
cd $node_root/device/transport/amqp
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-device
|
||||
npm rm azure-iot-common
|
||||
npm rm azure-iot-amqp-base
|
||||
|
||||
cd $node_root/device/core
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-common
|
||||
|
||||
cd $node_root/common
|
||||
cd $node_root/common/transport/mqtt
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-common
|
||||
|
||||
cd $node_root/common/transport/http
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-common
|
||||
|
||||
cd $node_root/common/transport/amqp
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
npm rm azure-iot-common
|
||||
|
||||
cd $node_root/common/core
|
||||
echo "-- Removing links for `pwd` --"
|
||||
npm rm
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
authorization: require('./lib/authorization.js'),
|
||||
ConnectionString: require('./lib/connection_string.js'),
|
||||
endpoint: require('./lib/endpoint.js'),
|
||||
errors: require('./lib/errors.js'),
|
||||
Http: require('./lib/http.js'),
|
||||
Mqtt: require('./lib/mqtt.js'),
|
||||
Message: require('./lib/message.js'),
|
||||
SharedAccessSignature: require('./lib/shared_access_signature.js'),
|
||||
AmqpMessage: require('./lib/amqp_message.js'),
|
||||
AmqpReceiver: require('./lib/amqp_receiver.js'),
|
||||
Amqp: require('./lib/amqp.js')
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
anHourFromNow: require('./lib/authorization.js').anHourFromNow,
|
||||
encodeUriComponentStrict: require('./lib/authorization.js').encodeUriComponentStrict,
|
||||
ConnectionString: require('./lib/connection_string.js'),
|
||||
endpoint: require('./lib/endpoint.js'),
|
||||
errors: require('./lib/errors.js'),
|
||||
Message: require('./lib/message.js'),
|
||||
SharedAccessSignature: require('./lib/shared_access_signature.js')
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "azure-iot-common",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "Common components shared by Azure IoT device and service SDKs",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"main": "common.js",
|
||||
"dependencies": {
|
||||
"crypto": "^0.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var mqtt= require('mqtt');
|
||||
|
||||
/*
|
||||
Codes_SRS_NODE_HTTP_12_001: MqttTransport shall accept the following argument:
|
||||
config [
|
||||
host: host address
|
||||
deviceID: device name
|
||||
sharedAccessSignature: SAS token created for IoTHub
|
||||
gatewayHostName: gateway host name]
|
||||
Codes_SRS_NODE_HTTP_12_002: [MqttTransport shall throw ReferenceError “Invalid transport configuration” error if either of the configuration field is falsy
|
||||
Codes_SRS_NODE_HTTP_12_003: [MqttTransport shall create a configuration structure for underlying MQTT.JS library and store it to a member variable
|
||||
Codes_SRS_NODE_HTTP_12_004: [MqttTransport shall return an instance itself
|
||||
*/
|
||||
function Mqtt(config) {
|
||||
if ((!config) ||
|
||||
(!config.deviceId) ||
|
||||
(!config.sharedAccessSignature) ||
|
||||
(!config.gatewayHostName))
|
||||
throw new ReferenceError('Invalid transport configuration');
|
||||
|
||||
this._gatewayHostName = config.gatewayHostName;
|
||||
this._topic_publish = "devices/"+ config.deviceId +"/messages/events";
|
||||
this._topic_subscribe = "devices/"+ config.deviceId +"/messages/devicebound";
|
||||
this._options =
|
||||
{
|
||||
cmd: 'connect',
|
||||
protocolId: 'MQTT',
|
||||
protocolVersion: 4,
|
||||
clean: false,
|
||||
clientId: config.deviceId,
|
||||
username: config.deviceId,
|
||||
password: new Buffer(config.sharedAccessSignature),
|
||||
rejectUnauthorized: false,
|
||||
};
|
||||
return this;
|
||||
}
|
||||
/* SRS_NODE_HTTP_12_005: The CONNECT method shall call connect on MQTT.JS library and return a promise with the result */
|
||||
Mqtt.prototype.connect = function (done) {
|
||||
this.client = mqtt.connect(this._gatewayHostName, this._options);
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
|
||||
this.client.on('connect', function () {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_006: The PUBLISH method shall throw ReferenceError “Invalid message” if the message is falsy */
|
||||
/* Codes_SRS_NODE_HTTP_12_007: The PUBLISH method shall call publish on MQTT.JS library with the given message */
|
||||
Mqtt.prototype.publish = function (message, done) {
|
||||
if (!message)
|
||||
throw new ReferenceError('Invalid message');
|
||||
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.publish(this._topic_publish, message.data.toString(), function () {
|
||||
if (done) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_008: The SUBSCRIBE method shall call subscribe on MQTT.JS library with the given message and with the hardcoded topic path */
|
||||
Mqtt.prototype.subscribe = function (done) {
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.subscribe(this._topic_subscribe , function () {
|
||||
if (done) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_010: The RECEIVE method shall implement the MQTT.JS library callback event and calls back to the caller with the given callback */
|
||||
Mqtt.prototype.receive = function (done) {
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.on('message', function(topic, msg) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
if (done) done(topic, msg);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
module.exports = Mqtt;
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
Amqp: require('./lib/amqp.js'),
|
||||
AmqpMessage: require('./lib/amqp_message.js'),
|
||||
AmqpReceiver: require('./lib/amqp_receiver.js')
|
||||
};
|
|
@ -4,7 +4,7 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var Message = require('./message.js');
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var AmqpMessage = require('./amqp_message.js');
|
||||
|
||||
describe('AmqpMessage', function () {
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
var amqp10 = require('amqp10');
|
||||
var AmqpMessage = require('./amqp_message.js');
|
||||
var errors = require('./errors.js');
|
||||
var AmqpReceiver = require('./amqp_receiver.js');
|
||||
var errors = require('azure-iot-common').errors;
|
||||
|
||||
/**
|
||||
* @class module:azure-iot-common.Amqp
|
|
@ -1,16 +1,13 @@
|
|||
{
|
||||
"name": "azure-iot-common",
|
||||
"name": "azure-iot-amqp-base",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "Azure IoT SDK - Common",
|
||||
"description": "AMQP operations used by Azure IoT device and service SDKs",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"main": "common.js",
|
||||
"dependencies": {
|
||||
"amqp10": "^2.2.0",
|
||||
"amqp10-transport-ws": "^0.0.2",
|
||||
"crypto": "^0.0.3",
|
||||
"mqtt": "^1.5.0",
|
||||
"nodejs-websocket": "^1.4.1"
|
||||
"azure-iot-common": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
Http: require('./lib/http.js')
|
||||
};
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Message = require('./message.js');
|
||||
var Message = require('azure-iot-common').Message;
|
||||
|
||||
/**
|
||||
* @class module:azure-iot-common.Http
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "azure-iot-http-base",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "HTTP operations used by Azure IoT device and service SDKs",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-common": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "echo \"No tests\"",
|
||||
"alltest-min": "echo \"No tests\"",
|
||||
"unittest": "echo \"No tests\"",
|
||||
"alltest": "echo \"No tests\"",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
Mqtt: require('./lib/mqtt.js')
|
||||
};
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Mqtt = require('./mqtt.js');
|
||||
|
||||
describe('Mqtt', function () {
|
||||
describe('#constructor', function () {
|
||||
/* Tests_SRS_NODE_HTTP_12_001: Mqtt shall accept the following argument:
|
||||
config [
|
||||
host: host address
|
||||
deviceID: device name
|
||||
sharedAccessSignature: SAS token created for IoTHub
|
||||
gatewayHostName: gateway host name]
|
||||
Tests_SRS_NODE_HTTP_12_002: [Mqtt shall throw ReferenceError “Invalid transport configuration” error if either of the configuration field is falsy
|
||||
*/
|
||||
it('throws if config structure is falsy', function () {
|
||||
[null, undefined, '', 0].forEach(function (config) {
|
||||
assert.throws(function () {
|
||||
return new Mqtt(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if deviceId is falsy', function () {
|
||||
[null, undefined].forEach(function (deviceId) {
|
||||
var config = {
|
||||
deviceId: deviceId,
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if sasToken is falsy', function () {
|
||||
[null, undefined].forEach(function (sasToken) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: sasToken,
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if gatewayHostName is falsy', function () {
|
||||
[null, undefined].forEach(function (gatewayHostName) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: gatewayHostName
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
/* Tests_SRS_NODE_HTTP_12_003: [Mqtt shall create a configuration structure for underlying MQTT.JS library and store it to a member variable */
|
||||
/* Tests_SRS_NODE_HTTP_12_004: [Mqtt shall return an instance itself */
|
||||
it('create options structure with config content and return itself', function () {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var transport = new Mqtt(config);
|
||||
assert.notEqual(transport, null);
|
||||
assert.notEqual(transport, 'undefined');
|
||||
assert.equal(transport._options.clientId, config.deviceId);
|
||||
assert.equal(transport._options.username, config.deviceId);
|
||||
assert.equal(transport._options.password, config.sharedAccessSignature);
|
||||
|
||||
assert.equal(transport._options.cmd, 'connect');
|
||||
assert.equal(transport._options.protocolId, 'MQTT');
|
||||
assert.equal(transport._options.protocolVersion, '4');
|
||||
assert.equal(transport._options.clean, false);
|
||||
assert.equal(transport._options.rejectUnauthorized, false);
|
||||
});
|
||||
});
|
||||
describe('#publish', function () {
|
||||
/* Tests_SRS_NODE_HTTP_12_006: The PUBLISH method shall throw ReferenceError “Invalid message” if the message is falsy */
|
||||
it('throws if message is falsy', function () {
|
||||
[null, undefined].forEach(function (message) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var transport = new Mqtt(config);
|
||||
assert.throws(function () {
|
||||
transport.publish(message);
|
||||
}, ReferenceError, 'Invalid message');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,108 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var mqtt = require('mqtt');
|
||||
|
||||
/*
|
||||
Codes_SRS_NODE_HTTP_12_001: MqttTransport shall accept the following argument:
|
||||
config [
|
||||
host: host address
|
||||
deviceID: device name
|
||||
sharedAccessSignature: SAS token created for IoTHub
|
||||
gatewayHostName: gateway host name]
|
||||
Codes_SRS_NODE_HTTP_12_002: [MqttTransport shall throw ReferenceError “Invalid transport configuration” error if either of the configuration field is falsy
|
||||
Codes_SRS_NODE_HTTP_12_003: [MqttTransport shall create a configuration structure for underlying MQTT.JS library and store it to a member variable
|
||||
Codes_SRS_NODE_HTTP_12_004: [MqttTransport shall return an instance itself
|
||||
*/
|
||||
function Mqtt(config) {
|
||||
if ((!config) ||
|
||||
(!config.deviceId) ||
|
||||
(!config.sharedAccessSignature) ||
|
||||
(!config.gatewayHostName))
|
||||
throw new ReferenceError('Invalid transport configuration');
|
||||
|
||||
this._gatewayHostName = config.gatewayHostName;
|
||||
this._topic_publish = "devices/" + config.deviceId + "/messages/events";
|
||||
this._topic_subscribe = "devices/" + config.deviceId + "/messages/devicebound";
|
||||
this._options =
|
||||
{
|
||||
cmd: 'connect',
|
||||
protocolId: 'MQTT',
|
||||
protocolVersion: 4,
|
||||
clean: false,
|
||||
clientId: config.deviceId,
|
||||
username: config.deviceId,
|
||||
password: new Buffer(config.sharedAccessSignature),
|
||||
rejectUnauthorized: false,
|
||||
};
|
||||
return this;
|
||||
}
|
||||
/* SRS_NODE_HTTP_12_005: The CONNECT method shall call connect on MQTT.JS library and return a promise with the result */
|
||||
Mqtt.prototype.connect = function (done) {
|
||||
this.client = mqtt.connect(this._gatewayHostName, this._options);
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
|
||||
this.client.on('connect', function () {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_006: The PUBLISH method shall throw ReferenceError “Invalid message” if the message is falsy */
|
||||
/* Codes_SRS_NODE_HTTP_12_007: The PUBLISH method shall call publish on MQTT.JS library with the given message */
|
||||
Mqtt.prototype.publish = function (message, done) {
|
||||
if (!message)
|
||||
throw new ReferenceError('Invalid message');
|
||||
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.publish(this._topic_publish, message.data.toString(), function () {
|
||||
if (done) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_008: The SUBSCRIBE method shall call subscribe on MQTT.JS library with the given message and with the hardcoded topic path */
|
||||
Mqtt.prototype.subscribe = function (done) {
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.subscribe(this._topic_subscribe, function () {
|
||||
if (done) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_HTTP_12_010: The RECEIVE method shall implement the MQTT.JS library callback event and calls back to the caller with the given callback */
|
||||
Mqtt.prototype.receive = function (done) {
|
||||
if (done) {
|
||||
var errCallback = function (error) {
|
||||
done(error);
|
||||
};
|
||||
this.client.on('error', errCallback);
|
||||
}
|
||||
this.client.on('message', function (topic, msg) {
|
||||
this.client.removeListener('error', errCallback);
|
||||
if (done) done(topic, msg);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
module.exports = Mqtt;
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "azure-iot-mqtt-base",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "MQTT operations used by Azure IoT device and service SDKs",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-common": "1.0.0-preview.9",
|
||||
"mqtt": "^1.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -46,10 +46,6 @@ var common = require('azure-iot-common');
|
|||
module.exports = {
|
||||
Client: require('./lib/client.js'),
|
||||
ConnectionString: require('./lib/connection_string.js'),
|
||||
Http: require('./lib/http.js'),
|
||||
Mqtt: require('./lib/mqtt.js'),
|
||||
Message: common.Message,
|
||||
SharedAccessSignature: require('./lib/shared_access_signature.js'),
|
||||
Amqp: require('./lib/amqp.js'),
|
||||
AmqpWS: require('./lib/amqp_ws.js')
|
||||
SharedAccessSignature: require('./lib/shared_access_signature.js')
|
||||
};
|
|
@ -34,16 +34,10 @@ describe('Client', function () {
|
|||
});
|
||||
});
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_004: [If Transport is falsy, fromConnectionString shall use the default transport, Http.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_005: [fromConnectionString shall derive and transform the needed parts from the connection string in order to create a new instance of Transport.]*/
|
||||
it('creates an instance of the default transport', function () {
|
||||
var client = Client.fromConnectionString(connectionString);
|
||||
assert.instanceOf(client._transport, require('./http.js'));
|
||||
});
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_006: [The fromConnectionString method shall return a new instance of the Client object, as by a call to new Client(new Transport(...)).]*/
|
||||
it('returns an instance of Client', function () {
|
||||
var client = Client.fromConnectionString(connectionString);
|
||||
var DummyTransport = function(){};
|
||||
var client = Client.fromConnectionString(connectionString, DummyTransport);
|
||||
assert.instanceOf(client, Client);
|
||||
});
|
||||
});
|
|
@ -3,10 +3,9 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var anHourFromNow = require('azure-iot-common').authorization.anHourFromNow;
|
||||
var anHourFromNow = require('azure-iot-common').anHourFromNow;
|
||||
var ArgumentError = require('azure-iot-common').errors.ArgumentError;
|
||||
var ConnectionString = require('./connection_string.js');
|
||||
var DefaultTransport = require('./http.js');
|
||||
var SharedAccessSignature = require('./shared_access_signature.js');
|
||||
|
||||
/**
|
||||
|
@ -39,9 +38,6 @@ Client.fromConnectionString = function fromConnectionString(value, Transport) {
|
|||
/*Codes_SRS_NODE_DEVICE_CLIENT_05_003: [The fromConnectionString method shall throw ReferenceError if the value argument is falsy.]*/
|
||||
if (!value) throw new ReferenceError('value is \'' + value + '\'');
|
||||
|
||||
/*Codes_SRS_NODE_DEVICE_CLIENT_05_004: [If Transport is falsy, fromConnectionString shall use the default transport, Http.]*/
|
||||
Transport = Transport || DefaultTransport;
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_005: [fromConnectionString shall derive and transform the needed parts from the connection string in order to create a new instance of Transport.]*/
|
||||
var cn = ConnectionString.parse(value);
|
||||
var sas = SharedAccessSignature.create(cn.HostName, cn.DeviceId, cn.SharedAccessKey, anHourFromNow());
|
||||
|
@ -65,7 +61,7 @@ Client.fromConnectionString = function fromConnectionString(value, Transport) {
|
|||
* @returns calls the given callback
|
||||
*/
|
||||
Client.prototype.open = function (done) {
|
||||
/* Codes_SRS_NODE_DEVICE_CLIENT_12_001: [The open function shall call the transport connect function] */
|
||||
/* Codes_SRS_NODE_DEVICE_CLIENT_12_001: [The open function shall call the transport’s connect function, if it exists.] */
|
||||
if (typeof this._transport.connect === 'function') {
|
||||
this._transport.connect(function () {
|
||||
done();
|
Двоичный файл не отображается.
|
@ -3,10 +3,10 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var ArgumentError = require('azure-iot-common').errors.ArgumentError;
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var SharedAccessSignature = require('./shared_access_signature.js');
|
||||
var EventEmitter = require('events');
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var ArgumentError = require('azure-iot-common').errors.ArgumentError;
|
||||
var SharedAccessSignature = require('./shared_access_signature.js');
|
||||
|
||||
function Response(statusCode) {
|
||||
this.statusCode = statusCode;
|
|
@ -4,7 +4,7 @@
|
|||
'use strict';
|
||||
|
||||
var Base = require('azure-iot-common').SharedAccessSignature;
|
||||
var encodeUriComponentStrict = require('azure-iot-common').authorization.encodeUriComponentStrict;
|
||||
var encodeUriComponentStrict = require('azure-iot-common').encodeUriComponentStrict;
|
||||
|
||||
module.exports = {
|
||||
create: function create(host, deviceId, key, expiry) {
|
|
@ -1,19 +1,17 @@
|
|||
{
|
||||
"name": "azure-iot-device",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "Azure IoT SDK - Device",
|
||||
"description": "Azure IoT device SDK",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"main": "device.js",
|
||||
"dependencies": {
|
||||
"azure-iot-common": "1.0.0-preview.9",
|
||||
"node-crontab": "^0.0.8"
|
||||
"azure-iot-common": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3",
|
||||
"sinon": "^1.17.2"
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
|
@ -1,232 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Client = require('./client.js');
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var SimulatedMqtt = require('./mqtt_simulated.js');
|
||||
var Mqtt_common = require('azure-iot-common').Mqtt;
|
||||
var Mqtt = require('./mqtt.js');
|
||||
|
||||
describe('Mqtt-Common', function () {
|
||||
describe('#constructor', function () {
|
||||
/* Tests_SRS_NODE_HTTP_12_001: Mqtt shall accept the following argument:
|
||||
config [
|
||||
host: host address
|
||||
deviceID: device name
|
||||
sharedAccessSignature: SAS token created for IoTHub
|
||||
gatewayHostName: gateway host name]
|
||||
Tests_SRS_NODE_HTTP_12_002: [Mqtt shall throw ReferenceError “Invalid transport configuration” error if either of the configuration field is falsy
|
||||
*/
|
||||
it('throws if config structure is falsy', function () {
|
||||
[null, undefined, '', 0].forEach(function (config) {
|
||||
assert.throws(function () {
|
||||
return new Mqtt_common(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if deviceId is falsy', function () {
|
||||
[null, undefined].forEach(function (deviceId) {
|
||||
var config = {
|
||||
deviceId: deviceId,
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt_common(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if sasToken is falsy', function () {
|
||||
[null, undefined].forEach(function (sasToken) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: sasToken,
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt_common(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
it('throws if gatewayHostName is falsy', function () {
|
||||
[null, undefined].forEach(function (gatewayHostName) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: gatewayHostName
|
||||
};
|
||||
assert.throws(function () {
|
||||
return new Mqtt_common(config);
|
||||
}, ReferenceError, 'Invalid transport configuration');
|
||||
});
|
||||
});
|
||||
/* Tests_SRS_NODE_HTTP_12_003: [Mqtt shall create a configuration structure for underlying MQTT.JS library and store it to a member variable */
|
||||
/* Tests_SRS_NODE_HTTP_12_004: [Mqtt shall return an instance itself */
|
||||
it('create options structure with config content and return itself', function () {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var transport = new Mqtt_common(config);
|
||||
assert.notEqual(transport, null);
|
||||
assert.notEqual(transport, 'undefined');
|
||||
assert.equal(transport._options.clientId, config.deviceId);
|
||||
assert.equal(transport._options.username, config.deviceId);
|
||||
assert.equal(transport._options.password, config.sharedAccessSignature);
|
||||
|
||||
assert.equal(transport._options.cmd, 'connect');
|
||||
assert.equal(transport._options.protocolId, 'MQTT');
|
||||
assert.equal(transport._options.protocolVersion, '4');
|
||||
assert.equal(transport._options.clean, false);
|
||||
assert.equal(transport._options.rejectUnauthorized, false);
|
||||
});
|
||||
});
|
||||
describe('#publish', function () {
|
||||
/* Tests_SRS_NODE_HTTP_12_006: The PUBLISH method shall throw ReferenceError “Invalid message” if the message is falsy */
|
||||
it('throws if message is falsy', function () {
|
||||
[null, undefined].forEach(function (message) {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var transport = new Mqtt_common(config);
|
||||
assert.throws(function () {
|
||||
transport.publish(message);
|
||||
}, ReferenceError, 'Invalid message');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mqtt', function () {
|
||||
describe('#constructor', function () {
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_001: [The Mqtt shall accept the transport configuration structure */
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_002: [The Mqtt shall store the configuration structure in a member variable */
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_003: [The Mqtt shall create an Mqtt object and store it in a member variable */
|
||||
it('stores config and created transport in member', function () {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var mqtt_obj = new Mqtt(config);
|
||||
assert.notEqual(mqtt_obj, null);
|
||||
assert.notEqual(mqtt_obj, 'undefined');
|
||||
assert.equal(mqtt_obj._config, config);
|
||||
assert.notEqual(mqtt_obj._mqtt, null);
|
||||
assert.notEqual(mqtt_obj._mqtt, 'undefined');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function badConfigTests(opName, badConnStrings, Transport, requestFn) {
|
||||
|
||||
function makeRequestWith(connectionString, test, done) {
|
||||
var client = Client.fromConnectionString(connectionString, Transport);
|
||||
requestFn(client, function (err, res) {
|
||||
test(err, res);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function expectHostNotFoundError(err) {
|
||||
assert.equal(err.message, 'Invalid host address');
|
||||
}
|
||||
|
||||
function expectGatewayNotFoundError(err) {
|
||||
assert.equal(err.message, 'Invalid gateway address');
|
||||
}
|
||||
|
||||
function expectRefused(err) {
|
||||
assert.isNotNull(err);
|
||||
assert.equal(err.message, 'Connection Refused');
|
||||
}
|
||||
|
||||
var tests = [
|
||||
{ name: 'hostname is malformed', expect: expectHostNotFoundError },
|
||||
{ name: 'device is not registered', expect: expectRefused },
|
||||
{ name: 'password is wrong', expect: expectRefused },
|
||||
{ name: 'gatewayurl is malformed', expect: expectGatewayNotFoundError },
|
||||
];
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_016: [When a Client method encounters an error in the transport, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - the standard JavaScript Error object, with a response property that points to a transport-specific response object, and a responseBody property that contains the body of the transport response.]*/
|
||||
badConnStrings.forEach(function (test, index) {
|
||||
it('fails to ' + opName + ' when the ' + tests[index].name, function (done) {
|
||||
makeRequestWith(test, tests[index].expect, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runTests(Transport, goodConnectionString, badConnectionStrings) {
|
||||
|
||||
describe('Client', function () {
|
||||
describe('#sendEvent', function () {
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_007: [The sendEvent method shall send the event indicated by the message argument via the transport associated with the Client instance.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_017: [With the exception of receive, when a Client method completes successfully, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - null
|
||||
response - a transport-specific response object]*/
|
||||
it('sends the event', function (done) {
|
||||
var client = Client.fromConnectionString(goodConnectionString, Transport);
|
||||
var message = new Message('hello');
|
||||
client.sendEvent(message, function (err, res) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res, 'OK');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
badConfigTests('send an event', badConnectionStrings, Transport, function (client, done) {
|
||||
client.sendEvent(new Message(''), done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#receive', function () {
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_009: [The receive method shall query the IoT Hub for the next message via the transport associated with the Client instance.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_018: [When receive completes successfully, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - null
|
||||
message - the received Message (for receive), otherwise null
|
||||
response - a transport-specific response object]*/
|
||||
it('queries the service for a message', function (done) {
|
||||
var client = Client.fromConnectionString(goodConnectionString, Transport);
|
||||
client.receive(function (err, msg, res) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res, 'OK');
|
||||
assert.instanceOf(msg, Message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
badConfigTests('receive messages', badConnectionStrings, Transport, function (client, done) {
|
||||
client.receive(function (err, message, response) {
|
||||
done(err, response);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function makeConnectionString(host, device, key, gateway) {
|
||||
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key+';GatewayHostName='+gateway;
|
||||
}
|
||||
|
||||
var connectionString = makeConnectionString('host', 'device', 'key', 'gateway');
|
||||
var badConnStrings = [
|
||||
makeConnectionString('bad', 'device', 'key', 'gateway'),
|
||||
makeConnectionString('host', 'bad', 'key', 'gateway'),
|
||||
makeConnectionString('host', 'device', 'bad', 'gateway'),
|
||||
makeConnectionString('host', 'device', 'key', 'bad'),
|
||||
];
|
||||
|
||||
describe('Over simulated MQTT', function () {
|
||||
runTests(SimulatedMqtt, connectionString, badConnStrings);
|
||||
});
|
||||
|
||||
module.exports = runTests;
|
Двоичные данные
device/lib/devdoc/device_amqp_requirements.docm
Двоичные данные
device/lib/devdoc/device_amqp_requirements.docm
Двоичный файл не отображается.
Двоичные данные
device/lib/devdoc/device_client_requirements.docm
Двоичные данные
device/lib/devdoc/device_client_requirements.docm
Двоичный файл не отображается.
Двоичные данные
device/lib/devdoc/http_requirements.docm
Двоичные данные
device/lib/devdoc/http_requirements.docm
Двоичный файл не отображается.
Двоичные данные
device/lib/devdoc/mqtt_requirements.docm
Двоичные данные
device/lib/devdoc/mqtt_requirements.docm
Двоичный файл не отображается.
|
@ -1,57 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var SharedAccessSignature = require('./shared_access_signature.js');
|
||||
|
||||
function makeError(errorMessage) {
|
||||
var err = new Error(errorMessage);
|
||||
return err;
|
||||
}
|
||||
|
||||
function SimulatedMqtt(config) {
|
||||
this.handleRequest = function(done) {
|
||||
var sig = SharedAccessSignature.parse(config.sharedAccessSignature);
|
||||
|
||||
if (config.host === 'bad') { // bad host
|
||||
done(new Error('Invalid host address'));
|
||||
}
|
||||
else if (config.deviceId === 'bad') { // bad policy
|
||||
done(makeError('Connection Refused'));
|
||||
}
|
||||
else if (config.gatewayHostName === 'bad') { // bad gateway url
|
||||
done(makeError('Invalid gateway address'));
|
||||
}
|
||||
else {
|
||||
var cmpSig = (SharedAccessSignature.create(config.host, config.deviceId, 'bad', sig.se)).toString();
|
||||
if (config.sharedAccessSignature === cmpSig) { // bad key
|
||||
done(makeError('Connection Refused'));
|
||||
}
|
||||
else {
|
||||
done(null, 'OK');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SimulatedMqtt.prototype.connect = function (done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, response);
|
||||
});
|
||||
};
|
||||
|
||||
SimulatedMqtt.prototype.sendEvent = function (message, done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, response);
|
||||
});
|
||||
};
|
||||
|
||||
SimulatedMqtt.prototype.receive = function (done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, err ? null : new Message(''), response);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = SimulatedMqtt;
|
|
@ -6,7 +6,10 @@
|
|||
"author": "Microsoft Corp.",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-device": "1.0.0-preview.9"
|
||||
"azure-iot-device": "1.0.0-preview.9",
|
||||
"azure-iot-device-amqp": "1.0.0-preview.9",
|
||||
"azure-iot-device-http": "1.0.0-preview.9",
|
||||
"azure-iot-device-mqtt": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "^2.8.0"
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString;
|
||||
var ConnectionString = require('azure-iot-device').ConnectionString;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
|
||||
// String containing Hostname, Device Id & Device Key in the following formats:
|
||||
// "HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
var connectionString = "[IoT Hub device connection string]";
|
||||
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;
|
||||
var connectionString = '[IoT Hub device connection string]';
|
||||
var deviceId = ConnectionString.parse(connectionString).DeviceId;
|
||||
|
||||
// Sensors data
|
||||
var temperature = 50;
|
||||
|
@ -16,7 +18,7 @@ var humidity = 50;
|
|||
var externalTemperature = 55;
|
||||
|
||||
// Create IoT Hub client
|
||||
var client = device.Client.fromConnectionString(connectionString);
|
||||
var client = clientFromConnectionString(connectionString);
|
||||
|
||||
// Helper function to print results for an operation
|
||||
function printErrorFor(op) {
|
||||
|
@ -27,7 +29,7 @@ function printErrorFor(op) {
|
|||
|
||||
// Helper function to generate random number between min and max
|
||||
function generateRandomIncrement() {
|
||||
return ((Math.random() * 2)-1);
|
||||
return ((Math.random() * 2) - 1);
|
||||
}
|
||||
|
||||
// function to send event data
|
||||
|
@ -37,14 +39,14 @@ function sendEventData() {
|
|||
humidity += generateRandomIncrement();
|
||||
|
||||
var data = JSON.stringify({
|
||||
"DeviceID":deviceId,
|
||||
"Temperature":temperature,
|
||||
"Humidity":humidity,
|
||||
"ExternalTemperature":externalTemperature
|
||||
'DeviceID': deviceId,
|
||||
'Temperature': temperature,
|
||||
'Humidity': humidity,
|
||||
'ExternalTemperature': externalTemperature
|
||||
});
|
||||
|
||||
console.log("Sending device event data:\n"+data);
|
||||
client.sendEvent(new device.Message(data), printErrorFor('send event'));
|
||||
console.log('Sending device event data:\n' + data);
|
||||
client.sendEvent(new Message(data), printErrorFor('send event'));
|
||||
}
|
||||
|
||||
// function to wait on messages
|
||||
|
@ -57,9 +59,9 @@ function waitForMessages() {
|
|||
console.log('receive data: ' + msg.getData());
|
||||
try {
|
||||
var command = JSON.parse(msg.getData());
|
||||
if (command.Name === "SetTemperature") {
|
||||
if (command.Name === 'SetTemperature') {
|
||||
temperature = command.Parameters.Temperature;
|
||||
console.log("New temperature set to :" + temperature + "F");
|
||||
console.log('New temperature set to :' + temperature + 'F');
|
||||
}
|
||||
|
||||
client.complete(msg, printErrorFor('complete'));
|
||||
|
@ -75,43 +77,43 @@ function waitForMessages() {
|
|||
|
||||
// Send device meta data
|
||||
var deviceMetaData = {
|
||||
"ObjectType":"DeviceInfo",
|
||||
"IsSimulatedDevice":0,
|
||||
"Version":"1.0",
|
||||
"DeviceProperties": {
|
||||
"DeviceID":deviceId,
|
||||
"HubEnabledState":1,
|
||||
"CreatedTime":"2015-09-21T20:28:55.5448990Z",
|
||||
"DeviceState":"normal",
|
||||
"UpdatedTime":null,
|
||||
"Manufacturer":"Contoso Inc.",
|
||||
"ModelNumber":"MD-909",
|
||||
"SerialNumber":"SER9090",
|
||||
"FirmwareVersion":"1.10",
|
||||
"Platform":"node.js",
|
||||
"Processor":"ARM",
|
||||
"InstalledRAM":"64 MB",
|
||||
"Latitude":47.617025,
|
||||
"Longitude":-122.191285
|
||||
'ObjectType': 'DeviceInfo',
|
||||
'IsSimulatedDevice': 0,
|
||||
'Version': '1.0',
|
||||
'DeviceProperties': {
|
||||
'DeviceID': deviceId,
|
||||
'HubEnabledState': 1,
|
||||
'CreatedTime': '2015-09-21T20:28:55.5448990Z',
|
||||
'DeviceState': 'normal',
|
||||
'UpdatedTime': null,
|
||||
'Manufacturer': 'Contoso Inc.',
|
||||
'ModelNumber': 'MD-909',
|
||||
'SerialNumber': 'SER9090',
|
||||
'FirmwareVersion': '1.10',
|
||||
'Platform': 'node.js',
|
||||
'Processor': 'ARM',
|
||||
'InstalledRAM': '64 MB',
|
||||
'Latitude': 47.617025,
|
||||
'Longitude': -122.191285
|
||||
},
|
||||
"Commands": [{
|
||||
"Name": "SetTemperature",
|
||||
"Parameters": [{
|
||||
"Name": "Temperature",
|
||||
"Type": "double"
|
||||
'Commands': [{
|
||||
'Name': 'SetTemperature',
|
||||
'Parameters': [{
|
||||
'Name': 'Temperature',
|
||||
'Type': 'double'
|
||||
}]
|
||||
},
|
||||
{
|
||||
"Name": "SetHumidity",
|
||||
"Parameters": [{
|
||||
"Name": "Humidity",
|
||||
"Type": "double"
|
||||
{
|
||||
'Name': 'SetHumidity',
|
||||
'Parameters': [{
|
||||
'Name': 'Humidity',
|
||||
'Type': 'double'
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
||||
console.log("Sending device metadata:\n" + JSON.stringify(deviceMetaData));
|
||||
client.sendEvent(new device.Message(JSON.stringify(deviceMetaData)), printErrorFor('send metadata'));
|
||||
console.log('Sending device metadata:\n' + JSON.stringify(deviceMetaData));
|
||||
client.sendEvent(new Message(JSON.stringify(deviceMetaData)), printErrorFor('send metadata'));
|
||||
|
||||
// start event data send routing
|
||||
setInterval(sendEventData, 1000);
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
|
||||
// String containing Hostname, Device Id & Device Key in the following formats:
|
||||
// "HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
var connectionString = '[IoT Hub device connection string]';
|
||||
var client = device.Client.fromConnectionString(connectionString);
|
||||
var client = clientFromConnectionString(connectionString);
|
||||
|
||||
// Create two messages and send them to the IoT hub as a batch.
|
||||
var data = [
|
||||
|
@ -18,7 +19,7 @@ var data = [
|
|||
|
||||
var messages = [];
|
||||
data.forEach(function (value) {
|
||||
messages.push(new device.Message(JSON.stringify(value)));
|
||||
messages.push(new Message(JSON.stringify(value)));
|
||||
});
|
||||
|
||||
console.log('sending ' + messages.length + ' events in a batch');
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var clientFromConnectionString = require('azure-iot-device-amqp').clientFromConnectionString;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
|
||||
// String containing Hostname, Device Id & Device Key in the following formats:
|
||||
// "HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
var connectionString = '[IoT Hub device connection string]';
|
||||
|
||||
var client = device.Client.fromConnectionString(connectionString, device.Amqp);
|
||||
var client = clientFromConnectionString(connectionString);
|
||||
|
||||
// Create a message and send it to the IoT Hub every second
|
||||
setInterval(function(){
|
||||
setInterval(function () {
|
||||
var windSpeed = 10 + (Math.random() * 4); // range: [10, 14]
|
||||
var data = JSON.stringify({ deviceId: 'myFirstDevice', windSpeed: windSpeed });
|
||||
var message = new device.Message(data);
|
||||
var message = new Message(data);
|
||||
message.properties.add('myproperty', 'myvalue');
|
||||
console.log("Sending message: " + message.getData());
|
||||
console.log('Sending message: ' + message.getData());
|
||||
client.sendEvent(message, printResultFor('send'));
|
||||
}, 1000);
|
||||
|
||||
client.getReceiver(function (err, receiver)
|
||||
{
|
||||
client.getReceiver(function (err, receiver) {
|
||||
receiver.on('message', function (msg) {
|
||||
console.log('Id: ' + msg.properties.messageId + ' Body: ' + msg.body);
|
||||
receiver.complete(msg, function() {
|
||||
receiver.complete(msg, function () {
|
||||
console.log('completed');
|
||||
});
|
||||
// receiver.reject(msg, function() {
|
||||
|
@ -35,8 +35,7 @@ client.getReceiver(function (err, receiver)
|
|||
// console.log('abandoned');
|
||||
// });
|
||||
});
|
||||
receiver.on('errorReceived', function(err)
|
||||
{
|
||||
receiver.on('errorReceived', function (err) {
|
||||
console.warn(err);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
|
||||
// String containing Hostname, Device Id & Device Key in the following formats:
|
||||
// "HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
var connectionString = '[IoT Hub device connection string]';
|
||||
|
||||
var client = device.Client.fromConnectionString(connectionString);
|
||||
var client = clientFromConnectionString(connectionString);
|
||||
|
||||
// Create a message and send it to the IoT hub every second
|
||||
setInterval(function () {
|
||||
|
@ -18,9 +19,9 @@ setInterval(function () {
|
|||
deviceId: 'myFirstDevice',
|
||||
windSpeed: windSpeed
|
||||
});
|
||||
var message = new device.Message(data);
|
||||
var message = new Message(data);
|
||||
message.properties.add('myproperty', 'myvalue');
|
||||
console.log("Sending message: " + message.getData());
|
||||
console.log('Sending message: ' + message.getData());
|
||||
client.sendEvent(message, printResultFor('send'));
|
||||
}, 1000);
|
||||
|
||||
|
|
|
@ -3,26 +3,26 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var mqtt = require('azure-iot-device').Mqtt;
|
||||
var device = require('azure-iot-device');
|
||||
var clientFromConnectionString = require('azure-iot-device-mqtt').clientFromConnectionString;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
|
||||
// String containing Hostname, Device Id & Device Key in the following formats:
|
||||
// "HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
// String containing hostname, gateway host name, device ID, device key in the following format:
|
||||
// "HostName=<iothub_hostname>;GatewayHostName=<gateway_hostname>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
|
||||
var connectionString = '[IoT Hub device connection string]';
|
||||
|
||||
var client = device.Client.fromConnectionString(connectionString, mqtt);
|
||||
var client = clientFromConnectionString(connectionString);
|
||||
|
||||
client.open(function (){
|
||||
client.open(function () {
|
||||
// Create a message and send it to the IoT Hub every second
|
||||
setInterval(function(){
|
||||
setInterval(function () {
|
||||
var windSpeed = 10 + (Math.random() * 4); // range: [10, 14]
|
||||
var data = JSON.stringify({
|
||||
deviceId: 'myFirstDevice',
|
||||
windSpeed: windSpeed
|
||||
});
|
||||
var message = new device.Message(data);
|
||||
var message = new Message(data);
|
||||
message.properties.add('myproperty', 'myvalue');
|
||||
console.log("Sending message: " + message.getData());
|
||||
console.log('Sending message: ' + message.getData());
|
||||
client.sendEvent(message);
|
||||
}, 1000);
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var AmqpWs = require('./lib/amqp_ws.js');
|
||||
|
||||
module.exports = {
|
||||
AmqpWs: AmqpWs,
|
||||
clientFromConnectionString: function (connectionString) {
|
||||
return device.Client.fromConnectionString(connectionString, AmqpWs);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var ConnectionString = require('azure-iot-common').ConnectionString;
|
||||
var runTests = require('azure-iot-device-amqp/lib/_client_test_integration.js');
|
||||
var AmqpWs = require('./amqp_ws.js');
|
||||
|
||||
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
|
||||
var deviceId = process.env.IOTHUB_DEVICE_ID;
|
||||
var key = process.env.IOTHUB_DEVICE_KEY;
|
||||
|
||||
function makeConnectionString(host, device, key) {
|
||||
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
|
||||
}
|
||||
|
||||
var connectionString = makeConnectionString(host, deviceId, key);
|
||||
|
||||
var badConnStrings = [
|
||||
makeConnectionString('bad', 'device', 'key'),
|
||||
makeConnectionString('host', 'bad', 'key'),
|
||||
makeConnectionString('host', 'device', 'bad')
|
||||
];
|
||||
|
||||
describe('Over AMQP/WS', function () {
|
||||
this.timeout(15000);
|
||||
runTests(AmqpWs, connectionString, badConnStrings);
|
||||
});
|
|
@ -4,16 +4,16 @@
|
|||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var Base = require('azure-iot-common').Amqp;
|
||||
var Amqp = require('./amqp.js');
|
||||
var Base = require('azure-iot-amqp-base').Amqp;
|
||||
var Amqp = require('azure-iot-device-amqp').Amqp;
|
||||
|
||||
/**
|
||||
* @class AmqpWS
|
||||
* @classdesc Constructs an {@linkcode AmqpWS} object that can be used on a device to send
|
||||
* @class AmqpWs
|
||||
* @classdesc Constructs an {@linkcode AmqpWs} object that can be used on a device to send
|
||||
* and receive messages to and from an IoT Hub instance, using the AMQP protocol over secure websockets.
|
||||
* @augments Amqp
|
||||
*/
|
||||
function AmqpWS(config) {
|
||||
function AmqpWs(config) {
|
||||
this._config = config;
|
||||
var uri = 'wss://';
|
||||
uri += encodeURIComponent(this._config.deviceId) +
|
||||
|
@ -27,6 +27,6 @@ function AmqpWS(config) {
|
|||
this._amqp = new Base(uri, false);
|
||||
}
|
||||
|
||||
util.inherits(AmqpWS, Amqp);
|
||||
util.inherits(AmqpWs, Amqp);
|
||||
|
||||
module.exports = AmqpWS;
|
||||
module.exports = AmqpWs;
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "azure-iot-device-amqp-ws",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "AMQP-over-WebSocket transport for Azure IoT device SDK",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-amqp-base": "1.0.0-preview.9",
|
||||
"azure-iot-device": "1.0.0-preview.9",
|
||||
"azure-iot-device-amqp": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"azure-iot-common": "1.0.0-preview.9",
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var Amqp = require('./lib/amqp.js');
|
||||
|
||||
module.exports = {
|
||||
Amqp: Amqp,
|
||||
clientFromConnectionString: function (connectionString) {
|
||||
return device.Client.fromConnectionString(connectionString, Amqp);
|
||||
}
|
||||
};
|
|
@ -5,21 +5,25 @@
|
|||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Client = require('./client.js');
|
||||
var Client = require('azure-iot-device').Client;
|
||||
var ConnectionString = require('azure-iot-common').ConnectionString;
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var Amqp = require('./amqp.js');
|
||||
var AmqpWS = require('./amqp_ws.js');
|
||||
|
||||
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
|
||||
var deviceId = process.env.IOTHUB_DEVICE_ID;
|
||||
var key = process.env.IOTHUB_DEVICE_KEY;
|
||||
|
||||
var connectionString = 'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=' + key;
|
||||
function makeConnectionString(host, device, key) {
|
||||
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
|
||||
}
|
||||
|
||||
var connectionString = makeConnectionString(host, deviceId, key);
|
||||
|
||||
var badConnStrings = [
|
||||
'HostName=bad;DeviceId=' + deviceId + ';SharedAccessKey=' + key,
|
||||
'HostName=' + host + ';DeviceId=bad;SharedAccessKey=' + key,
|
||||
'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=bad;'
|
||||
makeConnectionString('bad', deviceId, key),
|
||||
makeConnectionString(host, 'bad', key),
|
||||
makeConnectionString(host, deviceId, 'bad')
|
||||
];
|
||||
|
||||
function badConfigTests(opName, badConnStrings, Transport, requestFn) {
|
||||
|
@ -57,7 +61,7 @@ function badConfigTests(opName, badConnStrings, Transport, requestFn) {
|
|||
});
|
||||
}
|
||||
|
||||
function runAmqpTests(Transport, goodConnectionString, badConnectionStrings) {
|
||||
function runTests(Transport, goodConnectionString, badConnectionStrings) {
|
||||
|
||||
describe('Client', function () {
|
||||
describe('#sendEvent', function () {
|
||||
|
@ -107,22 +111,8 @@ function runAmqpTests(Transport, goodConnectionString, badConnectionStrings) {
|
|||
});
|
||||
}
|
||||
|
||||
function makeConnectionString(host, device, key) {
|
||||
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
|
||||
}
|
||||
|
||||
var badConnStrings = [
|
||||
makeConnectionString('bad', 'device', 'key'),
|
||||
makeConnectionString('host', 'bad', 'key'),
|
||||
makeConnectionString('host', 'device', 'bad')
|
||||
];
|
||||
|
||||
describe('Over AMQPS', function () {
|
||||
runAmqpTests(Amqp, connectionString, badConnStrings);
|
||||
describe('Over AMQP', function () {
|
||||
runTests(Amqp, connectionString, badConnStrings);
|
||||
});
|
||||
|
||||
describe('Over AMQP/WS', function () {
|
||||
runAmqpTests(AmqpWS, connectionString, badConnStrings);
|
||||
});
|
||||
|
||||
module.exports = runAmqpTests;
|
||||
module.exports = runTests;
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Base = require('azure-iot-common').Amqp;
|
||||
var Endpoint = require('azure-iot-common').endpoint;
|
||||
var Base = require('azure-iot-amqp-base').Amqp;
|
||||
var endpoint = require('azure-iot-common').endpoint;
|
||||
|
||||
/**
|
||||
* @class Amqp
|
||||
|
@ -61,8 +61,8 @@ Amqp.prototype.disconnect = function disconnect(done) {
|
|||
/* Codes_SRS_NODE_DEVICE_AMQP_16_003: [The sendEvent method shall call the done() callback with no arguments when the message has been successfully sent.] */
|
||||
/* Codes_SRS_NODE_DEVICE_AMQP_16_004: [If sendEvent encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message). ] */
|
||||
Amqp.prototype.sendEvent = function sendEvent(message, done) {
|
||||
var endpoint = Endpoint.eventPath(this._config.deviceId);
|
||||
this._amqp.send(message, endpoint, endpoint, done);
|
||||
var eventEndpoint = endpoint.eventPath(this._config.deviceId);
|
||||
this._amqp.send(message, eventEndpoint, eventEndpoint, done);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ Amqp.prototype.sendEvent = function sendEvent(message, done) {
|
|||
/* Codes_SRS_NODE_DEVICE_AMQP_16_006: [If a receiver for this endpoint has already been created, the getReceiver method should call the done() method with the existing instance as an argument.]*/
|
||||
/* Codes_SRS_NODE_DEVICE_AMQP_16_007: [If a receiver for this endpoint doesn’t exist, the getReceiver method should create a new AmqpReceiver object and then call the done() method with the object that was just created as an argument.]*/
|
||||
Amqp.prototype.getReceiver = function getMessageReceiver(done) {
|
||||
var messageEndpoint = Endpoint.messagePath(encodeURIComponent(this._config.deviceId));
|
||||
var messageEndpoint = endpoint.messagePath(encodeURIComponent(this._config.deviceId));
|
||||
this._amqp.getReceiver(messageEndpoint, done);
|
||||
};
|
||||
|
Двоичный файл не отображается.
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "azure-iot-device-amqp",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "AMQP transport for Azure IoT device SDK",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-amqp-base": "1.0.0-preview.9",
|
||||
"azure-iot-common": "1.0.0-preview.9",
|
||||
"azure-iot-device": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var Http = require('./lib/http.js');
|
||||
|
||||
module.exports = {
|
||||
Http: Http,
|
||||
clientFromConnectionString: function (connectionString) {
|
||||
return device.Client.fromConnectionString(connectionString, Http);
|
||||
}
|
||||
};
|
|
@ -4,7 +4,8 @@
|
|||
'use strict';
|
||||
|
||||
var ConnectionString = require('azure-iot-common').ConnectionString;
|
||||
var runTests = require('./_client_test.js');
|
||||
var runTests = require('azure-iot-device/lib/_client_test.js');
|
||||
var Http = require('./http.js');
|
||||
|
||||
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
|
||||
var deviceId = process.env.IOTHUB_DEVICE_ID;
|
||||
|
@ -19,5 +20,5 @@ var badConnStrings = [
|
|||
|
||||
describe('Over real HTTPS', function () {
|
||||
this.timeout(15000);
|
||||
runTests(null, connectionString, badConnStrings);
|
||||
runTests(Http, connectionString, badConnStrings);
|
||||
});
|
Двоичный файл не отображается.
|
@ -3,7 +3,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Base = require('azure-iot-common').Http;
|
||||
var Base = require('azure-iot-http-base').Http;
|
||||
var endpoint = require('azure-iot-common').endpoint;
|
||||
var HttpReceiver = require('./http_receiver.js');
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "azure-iot-device-http",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "HTTP transport for Azure IoT device SDK",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-http-base": "1.0.0-preview.9",
|
||||
"azure-iot-common": "1.0.0-preview.9",
|
||||
"azure-iot-device": "1.0.0-preview.9",
|
||||
"node-crontab": "^0.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3",
|
||||
"sinon": "^1.17.2"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var device = require('azure-iot-device');
|
||||
var Mqtt = require('./lib/mqtt.js');
|
||||
|
||||
module.exports = {
|
||||
Mqtt: Mqtt,
|
||||
clientFromConnectionString: function (connectionString) {
|
||||
return device.Client.fromConnectionString(connectionString, Mqtt);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,138 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
||||
var Client = require('azure-iot-device').Client;
|
||||
var Message = require('azure-iot-device').Message;
|
||||
var SimulatedMqtt = require('./mqtt_simulated.js');
|
||||
var Mqtt = require('./mqtt.js');
|
||||
|
||||
describe('Mqtt', function () {
|
||||
describe('#constructor', function () {
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_001: [The Mqtt shall accept the transport configuration structure */
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_002: [The Mqtt shall store the configuration structure in a member variable */
|
||||
/* Tests_SRS_NODE_DEVICE_HTTP_12_003: [The Mqtt shall create an Mqtt object and store it in a member variable */
|
||||
it('stores config and created transport in member', function () {
|
||||
var config = {
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken",
|
||||
gatewayHostName: "gatewayHostName"
|
||||
};
|
||||
var mqtt_obj = new Mqtt(config);
|
||||
assert.notEqual(mqtt_obj, null);
|
||||
assert.notEqual(mqtt_obj, 'undefined');
|
||||
assert.equal(mqtt_obj._config, config);
|
||||
assert.notEqual(mqtt_obj._mqtt, null);
|
||||
assert.notEqual(mqtt_obj._mqtt, 'undefined');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function badConfigTests(opName, badConnStrings, Transport, requestFn) {
|
||||
|
||||
function makeRequestWith(connectionString, test, done) {
|
||||
var client = Client.fromConnectionString(connectionString, Transport);
|
||||
requestFn(client, function (err, res) {
|
||||
test(err, res);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function expectHostNotFoundError(err) {
|
||||
assert.equal(err.message, 'Invalid host address');
|
||||
}
|
||||
|
||||
function expectGatewayNotFoundError(err) {
|
||||
assert.equal(err.message, 'Invalid gateway address');
|
||||
}
|
||||
|
||||
function expectRefused(err) {
|
||||
assert.isNotNull(err);
|
||||
assert.equal(err.message, 'Connection Refused');
|
||||
}
|
||||
|
||||
var tests = [
|
||||
{ name: 'hostname is malformed', expect: expectHostNotFoundError },
|
||||
{ name: 'device is not registered', expect: expectRefused },
|
||||
{ name: 'password is wrong', expect: expectRefused },
|
||||
{ name: 'gatewayurl is malformed', expect: expectGatewayNotFoundError },
|
||||
];
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_016: [When a Client method encounters an error in the transport, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - the standard JavaScript Error object, with a response property that points to a transport-specific response object, and a responseBody property that contains the body of the transport response.]*/
|
||||
badConnStrings.forEach(function (test, index) {
|
||||
it('fails to ' + opName + ' when the ' + tests[index].name, function (done) {
|
||||
makeRequestWith(test, tests[index].expect, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runTests(Transport, goodConnectionString, badConnectionStrings) {
|
||||
|
||||
describe('Client', function () {
|
||||
describe('#sendEvent', function () {
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_007: [The sendEvent method shall send the event indicated by the message argument via the transport associated with the Client instance.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_017: [With the exception of receive, when a Client method completes successfully, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - null
|
||||
response - a transport-specific response object]*/
|
||||
it('sends the event', function (done) {
|
||||
var client = Client.fromConnectionString(goodConnectionString, Transport);
|
||||
var message = new Message('hello');
|
||||
client.sendEvent(message, function (err, res) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res, 'OK');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
badConfigTests('send an event', badConnectionStrings, Transport, function (client, done) {
|
||||
client.sendEvent(new Message(''), done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#receive', function () {
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_009: [The receive method shall query the IoT Hub for the next message via the transport associated with the Client instance.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_05_018: [When receive completes successfully, the callback function (indicated by the done argument) shall be invoked with the following arguments:
|
||||
err - null
|
||||
message - the received Message (for receive), otherwise null
|
||||
response - a transport-specific response object]*/
|
||||
it('queries the service for a message', function (done) {
|
||||
var client = Client.fromConnectionString(goodConnectionString, Transport);
|
||||
client.receive(function (err, msg, res) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res, 'OK');
|
||||
assert.instanceOf(msg, Message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
badConfigTests('receive messages', badConnectionStrings, Transport, function (client, done) {
|
||||
client.receive(function (err, message, response) {
|
||||
done(err, response);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function makeConnectionString(host, device, key, gateway) {
|
||||
return 'HostName=' + host + ';DeviceId=' + device + ';SharedAccessKey=' + key + ';GatewayHostName=' + gateway;
|
||||
}
|
||||
|
||||
var connectionString = makeConnectionString('host', 'device', 'key', 'gateway');
|
||||
var badConnStrings = [
|
||||
makeConnectionString('bad', 'device', 'key', 'gateway'),
|
||||
makeConnectionString('host', 'bad', 'key', 'gateway'),
|
||||
makeConnectionString('host', 'device', 'bad', 'gateway'),
|
||||
makeConnectionString('host', 'device', 'key', 'bad'),
|
||||
];
|
||||
|
||||
describe('Over simulated MQTT', function () {
|
||||
runTests(SimulatedMqtt, connectionString, badConnStrings);
|
||||
});
|
||||
|
||||
module.exports = runTests;
|
Двоичный файл не отображается.
|
@ -3,7 +3,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Mqtt_common = require('azure-iot-common').Mqtt;
|
||||
var Base = require('azure-iot-mqtt-base').Mqtt;
|
||||
|
||||
/*
|
||||
Codes_SRS_NODE_DEVICE_HTTP_12_001: [The Mqtt shall accept the transport configuration structure
|
||||
|
@ -11,20 +11,20 @@ var Mqtt_common = require('azure-iot-common').Mqtt;
|
|||
Codes_SRS_NODE_DEVICE_HTTP_12_003: [The Mqtt shall create an MqttTransport object and store it in a member variable
|
||||
*/
|
||||
function Mqtt(config) {
|
||||
this._config = config;
|
||||
this._mqtt = new Mqtt_common(config);
|
||||
this._config = config;
|
||||
this._mqtt = new Base(config);
|
||||
}
|
||||
|
||||
/* Codes_SRS_NODE_DEVICE_HTTP_12_004: [The connect method shall call the connect method on MqttTransport */
|
||||
Mqtt.prototype.connect = function (done) {
|
||||
this._mqtt.connect(function (){
|
||||
if (done) done();
|
||||
});
|
||||
this._mqtt.connect(function () {
|
||||
if (done) done();
|
||||
});
|
||||
};
|
||||
|
||||
/* Codes_SRS_NODE_DEVICE_HTTP_12_005: [The sendEvent method shall call the publish method on MqttTransport */
|
||||
Mqtt.prototype.sendEvent = function (message) {
|
||||
this._mqtt.publish(message);
|
||||
this._mqtt.publish(message);
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -32,8 +32,8 @@ Mqtt.prototype.sendEvent = function (message) {
|
|||
Codes_SRS_NODE_DEVICE_HTTP_12_007: [The receive method shall receive on MqttTransport
|
||||
*/
|
||||
Mqtt.prototype.receive = function (done) {
|
||||
this._mqtt.subscribe();
|
||||
this._mqtt.receive(done);
|
||||
this._mqtt.subscribe();
|
||||
this._mqtt.receive(done);
|
||||
};
|
||||
|
||||
module.exports = Mqtt;
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
'use strict';
|
||||
|
||||
var Message = require('azure-iot-device').Message;
|
||||
var SharedAccessSignature = require('azure-iot-device').SharedAccessSignature;
|
||||
|
||||
function makeError(errorMessage) {
|
||||
var err = new Error(errorMessage);
|
||||
return err;
|
||||
}
|
||||
|
||||
function SimulatedMqtt(config) {
|
||||
this.handleRequest = function (done) {
|
||||
var sig = SharedAccessSignature.parse(config.sharedAccessSignature);
|
||||
|
||||
if (config.host === 'bad') { // bad host
|
||||
done(new Error('Invalid host address'));
|
||||
}
|
||||
else if (config.deviceId === 'bad') { // bad policy
|
||||
done(makeError('Connection Refused'));
|
||||
}
|
||||
else if (config.gatewayHostName === 'bad') { // bad gateway url
|
||||
done(makeError('Invalid gateway address'));
|
||||
}
|
||||
else {
|
||||
var cmpSig = (SharedAccessSignature.create(config.host, config.deviceId, 'bad', sig.se)).toString();
|
||||
if (config.sharedAccessSignature === cmpSig) { // bad key
|
||||
done(makeError('Connection Refused'));
|
||||
}
|
||||
else {
|
||||
done(null, 'OK');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SimulatedMqtt.prototype.connect = function (done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, response);
|
||||
});
|
||||
};
|
||||
|
||||
SimulatedMqtt.prototype.sendEvent = function (message, done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, response);
|
||||
});
|
||||
};
|
||||
|
||||
SimulatedMqtt.prototype.receive = function (done) {
|
||||
this.handleRequest(function (err, response) {
|
||||
done(err, err ? null : new Message(''), response);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = SimulatedMqtt;
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "azure-iot-device-mqtt",
|
||||
"version": "1.0.0-preview.9",
|
||||
"description": "MQTT transport for Azure IoT device SDK",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"azure-iot-mqtt-base": "1.0.0-preview.9",
|
||||
"azure-iot-device": "1.0.0-preview.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.3.0",
|
||||
"jshint": "^2.8.0",
|
||||
"mocha": "^2.3.3",
|
||||
"sinon": "^1.17.2"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "jshint --show-non-errors .",
|
||||
"unittest-min": "mocha --reporter dot lib/_*_test.js",
|
||||
"alltest-min": "mocha --reporter dot lib/_*_test*.js",
|
||||
"unittest": "mocha --reporter spec lib/_*_test.js",
|
||||
"alltest": "mocha --reporter spec lib/_*_test*.js",
|
||||
"ci": "npm -s run lint && npm -s run alltest-min",
|
||||
"test": "npm -s run lint && npm -s run unittest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^0.12 || ^4"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Azure/azure-iot-sdks.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Azure/azure-iot-sdks/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-iot-sdks#readme"
|
||||
}
|
|
@ -7,7 +7,7 @@ var assert = require('chai').assert;
|
|||
var Client = require('./client.js');
|
||||
var errors = require('azure-iot-common').errors;
|
||||
var Message = require('azure-iot-common').Message;
|
||||
var AmqpReceiver = require('azure-iot-common').AmqpReceiver;
|
||||
var AmqpReceiver = require('azure-iot-amqp-base').AmqpReceiver;
|
||||
|
||||
describe('Client', function () {
|
||||
describe('#constructor', function () {
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Base = require('azure-iot-common').Amqp;
|
||||
var Endpoint = require('azure-iot-common').endpoint;
|
||||
var Base = require('azure-iot-amqp-base').Amqp;
|
||||
var endpoint = require('azure-iot-common').endpoint;
|
||||
|
||||
/**
|
||||
* @class Amqp
|
||||
|
@ -63,7 +63,7 @@ Amqp.prototype.disconnect = function disconnect(done) {
|
|||
/*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_005: [If send encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
|
||||
Amqp.prototype.send = function send(deviceId, message, done) {
|
||||
var serviceEndpoint = '/messages/devicebound';
|
||||
var deviceEndpoint = Endpoint.messagePath(encodeURIComponent(deviceId));
|
||||
var deviceEndpoint = endpoint.messagePath(encodeURIComponent(deviceId));
|
||||
this._amqp.send(message, serviceEndpoint, deviceEndpoint, done);
|
||||
};
|
||||
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче