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

add webservice routes

parent 350ce343
Pipeline #4915 passed with stage
in 37 seconds
......@@ -31,15 +31,12 @@ console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot')
.then(modules => {
console.log('modules loaded... creating controller');
app.use('/', routes);
const controller = controllerFactory.create(runner, modules, config);
console.log('creating client');
// Automatic way use : controller.client('test-bot');
// Note: client returned object can be used to control further the browser
// e.g.: let client = controller.client('room'); client.end();
controller.client('test-bot');
app.use('/', routes.routesFactory(controller));
app.listen(config.api, () => {
console.log('App listening on port 3000');
});
......
......@@ -205,6 +205,8 @@ robot = {
robotController.disconnect();
robot.clearConnection();
robot.notifyEndToServer();
return true;
},
// 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) => {
//controller.client(req.params.room);
res.status(200).json({message: 'Room Name!' + req.params.room});
});
const controller = controllerFactory;
routes.get('/disconnect/:room', (req, res) => {
//controller.forceDisconnect(req.params.room);
res.status(200).json({message: 'Room Name!' + req.params.room});
});
routes.put('/connect/:room', (req, res) => {
const result = controller.client(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) => {
res.status(200).json({message: 'Room Test!'});
});
routes.delete('/disconnect/:room', (req, res) => {
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