33 lines
895 B
TypeScript
33 lines
895 B
TypeScript
import express from 'express';
|
|
import {robotLog as debug} from "../common/Debug";
|
|
import {singleton} from "../common/Singleton";
|
|
import {RobotManage} from "./RobotManage";
|
|
|
|
const router = express.Router();
|
|
|
|
router.get('/create', async (req, res, next) => {
|
|
let query = req.query;
|
|
let {host, room, sessionId } = query;
|
|
host = host as string;
|
|
room = room as string;
|
|
|
|
let manage = singleton(RobotManage);
|
|
try {
|
|
if (sessionId) {
|
|
sessionId = sessionId as string;
|
|
debug(`receive reconnect msg: ${host}, ${room}, ${sessionId}`);
|
|
await manage.reConnect({host, room, sessionId})
|
|
} else {
|
|
debug(`receive create robot msg: ${host}, ${room}`);
|
|
await manage.addOne({host, room});
|
|
}
|
|
res.json({errcode: 0});
|
|
} catch (err) {
|
|
res.json({errcode: 1})
|
|
}
|
|
|
|
|
|
})
|
|
|
|
export default router;
|