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);
});
};
存在一个名为"未定义"的错误:
ERROR: /home/root/.node_app_slot/node_modules/muzzley-bridge-node/lib/index.js:29
ERROR: bridgeData.appToken = account.appToken;
ERROR: ^
ERROR: TypeError: Cannot set property 'appToken' of undefined
你在代码中声明了bridgeData错误。
只需更改以下行:
var bridgeData;
自:
var bridgeData = {};
执行此操作时:var bridgeData;
变量未定义,并且无法将新属性分配给未定义的变量。
您是否使用此库将电路板连接到 Muzzley?它已经被修复了。跑:
npm 安装枪口桥节点
安装最新版本
我刚刚写信给作者。
他修复了库 -> ver.0.0.4 .
现在'npm更新枪口桥节点'!