Janus detaches already detached plugin on session destroy

1,198 views
Skip to first unread message

Alex Smirnov

unread,
Apr 26, 2017, 1:22:09 PM4/26/17
to meetecho-janus
Probably I'm missing something, but when videoroom's room got destroyed (for any reason) on the janus side user receives the following messages from janus:

{
   "janus": "event",
   "session_id": 2912462131376610,
   "sender": 829988245863921,
   "plugindata": {
      "plugin": "janus.plugin.videoroom",
      "data": {
         "videoroom": "destroyed",
         "room": 1870
      }
   }
}

{
   "janus": "detached",
   "session_id": 2912462131376610,
   "sender": 829988245863921
}

Now, when user tries to destroy the whole Janus session (using videroom's `ondetached` callback for it) it runs successfully:

{
  janus: "destroy",
  transaction: "7fBSAVW9fMWl"
}

{
   "janus": "success",
   "session_id": 2912462131376610,
   "transaction": "7fBSAVW9fMWl"
}

But inside of `destroySession` private method of janus*.js it gets a list of plugins and detaches all of them. And that's where the problem is. Janus still keeps already detached plugin data because it doesn't remove it on plugin's `detached` message. As a result, there's a 404 error when it tries to detach videoroom plugin:

{
   "janus": "error",
   "session_id": 2912462131376610,
   "transaction": "hMIA5xWfg6bt",
   "error": {
      "code": 458,
      "reason": "No such session 2912462131376610"
   }
}


If we'll look inside of `detached` message handler we'll see that in general it just calls plugin's `detach` method, which is `destroyHandle` private method of Janus:

} else if(json["janus"] === "detached") {
  // A plugin asked the core to detach one of our handles
  Janus.debug("Got a detached event on session " + sessionId);
  Janus.debug(json);
  var sender = json["sender"];
  if(sender === undefined || sender === null) {
    Janus.warn("Missing sender...");
    return;
  }
  var pluginHandle = pluginHandles[sender];
  if(pluginHandle === undefined || pluginHandle === null) {
    // Don't warn here because destroyHandle causes this situation.
    return;
  }
  pluginHandle.ondetached();
  pluginHandle.detach();
}


And inside of `destroyHandle` method we're detaching already detached plugin:

var request = { "janus": "detach", "transaction": Janus.randomString(12) };
// ... some code
Janus.ajax({
  type: 'POST',
  url: server + "/" + sessionId + "/" + handleId,
  async: asyncRequest, // Sometimes we need false here, or destroying in onbeforeunload won't work
  withCredentials: withCredentials,
  cache: false,
  contentType: "application/json",
  data: JSON.stringify(request),
  success: function(json) {
    Janus.log("Destroyed handle:");
    Janus.debug(json);
    if(json["janus"] !== "success") {
      Janus.error("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME
    }
    delete pluginHandles[handleId];
    callbacks.success();
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      Janus.error(textStatus + ": " + errorThrown); // FIXME
      // We cleanup anyway
      delete pluginHandles[handleId];
      callbacks.success();
    },
    dataType: "json"
});

And that's where 404 happens and plugin data finally gets removed in error callback.

So, the questions are:
1. Why Janus calls plugin's detach method when it receives a notification that plugin was already detached?
2. Is there any proper way of removing plugin's handle without calling detach and getting 404 when plugin was detached by the back-end, not the JS?

Lorenzo Miniero

unread,
Apr 26, 2017, 1:29:45 PM4/26/17
to meetecho-janus
When you do a destroySession, janus.js first iterates on all the handles to detach them, and then destroy the session. That's probably overkill and unneeded, as we can simply destroy the session and let Janus clean all the handles internally (which it does). Besides, it would make the shutdown process of the page much faster. I'll take note of this for future revisions.

L.

Anil Wadghule

unread,
Apr 26, 2017, 1:36:34 PM4/26/17
to Lorenzo Miniero, meetecho-janus
+1

Hope this gets fixed on priority and also similar possible calls which can be handled from Janus itself.

I had also faced similar issue.

Thanks,
Anil


--
You received this message because you are subscribed to the Google Groups "meetecho-janus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meetecho-janu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Alex Smirnov

unread,
Apr 26, 2017, 1:41:29 PM4/26/17
to meetecho-janus
Yes, that's I understand and I mentioned it, but the problem is, when plugin got detached on the Janus side, front end is calling detach to the already detached plugin, which causes 404.

Alex Smirnov

unread,
Apr 26, 2017, 2:04:19 PM4/26/17
to meetecho-janus
The temporary solution that works pretty good for me will be to replace:

pluginHandle.ondetached();
pluginHandle.detach();

with:
pluginHandle.ondetached();
delete pluginHandles[sender];

and add:
if (pluginHandles[handleId] === 'undefined') {
  return;
}
to the `destroyHandle` function before doing Janus.ajax call. We need to call destroyHandle for each plugin anyway, because it cleans up WebRTC, otherwise user will still have his camera ON and etc.



Reply all
Reply to author
Forward
0 new messages