session destroy fixed
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
{
|
||||
"ip" : "192.168.1.115",
|
||||
"port" : "3001",
|
||||
"mongodb_url" : "mongodb://127.0.0.1:27017",
|
||||
"mongodb_url" : "mongodb://pixel_admin:!G3432664499@192.168.1.163:27017",
|
||||
"database_name" : "pixel_streaming",
|
||||
"cors":[
|
||||
"http://192.168.1.171:3000",
|
||||
"http://localhost:3000"
|
||||
"http://localhost:3000",
|
||||
"https://stream.graff.tech/",
|
||||
"http://212.220.216.185:3005",
|
||||
"https://stream.graff.tech"
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
const db_connection = require('../database/connection.js')
|
||||
const crypto = require('crypto')
|
||||
|
||||
module.exports.emergency_shutdown = async (req, res, next) => {
|
||||
const emergency_shutdown = async (req, res, next) => {
|
||||
const db = await db_connection.get_db()
|
||||
var id = crypto.createHash('md5').update(req.query.ip+req.query.port).digest('hex')
|
||||
var id = req.query.id
|
||||
var query = {server_id:{$in:[id]}}
|
||||
await db.collection('session_active').deleteMany(query)
|
||||
res.json({msg:'SESSIONS_CLOSED'})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
emergency_shutdown
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
const config = require('../config.json')
|
||||
const db_connection = require('../database/connection.js')
|
||||
|
||||
module.exports.get_titles = async (req, res, next) => {
|
||||
const get_titles = async (req, res, next) => {
|
||||
try {
|
||||
const db = await db_connection.get_db()
|
||||
var titles = await db.collection('title').find().skip(parseInt(req.query.start)).limit(parseInt(req.query.count)).toArray()
|
||||
@@ -9,4 +9,8 @@ module.exports.get_titles = async (req, res, next) => {
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get_titles
|
||||
}
|
||||
Reference in New Issue
Block a user