Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Bridge.prototype.run = function(port, config, appServiceInstance, hostname) {
var self = this;
// Load the registration file into an AppServiceRegistration object.
if (typeof self.opts.registration === "string") {
var regObj = yaml.safeLoad(fs.readFileSync(self.opts.registration, 'utf8'));
self.opts.registration = AppServiceRegistration.fromObject(regObj);
if (self.opts.registration === null) {
throw new Error("Failed to parse registration file");
}
}
this._clientFactory = self.opts.clientFactory || new ClientFactory({
url: self.opts.homeserverUrl,
token: self.opts.registration.as_token,
appServiceUserId: (
"@" + self.opts.registration.sender_localpart + ":" + self.opts.domain
),
clientSchedulerBuilder: function() {
return new MatrixScheduler(retryAlgorithm, queueAlgorithm);
},
});
this._clientFactory.setLogFunction(function(text, isErr) {
if (!appService._events[name]) {
appService._events[name] = [];
}
appService._events[name].push(fn);
});
appService.emit = function(name, obj) {
var list = appService._events[name] || [];
var promises = list.map(function(fn) {
return fn(obj);
});
return Promise.all(promises);
};
bridgeCtrl = jasmine.createSpyObj("controller", [
"onEvent", "onAliasQuery", "onUserQuery"
]);
appServiceRegistration = AppServiceRegistration.fromObject({
id: "an_id",
hs_token: "h5_t0k3n",
as_token: "a5_t0k3n",
url: "http://app-service-url",
sender_localpart: BOT_LOCALPART,
namespaces: {
users: [{
exclusive: true,
regex: "@virtual_.*"
}],
aliases: [{
exclusive: true,
regex: "#virtual_.*"
}]
}
});
Cli.prototype._startWithConfig = function(config) {
this.opts.run(
this.opts.port, config,
AppServiceRegistration.fromObject(this._loadYaml(this.opts.registrationPath))
);
};