var Subscription = require('./Subscription');
var api = require('./api');
exports = module.exports = {};
var bridgeData;
function validateAccount(account) {
if (!account) throw new Error('Muzzley account details must be present!');
if (!account.appToken) throw new Error('appToken is not defined!');
if (!account.profileId) throw new Error('profileId is not defined!');
if (!account.serialNumber) throw new Error('serialNumber is not defined!');
}
function validateComponents(components) {
if (!components || components.length === 0) throw new Error('Bridge components must be defined!');
for (var i = 0; i != components.length; ++i) {
if(!components[i].id) throw new Error('Missing component id!');
if (!components[i].type) throw new Error('Missing component type!');
if (!components[i].label) throw new Error('Missing component label!');
}
}
exports.connect = function (account, components, callback) {
validateAccount(account);
validateComponents(components);
bridgeData.appToken = account.appToken;
bridgeData.profileId = account.profileId;
api.registerBridge(account, function (err, bridge) {
if (err) return callback(err);
bridgeData.deviceKey = bridge.deviceKey;
api.updateBridge(bridge, components, function (err) {
if (err) return callback(err);
var subscription = new Subscription(account.profileId, account.appToken);
subscription.load(function (err) {
return callback(err, subscription);
});
});
});
};
exports.updateComponents = function (components, callback) {
api.updateBridge(bridgeData, components, function (err) {
return callback(err);
});
};
有一个错误叫做undefined:
错误:/home/root/.node_app_slot/node_modules/muzzley-bridge-node/lib/index.js:29
错误:bridgeData.appToken = account.appToken;
错误:^
错误:TypeError:无法设置未定义的属性“ appToken”
最佳答案
您在代码中声明bridgeData错误。
只需更改以下行:
var bridgeData;
至:
var bridgeData = {};
当您执行以下操作时:
var bridgeData;
您的变量是未定义的,并且不能将新属性分配给未定义的变量。