I feel it is quite complex, involving a dedicated thread to maintain the websocket connection throughout the generation, but I could not make it work in a simpler way yet.
Hope it’ll help some of you. Also looking forward to hearing feedback from the community!
@arnoob Congratulations on solving the issue and your intention to help other developers by sharing the code. That’s very welcome. But the thing is, if you only post the link, it might get dead (e.g., you rename the GitHub repo). Please edit your answer above and add the code too.