Jibri Tip: send the recording folder name or a download link to the initiator

The following script send the recording folder name as a private message to the initiator (who starts the recording). It is possible to use it to send a download link too if the link is created based on this folder name.

/usr/share/jitsi-meet/body.html

<script>
  function sendSessionId() {
    try {
      const isRecorder = APP.store.getState()["features/base/config"].iAmRecorder;
      if (!isRecorder) return;

      const session = APP.store.getState()["features/recording"].sessionDatas[0];
      const session_id = session.id;
      const session_mode = session.mode;
      const initiator_id = session.initiator._id;
      if (session_mode !== "file") return;

      const msg = "The current recording folder is: " + session_id;
      APP.conference._room.sendMessage(msg, initiator_id);
    } catch(e) {
      setTimeout(function() {sendSessionId();}, 3000);
    }
  }

sendSessionId();
</script>
3 Likes

Hello Emrah,
I got the private message, that works. Thanks a lot.
But my machine always stores in /srv/recordings
How can I construct a link to download?
Best, Daniel

This depends on your system. Very simple example may be like the followings:

  • Install nginx in each jibri instances

  • Add an additional Nginx config for recording. TCP/5000 is reserved for recording in this example.

/etc/nginx/sites-enabled/jibri.conf

server {
  listen 5000;
  listen [::]:5000;

  root /var/www/html;
  index index.html;

  server_name _;

  location ~ /recordings/([a-zA-Z0-9]+) {
    root /srv;
    autoindex on;
  }

  location / {
    return 403;
  }
}
  • Change the message line in the script. JIBRI-INSTANCE-IP must be the real IP address or Jibri’s FQDN.
const msg = "To access to the recording folder: http://JIBRI-INSTANCE-IP:5000/recordings/" + session_id + "/";

Maybe I’m on a good way, but the server tells me, that the port is blocked, because it’s not for browsing in the web?

You can change the port. Use TCP/80 if it’s available in jibri server

To prevent access to the folder before the recording is complete:
(install nginx-extras for lua support)

server {
  listen 5000;
  listen [::]:5000;

  root /var/www/html;
  index index.html;

  server_name _;

  location ~ /recordings/([a-zA-Z0-9]+) {
    set $sid "$1";
    set $meta "/srv/recordings/${sid}/metadata.json";

    access_by_lua_block {
      if (os.execute("[ -f " .. ngx.var.meta .. " ]") == 0)
      then
        return;
      else
        return ngx.exit(ngx.HTTP_FORBIDDEN);
      end
    }

    root /srv;
    autoindex on;
  }

  location / {
    return 403;
  }
}

@xdaniel,

I just fixed a typo in the first nginx conf.

root /srv/recordings;

should be

root /srv;

When I change 10080 to 80 in above code it opens a new room instead?

If jibri and jitsi are on the same server then you cannot use a seperate Nginx config file for jibri. If this is the case, add the recording block as a first location block to the Jitsi config file

...
...
    gzip on;
    gzip_types text/plain text/css application/javascript application/json image/x-icon application/octet-stream application/wasm;                                                            
    gzip_vary on;
    gzip_proxied no-cache no-store private expired auth;
    gzip_min_length 512;

    location ~ /recordings/([a-zA-Z0-9]+) {
      root /srv;
      autoindex on;
    }

    location = /config.js {
...
...

And use https://your-jitsi-address/recordings/ in the script

1 Like

Emrah, you’re todays super hero :slight_smile: Thanks a lot, that worked!

One last question, is there a possibility to delete old recordings after 24/48 hours automatically?

It’s possible to delete old recording using cron. Add the following lines to

/etc/crontab

01 1    * * *   root    find /srv/recordings -mindepth 1 -type f -cmin +2880 -delete
03 1    * * *   root    find /srv/recordings -mindepth 1 -type d -empty -delete

Be carefull, this commands are very dangerous. They delete everything under /srv/recordings which are older than 2880 mins (2 days) at 01:01 (midnight)

3 Likes

Thank you Emrah, that’s really a great support!

1 Like

@emrah I use your cluster template which stores recordings in /usr/local/eb/recordings
is there a way to make a link from this folder or from another folder.

Is there any additioonal jibri server or are all jibri instances on the same server with JMS?

All are on same server.

  • first attach to eb-jitsi container
lxc-attach -n eb-jitsi
  • add the recordings block to nginx config as a first location block.

/etc/nginx/sites-available/YOUR-DOMAIN.conf

    ...
    gzip_min_length 512;

    location ~ /recordings/([a-zA-Z0-9]+) {
      root /usr/local/eb;
      autoindex on;
    }

    location = /config.js {
    ...
  • restart nginx
systemctl restart nginx.service
  • change /usr/share/jitsi-meet/body.html according to the first post. The msg line should be like the following
const msg = "To access to the recording folder: https://YOUR-DOMAIN/recordings/" + session_id + "/";

Edit 1: added the trailing slash

1 Like

I think it does not work with iframe api + jwt

It should work. Don’t you get the private message from jibri?

No, i do not get anything, i tried console.log at various steps but nothing is shown in the console also

Can you share your /usr/share/jitsi-meet/body.html after masked your host address?
And your Jitsi version…

I will be back 2 hour later