mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
major revamp of http client functionalit
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
const Emitter = require('events');
|
||||
const assert = require('assert');
|
||||
|
||||
/**
|
||||
* @classdesc This is a singleton class that tracks active sessions in a Map indexed
|
||||
* by callSid. Its function is to allow us to accept inbound REST callUpdate requests
|
||||
* for a callSid and to be able to retrieve and operate on the corresponding CallSession.
|
||||
*/
|
||||
class SessionTracker extends Emitter {
|
||||
constructor() {
|
||||
super();
|
||||
@@ -16,22 +21,39 @@ class SessionTracker extends Emitter {
|
||||
return this._logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new CallSession to the Map
|
||||
* @param {string} callSid
|
||||
* @param {CallSession} callSession
|
||||
*/
|
||||
add(callSid, callSession) {
|
||||
assert(callSid);
|
||||
this.sessions.set(callSid, callSession);
|
||||
this.logger.info(`SessionTracker:add callSid ${callSid}, we have ${this.sessions.size} session being tracked`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a CallSession from the Map
|
||||
* @param {string} callSid
|
||||
*/
|
||||
remove(callSid) {
|
||||
assert(callSid);
|
||||
this.sessions.delete(callSid);
|
||||
this.logger.info(`SessionTracker:remove callSid ${callSid}, we have ${this.sessions.size} being tracked`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given callSid is in the Map
|
||||
* @param {string} callSid
|
||||
*/
|
||||
has(callSid) {
|
||||
return this.sessions.has(callSid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the active CallSession for a given callSid
|
||||
* @param {string} callSid
|
||||
*/
|
||||
get(callSid) {
|
||||
return this.sessions.get(callSid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user