From 288718779de31ea9abbea8c48d1fdccdd8a3c613 Mon Sep 17 00:00:00 2001 From: C Date: Wed, 30 Nov 2022 16:07:56 +0500 Subject: [PATCH] session close added --- documentation/Session_close_Session_continue.txt | 8 ++++++++ {prototype => source}/coordinator/config.json | 2 +- {prototype => source}/coordinator/coordinator.js | 9 +++++++-- {prototype => source}/coordinator/mongodb_client.js | 0 {prototype => source}/coordinator/package-lock.json | 0 {prototype => source}/coordinator/package.json | 0 {prototype => source}/lib/http_client.js | 1 + {prototype => source}/lib/logger.js | 0 {prototype => source}/lib/port_alloc.js | 0 {prototype => source}/session_server/config.json | 4 ++++ {prototype => source}/session_server/package-lock.json | 0 {prototype => source}/session_server/package.json | 0 {prototype => source}/session_server/session_server.js | 9 ++++++++- {prototype => source}/session_server/titles.json | 0 14 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 documentation/Session_close_Session_continue.txt rename {prototype => source}/coordinator/config.json (80%) rename {prototype => source}/coordinator/coordinator.js (91%) rename {prototype => source}/coordinator/mongodb_client.js (100%) rename {prototype => source}/coordinator/package-lock.json (100%) rename {prototype => source}/coordinator/package.json (100%) rename {prototype => source}/lib/http_client.js (99%) rename {prototype => source}/lib/logger.js (100%) rename {prototype => source}/lib/port_alloc.js (100%) rename {prototype => source}/session_server/config.json (89%) rename {prototype => source}/session_server/package-lock.json (100%) rename {prototype => source}/session_server/package.json (100%) rename {prototype => source}/session_server/session_server.js (93%) rename {prototype => source}/session_server/titles.json (100%) diff --git a/documentation/Session_close_Session_continue.txt b/documentation/Session_close_Session_continue.txt new file mode 100644 index 0000000..74fbd25 --- /dev/null +++ b/documentation/Session_close_Session_continue.txt @@ -0,0 +1,8 @@ +завершение сессии: + WebRTC завершает своё выполнение если пользователи неактивны в течение N секунд + Session Server видит что WebRTC сервер завершил выполнение, отправляет уведомление Coordinator + Coordinator удаляет сессию из базы данных +продление сессии: + WebRTC сервер понимает что сессия подходит к концу спрашивает у Session Server продолжения сессии + Session Server отправляет запрос на продление сессии Coordinator + Coordinator смотрит можно ли продлить сессию и возвращает ответ diff --git a/prototype/coordinator/config.json b/source/coordinator/config.json similarity index 80% rename from prototype/coordinator/config.json rename to source/coordinator/config.json index 9689bb6..c7a64a5 100644 --- a/prototype/coordinator/config.json +++ b/source/coordinator/config.json @@ -1,5 +1,5 @@ { - "ip" : "127.0.0.1", + "ip" : "192.168.1.115", "port" : "3001", "mongodb_url" : "mongodb://127.0.0.1:27017/", "database_name" : "pixel_streaming" diff --git a/prototype/coordinator/coordinator.js b/source/coordinator/coordinator.js similarity index 91% rename from prototype/coordinator/coordinator.js rename to source/coordinator/coordinator.js index f5eda89..23ee1a8 100644 --- a/prototype/coordinator/coordinator.js +++ b/source/coordinator/coordinator.js @@ -70,7 +70,7 @@ async function create_response(request, callback) { // create session on session server new http_client(free_server.ip, free_server.port).post( - `{"verb":"CREATE_SESSION", "title":"${request.title}", "session_id":"${session_id}"}`, async function(answer) { + JSON.stringify({verb:'CREATE_SESSION', title:request.title, session_id:session_id}), async function(answer) { var json_answer = await JSON.parse(answer) @@ -90,7 +90,7 @@ async function create_response(request, callback) { await session_active.insertOne({ server_id:free_server.server_id, session_id:session_id, - link:json_answer.link, + connection_link:json_answer.link, connection_code:code }) response = {msg:'SESSION_CREATED', link:json_answer.link} @@ -106,6 +106,11 @@ async function create_response(request, callback) { } else if (request.verb == 'CONNECT_SESSION') { callback(response) return + } else if (request.verb == 'CLOSE_SESSION') { + await database.collection('session_active').deleteOne({session_id:request.session_id}) + response = {msg:"SESSION_CLOSED", session_id:request.session_id} + callback(response) + return } else { response = {msg:'UNKNOWN_VERB'} callback(response) diff --git a/prototype/coordinator/mongodb_client.js b/source/coordinator/mongodb_client.js similarity index 100% rename from prototype/coordinator/mongodb_client.js rename to source/coordinator/mongodb_client.js diff --git a/prototype/coordinator/package-lock.json b/source/coordinator/package-lock.json similarity index 100% rename from prototype/coordinator/package-lock.json rename to source/coordinator/package-lock.json diff --git a/prototype/coordinator/package.json b/source/coordinator/package.json similarity index 100% rename from prototype/coordinator/package.json rename to source/coordinator/package.json diff --git a/prototype/lib/http_client.js b/source/lib/http_client.js similarity index 99% rename from prototype/lib/http_client.js rename to source/lib/http_client.js index 0d9822d..7dd35ce 100644 --- a/prototype/lib/http_client.js +++ b/source/lib/http_client.js @@ -7,6 +7,7 @@ module.exports = class http_client { } async post(data, callback_answer, callback_error) { // Build the post string from an object + // An object of options to indicate where to post to var post_options = { host: this.#ip, diff --git a/prototype/lib/logger.js b/source/lib/logger.js similarity index 100% rename from prototype/lib/logger.js rename to source/lib/logger.js diff --git a/prototype/lib/port_alloc.js b/source/lib/port_alloc.js similarity index 100% rename from prototype/lib/port_alloc.js rename to source/lib/port_alloc.js diff --git a/prototype/session_server/config.json b/source/session_server/config.json similarity index 89% rename from prototype/session_server/config.json rename to source/session_server/config.json index 9acfcd8..1f5544e 100644 --- a/prototype/session_server/config.json +++ b/source/session_server/config.json @@ -6,6 +6,10 @@ "app_begin": 47000, "http_begin": 47500 }, + "coordinator":{ + "ip":"192.168.1.115", + "port":3001 + }, "webrtc_args_static":{ "cirrus_path":"D:/shared/Builds/Ivaz_Optimized_2/Samples/PixelStreaming/WebServers/SignallingWebServer/cirrus.js" }, diff --git a/prototype/session_server/package-lock.json b/source/session_server/package-lock.json similarity index 100% rename from prototype/session_server/package-lock.json rename to source/session_server/package-lock.json diff --git a/prototype/session_server/package.json b/source/session_server/package.json similarity index 100% rename from prototype/session_server/package.json rename to source/session_server/package.json diff --git a/prototype/session_server/session_server.js b/source/session_server/session_server.js similarity index 93% rename from prototype/session_server/session_server.js rename to source/session_server/session_server.js index 0c5565f..056f69c 100644 --- a/prototype/session_server/session_server.js +++ b/source/session_server/session_server.js @@ -88,7 +88,14 @@ async function create_response(request, callback) { else { app_proc.kill('SIGINT') } - //new http_client(ip, port).post() + new http_client(config.coordinator.ip, config.coordinator.port).post( + JSON.stringify({verb:'CLOSE_SESSION', session_id:request.session_id}), function(answer) { + + }, + function(error) { + + }) + }) response = {msg:'SESSION_CREATED', link:`http://${config.ip+':'+http_port}`} diff --git a/prototype/session_server/titles.json b/source/session_server/titles.json similarity index 100% rename from prototype/session_server/titles.json rename to source/session_server/titles.json