meetecho / janode

A Node.js adapter for the Janus WebRTC server
ISC License
98 stars 36 forks source link

listHandles only works on a session you created #18

Closed sampierson closed 1 year ago

sampierson commented 1 year ago

I'm building a tool to interrogate our Janus servers and build a graph of who is connected to whom. Part of this process is to list all sessions then list their handles.

I can do this with direct http calls, but I cannot do it with janode. If I try to list handles for a session I did not create, Connection._handleMessage complains that: "session xxxxxxxxxxxx not found for incoming message success". Here: https://github.com/meetecho/janode/blob/master/src/connection.js#L194

It seems that Connection keeps a cache of sessions so the right session can handle responses. But this is an admin function that takes a session parameter, and does not require one to establish a session first.

Here is some code to demonstrate the issue:

import Janode from 'janode';

const connection = await Janode.connect({
  is_admin: true,
  address: {
    url: "ws://127.0.0.1:7188/janus",
    apisecret: "janusoverlord"
  }
});

const r1 = await connection.listSessions();
console.log("Got sessions response", r1.sessions)
const r2 = await connection.listHandles(r1.sessions[0]);
console.log("Got handles response", handles);

connection.close();

I'm using a Janus with admin enabled on the websocket, and a videoroom call underway.

Here is the output:

2022-11-05T03:58:42.018Z - INFO : [janode.js] creating new connection
2022-11-05T03:58:42.021Z - INFO : [tmanager.js] [3340554914002515] creating new transaction manager (debug=false)
2022-11-05T03:58:42.021Z - INFO : [transport-ws.js] [3340554914002516] trying connection with ws://127.0.0.1:7188/janus
2022-11-05T03:58:42.032Z - INFO : [transport-ws.js] [3340554914002516] websocket connected
2022-11-05T03:58:42.032Z - INFO : [transport-ws.js] [3340554914002516] websocket ping task scheduled every 10 seconds
Got sessions response [ 5013312951136826, 353991153114233 ]
2022-11-05T03:58:42.035Z - INFO : [connection.js] [3340554914002516] requesting handle list
2022-11-05T03:58:42.036Z - WARN : [connection.js] [3340554914002516] session 5013312951136826 not found for incoming message success

I'm using janode version 1.6.4

atoppi commented 1 year ago

Thanks for reporting this @sampierson! Indeed janode keeps track of the existing sessions owned by a connection and heirs that abstraction from janus where sessions always live inside connections. I guess for admin connections this does not make much sense, since you can query the status of the server without actually owning the sessions. A possibile solution is to filter message handling for admin connections, I'll try to take a look in the next days.

Meanwhile you might want to check this new tool for janus that could accomplish the same task without janode.

sampierson commented 1 year ago

Thanks for responding @atoppi. I should have mentioned I have a workaround - I just send a list_handles directly to the Janus HTTP admin API.

atoppi commented 1 year ago

@sampierson this should be fixed now, thanks again for reporting!