Commit 19dd8d3b authored by Tom JORQUERA's avatar Tom JORQUERA

Merge branch '35-rest-api-for-hublot-control' into 'master'

Resolve "REST API for hublot control"

Closes #35

See merge request !46
parents 4817442a 86135d8f
Pipeline #5135 passed with stage
in 46 seconds
......@@ -17,6 +17,8 @@
* 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 app = require('express')();
const routes = require('./lib/webserver/routes');
const config = require('./config.json');
......@@ -31,12 +33,13 @@ loader.loadAll('controller', 'lib', 'robot')
console.log('modules loaded... creating controller');
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');
});
})
.catch(err => {
console.error(err);
......
......@@ -205,6 +205,8 @@ robot = {
robotController.disconnect();
robot.clearConnection();
robot.notifyEndToServer();
return true;
},
// This function will be overridden by a server callback
......
......@@ -36,5 +36,6 @@
"port": 8080,
"reconnectInterval": 5000
}
}
},
"api": 3000
}
/*
* 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();
const controller = controllerFactory;
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.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});
}
});
return routes;
};
module.exports = {
routesFactory
};
......@@ -13,6 +13,8 @@
"webdriver-stop": "./bin/webdriver-stop"
},
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2",
"mz": "2.6.0",
"webdriverio": "4.7.1"
},
......
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