javascript record getusermedia video and save the last 2 Minutes in a floating way

i want to record the video stream from getUserMedia ob my web page constantly, but only the last two minutes be available for a replay or an analasys.
I found some solutions where i can rocord for a certain time and cut i afterwards, but here i want to record for a lang time and only save if something special happened. For my scenario i dont have any way to solve it, so i cant provide my code.

Background is that i want to record the video when playing billard over a long time and be able to recap the last 2 minutes when there was something special or tr