asciinema / asciinema-player

Web player for terminal session recordings
https://docs.asciinema.org/manual/player/
Apache License 2.0
2.66k stars 264 forks source link

Let asciinema user's code get feeded data #220

Closed ludolpif closed 1 year ago

ludolpif commented 1 year ago

Hi, I try to use asciinema for doing fun things live on Twitch. I want a web page that makes sounds and play asciinema. I want to play some sound on asciinema rec --stdin events like [42.0, "i", "\r"]. I tried to use the player in html page as

<script src="asciinema-player.min.js"></script>
<script>var asciinemaPlayer = AsciinemaPlayer.create(...)</script>

I think I can't get data that has been just pushed to the vt because : 1) Core's feed() function is private, and not exposed/overridable from props returned by AsciinemaPlayer.create() 2) Core's feed() function triggers terminalUpdate event without passing it data (I get the default {} in e) :

  feed(data) {
    this.doFeed(data);
    this.dispatchEvent('terminalUpdate');
  }

Do you think this could be changed without breaking things or risking future breakages (on data internal format or so) ? Thanks for all the fish, it's very very great !

ludolpif commented 1 year ago

I've tried to add data arg to the event and rebuild/bundle myself locally, and I see now that is only "o" values. terminalUpdate events seems inappropriate to catch [42.0, "i", "\r"] because input and terminalUpdate aren't related that much. I've done a dirty usage of this for keypress background noise here : https://ludolpif.fr/waiting-screen/github.html I think now that an event about the next scheduled event "i" or "o" could be more desirable, specially for timing issues (play sound before and not after display update). May be it's too much and I should extend the asciinema module instead of asking for events. There may exist some related stuff for keypress displaying.

ku1ik commented 1 year ago

This is very legit use case. I've been thinking myself about adding some hook/event for input ("i") stream events so we can play some click-clack.wav or show keystroke overlay (#167).

Like you noticed, terminalUpdate is separate from input, and for a reason. I believe we need a proper treatment of "i" asciicast events at the core level, which could be used internally for keystroke overlay, as well as exposed through player.addEventListener for anyone who wants to annoy people with sound :)

ku1ik commented 1 year ago

Solution in #222 will hopefully allow you to achieve what you want to do.

ku1ik commented 1 year ago

I've released v3.3.0 which includes input events: https://github.com/asciinema/asciinema-player/releases/tag/v3.3.0

ludolpif commented 1 year ago

Solution #222 fully solve this for me ! I think I've found a typo in README, I've done a PR for that (#224).