Commit 86135d8f authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

add webservice routes

parent 350ce343
Pipeline #4915 passed with stage
in 37 seconds
...@@ -31,15 +31,12 @@ console.log('starting hublot...'); ...@@ -31,15 +31,12 @@ console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot') loader.loadAll('controller', 'lib', 'robot')
.then(modules => { .then(modules => {
console.log('modules loaded... creating controller'); console.log('modules loaded... creating controller');
app.use('/', routes);
const controller = controllerFactory.create(runner, modules, config); const controller = controllerFactory.create(runner, modules, config);
console.log('creating client'); console.log('creating client');
// Automatic way use : controller.client('test-bot');
// Note: client returned object can be used to control further the browser app.use('/', routes.routesFactory(controller));
// e.g.: let client = controller.client('room'); client.end();
controller.client('test-bot');
app.listen(config.api, () => { app.listen(config.api, () => {
console.log('App listening on port 3000'); console.log('App listening on port 3000');
}); });
......
...@@ -205,6 +205,8 @@ robot = { ...@@ -205,6 +205,8 @@ robot = {
robotController.disconnect(); robotController.disconnect();
robot.clearConnection(); robot.clearConnection();
robot.notifyEndToServer(); robot.notifyEndToServer();
return true;
}, },
// This function will be overridden by a server callback // This function will be overridden by a server callback
......
const routes = require('express').Router(); /*
* 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/>.
*/
const routesFactory = controllerFactory => {
/* eslint new-cap: ["error", { "capIsNew": false }] */
const routes = require('express').Router();
routes.get('/connect/:room', (req, res) => { const controller = controllerFactory;
//controller.client(req.params.room);
res.status(200).json({message: 'Room Name!' + req.params.room});
});
routes.get('/disconnect/:room', (req, res) => { routes.put('/connect/:room', (req, res) => {
//controller.forceDisconnect(req.params.room); const result = controller.client(req.params.room);
res.status(200).json({message: 'Room Name!' + req.params.room}); if (result) {
}); res.status(201).json({message: 'Room ' + req.params.room + ' created'});
} else {
res.status(500).json({message: 'Unable to create Room ' + req.params.room});
}
});
routes.get('/test/', (req, res) => { routes.delete('/disconnect/:room', (req, res) => {
res.status(200).json({message: 'Room Test!'}); const result = controller.forceDisconnect(req.params.room);
}); if (result) {
res.status(200).json({message: 'Room ' + req.params.room + ' deleted'});
} else {
res.status(404).json({message: 'Unable to delete Room : ' + req.params.room});
}
});
module.exports = routes; return routes;
};
module.exports = {
routesFactory
};
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