Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
subscribeEvent (roomId, callback) {
if (is.undefined(roomId)) throw new Error('`roomId` required')
if (is.not.string(roomId)) throw new TypeError('`roomId` must have type of string')
if (is.undefined(callback)) throw new Error('`callback` required')
if (is.not.function(callback)) throw new TypeError('`callback` must have type of function')
const topic = getTopic(roomId)
// Only allow 1 subcription for now
if (subscribedTopics[topic]) return
mqttAdapter.mqtt.subscribe(topic)
const cb = (payload) => {
const parsedPayload = JSON.parse(payload)
callback(parsedPayload)
}
events.on(topic, cb)
subscribedTopics[topic] = cb
},
// if object was passed instead of key-value pair
// iterate over that object and call .where(key, value)
if (is.object(key)) {
let conditions = key;
let keys = Object.keys(conditions);
keys.forEach(key => {
this.where(key, conditions[key]);
});
}
if (is.string(key)) {
// if only one argument was supplied
// save the key in this.lastKey
// for future methods, like .equals()
if (is.undefined(value)) {
this.lastKey = key;
return this;
}
// if value is a regular expression
// use $regex modifier
if (is.regexp(value)) {
value = { $regex: value };
}
this.query[key] = value;
}
return this;
}
subscribeEvent (roomId, callback) {
if (is.undefined(roomId)) throw new Error('`roomId` required')
if (is.not.string(roomId)) throw new TypeError('`roomId` must have type of string')
if (is.undefined(callback)) throw new Error('`callback` required')
if (is.not.function(callback)) throw new TypeError('`callback` must have type of function')
const topic = getTopic(roomId)
// Only allow 1 subcription for now
if (subscribedTopics[topic]) return
mqttAdapter.mqtt.subscribe(topic)
const cb = (payload) => {
const parsedPayload = JSON.parse(payload)
callback(parsedPayload)
}
events.addListener(topic, cb)
subscribedTopics[topic] = cb
},
unsubscribeEvent (roomId) {
subscribeEvent (roomId, callback) {
if (is.undefined(roomId)) throw new Error('`roomId` required')
if (is.not.string(roomId)) throw new TypeError('`roomId` must have type of string')
if (is.undefined(callback)) throw new Error('`callback` required')
if (is.not.function(callback)) throw new TypeError('`callback` must have type of function')
const topic = getTopic(roomId)
// Only allow 1 subcription for now
if (subscribedTopics[topic]) return
mqttAdapter.mqtt.subscribe(topic)
const cb = (payload) => {
const parsedPayload = JSON.parse(payload)
callback(parsedPayload)
}
events.on(topic, cb)
subscribedTopics[topic] = cb
},
unsubscribeEvent (roomId) {
.on('end', function () {
var sdkConf = require(path.join(process.cwd(), 'sdk.conf.json'));
if (!is.undefined(sdkConf.ng)) {
gutil.log(gutil.colors.red('Angularjs support is already enabled on this project.'));
process.exit(1);
}
})
.on('error', function () {
keys.forEach(function (key) {
var defaultValue = defaults[key];
var actualValue = _this.get(key);
if (is.undefined(actualValue)) {
_this.set(key, defaultValue);
}
});
};
keys.forEach(function (key) {
let defaultValue = defaults[key];
let actualValue = self.get(key);
if (is.undefined(actualValue)) {
self.set(key, defaultValue);
}
});
};
_on(method, path, handler) {
if (is.undefined(handler)) handler = () => {};
if (is.not.function(handler)) throw new Exception('invalid handler');
if (is.not.function(this.$r[method])) throw new Exception('invalid method');
this.$r[method](path, (req, res, params) => {
req.params = params || {};
const query = url.parse(req.url, true);
req.query = query ? query.query || {} : {};
body(req, (e, payload) => {
req.body = payload;
handler(req, res)
.then(r => {
if (r instanceof Buffer) return r.toString();
else if (r instanceof Array || is.object(r)) return JSON.stringify(r);
else if (is.not.existy(r) || is.nan(r)) throw new Exception('invalid value');
else return r.toString();
})
keys.forEach(key => {
let defaultValue = defaults[key];
let actualValue = this.get(key);
if (is.undefined(actualValue)) {
this.set(key, defaultValue);
}
});
}