Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(connStr: string, protocol: any, sendInterval: number, sendTimeout: number) {
super();
this._sendInterval = sendInterval;
this._sendTimeout = sendTimeout;
const authProvider = SharedAccessKeyAuthenticationProvider.fromConnectionString(connStr);
this._client = Client.fromAuthenticationProvider(authProvider, protocol);
this._client.on('error', (err) => {
debug('error emitted by client: ' + err.toString());
this.stop((stopErr) => {
debug('error stopping: ' + stopErr.toString());
});
});
this._client.on('disconnect', (err) => {
this.stop((stopErr) => {
debug('error stopping: ' + stopErr.toString());
});
});
}
provisioningClient.register(function(err, result) {
if (err) {
console.log("error registering device: " + err);
} else {
console.log('registration succeeded');
console.log('assigned hub=' + result.registrationState.assignedHub);
console.log('deviceId=' + result.registrationState.deviceId);
var tpmAuthenticationProvider = tpmSecurity.TpmAuthenticationProvider.fromTpmSecurityClient(result.registrationState.deviceId, result.registrationState.assignedHub, securityClient);
var hubClient = Client.fromAuthenticationProvider(tpmAuthenticationProvider, iotHubTransport);
var connectCallback = function (err) {
if (err) {
console.error('Could not connect: ' + err.message);
} else {
console.log('Client connected');
var message = new Message('Hello world');
hubClient.sendEvent(message, printResultFor('send'));
}
};
hubClient.open(connectCallback);
function printResultFor(op) {
return function printResult(err, res) {
if (err) console.log(op + ' error: ' + err.toString());