Commit 2e287af4 authored by Tom Jorquera's avatar Tom Jorquera

lib: refactor the client creation logic into a controller

The (currently very basic) client creation logic is now into a
dedicated (actual) `controller` module.

This will allow for cleaner dev and (especially) tests.
parent 14d31e4f
......@@ -22,6 +22,7 @@ const config = require('./config.json');
const runner = require('./lib/runner.js')(config.runner);
const loader = require('./lib/loader.js')('./client');
const controllerFactory = require('./lib/controller.js');
const registry = {};
......@@ -29,17 +30,16 @@ console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot')
.then(modules => {
console.log('modules loaded... launching runner');
console.log('modules loaded... creating controller');
// Note: client returned object can be used to control further the browser
// e.g.: let c = client('room'); c.end();
const client = room => runner.run(modules,
config.visio.url,
room,
config.client);
const controller = controllerFactory.create(runner, modules, config);
console.log('creating client');
// Note: client returned object can be used to control further the browser
// e.g.: let client = controller.client('room'); client.end();
const room = 'test-bot';
registry[room] = client(room);
registry[room] = controller.client(room);
})
.catch(err => {
console.error(err);
......
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of Hublot
* (see https://ci.linagora.com/linagora/lgs/labs/hublot).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
// Module to control the server-side behavior and state
const create = (runner, modules, config) => {
const controller = {
client: room => runner.run(modules,
config.visio.url,
room,
config.client)
};
return controller;
};
module.exports = {
create
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment