Problem in GET /api-sessions/:sessionId

Hello,

Developing in localhost.My imports:

var OpenVidu = require(‘openvidu-node-client’).OpenVidu;

var Session = require(‘openvidu-node-client’).Session;

var Connection = require(‘openvidu-node-client’).Connection;

var Stream = require(‘openvidu-node-client’).Stream;

var OpenViduRole = require(‘openvidu-node-client’).OpenViduRole;

var TokenOptions = require(‘openvidu-node-client’).TokenOptions;

Part of my code:

Blockquote
// Get token (add new user to session)
app.post(‘/api-sessions/get-token’, function (req, res) {

    // The video-call to connect
    var sessionId = req.body.customSessionId;
    console.log(sessionId);

    var serverData = req.body.serverData;
    console.log(serverData);

    var role = req.body.role;

    console.log(role);

    // Build TokenOptions object with the serverData and the role
    var tokenOptions = {
    role: role
    }

    if (mapSessions[sessionId]) {
        console.log(sessionId);
        // Session already exists
        console.log('Existing session ' + sessionId);

        // Get the existing Session from the collection
        var mySession = mapSessions[sessionId];
        console.log(mySession);
        // Generate a new token asynchronously with the recently created TokenOptions
        mySession.generateToken(tokenOptions)
            .then(token => {

                // Store the new token in the collection of tokens
                mapSessionIdTokens[sessionId].push(token);

                console.log(token);

                // Return the token to the client
                res.status(200).send({
                    0: token
                });
            })
            .catch(error => {
                console.error(error);
            });
    } else {
        // New sessioncd 
        console.log('New session ' + sessionId);

        // Create a new OpenVidu Session asynchronously
        OV.createSession()
            .then(session => {
                // Store the new Session in the collection of Sessions
                mapSessions[sessionId] = session;
                // Store a new empty array in the collection of tokens
                mapSessionIdTokens[sessionId] = [];

                // Generate a new token asynchronously with the recently created TokenOptions
                session.generateToken(tokenOptions)
                    .then(token => {

                        // Store the new token in the collection of tokens
                        mapSessionIdTokens[sessionId].push(token);

                        console.log(token);
                        
                        // Return the Token to the client
                        res.status(200).send({
                            0: token
                        });

                        session.fetch().then(anyChange => {
                          console.log('FETCHED');
                        });
                    })
                    .catch(error => {
                        console.error(error);
                    });
            })
            .catch(error => {
                console.error(error);
            });
    }
});

// Remove user from session
app.post(‘/api-sessions/remove-user’, function (req, res) {
// Retrieve params from POST body
var sessionId = req.body.sessionId;
var token = req.body.token;
console.log(‘Removing user | {sessionName, token}={’ + sessionId + ', ’ + token + ‘}’);

    // If the session exists
    if (mapSessions[sessionId] && mapSessionIdTokens[sessionId]) {
        var tokens = mapSessionIdTokens[sessionId];
        console.log(tokens);
        var index = tokens.indexOf(token);

        // If the token exists
        if (index !== -1) {
            // Token removed
            tokens.splice(index, 1);
            console.log(sessionId + ': ' + tokens.toString());
        } else {
            var msg = 'Problems in the app server: the TOKEN wasn\'t valid';
            console.log(msg);
            res.status(500).send(msg);
        }
        if (tokens.length == 0) {
            // Last user left: session must be removed
            console.log(sessionId + ' empty!');
            delete mapSessions[sessionId];
        }
        res.status(200).send();
    } else {
        var msg = 'Problems in the app server: the SESSION does not exist';
        console.log(msg);
        res.status(500).send(msg);
    }
});

app.get(‘/api-sessions/:sessionId’, function (req, res){
var sessionId = req;
console.log(sessionId);
session.fetch()
.then(anyChange =>{
// Fetch one session info from OpenVidu Server
var activeConnections = session.activeConnections;
console.log(activeConnections);
res.status(200).send();
})
});

Here I paste my output from node in the terminal with a didi session created succesfully and doing in Postman https://localhost:5000/api-sessions/didi GET request. It gave me a lot of output (I paste here part of it) and complaint about session.fetch function. Any help will be very useful. Am I doing something wrong? I am missing something in session lifecycle?:

Mongoose connected to mongodb://localhost:27017/vcnton
didi
{ username: ‘madrona’ }
MODERATOR
New session didi
wss://hsjdvc.i2cat.net:4443?sessionId=erynlbruigwqppln&token=kt8hvicgunja3ffo&role=MODERATOR&version=2.11.0&turnUsername=GTLGEJ&turnCredential=bdxrhq
Session info fetched for session ‘erynlbruigwqppln’. Any change: true
FETCHED
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: true,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: true,
readableListening: false,
resumeScheduled: false,
paused: true,
emitClose: true,
destroyed: false,
defaultEncoding: ‘utf8’,
awaitDrain: 0,
readingMore: true,
decoder: null,
encoding: null },
readable: true,
_events:
[Object: null prototype] { end: [Function: resetHeadersTimeoutOnReqEnd] },
_eventsCount: 1,
_maxListeners: undefined,
socket:
TLSSocket {
_tlsOptions:
{ secureContext: [SecureContext],
isServer: true,
server: [Server],
requestCert: false,
rejectUnauthorized: true,
handshakeTimeout: 120000,
ALPNProtocols: <Buffer 08 68 74 74 70 2f 31 2e 31>,
SNICallback: [Function: SNICallback] },
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: ‘localhost’,
alpnProtocol: false,
authorized: false,
authorizationError: null,
encrypted: true,
_events:
[Object: null prototype] {
close: [Array],
end: [Array],
secure: [Function: onSocketSecure],
_tlsError: [Function: onSocketTLSError],
drain: [Array],
timeout: [Function: socketOnTimeout],
data: [Function: bound socketOnData],
error: [Function: socketOnError],
resume: [Function: onSocketResume],
pause: [Function: onSocketPause] },
_eventsCount: 10,
connecting: false,
_hadError: false,
_handle:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
_parent:
Socket {
connecting: false,
_hadError: false,
_handle: [TCP],
_parent: null,
_host: null,
_readableState: [ReadableState],
readable: true,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: ‘’,
server: [Server],
_server: [Server],
[Symbol(asyncId)]: 381,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 },
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: false,
emitClose: false,
destroyed: false,
defaultEncoding: ‘utf8’,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: ‘utf8’,
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: ‘’,
server:
Server {
_contexts: ,
requestCert: false,
rejectUnauthorized: true,
key:
<Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 45 6f 77 49 42 41 41 4b 43 41 51 45 41 77 32 … >,
cert:
<Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 67 7a 43 43 41 6d 75 67 41 77 49 42 41 67 49 4a 41 4c … >,
honorCipherOrder: true,
ALPNProtocols: <Buffer 08 68 74 74 70 2f 31 2e 31>,
sessionIdContext: ‘02bb4648221449d0b7d44bc3c35116fc’,
_sharedCreds: [SecureContext],
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
_connections: 1,
_handle: [TCP],
_usingWorkers: false,
_workers: ,
_unref: false,
allowHalfOpen: false,
pauseOnConnect: false,
httpAllowHalfOpen: false,
timeout: 120000,
keepAliveTimeout: 5000,
maxHeadersCount: null,
headersTimeout: 40000,
_connectionKey: ‘6::::5000’,
[Symbol(IncomingMessage)]: [Function],
[Symbol(ServerResponse)]: [Function],
[Symbol(handshake-timeout)]: 120000,
[Symbol(snicallback)]: undefined,
[Symbol(asyncId)]: 7 },
_server: null,
ssl:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
_requestCert: false,
_rejectUnauthorized: true,
timeout: 120000,
parser:
HTTPParser {
‘0’: [Function: parserOnHeaders],
‘1’: [Function: parserOnHeadersComplete],
‘2’: [Function: parserOnBody],
‘3’: [Function: parserOnMessageComplete],
‘4’: [Function: bound onParserExecute],
_headers: ,
_url: ‘’,
socket: [Circular],
incoming: [Circular],
outgoing: null,
maxHeaderPairs: 2000,
_consumed: true,
onIncoming: [Function: bound parserOnIncoming],
parsingHeadersStart: 0,
[Symbol(isReused)]: true },
on: [Function: socketOnWrap],
_paused: false,
_httpMessage:
ServerResponse {
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
output: ,
outputEncodings: ,
outputCallbacks: ,
outputSize: 0,
writable: true,
_last: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: true,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: ‘’,
finished: false,
_headerSent: false,
socket: [Circular],
connection: [Circular],
_header: null,
_onPendingData: [Function: bound updateOutgoingData],
_sent100: false,
_expect_continue: false,
req: [Circular],
locals: [Object: null prototype] {},
writeHead: [Function: writeHead],
end: [Function: end],
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object] },
[Symbol(res)]:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
[Symbol(asyncId)]: 382,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]:
Timeout {
_called: false,
_idleTimeout: 120000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 37810,
_onTimeout: [Function: bound ],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(unrefed)]: true,
[Symbol(asyncId)]: 391,
[Symbol(triggerId)]: 382 },
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(error-emitted)]: false },
connection:
TLSSocket {
_tlsOptions:
{ secureContext: [SecureContext],
isServer: true,
server: [Server],
requestCert: false,
rejectUnauthorized: true,
handshakeTimeout: 120000,
ALPNProtocols: <Buffer 08 68 74 74 70 2f 31 2e 31>,
SNICallback: [Function: SNICallback] },
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: ‘localhost’,
alpnProtocol: false,
authorized: false,
authorizationError: null,
encrypted: true,
_events:
[Object: null prototype] {
close: [Array],
end: [Array],
secure: [Function: onSocketSecure],
_tlsError: [Function: onSocketTLSError],
drain: [Array],
timeout: [Function: socketOnTimeout],
data: [Function: bound socketOnData],
error: [Function: socketOnError],
resume: [Function: onSocketResume],
pause: [Function: onSocketPause] },
_eventsCount: 10,
connecting: false,
_hadError: false,
_handle:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
_parent:
Socket {
connecting: false,
_hadError: false,
_handle: [TCP],
_parent: null,
_host: null,
_readableState: [ReadableState],
readable: true,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: ‘’,
server: [Server],
_server: [Server],
[Symbol(asyncId)]: 381,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 },
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: false,
emitClose: false,
destroyed: false,
defaultEncoding: ‘utf8’,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: ‘utf8’,
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: ‘’,
server:
Server {
_contexts: ,
requestCert: false,
rejectUnauthorized: true,
key:
<Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 45 6f 77 49 42 41 41 4b 43 41 51 45 41 77 32 … >,
cert:
<Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 67 7a 43 43 41 6d 75 67 41 77 49 42 41 67 49 4a 41 4c … >,
honorCipherOrder: true,
ALPNProtocols: <Buffer 08 68 74 74 70 2f 31 2e 31>,
sessionIdContext: ‘02bb4648221449d0b7d44bc3c35116fc’,
_sharedCreds: [SecureContext],
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
_connections: 1,
_handle: [TCP],
_usingWorkers: false,
_workers: ,
_unref: false,
allowHalfOpen: false,
pauseOnConnect: false,
httpAllowHalfOpen: false,
timeout: 120000,
keepAliveTimeout: 5000,
maxHeadersCount: null,
headersTimeout: 40000,
_connectionKey: ‘6::::5000’,
[Symbol(IncomingMessage)]: [Function],
[Symbol(ServerResponse)]: [Function],
[Symbol(handshake-timeout)]: 120000,
[Symbol(snicallback)]: undefined,
[Symbol(asyncId)]: 7 },
_server: null,
ssl:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
_requestCert: false,
_rejectUnauthorized: true,
timeout: 120000,
parser:
HTTPParser {
‘0’: [Function: parserOnHeaders],
‘1’: [Function: parserOnHeadersComplete],
‘2’: [Function: parserOnBody],
‘3’: [Function: parserOnMessageComplete],
‘4’: [Function: bound onParserExecute],
_headers: ,
_url: ‘’,
socket: [Circular],
incoming: [Circular],
outgoing: null,
maxHeaderPairs: 2000,
_consumed: true,
onIncoming: [Function: bound parserOnIncoming],
parsingHeadersStart: 0,
[Symbol(isReused)]: true },
on: [Function: socketOnWrap],
_paused: false,
_httpMessage:
ServerResponse {
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
output: ,
outputEncodings: ,
outputCallbacks: ,
outputSize: 0,
writable: true,
_last: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: true,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: ‘’,
finished: false,
_headerSent: false,
socket: [Circular],
connection: [Circular],
_header: null,
_onPendingData: [Function: bound updateOutgoingData],
_sent100: false,
_expect_continue: false,
req: [Circular],
locals: [Object: null prototype] {},
writeHead: [Function: writeHead],
end: [Function: end],
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object] },
[Symbol(res)]:
TLSWrap {
_parent: [TCP],
_parentWrap: [Socket],
_secureContext: [SecureContext],
reading: true,
onread: [Function: onStreamRead],
onhandshakestart: [Function: onhandshakestart],
onhandshakedone: [Function: onhandshakedone],
onclienthello: [Function: loadSession],
oncertcb: [Function: loadSNI],
onnewsession: [Function: onnewsession],
lastHandshakeTime: 37807,
handshakes: 0,
onerror: [Function: onerror],
_consumed: true,
[Symbol(owner)]: [Circular] },
[Symbol(asyncId)]: 382,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]:
Timeout {
_called: false,
_idleTimeout: 120000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 37810,
_onTimeout: [Function: bound ],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(unrefed)]: true,
[Symbol(asyncId)]: 391,
[Symbol(triggerId)]: 382 },
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(error-emitted)]: false },
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: ‘1.1’,
complete: true,
headers:
{ ‘content-type’: ‘application/json’,
authorization: ‘Basic Ok1ZX1NFQ1JFVA==’,
‘user-agent’: ‘PostmanRuntime/7.15.0’,
accept: ‘/’,
‘cache-control’: ‘no-cache’,
host: ‘localhost:5000’,
cookie:
‘connect.sid=s%3AOqopKhFh2TqIdyTLDvUSAzPI6CBtGNWt.Z41BKdVx123Hh%2FvX%2F0FbXtQMDBPsKcctK3lGnt3epQw; JSESSIONID=122DA32455D85AD72D5498AA70EE8ED4’,
‘accept-encoding’: ‘gzip, deflate’,
connection: ‘keep-alive’ },
rawHeaders:
[ ‘Content-Type’,
‘application/json’,
‘Authorization’,
‘Basic Ok1ZX1NFQ1JFVA==’,
‘User-Agent’,
‘PostmanRuntime/7.15.0’,
‘Accept’,
/’,
‘Cache-Control’,
‘no-cache’,
‘Host’,
‘localhost:5000’,
‘cookie’,
‘connect.sid=s%3AOqopKhFh2TqIdyTLDvUSAzPI6CBtGNWt.Z41BKdVx123Hh%2FvX%2F0FbXtQMDBPsKcctK3lGnt3epQw; JSESSIONID=122DA32455D85AD72D5498AA70EE8ED4’,
‘accept-encoding’,
‘gzip, deflate’,
‘Connection’,
‘keep-alive’ ],
trailers: {},
rawTrailers: ,
aborted: false,
upgrade: false,
url: ‘/api-sessions/didi’,
method: ‘GET’,
statusCode: null,
statusMessage: null
TypeError: session.fetch is not a function