session destroy fixed
This commit is contained in:
@@ -4,13 +4,13 @@ const db_connection = require('../database/connection.js')
|
||||
const http_client = require('../../lib/http_client.js')
|
||||
const crypto = require('crypto')
|
||||
|
||||
module.exports.plan_session = async (req, res, next) => {
|
||||
const plan_session = async (req, res, next) => {
|
||||
//var session_sheduled = database.collection('session_sheduled')
|
||||
//var sessions = await session_sheduled.find().toArray()
|
||||
//callback(response)
|
||||
}
|
||||
|
||||
module.exports.create_session = async (req, res, next) => {
|
||||
const create_session = async (req, res, next) => {
|
||||
//create?title=name&next_var=0
|
||||
try {
|
||||
const db = await db_connection.get_db()
|
||||
@@ -41,27 +41,30 @@ module.exports.create_session = async (req, res, next) => {
|
||||
port: free_server.port,
|
||||
path: `/session/create?title=${req.query.title}&session_id=${session_id}`
|
||||
}, async function(answer) {
|
||||
answer = JSON.parse(answer)
|
||||
//console.log(answer.method)
|
||||
if (!answer.link) {
|
||||
next(Error('session not created'))
|
||||
return
|
||||
try {
|
||||
answer = JSON.parse(answer)
|
||||
//console.log(answer.method)
|
||||
if (!answer.link)
|
||||
throw new Error('session not created')
|
||||
|
||||
// generate random code for session access
|
||||
var code = Math.floor(1000 + Math.random() * 9000)
|
||||
while ((await session_active.find({'code':code}).toArray()).length) {
|
||||
code = Math.floor(1000 + Math.random() * 9000)
|
||||
}
|
||||
|
||||
// add session to database
|
||||
await session_active.insertOne({
|
||||
server_id:free_server.server_id,
|
||||
session_id:session_id,
|
||||
connection_link:answer.link,
|
||||
connection_code:code
|
||||
})
|
||||
// SHALL REMOVE CONNECTION CODE BECAUSE IN WEB WE DO NOT NEED IT
|
||||
res.json({msg:'SESSION_CREATED', link:answer.link, connection_code:code})
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
// generate random code for session access
|
||||
var code = Math.floor(1000 + Math.random() * 9000)
|
||||
while ((await session_active.find({'code':code}).toArray()).length) {
|
||||
code = Math.floor(1000 + Math.random() * 9000)
|
||||
}
|
||||
|
||||
// add session to database
|
||||
await session_active.insertOne({
|
||||
server_id:free_server.server_id,
|
||||
session_id:session_id,
|
||||
connection_link:answer.link,
|
||||
connection_code:code
|
||||
})
|
||||
// SHALL REMOVE CONNECTION CODE BECAUSE IN WEB WE DO NOT NEED IT
|
||||
res.json({msg:'SESSION_CREATED', link:answer.link, connection_code:code})
|
||||
}, function(err) {
|
||||
next(Error('session server not working'))
|
||||
})
|
||||
@@ -70,20 +73,28 @@ module.exports.create_session = async (req, res, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.connect_session = async (req, res, next) => {
|
||||
const connect_session = async (req, res, next) => {
|
||||
try {
|
||||
const db = await db_connection.get_db()
|
||||
var session = await db.collection('session_active').findOne({connection_code:parseInt(req.query.connection_code)})
|
||||
if (!session)
|
||||
throw new Error('sessions not found')
|
||||
res.json({connection_link:session.connection_link})
|
||||
|
||||
res.json({msg:'SESSION_DATA', link:session.connection_link, connection_code:session.connection_code})
|
||||
} catch (e) {
|
||||
next (e)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.close_session = async (req, res, next) => {
|
||||
const close_session = async (req, res, next) => {
|
||||
const db = await db_connection.get_db()
|
||||
await db.collection('session_active').deleteOne({session_id:req.query.session_id})
|
||||
res.json({msg:"SESSION_CLOSED", session_id:req.session_id})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
plan_session,
|
||||
create_session,
|
||||
connect_session,
|
||||
close_session
|
||||
}
|
||||
Reference in New Issue
Block a user